summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/DebugInfo/DIContext.h1
-rw-r--r--llvm/lib/DebugInfo/DWARF/DWARFDie.cpp17
-rw-r--r--llvm/test/tools/llvm-dwarfdump/X86/debug_info_offset.test15
-rw-r--r--llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp9
4 files changed, 40 insertions, 2 deletions
diff --git a/llvm/include/llvm/DebugInfo/DIContext.h b/llvm/include/llvm/DebugInfo/DIContext.h
index 0d9ea0028e9..12093fed12f 100644
--- a/llvm/include/llvm/DebugInfo/DIContext.h
+++ b/llvm/include/llvm/DebugInfo/DIContext.h
@@ -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;
};
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
index 57734984d75..f588f2599c2 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
@@ -367,6 +367,16 @@ void DWARFDie::getCallerFrame(uint32_t &CallFile, uint32_t &CallLine,
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, unsigned RecurseDepth, unsigned Indent,
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);
diff --git a/llvm/test/tools/llvm-dwarfdump/X86/debug_info_offset.test b/llvm/test/tools/llvm-dwarfdump/X86/debug_info_offset.test
index caae816ad9a..59c8c7c7b45 100644
--- a/llvm/test/tools/llvm-dwarfdump/X86/debug_info_offset.test
+++ b/llvm/test/tools/llvm-dwarfdump/X86/debug_info_offset.test
@@ -20,3 +20,18 @@ RUN: | FileCheck %s --check-prefix=CHILDREN
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: {{:}}
diff --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
index c2bcd382ee3..b8d0f07ce59 100644
--- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
+++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
@@ -131,10 +131,16 @@ 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"));
+ "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;
OpenPOWER on IntegriCloud