This is an archive of the discontinued LLVM Phabricator instance.

[llvm-dwarfdump] - Print an error message if section decompression failed.
ClosedPublic

Authored by grimar on May 4 2017, 7:47 AM.

Details

Summary

llvm-dwarfdump currently prints no message if decompression fails
for some reason. I noticed that during work on one of LLD patches
where LLD produced an broken output. It was a bit confusing to see
no output for section dumped and no any error message at all.

Patch adds error message for such cases.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.May 4 2017, 7:47 AM
aprantl accepted this revision.May 4 2017, 8:23 AM

Seems generally fine, couple of suggestions inline.

include/llvm/DebugInfo/DWARF/DWARFContext.h
313 ↗(On Diff #97827)

I would remove the "maybe" here.

lib/DebugInfo/DWARF/DWARFContext.cpp
948 ↗(On Diff #97827)

Is a section likely to be < 32 bytes?

This revision is now accepted and ready to land.May 4 2017, 8:23 AM
grimar added a comment.May 5 2017, 3:59 AM

Thanks for review Adrian ! My answers inline.

include/llvm/DebugInfo/DWARF/DWARFContext.h
313 ↗(On Diff #97827)

It can be a bit confusing as "decompress" looks like we always do that but this method do nothing if content is uncompressed.
Looking in other LLVM code, maybeDoSomething looks to be used naming for such purposes.
I can't say I like it though, but not sure what can be some different good naming for functionality like "decompess data only if it is compressed".

One way would be to rename it to "decompress" but wrap in check like:

 if (Decompressor::isCompressed(Sec)) {
     if (auto Err = decompress(Section, name, data)) {
        errs() << "error: failed to decompress '" + name + "', " +
                    toString(std::move(Err))
             << '\n';
      continue;
}

but that would expose Decompressor outside decompress() method and looks not better IMO.

lib/DebugInfo/DWARF/DWARFContext.cpp
948 ↗(On Diff #97827)

I don't think so. But that is a part of original code, I just moved this line and would not do any changes
in this patch for it.

32 probably can be a good size estimation for testcases we have around, though not sure it is worth to rely on them.

One more thing I just noticed. 'Out' is used for decompress() call which has next interface:

Error Decompressor::decompress(SmallString<32> &Out)

so changing it needs update of API. I think it is probably reasonable to make it be more generic like

Error Decompressor::decompress(SmallVectorImpl<char> &Out)
This revision was automatically updated to reflect the committed changes.
aprantl added inline comments.May 5 2017, 8:29 AM
include/llvm/DebugInfo/DWARF/DWARFContext.h
313 ↗(On Diff #97827)

Okay, thanks for the explanation it wasn't clear to me that it is also expected to be used with uncompressed input. Could you please add a doxygen comment to the function explaining that it decompresses the section or otherwise returns its contents verbatim?

lib/DebugInfo/DWARF/DWARFContext.cpp
948 ↗(On Diff #97827)

Yes, I agree. I would personally prefer a std::vector& here, because it is highly unlikely to ever use the "small" case and the small vector then just adds extra overhead.

grimar added inline comments.May 5 2017, 9:29 AM
include/llvm/DebugInfo/DWARF/DWARFContext.h
313 ↗(On Diff #97827)

r302249. Hope it looks ok :]

lib/DebugInfo/DWARF/DWARFContext.cpp
948 ↗(On Diff #97827)

I'll try to revisit this place and Decompressor API on next week.