diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp @@ -781,10 +781,13 @@ // Tolerate zero-length; assume length is correct and soldier on. if (Len == 0) { - if (Verbose) + if (Cursor && Verbose) *OS << "Badly formed extended line op (length 0)\n"; - if (!Cursor) + if (!Cursor) { + if (Verbose) + *OS << "\n"; RecoverableErrorHandler(Cursor.takeError()); + } *OffsetPtr = Cursor.tell(); continue; } @@ -802,11 +805,11 @@ // address is that of the byte after the last target machine instruction // of the sequence. State.Row.EndSequence = true; - if (Verbose) { + if (Cursor && Verbose) { *OS << "\n"; OS->indent(12); } - if (OS) + if (Cursor && OS) State.Row.dump(*OS); State.appendRowToMatrix(); State.resetRowAndSequence(); @@ -855,7 +858,7 @@ TableData.setAddressSize(ExtractorAddressSize); } - if (Verbose) + if (Cursor && Verbose) *OS << format(" (0x%16.16" PRIx64 ")", State.Row.Address.Address); } break; @@ -890,7 +893,7 @@ FileEntry.ModTime = TableData.getULEB128(Cursor); FileEntry.Length = TableData.getULEB128(Cursor); Prologue.FileNames.push_back(FileEntry); - if (Verbose) + if (Cursor && Verbose) *OS << " (" << Name << ", dir=" << FileEntry.DirIdx << ", mod_time=" << format("(0x%16.16" PRIx64 ")", FileEntry.ModTime) << ", length=" << FileEntry.Length << ")"; @@ -899,12 +902,12 @@ case DW_LNE_set_discriminator: State.Row.Discriminator = TableData.getULEB128(Cursor); - if (Verbose) + if (Cursor && Verbose) *OS << " (" << State.Row.Discriminator << ")"; break; default: - if (Verbose) + if (Cursor && Verbose) *OS << format("Unrecognized extended op 0x%02.02" PRIx8, SubOpcode) << format(" length %" PRIx64, Len); // Len doesn't include the zero opcode byte or the length itself, but diff --git a/llvm/test/tools/llvm-dwarfdump/X86/debug_line_invalid.test b/llvm/test/tools/llvm-dwarfdump/X86/debug_line_invalid.test --- a/llvm/test/tools/llvm-dwarfdump/X86/debug_line_invalid.test +++ b/llvm/test/tools/llvm-dwarfdump/X86/debug_line_invalid.test @@ -283,7 +283,7 @@ # VERBOSE-NEXT: DW_LNE_set_address (0x00000000feedfeed) # VERBOSE-NEXT: DW_LNS_copy # NONFATAL-NEXT: 0x00000000feedfeed -# VERBOSE-NEXT: DW_LNE_set_address (0x0000000000000000) +# VERBOSE-NEXT: DW_LNE_set_address{{$}} # MORE-ERR-NEXT: warning: unexpected end of data at offset 0x419 while reading [0x412, 0x41a) # MORE-ERR-NEXT: warning: last sequence in debug line table at offset 0x000003c9 is not terminated diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp --- a/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp +++ b/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp @@ -1470,18 +1470,17 @@ TruncatedExtendedOpcodeParams, TruncatedExtendedOpcodeFixture, Values( std::make_tuple(1, 1, DW_LNE_end_sequence, ValueAndLengths(), - "Badly formed extended line op (length 0)", + "", "unable to decode LEB128 at offset 0x00000030: " "malformed uleb128, extends past end"), std::make_tuple( 2, 9, DW_LNE_set_address, - ValueAndLengths{{0x12345678, LineTable::Quad}}, - "Unrecognized extended op 0x00 length 9", + ValueAndLengths{{0x12345678, LineTable::Quad}}, "", "unexpected end of data at offset 0x31 while reading [0x31, 0x32)"), std::make_tuple( 3, 9, DW_LNE_set_address, ValueAndLengths{{0x12345678, LineTable::Quad}}, - "DW_LNE_set_address (0x0000000000000000)", + "DW_LNE_set_address", "unexpected end of data at offset 0x32 while reading [0x32, 0x3a)"), std::make_tuple(3, 5, DW_LNE_define_file, ValueAndLengths{{'a', LineTable::Byte}, @@ -1489,8 +1488,7 @@ {1, LineTable::ULEB}, {1, LineTable::ULEB}, {1, LineTable::ULEB}}, - "DW_LNE_define_file (, dir=0, " - "mod_time=(0x0000000000000000), length=0)", + "DW_LNE_define_file", "no null terminated string at offset 0x32"), std::make_tuple(5, 5, DW_LNE_define_file, ValueAndLengths{{'a', LineTable::Byte}, @@ -1498,8 +1496,7 @@ {1, LineTable::ULEB}, {1, LineTable::ULEB}, {1, LineTable::ULEB}}, - "DW_LNE_define_file (a, dir=0, " - "mod_time=(0x0000000000000000), length=0)", + "DW_LNE_define_file", "unable to decode LEB128 at offset 0x00000034: " "malformed uleb128, extends past end"), std::make_tuple(6, 5, DW_LNE_define_file, @@ -1508,8 +1505,7 @@ {1, LineTable::ULEB}, {1, LineTable::ULEB}, {1, LineTable::ULEB}}, - "DW_LNE_define_file (a, dir=1, " - "mod_time=(0x0000000000000000), length=0)", + "DW_LNE_define_file", "unable to decode LEB128 at offset 0x00000035: " "malformed uleb128, extends past end"), std::make_tuple(7, 5, DW_LNE_define_file, @@ -1518,13 +1514,12 @@ {1, LineTable::ULEB}, {1, LineTable::ULEB}, {1, LineTable::ULEB}}, - "DW_LNE_define_file (a, dir=1, " - "mod_time=(0x0000000000000001), length=0)", + "DW_LNE_define_file", "unable to decode LEB128 at offset 0x00000036: " "malformed uleb128, extends past end"), std::make_tuple(3, 2, DW_LNE_set_discriminator, ValueAndLengths{{1, LineTable::ULEB}}, - "DW_LNE_set_discriminator (0)", + "DW_LNE_set_discriminator", "unable to decode LEB128 at offset 0x00000032: " "malformed uleb128, extends past end")), );