[llvm] 050c9dd - [DebugInfo] Fix printing values of forms which depend on the DWARF format.
Igor Kudrin via llvm-commits
llvm-commits at lists.llvm.org
Fri May 8 01:15:37 PDT 2020
Author: Igor Kudrin
Date: 2020-05-08T15:14:41+07:00
New Revision: 050c9dd43a0fd32c0bb8b944b6adb8f780c83c1c
URL: https://github.com/llvm/llvm-project/commit/050c9dd43a0fd32c0bb8b944b6adb8f780c83c1c
DIFF: https://github.com/llvm/llvm-project/commit/050c9dd43a0fd32c0bb8b944b6adb8f780c83c1c.diff
LOG: [DebugInfo] Fix printing values of forms which depend on the DWARF format.
The values are 8 bytes long in DWARF64, so they should not be truncated
to uint32_t on dumping.
Differential Revision: https://reviews.llvm.org/D79093
Added:
Modified:
llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp
llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp b/llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp
index d93253f47f37..1d0bf114d8da 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp
@@ -481,12 +481,12 @@ void DWARFFormValue::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const {
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 @@ void DWARFFormValue::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const {
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:
diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp
index 378440abccc0..b0eabbce2f45 100644
--- a/llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp
@@ -339,4 +339,60 @@ INSTANTIATE_TEST_CASE_P(
ErrorParams{DW_FORM_strp_sup, {}},
ErrorParams{DW_FORM_ref_sig8, {}}), );
+using DumpValueParams =
+ std::tuple<Form, ArrayRef<uint8_t>, DwarfFormat, StringRef>;
+struct DumpValueFixture : public testing::TestWithParam<DumpValueParams> {
+ void SetUp() override {
+ std::tie(Fm, InitialData, Format, ExpectedResult) = GetParam();
+ }
+
+ Form Fm;
+ ArrayRef<uint8_t> InitialData;
+ DwarfFormat Format;
+ StringRef ExpectedResult;
+};
+
+TEST_P(DumpValueFixture, Test) {
+ SCOPED_TRACE(formatv("Fm = {0}, InitialData = [{1}], Format = {2}", Fm,
+ toHex(InitialData),
+ Format == DWARF64 ? "DWARF64" : "DWARF32"));
+ DWARFDataExtractor Data(InitialData, sys::IsLittleEndianHost, 8);
+ DWARFFormValue Form(Fm);
+ uint64_t Offset = 0;
+ Form.extractValue(Data, &Offset, {0, 0, Format});
+
+ std::string Output;
+ raw_string_ostream OS(Output);
+
+ DIDumpOptions Opts;
+ Opts.Verbose = true;
+ Opts.ShowAddresses = true;
+
+ Form.dump(OS, Opts);
+ OS.flush();
+
+ EXPECT_EQ(Output, ExpectedResult);
+}
+
+const uint32_t DumpTestSample32Val = 0x112233;
+ArrayRef<uint8_t> DumpTestSample32 = toBytes(DumpTestSample32Val);
+const uint64_t DumpTestSample64Val = 0x11223344556677;
+ArrayRef<uint8_t> DumpTestSample64 = toBytes(DumpTestSample64Val);
+
+INSTANTIATE_TEST_CASE_P(
+ DumpValueParams, DumpValueFixture,
+ testing::Values(DumpValueParams{DW_FORM_strp, DumpTestSample32, DWARF32,
+ " .debug_str[0x00112233] = "},
+ DumpValueParams{DW_FORM_strp, DumpTestSample64, DWARF64,
+ " .debug_str[0x11223344556677] = "},
+ DumpValueParams{DW_FORM_line_strp, DumpTestSample32,
+ DWARF32, " .debug_line_str[0x00112233] = "},
+ DumpValueParams{DW_FORM_line_strp, DumpTestSample64,
+ DWARF64,
+ " .debug_line_str[0x11223344556677] = "},
+ DumpValueParams{DW_FORM_sec_offset, DumpTestSample32,
+ DWARF32, "0x00112233"},
+ DumpValueParams{DW_FORM_sec_offset, DumpTestSample64,
+ DWARF64, "0x11223344556677"}), );
+
} // end anonymous namespace
More information about the llvm-commits
mailing list