This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Report errors for truncated debug line standard opcode
ClosedPublic

Authored by jhenderson on Jun 9 2020, 7:43 AM.

Details

Summary

Standard opcodes usually have ULEB128 arguments, so it is generally not possible to recover from such errors. This patch causes the parser to stop parsing the table in such situations.

Also don't emit the operands or add data to the table if there is an error reading these opcodes.

Diff Detail

Event Timeline

jhenderson created this revision.Jun 9 2020, 7:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 9 2020, 7:43 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
JDevlieghere added inline comments.Jun 9 2020, 10:20 AM
llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
940–946

A helper function might simplify this code a little bit:

template <typename T>
Optional<T> parseULEB128(DWARFDataExtractor &TableData,
                         DataExtractor::Cursor &Cursor) {
  T Value = TableData.getULEB128(Cursor);
  if (Cursor)
    return Value;
  return {};
}
if (auto Operand = parseULEB128<uint64_t>(TableData, Cursor)) {
  uint64_t AddrOffset =
      State.advanceAddr(*Operand, Opcode, OpcodeOffset);
  if (Verbose)
    *OS << " (" << AddrOffset << ")";
}

I was considering making the helper more generic so it could do both ULEB and SLEB but I don't think that's worth the extra complexity.

jhenderson marked an inline comment as done.

Address @JDevlieghere's suggestion.

Address @JDevlieghere's suggestion.

I think you might have re-uploaded the old patch?

Upload correct diff. Sorry @JDevlieghere!

JDevlieghere accepted this revision.Jun 11 2020, 11:09 AM

Upload correct diff. Sorry @JDevlieghere!

No worries! This LGTM.

llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
939–940

The lexical block is no longer necessary with the helper.

This revision is now accepted and ready to land.Jun 11 2020, 11:09 AM
This revision was automatically updated to reflect the committed changes.
jhenderson marked an inline comment as done.