[llvm] 2f81550 - [DebugInfo] Fix printing of DW_LNS_set_isa

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 11 05:39:34 PST 2019


Author: James Henderson
Date: 2019-12-11T13:38:41Z
New Revision: 2f8155023ad49ca88151d954c1a6d6069b072ca3

URL: https://github.com/llvm/llvm-project/commit/2f8155023ad49ca88151d954c1a6d6069b072ca3
DIFF: https://github.com/llvm/llvm-project/commit/2f8155023ad49ca88151d954c1a6d6069b072ca3.diff

LOG: [DebugInfo] Fix printing of DW_LNS_set_isa

The Isa register is a uint8_t, but at least on Windows this is
internally an unsigned char, which meant that prior to this patch it got
formatted as an ASCII character, rather than a decimal number. This
patch fixes this by casting it to a uint64_t before printing. I did it
this way instead of using a uint8_t formatter because a) it is simpler,
and b) it allows us to change the internal type of Isa in the future
without this code breaking.

I also took the opportunity to test the printing of the other standard
opcodes.

Reviewed by: probinson

Differential Revision: https://reviews.llvm.org/D71274

Added: 
    

Modified: 
    llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
    llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index dbee28ff5ab1..a1835be344e5 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -813,7 +813,7 @@ Error DWARFDebugLine::LineTable::parse(
         // column register of the state machine.
         State.Row.Isa = DebugLineData.getULEB128(OffsetPtr);
         if (OS)
-          *OS << " (" << State.Row.Isa << ")";
+          *OS << " (" << (uint64_t)State.Row.Isa << ")";
         break;
 
       default:

diff  --git a/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp
index bf2dee4ce248..ca78e18a38d8 100644
--- a/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp
@@ -675,4 +675,56 @@ TEST_F(DebugLineBasicFixture, ParserIgnoresNonPrologueErrorsWhenSkipping) {
   EXPECT_FALSE(Unrecoverable);
 }
 
+TEST_F(DebugLineBasicFixture, ParserPrintsStandardOpcodesWhenRequested) {
+  if (!setupGenerator())
+    return;
+
+  using ValLen = dwarfgen::LineTable::ValueAndLength;
+  LineTable &LT = Gen->addLineTable(DWARF32);
+  LT.addStandardOpcode(DW_LNS_copy, {});
+  LT.addStandardOpcode(DW_LNS_advance_pc, {ValLen{11, LineTable::ULEB}});
+  LT.addStandardOpcode(DW_LNS_advance_line, {ValLen{22, LineTable::SLEB}});
+  LT.addStandardOpcode(DW_LNS_set_file, {ValLen{33, LineTable::ULEB}});
+  LT.addStandardOpcode(DW_LNS_set_column, {ValLen{44, LineTable::ULEB}});
+  LT.addStandardOpcode(DW_LNS_negate_stmt, {});
+  LT.addStandardOpcode(DW_LNS_set_basic_block, {});
+  LT.addStandardOpcode(DW_LNS_const_add_pc, {});
+  LT.addStandardOpcode(DW_LNS_fixed_advance_pc, {ValLen{55, LineTable::Half}});
+  LT.addStandardOpcode(DW_LNS_set_prologue_end, {});
+  LT.addStandardOpcode(DW_LNS_set_epilogue_begin, {});
+  LT.addStandardOpcode(DW_LNS_set_isa, {ValLen{66, LineTable::ULEB}});
+  LT.addExtendedOpcode(1, DW_LNE_end_sequence, {});
+  generate();
+
+  DWARFDebugLine::SectionParser Parser(LineData, *Context, CUs, TUs);
+  std::string Output;
+  raw_string_ostream OS(Output);
+  Parser.parseNext(RecordRecoverable, RecordUnrecoverable, &OS);
+  OS.flush();
+
+  EXPECT_FALSE(Recoverable);
+  EXPECT_FALSE(Unrecoverable);
+  auto InOutput = [&Output](char const *Str) {
+    return Output.find(Str) != std::string::npos;
+  };
+  EXPECT_TRUE(InOutput("0x0000002e: 01 DW_LNS_copy\n")) << Output;
+  EXPECT_TRUE(InOutput("0x0000002f: 02 DW_LNS_advance_pc (11)\n")) << Output;
+  // FIXME: The value printed after DW_LNS_advance_line is currently the result
+  // of the advance, but it should be the value being advanced by. See
+  // https://bugs.llvm.org/show_bug.cgi?id=44261 for details.
+  EXPECT_TRUE(InOutput("0x00000031: 03 DW_LNS_advance_line (23)\n")) << Output;
+  EXPECT_TRUE(InOutput("0x00000033: 04 DW_LNS_set_file (33)\n")) << Output;
+  EXPECT_TRUE(InOutput("0x00000035: 05 DW_LNS_set_column (44)\n")) << Output;
+  EXPECT_TRUE(InOutput("0x00000037: 06 DW_LNS_negate_stmt\n")) << Output;
+  EXPECT_TRUE(InOutput("0x00000038: 07 DW_LNS_set_basic_block\n")) << Output;
+  EXPECT_TRUE(
+      InOutput("0x00000039: 08 DW_LNS_const_add_pc (0x0000000000000011)\n"))
+      << Output;
+  EXPECT_TRUE(InOutput("0x0000003a: 09 DW_LNS_fixed_advance_pc (0x0037)\n"))
+      << Output;
+  EXPECT_TRUE(InOutput("0x0000003d: 0a DW_LNS_set_prologue_end\n")) << Output;
+  EXPECT_TRUE(InOutput("0x0000003e: 0b DW_LNS_set_epilogue_begin\n")) << Output;
+  EXPECT_TRUE(InOutput("0x0000003f: 0c DW_LNS_set_isa (66)\n")) << Output;
+}
+
 } // end anonymous namespace


        


More information about the llvm-commits mailing list