]> granicus.if.org Git - llvm/commitdiff
llvm-dwarfdump: support a --show-children option
authorAdrian Prantl <aprantl@apple.com>
Sat, 16 Sep 2017 17:28:00 +0000 (17:28 +0000)
committerAdrian Prantl <aprantl@apple.com>
Sat, 16 Sep 2017 17:28:00 +0000 (17:28 +0000)
This will print all children of a DIE when selectively printing only
one DIE at a given offset.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313464 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/DebugInfo/DIContext.h
lib/DebugInfo/DWARF/DWARFContext.cpp
test/tools/llvm-dwarfdump/X86/debug_info_offset.test
test/tools/llvm-dwarfdump/X86/debug_type_offset.test
tools/llvm-dwarfdump/llvm-dwarfdump.cpp

index 59f8e297296b16467866201a390ba4599f55fbde..9da31e6e173b888e415f36dc3186353a198f4fc3 100644 (file)
@@ -139,6 +139,7 @@ enum DIDumpType : unsigned {
 struct DIDumpOptions {
   unsigned DumpType = DIDT_All;
   bool DumpEH = false;
+  bool ShowChildren = false;
   bool SummarizeTypes = false;
   bool Verbose = false;
 };
index 02d37f21c38b5365b5d1dfd065244d1e0d42a749..373452a927891df4472de4e16f7e74b21ecd2b58 100644 (file)
@@ -223,6 +223,8 @@ void DWARFContext::dump(
   Optional<uint64_t> DumpOffset;
   uint64_t DumpType = DumpOpts.DumpType;
   bool DumpEH = DumpOpts.DumpEH;
+  unsigned RecDepth =
+      DumpOpts.ShowChildren ? std::numeric_limits<unsigned>::max() : 0;
 
   StringRef Extension = sys::path::extension(DObj->getFileName());
   bool IsDWO = (Extension == ".dwo") || (Extension == ".dwp");
@@ -260,7 +262,7 @@ void DWARFContext::dump(
     if (shouldDump(IsExplicit, Name, DIDT_ID_DebugInfo, Section.Data)) {
       for (const auto &CU : CUs)
         if (DumpOffset)
-        CU->getDIEForOffset(DumpOffset.getValue()).dump(OS, 0);
+          CU->getDIEForOffset(DumpOffset.getValue()).dump(OS, RecDepth);
         else
           CU->dump(OS, DumpOpts);
     }
@@ -277,7 +279,7 @@ void DWARFContext::dump(
     for (const auto &TUS : TUSections)
       for (const auto &TU : TUS)
         if (DumpOffset)
-          TU->getDIEForOffset(*DumpOffset).dump(OS, 0);
+          TU->getDIEForOffset(*DumpOffset).dump(OS, RecDepth);
         else
           TU->dump(OS, DumpOpts);
   };
index d3d1b6a94c6dec34a8df7a6d1e801244c5d16a88..0c95eabf0f9139d2ad2e9e68bb1388bce88b1843 100644 (file)
@@ -6,5 +6,17 @@ CHECK:               DW_AT_name
 CHECK-NOT: {{:}}
 
 RUN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o - \
-RUN:   | llvm-dwarfdump -debug-info=0 - | FileCheck --allow-empty --check-prefix=EMPTY %s
+RUN:   | llvm-dwarfdump -debug-info=0 - \
+RUN:   | FileCheck --allow-empty --check-prefix=EMPTY %s
 EMPTY-NOT: DW_TAG
+
+RUN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o - \
+RUN:   | llvm-dwarfdump -debug-info=0x0000000b -c - \
+RUN:   | FileCheck %s --check-prefix=CHILDREN
+
+UN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o - \
+UN:   | llvm-dwarfdump -debug-info=0x0000000b --show-children - \
+UN:   | FileCheck %s --check-prefix=CHILDREN
+CHILDREN: .debug_info contents:
+CHILDREN: 0x0000000b: DW_TAG_compile_unit
+CHILDREN: DW_TAG_subprogram
index b1fcad4312dde0d2936173a4484a174817bf8913..5be0bff2009ebc11d83fcd1976de50db4cf1147a 100644 (file)
@@ -6,3 +6,12 @@ CHECK: .debug_types contents:
 CHECK: 0x00000019: DW_TAG_structure_type
 CHECK:               DW_AT_visibility
 CHECK-NOT: {{:}}
+
+RUN: llvm-mc %S/../../../DebugInfo/Inputs/typeunit-header.s -filetype obj \
+RUN:   -triple x86_64-unknown-elf -o - \
+RUN:   | llvm-dwarfdump -c -debug-types=0x0000017 - \
+RUN:   | FileCheck %s --check-prefix=CHILDREN
+CHILDREN: .debug_types contents:
+CHILDREN: 0x00000017: DW_TAG_type_unit
+CHILDREN: 0x00000019:   DW_TAG_structure_type
+CHECK-NOT: {{:}}
index 0ac3354a7aa374e88999567e5be22f694e261108..725152161a6d55c130a56ed2246b4c5c727c617a 100644 (file)
@@ -126,6 +126,12 @@ static opt<bool> DumpUUID("uuid", desc("Show the UUID for each architecture"),
                           cat(DwarfDumpCategory));
 static alias DumpUUIDAlias("u", desc("Alias for -uuid"), aliasopt(DumpUUID));
 
+static opt<bool>
+    ShowChildren("show-children",
+                 desc("Show a debug info entry's children when selectively "
+                      "printing with the =<Offset> option"));
+static alias ShowChildrenAlias("c", desc("Alias for -show-children"),
+                               aliasopt(ShowChildren));
 static opt<bool>
     SummarizeTypes("summarize-types",
                    desc("Abbreviate the description of type unit entries"));
@@ -153,6 +159,7 @@ static void error(StringRef Filename, std::error_code EC) {
 static DIDumpOptions getDumpOpts() {
   DIDumpOptions DumpOpts;
   DumpOpts.DumpType = DumpType;
+  DumpOpts.ShowChildren = ShowChildren;
   DumpOpts.SummarizeTypes = SummarizeTypes;
   DumpOpts.Verbose = Verbose;
   return DumpOpts;