Page MenuHomePhabricator

[llvm-dwarfdump] - Print section name and index when dumping .debug_info ranges
ClosedPublic

Authored by grimar on Aug 4 2017, 8:10 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.Aug 4 2017, 8:10 AM
aprantl added inline comments.Aug 4 2017, 10:26 AM
lib/DebugInfo/DWARF/DWARFDie.cpp
64 ↗(On Diff #109741)

I think I would prefer an empty string instead of "N/A".

dblaikie edited edge metadata.

Thanks a bunch for working on this - I reckon it's a great direction!

lib/DebugInfo/DWARF/DWARFContext.cpp
1044 ↗(On Diff #109741)

If/how do section indexes work in this codepath? Are they provided & printed but without names (because the section itself cannot be looked up)? Is there a way to support that? (probably not necessary, but consistency is nice where it's possible)

1194–1200 ↗(On Diff #109741)

Maybe invert this for an early return:

if (!Obj)
  return "";
return std::next(Obj->sections(), Index)->getName(Ret);
lib/DebugInfo/DWARF/DWARFDie.cpp
64–67 ↗(On Diff #109741)

Rather than creating a temporary string, maybe move this to after the format line, and print it directly to the stream with a format call as well?

test/DebugInfo/X86/dwarfdump-ranges-unrelocated.s
7–8 ↗(On Diff #109741)

It'd be nice to columnize the section number - but maybe that's too much work? (scanning through to find the longest section name, etc)

Also, similar amount of work: Do you think it'd be worth it/good to omit the section number if the section names are not ambiguous in this list? (or perhaps necessary to only do this if the name is not ambiguous in the whole file (so you on't look at the ranges for two functions and see them describing what appears to be the same section))

& what about omitting the name or putting it somewhere else (like at the start on a separate line) if every entry is in the same section? (which will be the case for all ranges except the compile_unit ranges, most likely)

Maybe that's all overkill - wouldn't mind getting Adrian's take on this, as he was driving a bunch of the dwarfdump improvements like this inline range dumping.

test/DebugInfo/dwarfdump-ranges.test
7–8 ↗(On Diff #109741)

Why does this print N/A in this test case?

grimar updated this revision to Diff 109985.Aug 7 2017, 7:20 AM
  • Addressed review comments.
lib/DebugInfo/DWARF/DWARFContext.cpp
1044 ↗(On Diff #109741)

Currently I think only 2 tools use DIContext::dump() call: llvm-dwarfdump and llvm-objdump,
both are creating DWARFObjInMemory using another codepatch, where ObjectFile is provided.
If it is not, then getSectionName() (introduced in this patch) would just return empty section name
for any index, because it checks Obj member and takes section index from it.

But that is not so simple to implement because currently we take SectionIndex from relocations and
this constructor assumes to take relocated data. That mean we have no section index to take from.

Fortunately tools do not need it. I would leave this place as is.

1194–1200 ↗(On Diff #109741)

Done.

lib/DebugInfo/DWARF/DWARFDie.cpp
64 ↗(On Diff #109741)

Done.

64–67 ↗(On Diff #109741)

Done.

test/DebugInfo/X86/dwarfdump-ranges-unrelocated.s
7–8 ↗(On Diff #109741)

I would not scan over all sections of file, because it looks too much. Scanning over all sections can be slow.
I would not omit something dependent on third conditions too, because it makes logic of output unclear for
people that are not familar with tool. ("Why it prints section index for "foo" and does not for "bar" ? BUUUG !")

Also I think often I am looking for section number in readelf/objdump/other tools, so I would not omit
it to be able to find it as fast as possible without manual eye-mapping name to index by myself.

Basing on above I think I like "omitting the name or putting it somewhere else (like at the start on a separate line) if every entry is in the same section" as it avoids printing the same name+index multiple times.
It also removes need to columnize anything probably and thus scan through to find longest index/section name, what should leave code simple.

What do you think about new version of output ? (I am wondering if we still want to columnize the section index, I am not sure).

test/DebugInfo/dwarfdump-ranges.test
7–8 ↗(On Diff #109741)

dwarfdump-test4.elf-x86-64 is not an object but DSO. It does not have .rel[a] sections
(targeted to debug sections I mean), and so all RelocAddrMaps are empty and we can not
take SectionIndex from relocation.

grimar updated this revision to Diff 110338.Aug 9 2017, 2:35 AM

Changed inplementation.

  • Do not print section/index when -brief=true
  • Do not print section index when name is unique.

I am not sure last one worth all the code complication it requires,
I would probably just pring section index always. Though
such approach has its own benefits, so I think I am fine with it.

grimar updated this revision to Diff 110339.Aug 9 2017, 2:41 AM
  • Minor update.
dblaikie accepted this revision.Aug 14 2017, 4:57 PM

Looks OK to me - though please refactor the section name/uniqueness gathering so it's done once (probably lazily) rather than every time a range is dumped.

lib/DebugInfo/DWARF/DWARFDie.cpp
60–71 ↗(On Diff #110339)

Presumably this shouldn't be computed for each range that's dumped?

Maybe a lazy accessor on DWARFContext that populates the list the first time it's called?

This revision is now accepted and ready to land.Aug 14 2017, 4:57 PM

Looks OK to me - though please refactor the section name/uniqueness gathering so it's done once (probably lazily) rather than every time a range is dumped.

Thanks, David ! I'll post refactoring patch soon.

This revision was automatically updated to reflect the committed changes.