llvm-dwarfdump: add a --show-parents options when selectively dumping DIEs.

llvm-svn: 313567
This commit is contained in:
Adrian Prantl 2017-09-18 21:27:44 +00:00
parent f077b5b885
commit c2bc717028
4 changed files with 40 additions and 2 deletions

View File

@ -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;
};

View File

@ -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);

View File

@ -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: {{:}}

View File

@ -131,9 +131,15 @@ 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"));
@ -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;