]> granicus.if.org Git - llvm/commitdiff
llvm-dwarfdump: honor the --show-children option when dumping a specific DIE.
authorAdrian Prantl <aprantl@apple.com>
Wed, 29 Nov 2017 01:12:22 +0000 (01:12 +0000)
committerAdrian Prantl <aprantl@apple.com>
Wed, 29 Nov 2017 01:12:22 +0000 (01:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319271 91177308-0d34-0410-b5e6-96231b3b80d8

lib/DebugInfo/DWARF/DWARFDie.cpp
test/tools/llvm-dwarfdump/X86/name.test
tools/llvm-dwarfdump/llvm-dwarfdump.cpp

index c4bb2259244b9825f6343205ebf0a30146bfd6c0..1b8b46385af09c8a3849381b903f4b5bf1e6830d 100644 (file)
@@ -488,7 +488,7 @@ void DWARFDie::dump(raw_ostream &OS, unsigned Indent,
         }
 
         DWARFDie child = getFirstChild();
-        if (DumpOpts.RecurseDepth > 0 && child) {
+        if (DumpOpts.ShowChildren && DumpOpts.RecurseDepth > 0 && child) {
           DumpOpts.RecurseDepth--;
           while (child) {
             child.dump(OS, Indent + 2, DumpOpts);
index 66483179b5abbe7de4993bcb372c08b135e1b6e5..e8e90abc0cbfce89bd800c4b16c0de53da878fa8 100644 (file)
@@ -61,3 +61,9 @@ RUN:   | FileCheck %s --check-prefix=MULTI
 RUN: llvm-dwarfdump %S/../../dsymutil/Inputs/libfat-test.a \
 RUN:   -x -name=.*86.*_var \
 RUN:   | FileCheck %s --check-prefix=MULTI
+
+Test the -show-children behavior.
+RUN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o - \
+RUN:   | llvm-dwarfdump -name="brief.c" - | FileCheck %s -check-prefix=NOCHILDREN
+NOCHILDREN: DW_AT_name ("brief.c")
+NOCHILDREN-NOT: DW_TAG
index 04371b7da841a3b966832a2fc7e6a5a0c66a2816..40a90e1662d8667800dbd3df76c94575108ea922 100644 (file)
@@ -536,14 +536,17 @@ int main(int argc, char **argv) {
   }
 
   raw_ostream &OS = OutputFile ? OutputFile->os() : outs();
+  bool OffsetRequested = false;
 
   // Defaults to dumping all sections, unless brief mode is specified in which
   // case only the .debug_info section in dumped.
 #define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME)                \
   if (Dump##ENUM_NAME.IsRequested) {                                           \
     DumpType |= DIDT_##ENUM_NAME;                                              \
-    if (Dump##ENUM_NAME.HasValue)                                              \
+    if (Dump##ENUM_NAME.HasValue) {                                            \
       DumpOffsets[DIDT_ID_##ENUM_NAME] = Dump##ENUM_NAME.Val;                  \
+      OffsetRequested = true;                                                  \
+    }                                                                          \
   }
 #include "llvm/BinaryFormat/Dwarf.def"
 #undef HANDLE_DWARF_SECTION
@@ -558,6 +561,10 @@ int main(int argc, char **argv) {
       DumpType = DIDT_DebugInfo;
   }
 
+  // Unless dumping a specific DIE, default to --show-children.
+  if (!ShowChildren && !Verify && !OffsetRequested && Name.empty() && Find.empty())
+    ShowChildren = true;
+
   // Defaults to a.out if no filenames specified.
   if (InputFilenames.size() == 0)
     InputFilenames.push_back("a.out");