This is an archive of the discontinued LLVM Phabricator instance.

[LLDB][Minidump] Merge executable module's architecture into target's architecture.
ClosedPublic

Authored by zequanwu on Nov 11 2022, 3:41 PM.

Details

Summary

This allows minidump process ABI to match the PE/COFF file ABI.

Diff Detail

Event Timeline

zequanwu created this revision.Nov 11 2022, 3:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 11 2022, 3:41 PM
zequanwu requested review of this revision.Nov 11 2022, 3:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 11 2022, 3:41 PM

This dual environment thing is tricky.. MSVC is probably a better default, but it would still mean that the same bugs will appear if the situation is reversed (we assume MSVC environ, but the binary actually uses GNU). Have you looked at how this interacts with https://reviews.llvm.org/D127048 (and the setting introduced there) and whether you can achieve the same effect by changing that setting?

zequanwu abandoned this revision.Nov 15 2022, 11:12 AM

This dual environment thing is tricky.. MSVC is probably a better default, but it would still mean that the same bugs will appear if the situation is reversed (we assume MSVC environ, but the binary actually uses GNU). Have you looked at how this interacts with https://reviews.llvm.org/D127048 (and the setting introduced there) and whether you can achieve the same effect by changing that setting?

Thanks, I didn't realize the existence of this setting.

zequanwu reclaimed this revision.Nov 15 2022, 11:15 AM

Oh, they are not the same. I will work on a similar setting for minidump.

zequanwu updated this revision to Diff 475628.Nov 15 2022, 4:43 PM

Add settings set plugin.process.minidump.abi msvc/gnu to override minidump abi triple.

Herald added a project: Restricted Project. · View Herald TranscriptNov 15 2022, 4:43 PM

Adding a new setting isn't exactly what I had in mind. I was actually hoping that it would be enough to fiddle with that setting and leave the minidump environment blank (because we have code to fill in the missing pieces of a target ArchSpec from other sources.

