This is an archive of the discontinued LLVM Phabricator instance.

[llvm-dwarfdump] Warn user when it encounters no null terminated strings.
ClosedPublic

Authored by Higuoxing on Sep 1 2020, 7:48 PM.

Details

Summary

When llvm-dwarfdump encounters no null terminated strings, we should
warn user about it rather than ignore it and print nothing.

Before this patch, when llvm-dwarfdump dumps a .debug_str section whose
content is "abc", it prints:

.debug_str contents:

After this patch:

.debug_str contents:
warning: no null terminated string at offset 0x0

Diff Detail

Event Timeline

Higuoxing created this revision.Sep 1 2020, 7:48 PM
Higuoxing requested review of this revision.Sep 1 2020, 7:48 PM
MaskRay added inline comments.Sep 1 2020, 9:20 PM
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
533

operator bool sets the checked state if Error is in a success state.

So you can just run: (void)!Err

If you want to ensure an Error in a success state is also checked (not in this case), ErrorAsOutParameter ...(&Err)

Higuoxing updated this revision to Diff 289352.Sep 1 2020, 10:16 PM
Higuoxing marked an inline comment as done.

Address comment.

llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
533

Thanks. Actually I'm not sure about it. I didn't find anything about creating a checked error in LLVM Programmer's manual.

I usually do it using

Error Err = Error::success();
cantFail(std::move(Err));

Can we record it in programmer's manual?

jhenderson added inline comments.Sep 2 2020, 1:24 AM
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
533

Do you actually need this here? It seems to me a cantFail(std::move(Err)); after the loop might be more appropriate. The getCStr function handles the Error that gets passed in, so that it doesn't need checking beforehand.

llvm/test/tools/llvm-dwarfdump/debug-str.yaml
48

I think this reads better.

Higuoxing added inline comments.Sep 2 2020, 1:54 AM
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
533

I'm not sure whether to put it after the loop or put it after Error::success() but I'm sure we need it. If we remove the cantFail(std::move(Err)) or (void)!Err, it will crash due to an unhandled error when parsing the following object file.

...
Sections:
  - Name: .debug_str
    Type: SHT_PROGBITS
    Size: 0
Higuoxing updated this revision to Diff 289386.Sep 2 2020, 3:29 AM
Higuoxing marked an inline comment as done.

Address comment.

llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
533

Sorry, I missed your point. We can remove the cantFail(std::move(Err)).

jhenderson accepted this revision.Sep 2 2020, 3:59 AM

LGTM!

llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
533

Actually that wasn't my point, but the solution is much better this way, thanks!

This revision is now accepted and ready to land.Sep 2 2020, 3:59 AM
MaskRay accepted this revision.Sep 2 2020, 4:54 PM

LGTM.

This revision was landed with ongoing or failed builds.Sep 2 2020, 5:50 PM
This revision was automatically updated to reflect the committed changes.