[lldb] Fix loading DLL from some ramdisk on Windows
authorAlvin Wong <alvin@alvinhc.com>
Wed, 15 Jun 2022 13:07:36 +0000 (16:07 +0300)
committerMartin Storsjö <martin@martin.st>
Wed, 15 Jun 2022 14:02:33 +0000 (17:02 +0300)
commit87a2dba14ec82629317e13c2bce4c93b4d0a837d
treec44af8be6378ca875b8595d25ace63833e2dc6a7
parent462def25ec134d30aade4ffbf1ddc4185f2ec616
[lldb] Fix loading DLL from some ramdisk on Windows

The WinAPI `GetFinalPathNameByHandle` is used to retrieve the DLL file
name from the HANDLE provided to `LOAD_DLL_DEBUG_EVENT` in the debug
loop. When this API fails, lldb will simply ignore that module.

Certain ramdisk (e.g. ImDisk) does not work with this API, which means
it is impossible to use lldb to debug a process which loads DLLs located
on this type of ramdisk. In order to make this work, we need to use a
fallback routine which involves creating a file mapping, using
`GetMappedFileName` to get a device path, then substitutes the device
path with its drive letter.

References:
* https://developercommunity.visualstudio.com/t/cannot-debug-program-when-compiled-to-ram-drive/43004#T-N109926
* https://github.com/jrfonseca/drmingw/issues/65
* https://docs.microsoft.com/en-us/windows/win32/memory/obtaining-a-file-name-from-a-file-handle

Reviewed By: labath

Differential Revision: https://reviews.llvm.org/D126657
lldb/source/Plugins/Process/Windows/Common/DebuggerThread.cpp