lib/DebugInfoDWARF depends on MC and the dependency is only based on MCRegisterInfo. This patch is a refactoring of the DebugInfoDWARF code to make it so that lib/DebugInfoDWARF doesn't depend on MC
Details
Diff Detail
Event Timeline
I think this is a good change to make, I just have a couple of comments inline about the exact implementation.
lldb/source/Expression/DWARFExpression.cpp | ||
---|---|---|
73 | Since a StringRef can be empty(), it usually doesn't make a lot of sense to wrap it inside of Optional. I would just use a plain StringRef. | |
llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h | ||
124 | Callback isn't a very descriptive name: What about GetNameForDWARFReg or something like that? | |
llvm/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h | ||
167 | I am mildly surprised that = nullptr works. Should the default argument be a lambda or static function that returns llvm::None? | |
226 | This type appears a lot of times. What about declaring it with a using directive or making it a class object instead? | |
llvm/lib/DebugInfo/DWARF/CMakeLists.txt | ||
39 | Very nice! | |
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp | ||
338 | Would there any benefit of having DWARFContext own Callback instead of passing it through here everywhere? | |
llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp | ||
287 | @clayborg Would this be a regression? It seems to not be tested... |
llvm/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h | ||
---|---|---|
167 | Ah I see, there's a constructor for std::function that explicitly takes a nullptr and you are checking the operator bool() before calling it. |
lldb/source/Expression/DWARFExpression.cpp | ||
---|---|---|
73 | The reason I used an Optional is because in my mind the RegName for a register can be empty itself, maybe? The Optional tells me that there was no RegName or no LLVMRegNum found and helps me output any error messages if needed. | |
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp | ||
338 | Not sure what you mean, DWARFContext dows own Callback, but this is a static function which is not related to class DWARFContext, so Callback has to be passed as an argument |
Many of these changes involve modifying functions that are dumping some DWARF and the functions used to take a DIDumpOptions + MRI, but now take a DIDumpOptions + std::function<...>. We should add the callback into DIDumpOptions. I believe the "bool isEH" is also mainly needed for this function callback in order to make sure we get the right register number as sometimes DWARF register numbers differ from compiler register numbers found in .eh_frame.
So would adding more members to DIDumpOptions make these functions cleaner and easier to use?
llvm/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h | ||
---|---|---|
463–466 | I would suggest we add the std::function callback to the DIDumpOptions since any DWARF that needs to dump something could be able to use the mapping of register number to register name. If "bool isEH" is also only used for this, maybe we can add that to DIDumpOptions as well. |
llvm/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h | ||
---|---|---|
463–466 | I think this is a good suggestion and very do-able |
Added the std::function and isEH in struct DIDumpOptions instead of passing it around to every dump function as an argument
llvm/include/llvm/DebugInfo/DIContext.h | ||
---|---|---|
204 | Case should be "IsEH" according to llvm guidelines. | |
llvm/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h | ||
165–167 | Do we want to just pass in DIDumpOptions here as well? | |
225–227 | ditto | |
308–310 | ditto | |
355–357 | ditto | |
llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp | ||
118 | Seeing this is another reason we might want to pass in DIDumpOptions to this function. Then we wouldn't need to create a temp on here. | |
llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp | ||
559–560 | Use Expected<std::unique_ptr<MCRegisterInfo>> as the return value? | |
llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp | ||
288 | Was this not needed? |
I think this is looking good now. I have a few very minor comments, but otherwise this is good to go.
lldb/source/Expression/DWARFExpression.cpp | ||
---|---|---|
73 | I guess that's technically correct, but it would be weird. Then we would print an empty string instead of the DWARF register number, which means there would be no record of that there was a register? I would probably just treat an empty string like a nullptr. | |
llvm/include/llvm/DebugInfo/DIContext.h | ||
204 | Can you swap the order between the fields? The bools may have a smaller alignment than the std::function and so the whole struct could be smaller if they are grouped together. | |
llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp | ||
1256 | I think the suggestion to pass IsEH in DumpOpts was well-intentioned, but it's not so elegant that we need to update it here. I don;t feel strongly enough about it to be bothered by it though. | |
llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp | ||
248 | Wouldn't it be more efficient to say OS << ' ' << RegName << format("%+" PRId64, Operands[OpNum]); ? |
llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp | ||
---|---|---|
288 | It seems like this is not tested, and the DICtx that owns the registerinfo doesn't do anything with it, so I just removed it |
This patch is not rebased on the top of main branch so it fails to apply. For such a patch we probably want to check pre-commit tests https://buildkite.com/llvm-project/diff-checks/builds/129386
llvm/include/llvm/DebugInfo/DIContext.h | ||
---|---|---|
203 | also delete =nullptr here |
I was not able to land this patch earlier because of some bot failures and then I got busy with some other stuff, this is just an update of the patch with merge conflicts resolved
Fix the lldb test failures:
lldb-shell :: SymbolFile/DWARF/x86/DW_AT_loclists_base.s lldb-shell :: SymbolFile/DWARF/x86/debug_loc.s lldb-shell :: SymbolFile/DWARF/x86/debug_loc_and_loclists.s lldb-shell :: SymbolFile/DWARF/x86/debug_loclists-dwo.s lldb-shell :: SymbolFile/DWARF/x86/debug_loclists-dwp.s lldb-shell :: SymbolFile/DWARF/x86/dwp.s lldb-shell :: SymbolFile/DWARF/x86/unused-inlined-params.test lldb-shell :: SymbolFile/NativePDB/inline_sites.test lldb-shell :: SymbolFile/NativePDB/local-variables-registers.s lldb-shell :: SymbolFile/NativePDB/nested-blocks-same-address.s
delete blank line