If that doesn't work then (besides knowing why), I'd like us try some kind of a single-setting solution, as I don't think it makes sense to have two different settings like this (happy to hear counterarguments to that). I'd consider either moving that environment setting to some place more generic (so it can be accessed from both plugins) or just having the minidump plugin fetch the setting from inside ObjectFilePECOFF (I'd say that a process->object dependency is kinda OK, and we already have ProcessMachCore depending on ObjectFileMachO).

lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
392

Is "overrides" the correct word here? Are there any circumstances in which we are able to determine the environment from the minidump file? Because if it is, then I would expect this to be the other way around (that the environment from a specific file overrides the generic catch-all setting)...

If that doesn't work then (besides knowing why), I'd like us try some kind of a single-setting solution, as I don't think it makes sense to have two different settings like this (happy to hear counterarguments to that)

Overall, the ideal is if the user usually needs to twiddle one single setting. For a majority of cases, picking the default format (like is done for the objectfile setting, and afaik this one does too even though I didn't quite clearly see the codepath for it) will be what you'd want: If you're working with mingw tools, debugging with a mingw built lldb, then your app that you're debugging also probably uses mingw ABIs. But it's clearly not implausible to want to debug executables from the other ecosystem, so being able to change it with a single setting is good too.

And for the objectfile setting, it's possible to set it even on a per-DLL basis. This may sound contrieved, but it's actually totally reasonable. While the C++ ABIs are incompatible, such DLLs can interoperate over C APIs - this is not an uncommon scenario. Plus, every mingw executable links against msvcrt.dll or ucrtbase.dll (provided by the system) which use the MSVC C++ ABIs internally (if you use the versions of them with debug info).

So the ability to set it per DLL for the objectfile part is totally warranted. How that fits in towards minidump reading, I don't really know though (since the whole minidump contains stuff for the whole process). In which cases does the C++ ABI form matter for the minidump btw - since the actual interpretation of things still would be based on per-DLL debug info (either as DWARF or PDB)?

zequanwu added a comment.EditedNov 16 2022, 2:34 PM

If that doesn't work then (besides knowing why), I'd like us try some kind of a single-setting solution, as I don't think it makes sense to have two different settings like this (happy to hear counterarguments to that)

Overall, the ideal is if the user usually needs to twiddle one single setting. For a majority of cases, picking the default format (like is done for the objectfile setting, and afaik this one does too even though I didn't quite clearly see the codepath for it) will be what you'd want: If you're working with mingw tools, debugging with a mingw built lldb, then your app that you're debugging also probably uses mingw ABIs. But it's clearly not implausible to want to debug executables from the other ecosystem, so being able to change it with a single setting is good too.

And for the objectfile setting, it's possible to set it even on a per-DLL basis. This may sound contrieved, but it's actually totally reasonable. While the C++ ABIs are incompatible, such DLLs can interoperate over C APIs - this is not an uncommon scenario. Plus, every mingw executable links against msvcrt.dll or ucrtbase.dll (provided by the system) which use the MSVC C++ ABIs internally (if you use the versions of them with debug info).

So the ability to set it per DLL for the objectfile part is totally warranted. How that fits in towards minidump reading, I don't really know though (since the whole minidump contains stuff for the whole process). In which cases does the C++ ABI form matter for the minidump btw - since the actual interpretation of things still would be based on per-DLL debug info (either as DWARF or PDB)?

lldb creates AST for user input expression which uses the abi from minidump process. That AST's class layout info is imported from another AST created from debug info that uses the abi specified in debug info. The current situation is that minidump process uses itanium ABI (because it's not specified in minidump, falls back to use itanium), but the debug info uses msvc ABI. The inconsistent causes crash when lowering class.

It looks like it's impossible to make it works with DLLs that have different ABIs, no matter which ABI we set for minidump. Unless we change how clang interacts with external layout: https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/RecordLayoutBuilder.cpp#L1357. Maybe change it so that if using external layout failed due to mismatched ABI, try again with another ABI https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/RecordLayoutBuilder.cpp#L3302?

Or maybe for now, we should just choose the default ABI for windows minidump to be MSVC to at least to prevent that crash happening in our case. That's what I did in first diff.

lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp
392

Yeah, the word is not correct. It should be "sets".
I think minidump file just doesn't have that environment info: https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/BinaryFormat/Minidump.h#L161-L179. lldb sets the environment based on platform for android: https://github.com/llvm/llvm-project/blob/main/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp#L195.

I think the module spec of the modules should reflect the value of the plugin.object-file.pe-coff.abi setting. Can ProcessMinidump take the module spec of the executable module to use its target environment?

Mixing MSVC and MinGW DLLs is a tricky case so I will not be surprised if something doesn't work correctly. It would be nice to have it working but that would be outside the scope of this review. (I don't yet have a use case for this but I am getting close with some COM / WinRT experiments.)

I think the module spec of the modules should reflect the value of the plugin.object-file.pe-coff.abi setting. Can ProcessMinidump take the module spec of the executable module to use its target environment?

That's kinda what Target::MergeArchitecture is for.

Mixing MSVC and MinGW DLLs is a tricky case so I will not be surprised if something doesn't work correctly. It would be nice to have it working but that would be outside the scope of this review. (I don't yet have a use case for this but I am getting close with some COM / WinRT experiments.)

Sounds fun. :)

zequanwu updated this revision to Diff 476221.EditedNov 17 2022, 1:34 PM

Use plugin.object-file.pe-coff.abi as minidump process abi when OS is Windows.

zequanwu retitled this revision from [LLDB][Minidump] Set abi environment for windows. to [LLDB][Minidump] Use plugin.object-file.pe-coff.abi as minidump process abi when OS is Windows..Nov 17 2022, 1:41 PM
zequanwu edited the summary of this revision. (Show Details)

Did you look at the Target::MergeArchitecture function? Is there a suitable place where we could insert a call to that function so that the executable object file environment is automatically propagated to the target?

zequanwu updated this revision to Diff 477008.Nov 21 2022, 2:43 PM
zequanwu edited the summary of this revision. (Show Details)

Merge executable module's architecture into target's architecture.

zequanwu added inline comments.Nov 21 2022, 2:45 PM
lldb/test/Shell/SymbolFile/Breakpad/unwind-via-stack-win-no-memory-info.yaml
74

Processor Arch is X86, so this should be i386.

labath accepted this revision.Nov 22 2022, 5:33 AM

Cool, great.

This revision is now accepted and ready to land.Nov 22 2022, 5:33 AM
zequanwu retitled this revision from [LLDB][Minidump] Use plugin.object-file.pe-coff.abi as minidump process abi when OS is Windows. to [LLDB][Minidump] Merge executable module's architecture into target's architecture..Nov 22 2022, 10:21 AM