diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp index c4bb2259244b..1b8b46385af0 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp +++ b/llvm/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/llvm/test/tools/llvm-dwarfdump/X86/name.test b/llvm/test/tools/llvm-dwarfdump/X86/name.test index 66483179b5ab..e8e90abc0cbf 100644 --- a/llvm/test/tools/llvm-dwarfdump/X86/name.test +++ b/llvm/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/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp index 04371b7da841..40a90e1662d8 100644 --- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/llvm/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");