This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Fix loading DLL from some ramdisk on Windows
ClosedPublic

Authored by alvinhochun on May 30 2022, 8:27 AM.

Details

Summary

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:

Diff Detail

Event Timeline

alvinhochun created this revision.May 30 2022, 8:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 30 2022, 8:27 AM
Herald added a subscriber: mstorsjo. · View Herald Transcript
alvinhochun requested review of this revision.May 30 2022, 8:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 30 2022, 8:27 AM

The implementation looks reasonable to me (I didn't investigate alternative ways of doing it but trust the reasoning that this is the most reasonable way of finding the pathname of an open handle with this filesystem driver).

lldb/source/Plugins/Process/Windows/Common/DebuggerThread.cpp
427

Do you need a check against NULL here in view_deleter?

alvinhochun added inline comments.May 31 2022, 5:21 AM
lldb/source/Plugins/Process/Windows/Common/DebuggerThread.cpp
427

I think unique_ptr guarantees the deleter won't be called if the pointer is null, so I didn't put a null check here.

mstorsjo added inline comments.May 31 2022, 5:26 AM
lldb/source/Plugins/Process/Windows/Common/DebuggerThread.cpp
427

Sounds plausible - I tried browsing the documentation for that but didn't find it spelled out explicitly (in the couple minutes I was browsing at least).

labath accepted this revision.Jun 13 2022, 11:58 PM
This revision is now accepted and ready to land.Jun 13 2022, 11:58 PM
This revision was automatically updated to reflect the committed changes.
mstorsjo added inline comments.Jun 15 2022, 7:20 AM
lldb/source/Plugins/Process/Windows/Common/DebuggerThread.cpp
445

FWIW, I had to change auto it = drive_strings.cbegin() here into const wchar_t *it = drive_strings.data() here, before pushing it, because with MSVC, wcslen(it) didn't automatically convert the iterator to a pointer.