[llvm] r313567 - llvm-dwarfdump: add a --show-parents options when selectively dumping DIEs.

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 18 14:27:44 PDT 2017


Author: adrian
Date: Mon Sep 18 14:27:44 2017
New Revision: 313567

URL: http://llvm.org/viewvc/llvm-project?rev=313567&view=rev
Log:
llvm-dwarfdump: add a --show-parents options when selectively dumping DIEs.

Modified:
    llvm/trunk/include/llvm/DebugInfo/DIContext.h
    llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp
    llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_info_offset.test
    llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp

Modified: llvm/trunk/include/llvm/DebugInfo/DIContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DIContext.h?rev=313567&r1=313566&r2=313567&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DIContext.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DIContext.h Mon Sep 18 14:27:44 2017
@@ -139,6 +139,7 @@ enum DIDumpType : unsigned {
 struct DIDumpOptions {
   unsigned DumpType = DIDT_All;
   bool ShowChildren = false;
+  bool ShowParents = false;
   bool SummarizeTypes = false;
   bool Verbose = false;
 };

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp?rev=313567&r1=313566&r2=313567&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp Mon Sep 18 14:27:44 2017
@@ -367,6 +367,16 @@ void DWARFDie::getCallerFrame(uint32_t &
   CallDiscriminator = toUnsigned(find(DW_AT_GNU_discriminator), 0);
 }
 
+/// Helper to dump a DIE with all of its parents, but no siblings.
+static unsigned dumpParentChain(DWARFDie Die, raw_ostream &OS, unsigned Indent,
+                                DIDumpOptions DumpOpts) {
+  if (!Die)
+    return Indent;
+  Indent = dumpParentChain(Die.getParent(), OS, Indent, DumpOpts);
+  Die.dump(OS, 0, Indent, DumpOpts);
+  return Indent + 2;
+}
+
 void DWARFDie::dump(raw_ostream &OS, unsigned RecurseDepth, unsigned Indent,
                     DIDumpOptions DumpOpts) const {
   if (!isValid())
@@ -374,7 +384,12 @@ void DWARFDie::dump(raw_ostream &OS, uns
   DWARFDataExtractor debug_info_data = U->getDebugInfoExtractor();
   const uint32_t Offset = getOffset();
   uint32_t offset = Offset;
-  RecurseDepth += DumpOpts.ShowChildren ? 1 : 0;
+  if (DumpOpts.ShowChildren)
+    RecurseDepth++;
+  if (DumpOpts.ShowParents) {
+    DumpOpts.ShowParents = false;
+    Indent = dumpParentChain(getParent(), OS, Indent, DumpOpts);
+  }
 
   if (debug_info_data.isValidOffset(offset)) {
     uint32_t abbrCode = debug_info_data.getULEB128(&offset);

Modified: llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_info_offset.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_info_offset.test?rev=313567&r1=313566&r2=313567&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_info_offset.test (original)
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_info_offset.test Mon Sep 18 14:27:44 2017
@@ -20,3 +20,18 @@ RUN:   | FileCheck %s --check-prefix=CHI
 CHILDREN: .debug_info contents:
 CHILDREN: 0x0000000b: DW_TAG_compile_unit
 CHILDREN: DW_TAG_subprogram
+
+RUN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o - \
+RUN:   | llvm-dwarfdump -debug-info=0x00000043 --show-parents - \
+RUN:   | FileCheck %s --check-prefix=PARENTS
+
+RUN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o - \
+RUN:   | llvm-dwarfdump -debug-info=0x00000043 -p - \
+RUN:   | FileCheck %s --check-prefix=PARENTS
+PARENTS: .debug_info contents:
+PARENTS: 0x0000000b:{{ }}DW_TAG_compile_unit
+PARENTS:                   DW_AT_name
+PARENTS-NOT: {{:}}
+PARENTS: 0x00000043:{{   }}DW_TAG_base_type
+PARENTS:                     DW_AT_name
+PARENTS-NOT: {{:}}

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=313567&r1=313566&r2=313567&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp (original)
+++ llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp Mon Sep 18 14:27:44 2017
@@ -131,10 +131,16 @@ static alias DumpUUIDAlias("u", desc("Al
 static opt<bool>
     ShowChildren("show-children",
                  desc("Show a debug info entry's children when selectively "
-                      "printing with the =<Offset> option"));
+                      "printing with the =<offset> option"));
 static alias ShowChildrenAlias("c", desc("Alias for -show-children"),
                                aliasopt(ShowChildren));
 static opt<bool>
+    ShowParents("show-parents",
+                desc("Show a debug info entry's parents when selectively "
+                     "printing with the =<offset> option"));
+static alias ShowParentsAlias("p", desc("Alias for -show-parents"),
+                              aliasopt(ShowParents));
+static opt<bool>
     SummarizeTypes("summarize-types",
                    desc("Abbreviate the description of type unit entries"));
 static opt<bool> Verify("verify", desc("Verify the DWARF debug info"),
@@ -162,6 +168,7 @@ static DIDumpOptions getDumpOpts() {
   DIDumpOptions DumpOpts;
   DumpOpts.DumpType = DumpType;
   DumpOpts.ShowChildren = ShowChildren;
+  DumpOpts.ShowParents = ShowParents;
   DumpOpts.SummarizeTypes = SummarizeTypes;
   DumpOpts.Verbose = Verbose;
   return DumpOpts;




More information about the llvm-commits mailing list