From 144e4c5a32007bb2fe7b18930dcc4d806ef4f92f Mon Sep 17 00:00:00 2001 From: George Rimar Date: Fri, 27 Oct 2017 10:42:04 +0000 Subject: [llvm-dwarfdump] - Teach verifier to report broken DWARF expressions. Patch improves next things: * Fixes assert/crash in getOpDesc when giving it a invalid expression op code. * DWARFExpression::print() called DWARFExpression::Operation::getEndOffset() which returned and used uninitialized field EndOffset. Patch fixes that. * Teaches verifier to verify DW_AT_location and error out on broken expressions. Differential revision: https://reviews.llvm.org/D39294 llvm-svn: 316756 --- llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp') diff --git a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp index 3417fee14c0..16058e461f4 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp @@ -104,7 +104,9 @@ static DescVector getDescriptions() { static DWARFExpression::Operation::Description getOpDesc(unsigned OpCode) { // FIXME: Make this constexpr once all compilers are smart enough to do it. static DescVector Descriptions = getDescriptions(); - assert(OpCode < Descriptions.size()); + // Handle possible corrupted or unsupported operation. + if (OpCode >= Descriptions.size()) + return {}; return Descriptions[OpCode]; } @@ -117,8 +119,10 @@ bool DWARFExpression::Operation::extract(DataExtractor Data, uint16_t Version, Opcode = Data.getU8(&Offset); Desc = getOpDesc(Opcode); - if (Desc.Version == Operation::DwarfNA) + if (Desc.Version == Operation::DwarfNA) { + EndOffset = Offset; return false; + } for (unsigned Operand = 0; Operand < 2; ++Operand) { unsigned Size = Desc.Op[Operand]; @@ -221,7 +225,7 @@ bool DWARFExpression::Operation::print(raw_ostream &OS, const MCRegisterInfo *RegInfo, bool isEH) { if (Error) { - OS << "decoding error."; + OS << ""; return false; } -- cgit v1.2.3