This is an archive of the discontinued LLVM Phabricator instance.

dwarfgen: Add support for generating the debug_str_offsets section
ClosedPublic

Authored by labath on Jul 23 2018, 7:53 AM.

Details

Summary

The motivation for this is D49493, where we'd like to test details of
debug_str_offsets behavior which is difficult to trigger from a
traditional test.

This adds the plubming necessary for dwarfgen to generate this section.
The more interesting changes are:

  • I've moved emitStringOffsetsTableHeader function from DwarfFile to DwarfStringPool, so I can generate the section header more easily from the unit test.
  • added a new addAttribute overload taking an MCExpr*. This is used to generate the DW_AT_str_offsets_base, which links a compile unit to the offset table.

I've also added a basic test for reading and writing DW_form_strx forms.

Diff Detail

Repository
rL LLVM

Event Timeline

labath created this revision.Jul 23 2018, 7:53 AM

+ @clayborg who IIRC did the original generator

clayborg added inline comments.Jul 23 2018, 11:15 AM
unittests/DebugInfo/DWARF/DwarfGenerator.h
253 ↗(On Diff #156789)

Does this need to be initialized to nullptr somewhere?

dblaikie added inline comments.Jul 23 2018, 5:57 PM
lib/CodeGen/AsmPrinter/DwarfStringPool.h
40 ↗(On Diff #156789)

Is a forward decl of MCSymbol required up with MCSection/AsmPrinter then?

unittests/DebugInfo/DWARF/DwarfGenerator.cpp
473–476 ↗(On Diff #156789)

Why split this into two functions rather than having emit do the table header itself/internally?

labath marked an inline comment as done.Jul 24 2018, 2:45 AM
labath added inline comments.
lib/CodeGen/AsmPrinter/DwarfStringPool.h
40 ↗(On Diff #156789)

It wasn't necessary in my build, but it's a good idea nonetheless.

unittests/DebugInfo/DWARF/DwarfGenerator.cpp
473–476 ↗(On Diff #156789)

The functions were already split, I did not split them. I looked at how things would work if this was done by a single function, but things started to get a bit messy. The thing is we don't always need to emit the header -- we only do it (in the main generator) if DwarfDebug::useSegmentedStringOffsetsTable() is true. So I would have to pass that flag into emit in addition to the StringOffsetsStartSym symbol. That wouldn't look good as the emit function already has two arguments with default values. It might be possible to clean this up, but this would need a larger refactor.

unittests/DebugInfo/DWARF/DwarfGenerator.h
253 ↗(On Diff #156789)

It's initialized in Generator::init. The only way we can get a valid Generator object is if that functions succeeds, so this variable will always be initialized (and not null).

labath updated this revision to Diff 156988.Jul 24 2018, 2:46 AM
labath marked an inline comment as done.

Add MCSymbol forward decl

Looks good to me but I'll defer to Greg and Dave who had actual feedback.

clayborg added inline comments.Jul 24 2018, 7:23 AM
lib/CodeGen/AsmPrinter/DwarfStringPool.cpp
17 ↗(On Diff #156988)

Do we even need this include? We just pass the pointer on into another call so this is probably not needed.

labath marked an inline comment as done.Jul 24 2018, 7:30 AM
labath added inline comments.
lib/CodeGen/AsmPrinter/DwarfStringPool.cpp
17 ↗(On Diff #156988)

Good point. I've gotten a bit over-zealous with IWYU here. I'll remove it.

labath updated this revision to Diff 157034.Jul 24 2018, 7:34 AM
labath marked an inline comment as done.

Remove the extra #include

DwarfGenerator stuff looks good. I'll let someone else the final go ahead.

dblaikie accepted this revision.Jul 24 2018, 12:29 PM

Looks good

This revision is now accepted and ready to land.Jul 24 2018, 12:29 PM
This revision was automatically updated to reflect the committed changes.