This is an archive of the discontinued LLVM Phabricator instance.

[DWARF] Return Error from DWARFDebugArangeSet::extract().
ClosedPublic

Authored by ikudrin on Dec 25 2019, 4:10 AM.

Details

Summary

This helps to detect and report parsing errors better. The patch follows the ideas of LLDB's patches D59370 and D59381.

It adds tests for valid and some invalid cases. More checks and tests to come. Note that the patch fixes validation of the Length field because the value does not include the field itself.

Diff Detail

Event Timeline

ikudrin created this revision.Dec 25 2019, 4:10 AM
dblaikie accepted this revision.Dec 25 2019, 10:24 AM
dblaikie added inline comments.
llvm/lib/DebugInfo/DWARF/DWARFDebugArangeSet.cpp
85

In a separate patch, might be good to add error handling to stop when the Header length is reached, rather than when the section end is reached.

91

I'd probably write these ays "x == 0" rather than "!x"

91–92

Potentially another error case could be added here (in another patch) in the case where the list is terminated earlier than the Length specified in the header.

96

Looks like the old code fails if the range list is empty - and maybe the new code deosn't fail in that case? Worth adding a test case? (it actually seems reasonable to me to support it - you could imagine a CU with only type information in it & so no covered addresses, and having an arange entry describing that so the consumer didn't have to go discover it through parsing the CU, etc)

This revision is now accepted and ready to land.Dec 25 2019, 10:24 AM
ikudrin updated this revision to Diff 235420.Dec 27 2019, 8:14 AM
ikudrin edited the summary of this revision. (Show Details)
  • "!x" -> "x == 0";
  • Improved error messages wordings;
  • Added more tests;
  • Fixed checking the value of the Length field.
ikudrin edited the summary of this revision. (Show Details)

Thanks for the suggestions, @dblaikie! I've added D71931 and D71932 with corresponding patches.

dblaikie added inline comments.Dec 27 2019, 11:18 AM
llvm/lib/DebugInfo/DWARF/DWARFDebugArangeSet.cpp
60–63

Could this be phrased more specifically - "length exceeds section size" or something like that?

64–68

Could this be more specific about what's invalid about the address size ("unsupported address size: 5 (4 and 8 supported)" or the like?)

clayborg added inline comments.Jan 9 2020, 3:19 PM
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
463

does "toString()" consume the error?

llvm/lib/DebugInfo/DWARF/DWARFDebugArangeSet.cpp
34

return error instead of crashing the program

llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp
23

return llvm::Error here?

29–34

return an error if Set.extract fails? Seems weird to add error handling to only convert it to bool and ignore the error?

llvm/tools/obj2yaml/dwarf2yaml.cpp
65–68

Dump the error if Set.extract() fails?

ikudrin updated this revision to Diff 237651.Jan 13 2020, 6:20 AM
  • Update wordings.
  • Replace most of the lit tests to check error cases with gtest-based ones.
  • Do not silently absorb the error messages.
  • Update existing tests and add new ones to reflect the changes.
ikudrin marked 13 inline comments as done.Jan 13 2020, 6:38 AM
ikudrin added inline comments.
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
463

Yes. It uses handleAllErrors() internally.

llvm/lib/DebugInfo/DWARF/DWARFDebugArangeSet.cpp
34

This just checks for the precondition. Callers are responsible to call the method with valid arguments. Therefore, if this triggers, it should be considered as an internal error and fixed.

llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp
23

As this is just a private helper method for DWARFDebugAranges::generate(), I opted to print the errors here.

llvm/tools/obj2yaml/dwarf2yaml.cpp
65–68

Done, but it pulled a lot of changes. Maybe it worth to move all them into a separate patch.

lgtm with Error being returned everywhere now.

llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
461–462

do we want {} on this while now?

ikudrin updated this revision to Diff 237913.Jan 14 2020, 3:30 AM
ikudrin marked 2 inline comments as done.
  • Used curly brackets for the while loop in dumping .debug_aranges in DWARFContext::dump().
  • Removed else branch after break.

Thanks, @clayborg!

This revision was automatically updated to reflect the committed changes.
ikudrin marked an inline comment as done.
dblaikie added inline comments.Jan 24 2020, 11:59 PM
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
457–460

Might this eventually want to go in the direction of having fallible errors and errors that can continue, like some of @jhenderson 's work? Should we come up with a consistent strategy for this sort of thing as it seems we've developed a few different error handling parsing schemes at this point.

jhenderson added inline comments.Jan 27 2020, 1:34 AM
llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
457–460

Yeah, we should a) be consistent (though I don't mind specifically what we standardise on) and b) avoid printing such low-level errors in a library, as it makes things hard for clients. See my lightning talk on the subject that was inspired by my debug line error handling work some time ago: https://www.youtube.com/watch?v=YSEY4pg1YB0