This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Use Cursor to detect errors in debug line prologue parser
ClosedPublic

Authored by jhenderson on Jul 2 2020, 6:19 AM.

Details

Summary

Previously, the debug line parser would keep attempting to read data even if it had run out of data to read. This meant errors in parsing would often end up being reported as something else, such as an unknown version or malformed directory/filename table. This patch fixes the issues by using the Cursor API to capture errors.

Diff Detail

Event Timeline

jhenderson created this revision.Jul 2 2020, 6:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 2 2020, 6:19 AM
labath accepted this revision.Jul 2 2020, 6:43 AM
labath added inline comments.
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
404–407

Maybe DebugLineData.getU8(Cursor, StandardOpcodeLengths.begin(), OpcodeBase-1)

This revision is now accepted and ready to land.Jul 2 2020, 6:43 AM
jhenderson marked an inline comment as done.Jul 2 2020, 8:01 AM
jhenderson added inline comments.
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
404–407

That didn't quite work. I think the signature requires either a SmallVector or a pre-sized vector and .data(). I'll make some changes for this in a separate change.

This revision was automatically updated to reflect the committed changes.
jhenderson marked an inline comment as done.Jul 3 2020, 5:56 AM
jhenderson added inline comments.
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
404–407

I looked at this again, and it is trivial to change the function signature of the getU8 function to allow any vector type, via templating it, but having done that, I realised there was a behaviour change, which I don't believe to be beneficial, so I haven't adopted this suggestion.

Without using this function, those operand lengths that could be read were printed. With the function, if the whole array can't be read, none of it is. I think the old behaviour is more useful, since it allows users to read a slightly broken prologue to see what could be salvaged from it.

labath added inline comments.Jul 3 2020, 6:27 AM
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
404–407

Sounds good.