[llvm] r320214 - dwarfdump: Add support for the --diff option.

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 8 15:32:47 PST 2017


Author: adrian
Date: Fri Dec  8 15:32:47 2017
New Revision: 320214

URL: http://llvm.org/viewvc/llvm-project?rev=320214&view=rev
Log:
dwarfdump: Add support for the --diff option.

--diff      Emit the output in a diff-friendly way by omitting offsets and
            addresses.

<rdar://problem/34502625>

Added:
    llvm/trunk/test/tools/llvm-dwarfdump/X86/diff.test
Modified:
    llvm/trunk/docs/CommandGuide/llvm-dwarfdump.rst
    llvm/trunk/include/llvm/DebugInfo/DIContext.h
    llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp
    llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp
    llvm/trunk/test/tools/llvm-dwarfdump/cmdline.test
    llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp

Modified: llvm/trunk/docs/CommandGuide/llvm-dwarfdump.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CommandGuide/llvm-dwarfdump.rst?rev=320214&r1=320213&r2=320214&view=diff
==============================================================================
--- llvm/trunk/docs/CommandGuide/llvm-dwarfdump.rst (original)
+++ llvm/trunk/docs/CommandGuide/llvm-dwarfdump.rst Fri Dec  8 15:32:47 2017
@@ -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

Modified: llvm/trunk/include/llvm/DebugInfo/DIContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DIContext.h?rev=320214&r1=320213&r2=320214&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DIContext.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DIContext.h Fri Dec  8 15:32:47 2017
@@ -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;

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp?rev=320214&r1=320213&r2=320214&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp Fri Dec  8 15:32:47 2017
@@ -236,12 +236,14 @@ static void dumpAttribute(raw_ostream &O
     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, uns
 
   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();

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp?rev=320214&r1=320213&r2=320214&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFFormValue.cpp Fri Dec  8 15:32:47 2017
@@ -396,18 +396,19 @@ bool DWARFFormValue::extractValue(const
 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 &O
     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 &O
   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 &O
 
   // 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:

Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/diff.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/diff.test?rev=320214&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/diff.test (added)
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/diff.test Fri Dec  8 15:32:47 2017
@@ -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	()

Modified: llvm/trunk/test/tools/llvm-dwarfdump/cmdline.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/cmdline.test?rev=320214&r1=320213&r2=320214&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-dwarfdump/cmdline.test (original)
+++ llvm/trunk/test/tools/llvm-dwarfdump/cmdline.test Fri Dec  8 15:32:47 2017
@@ -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

Modified: llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp?rev=320214&r1=320213&r2=320214&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp (original)
+++ llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp Fri Dec  8 15:32:47 2017
@@ -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;




More information about the llvm-commits mailing list