This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Handle fixed-width DW_FORM_addrx variants in DWARFFormValue::getAsSectionedAddress()
ClosedPublic

Authored by benmxwl-arm on Feb 1 2023, 7:39 AM.

Details

Summary

Previously this would incorrectly return the raw offset into the .debug_addr section for the
DW_FORM_addrx1/2/3/4 forms rather than the actual address.

Note that this was handled correctly in the dump() function so this issue only occurs for users
of this API and not in tools such as llvm-dwarfdump.

Diff Detail

Event Timeline

benmxwl-arm created this revision.Feb 1 2023, 7:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 1 2023, 7:39 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
benmxwl-arm requested review of this revision.Feb 1 2023, 7:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 1 2023, 7:39 AM

Could this be refactored to share some support/implementation with the dumping code so that the code is better tested?

(is this really untestable through LLVM tools? If you put an assert(false) in this if block, does it not fire on any LLVM tests?)

Some tests call into this function, but I don't see any ones that are (directly) testing the indexed variants. I might have missed something though.
Maybe it'd be possible to write a new test case for DWARFDebugInfoTest.cpp?

Also, I think it would be easy enough to make dump() call this method to get the address.

benmxwl-arm updated this revision to Diff 494579.EditedFeb 3 2023, 3:16 AM

I've updated DWARFFormValue::dump() to make use of getAsSectionedAddress(), which slightly simplifies it.

I've now also added some unit tests for the DWARF5 indexed address forms to DWARFDebugInfoTest. Previously, this was only testing the non-indexed addresses in TestAllForms().

To do this I had to add support for the indexed addresses in the unittest DwarfGenerator, so please let me know if that looks correct.

(One thing to note and [I need to confirm] it seems like DW_FORM_addrx3 currently fails to parse, it looks like it's missed off the DWARFFormValue::skipValue() switch case)

dblaikie accepted this revision.Feb 3 2023, 10:56 AM

Looks great, thanks!

Yeah, if you wanted to address the addrx3 issue, I'm happy to review that. (any particular motivation for this work direction? Got other compilers producing interesting DWARF forms?)

This revision is now accepted and ready to land.Feb 3 2023, 10:56 AM

Thanks a lot! The motivation here is more just completeness, as I've recently been working on enabling some DWARF5 features in a debugger (looking at the spec and LLVM).

Thanks a lot! The motivation here is more just completeness, as I've recently been working on enabling some DWARF5 features in a debugger (looking at the spec and LLVM).

Cool - good to know :)

Do you need me to submit this for you, or can you submit it yourself?

Do you need me to submit this for you, or can you submit it yourself?

I can submit it myself thanks :)

nickdesaulniers added inline comments.
llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
63
/android0/llvm-project/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp:63:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
  default:
  ^
/android0/llvm-project/llvm/unittests/DebugInfo/DWARF/DwarfGenerator.cpp:63:3: note: insert 'break;' to avoid fall-through
  default:
  ^
  break;