This is an archive of the discontinued LLVM Phabricator instance.

Remove the dependency between lib/DebugInfoDWARF and MC
ClosedPublic

Authored by rastogishubham on Sep 28 2022, 10:48 AM.

Details

Summary

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

Diff Detail

Event Timeline

Herald added a reviewer: MaskRay. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
rastogishubham requested review of this revision.Sep 28 2022, 10:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 28 2022, 10:48 AM

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
169

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
336

Would there any benefit of having DWARFContext own Callback instead of passing it through here everywhere?

llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
288–289

@clayborg Would this be a regression? It seems to not be tested...

aprantl added inline comments.Sep 28 2022, 11:09 AM
llvm/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h
169

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
336

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
457–459

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
457–459

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

rastogishubham marked 7 inline comments as done.Sep 29 2022, 4:57 PM
clayborg added inline comments.Sep 29 2022, 5:12 PM
llvm/include/llvm/DebugInfo/DIContext.h
205

Case should be "IsEH" according to llvm guidelines.

llvm/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h
167–168

Do we want to just pass in DIDumpOptions here as well?

225–226

ditto

306–307

ditto

351–352

ditto

llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
113

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
561–562

Use Expected<std::unique_ptr<MCRegisterInfo>> as the return value?

llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
289

Was this not needed?

aprantl accepted this revision.Sep 29 2022, 5:21 PM

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
205

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
1243

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
249

Wouldn't it be more efficient to say

OS << '  ' << RegName << format("%+" PRId64, Operands[OpNum]);

?

This revision is now accepted and ready to land.Sep 29 2022, 5:21 PM
rastogishubham marked 10 inline comments as done.
rastogishubham added inline comments.Oct 3 2022, 8:48 PM
llvm/tools/llvm-gsymutil/llvm-gsymutil.cpp
289

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

MaskRay added inline comments.Oct 3 2022, 11:44 PM
lldb/source/Expression/DWARFExpression.cpp
72

delete blank line

74

delete = nullptr

rastogishubham marked 2 inline comments as done.

Addressed @MaskRay comments.

Thanks for the review!

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

Removed nullptr and rebased

rastogishubham marked an inline comment as done.Oct 4 2022, 12:32 PM

@MaskRay if everything looks good can I consider this patch approved?

MaskRay accepted this revision.Oct 6 2022, 12:56 AM
This revision was landed with ongoing or failed builds.Oct 6 2022, 9:26 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptOct 6 2022, 9:26 AM

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

This revision was landed with ongoing or failed builds.Dec 14 2022, 6:17 PM

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
This revision was landed with ongoing or failed builds.Dec 15 2022, 6:23 PM