diff options
author | Adrian Prantl <aprantl@apple.com> | 2017-12-08 23:32:47 +0000 |
---|---|---|
committer | Adrian Prantl <aprantl@apple.com> | 2017-12-08 23:32:47 +0000 |
commit | b5b768dedeb4ffa94b60ff0c6c19f1095964086b (patch) | |
tree | 35a71101143cac6f3dcd9a56916cb430451e2648 | |
parent | b6b1c519440746d5e3aa29290057e01b5cb83874 (diff) |
dwarfdump: Add support for the --diff option.
--diff Emit the output in a diff-friendly way by omitting offsets and
addresses.
<rdar://problem/34502625>
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320214 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | docs/CommandGuide/llvm-dwarfdump.rst | 5 | ||||
-rw-r--r-- | include/llvm/DebugInfo/DIContext.h | 1 | ||||
-rw-r--r-- | lib/DebugInfo/DWARF/DWARFDie.cpp | 17 | ||||
-rw-r--r-- | lib/DebugInfo/DWARF/DWARFFormValue.cpp | 33 | ||||
-rw-r--r-- | test/tools/llvm-dwarfdump/X86/diff.test | 6 | ||||
-rw-r--r-- | test/tools/llvm-dwarfdump/cmdline.test | 1 | ||||
-rw-r--r-- | tools/llvm-dwarfdump/llvm-dwarfdump.cpp | 5 |
7 files changed, 47 insertions, 21 deletions
diff --git a/docs/CommandGuide/llvm-dwarfdump.rst b/docs/CommandGuide/llvm-dwarfdump.rst index a3b62664cbe..e7f7c44ffd3 100644 --- a/docs/CommandGuide/llvm-dwarfdump.rst +++ b/docs/CommandGuide/llvm-dwarfdump.rst @@ -35,6 +35,11 @@ OPTIONS the :option:`--debug-info`, :option:`--find`, and :option:`--name` options. +.. option:: --diff + + Emit the output in a diff-friendly way by omitting offsets and + addresses. + .. option:: -f <name>, --find=<name> Search for the exact text <name> in the accelerator tables diff --git a/include/llvm/DebugInfo/DIContext.h b/include/llvm/DebugInfo/DIContext.h index 4a368bec85c..abace937860 100644 --- a/include/llvm/DebugInfo/DIContext.h +++ b/include/llvm/DebugInfo/DIContext.h @@ -153,6 +153,7 @@ enum DIDumpType : unsigned { struct DIDumpOptions { unsigned DumpType = DIDT_All; unsigned RecurseDepth = -1U; + bool ShowAddresses = true; bool ShowChildren = false; bool ShowParents = false; bool ShowForm = false; diff --git a/lib/DebugInfo/DWARF/DWARFDie.cpp b/lib/DebugInfo/DWARF/DWARFDie.cpp index 1b8b46385af..91f0f8501f0 100644 --- a/lib/DebugInfo/DWARF/DWARFDie.cpp +++ b/lib/DebugInfo/DWARF/DWARFDie.cpp @@ -236,12 +236,14 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die, OS << *formValue.getAsUnsignedConstant(); else if (Attr == DW_AT_high_pc && !DumpOpts.ShowForm && !DumpOpts.Verbose && formValue.getAsUnsignedConstant()) { - // Print the actual address rather than the offset. - uint64_t LowPC, HighPC, Index; - if (Die.getLowAndHighPC(LowPC, HighPC, Index)) - OS << format("0x%016" PRIx64, HighPC); - else - formValue.dump(OS, DumpOpts); + if (DumpOpts.ShowAddresses) { + // Print the actual address rather than the offset. + uint64_t LowPC, HighPC, Index; + if (Die.getLowAndHighPC(LowPC, HighPC, Index)) + OS << format("0x%016" PRIx64, HighPC); + else + formValue.dump(OS, DumpOpts); + } } else if (Attr == DW_AT_location || Attr == DW_AT_frame_base || Attr == DW_AT_data_member_location || Attr == DW_AT_GNU_call_site_value) @@ -458,7 +460,8 @@ void DWARFDie::dump(raw_ostream &OS, unsigned Indent, if (debug_info_data.isValidOffset(offset)) { uint32_t abbrCode = debug_info_data.getULEB128(&offset); - WithColor(OS, syntax::Address).get() << format("\n0x%8.8x: ", Offset); + if (DumpOpts.ShowAddresses) + WithColor(OS, syntax::Address).get() << format("\n0x%8.8x: ", Offset); if (abbrCode) { auto AbbrevDecl = getAbbreviationDeclarationPtr(); diff --git a/lib/DebugInfo/DWARF/DWARFFormValue.cpp b/lib/DebugInfo/DWARF/DWARFFormValue.cpp index c4abd49797b..14e2fe3eeb5 100644 --- a/lib/DebugInfo/DWARF/DWARFFormValue.cpp +++ b/lib/DebugInfo/DWARF/DWARFFormValue.cpp @@ -396,18 +396,19 @@ bool DWARFFormValue::extractValue(const DWARFDataExtractor &Data, void DWARFFormValue::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const { uint64_t UValue = Value.uval; bool CURelativeOffset = false; - + raw_ostream &AddrOS = + DumpOpts.ShowAddresses ? WithColor(OS, syntax::Address).get() : nulls(); switch (Form) { case DW_FORM_addr: - OS << format("0x%016" PRIx64, UValue); + AddrOS << format("0x%016" PRIx64, UValue); break; case DW_FORM_GNU_addr_index: { - OS << format(" indexed (%8.8x) address = ", (uint32_t)UValue); + AddrOS << format(" indexed (%8.8x) address = ", (uint32_t)UValue); uint64_t Address; if (U == nullptr) OS << "<invalid dwarf unit>"; else if (U->getAddrOffsetSectionItem(UValue, Address)) - OS << format("0x%016" PRIx64, Address); + AddrOS << format("0x%016" PRIx64, Address); else OS << "<no .debug_addr section>"; break; @@ -426,6 +427,8 @@ void DWARFFormValue::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const { OS << format("0x%08x", (uint32_t)UValue); break; case DW_FORM_ref_sig8: + AddrOS << format("0x%016" PRIx64, UValue); + break; case DW_FORM_data8: OS << format("0x%016" PRIx64, UValue); break; @@ -488,38 +491,40 @@ void DWARFFormValue::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const { case DW_FORM_strx3: case DW_FORM_strx4: case DW_FORM_GNU_str_index: - OS << format(" indexed (%8.8x) string = ", (uint32_t)UValue); + if (DumpOpts.Verbose) + OS << format(" indexed (%8.8x) string = ", (uint32_t)UValue); dumpString(OS); break; case DW_FORM_GNU_strp_alt: - OS << format("alt indirect string, offset: 0x%" PRIx64 "", UValue); + if (DumpOpts.Verbose) + OS << format("alt indirect string, offset: 0x%" PRIx64 "", UValue); dumpString(OS); break; case DW_FORM_ref_addr: - OS << format("0x%016" PRIx64, UValue); + AddrOS << format("0x%016" PRIx64, UValue); break; case DW_FORM_ref1: CURelativeOffset = true; - OS << format("cu + 0x%2.2x", (uint8_t)UValue); + AddrOS << format("cu + 0x%2.2x", (uint8_t)UValue); break; case DW_FORM_ref2: CURelativeOffset = true; - OS << format("cu + 0x%4.4x", (uint16_t)UValue); + AddrOS << format("cu + 0x%4.4x", (uint16_t)UValue); break; case DW_FORM_ref4: CURelativeOffset = true; - OS << format("cu + 0x%4.4x", (uint32_t)UValue); + AddrOS << format("cu + 0x%4.4x", (uint32_t)UValue); break; case DW_FORM_ref8: CURelativeOffset = true; - OS << format("cu + 0x%8.8" PRIx64, UValue); + AddrOS << format("cu + 0x%8.8" PRIx64, UValue); break; case DW_FORM_ref_udata: CURelativeOffset = true; - OS << format("cu + 0x%" PRIx64, UValue); + AddrOS << format("cu + 0x%" PRIx64, UValue); break; case DW_FORM_GNU_ref_alt: - OS << format("<alt 0x%" PRIx64 ">", UValue); + AddrOS << format("<alt 0x%" PRIx64 ">", UValue); break; // All DW_FORM_indirect attributes should be resolved prior to calling @@ -530,7 +535,7 @@ void DWARFFormValue::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const { // Should be formatted to 64-bit for DWARF64. case DW_FORM_sec_offset: - OS << format("0x%08x", (uint32_t)UValue); + AddrOS << format("0x%08x", (uint32_t)UValue); break; default: diff --git a/test/tools/llvm-dwarfdump/X86/diff.test b/test/tools/llvm-dwarfdump/X86/diff.test new file mode 100644 index 00000000000..2cca72c961a --- /dev/null +++ b/test/tools/llvm-dwarfdump/X86/diff.test @@ -0,0 +1,6 @@ +RUN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o - \ +RUN: | llvm-dwarfdump -diff - | FileCheck %s +CHECK: {{^DW_TAG_compile_unit}} +CHECK: DW_AT_stmt_list () +CHECK: DW_AT_low_pc () +CHECK: DW_AT_high_pc () diff --git a/test/tools/llvm-dwarfdump/cmdline.test b/test/tools/llvm-dwarfdump/cmdline.test index fd9424253e9..7fb9e8389d0 100644 --- a/test/tools/llvm-dwarfdump/cmdline.test +++ b/test/tools/llvm-dwarfdump/cmdline.test @@ -6,6 +6,7 @@ HELP: Section-specific Dump Options HELP: -debug-info - Dump the .debug_info section HELP: -eh-frame HELP: Specific Options +HELP: -diff HELP: -find HELP: -ignore-case HELP: -lookup diff --git a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp index 40a90e1662d..71db88ad9db 100644 --- a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -136,6 +136,10 @@ static list<std::string> "name or by number. This option can be specified " "multiple times, once for each desired architecture."), cat(DwarfDumpCategory)); +static opt<bool> + Diff("diff", + desc("Emit diff-friendly output by omitting offsets and addresses."), + cat(DwarfDumpCategory)); static list<std::string> Find("find", desc("Search for the exact match for <name> in the accelerator tables " @@ -237,6 +241,7 @@ static DIDumpOptions getDumpOpts() { DIDumpOptions DumpOpts; DumpOpts.DumpType = DumpType; DumpOpts.RecurseDepth = RecurseDepth; + DumpOpts.ShowAddresses = !Diff; DumpOpts.ShowChildren = ShowChildren; DumpOpts.ShowParents = ShowParents; DumpOpts.ShowForm = ShowForm; |