[PATCH] D79093: [DebugInfo] Fix printing values of forms which depend on the DWARF format.

Igor Kudrin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 29 08:00:59 PDT 2020


ikudrin created this revision.
ikudrin added reviewers: dblaikie, probinson, jhenderson, aprantl.
ikudrin added projects: LLVM, debug-info.
Herald added a subscriber: hiraditya.

The values are 8 bytes long in DWARF64, so they should not be cut to uint32_t on dumping.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79093

Files:
  llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp
  llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp


Index: llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp
===================================================================
--- llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp
+++ llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp
@@ -339,4 +339,44 @@
         ErrorParams{DW_FORM_strp_sup, {}},
         ErrorParams{DW_FORM_ref_sig8, {}}), );
 
+using DumpValueParams = std::tuple<Form, uint64_t, StringRef>;
+struct DumpValueFixture : public testing::TestWithParam<DumpValueParams> {
+  void SetUp() override { std::tie(Fm, Value, ExpectedResult) = GetParam(); }
+
+  Form Fm;
+  uint64_t Value;
+  StringRef ExpectedResult;
+};
+
+TEST_P(DumpValueFixture, Test) {
+  SCOPED_TRACE(formatv("Fm = {0}, Value = {1:x}", Fm, Value));
+  char Raw[8];
+  memcpy(Raw, &Value, 8);
+  DWARFDataExtractor Data(StringRef(Raw, 8), sys::IsLittleEndianHost, 8);
+  DWARFFormValue TestValue(Fm);
+  uint64_t Offset = 0;
+  TestValue.extractValue(Data, &Offset, {0, 0, dwarf::DwarfFormat::DWARF64});
+
+  std::string Output;
+  raw_string_ostream OS(Output);
+
+  DIDumpOptions Opts;
+  Opts.Verbose = true;
+  Opts.ShowAddresses = true;
+
+  TestValue.dump(OS, Opts);
+  OS.flush();
+
+  EXPECT_EQ(Output, ExpectedResult);
+}
+
+INSTANTIATE_TEST_CASE_P(
+    DumpValueParams, DumpValueFixture,
+    testing::Values(DumpValueParams{DW_FORM_strp, 0x1122334455667788,
+                                    " .debug_str[0x1122334455667788] = "},
+                    DumpValueParams{DW_FORM_line_strp, 0x1122334455667788,
+                                    " .debug_line_str[0x1122334455667788] = "},
+                    DumpValueParams{DW_FORM_sec_offset, 0x1122334455667788,
+                                    "0x1122334455667788"}), );
+
 } // end anonymous namespace
Index: llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp
===================================================================
--- llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp
+++ llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp
@@ -481,12 +481,12 @@
     break;
   case DW_FORM_strp:
     if (DumpOpts.Verbose)
-      OS << format(" .debug_str[0x%8.8x] = ", (uint32_t)UValue);
+      OS << format(" .debug_str[0x%8.8" PRIx64 "] = ", UValue);
     dumpString(OS);
     break;
   case DW_FORM_line_strp:
     if (DumpOpts.Verbose)
-      OS << format(" .debug_line_str[0x%8.8x] = ", (uint32_t)UValue);
+      OS << format(" .debug_line_str[0x%8.8" PRIx64 "] = ", UValue);
     dumpString(OS);
     break;
   case DW_FORM_strx:
@@ -550,9 +550,8 @@
     OS << format("indexed (0x%x) loclist = ", (uint32_t)UValue);
     break;
 
-  // Should be formatted to 64-bit for DWARF64.
   case DW_FORM_sec_offset:
-    AddrOS << format("0x%08x", (uint32_t)UValue);
+    AddrOS << format("0x%08" PRIx64, UValue);
     break;
 
   default:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79093.260918.patch
Type: text/x-patch
Size: 2784 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200429/588d6ed0/attachment.bin>


More information about the llvm-commits mailing list