This is an archive of the discontinued LLVM Phabricator instance.

[DWARF] Detect extraction errors in DWARFFormValue::extractValue
ClosedPublic

Authored by labath on Apr 2 2020, 7:35 AM.

Details

Summary

Although the function had a bool return value, it was always returning
true. Presumably this is because the main type of errors one can
encounter here is running off the end of the stream, and until very
recently, the DataExtractor class made it very difficult to detect that.

The situation has changed now, and we can easily detect errors here,
which this patch does.

Diff Detail

Event Timeline

labath created this revision.Apr 2 2020, 7:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 2 2020, 7:35 AM
Herald added a subscriber: hiraditya. · View Herald Transcript

Code change LGTM and the tidy-up of block handling in particular is a nice consequence.
I'm not comfortable enough with the test infrastructure used by this patch to click Accept, though.

Re the bool return value, there might have been actual false returns before I worked it over as part of the v5 implementation. But I don't remember. I'm moderately sure i wouldn't have introduced an always-true return value on my own.

This change adds a bunch more error handling, if I understand correctly (previously extractValue would've silently succeeded (it could only return true) where now it will fail) - I'd expect some negative test cases demonstrating the new failure modes/error cases being handled? Is there a reason they're not tested?

I guess this might be unit-testable by supplying too-short DataExtractors?

labath added a comment.Apr 6 2020, 6:15 AM

I guess this might be unit-testable by supplying too-short DataExtractors?

That is what the code DWARFFormValueTest is doing. Maybe it's somewhat over-engineered (I would have just written a sequence of EXPECTS, instead of instantiating a separate test for each form), but I tried to follow the style of the other tests in that file.

@dblaikie: Is that what you had in mind, or were you expecting to see some higher-level tests?

dblaikie accepted this revision.Apr 6 2020, 11:10 AM

I guess this might be unit-testable by supplying too-short DataExtractors?

That is what the code DWARFFormValueTest is doing. Maybe it's somewhat over-engineered (I would have just written a sequence of EXPECTS, instead of instantiating a separate test for each form), but I tried to follow the style of the other tests in that file.

@dblaikie: Is that what you had in mind, or were you expecting to see some higher-level tests?

Nah, that looks good to me - I think I was probably just going change blind with all the reviews.

This revision is now accepted and ready to land.Apr 6 2020, 11:10 AM
This revision was automatically updated to reflect the committed changes.