From: Adrian Prantl Date: Wed, 29 Nov 2017 01:12:22 +0000 (+0000) Subject: llvm-dwarfdump: honor the --show-children option when dumping a specific DIE. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c97df2361b242a5f00ade73e1820f0cbc39ba99b;p=llvm llvm-dwarfdump: honor the --show-children option when dumping a specific DIE. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319271 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/DebugInfo/DWARF/DWARFDie.cpp b/lib/DebugInfo/DWARF/DWARFDie.cpp index c4bb2259244..1b8b46385af 100644 --- a/lib/DebugInfo/DWARF/DWARFDie.cpp +++ b/lib/DebugInfo/DWARF/DWARFDie.cpp @@ -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); diff --git a/test/tools/llvm-dwarfdump/X86/name.test b/test/tools/llvm-dwarfdump/X86/name.test index 66483179b5a..e8e90abc0cb 100644 --- a/test/tools/llvm-dwarfdump/X86/name.test +++ b/test/tools/llvm-dwarfdump/X86/name.test @@ -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 diff --git a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp index 04371b7da84..40a90e1662d 100644 --- a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -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");