llvm.org GIT mirror llvm / 1a23ac0
[dwarfdump] Add flag to limit the number of parents DIEs This adds `-parent-recurse-depth` which limits the number of parent DIEs being dumped. Differential revision: https://reviews.llvm.org/D62359 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361671 91177308-0d34-0410-b5e6-96231b3b80d8 Jonas Devlieghere 4 months ago
6 changed file(s) with 46 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
9696 void addFrame(const DILineInfo &Frame) {
9797 Frames.push_back(Frame);
9898 }
99
99
100100 void resize(unsigned i) {
101101 Frames.resize(i);
102102 }
103
104103 };
105104
106105 /// Container for description of a global variable.
156155 /// dumped.
157156 struct DIDumpOptions {
158157 unsigned DumpType = DIDT_All;
159 unsigned RecurseDepth = -1U;
158 unsigned ChildRecurseDepth = -1U;
159 unsigned ParentRecurseDepth = -1U;
160160 uint16_t Version = 0; // DWARF version to assume when extracting.
161161 uint8_t AddrSize = 4; // Address byte size to assume when extracting.
162162 bool ShowAddresses = true;
170170 /// Return default option set for printing a single DIE without children.
171171 static DIDumpOptions getForSingleDIE() {
172172 DIDumpOptions Opts;
173 Opts.RecurseDepth = 0;
173 Opts.ChildRecurseDepth = 0;
174 Opts.ParentRecurseDepth = 0;
174175 return Opts;
175176 }
176177
177178 /// Return the options with RecurseDepth set to 0 unless explicitly required.
178179 DIDumpOptions noImplicitRecursion() const {
179180 DIDumpOptions Opts = *this;
180 if (RecurseDepth == -1U && !ShowChildren)
181 Opts.RecurseDepth = 0;
181 if (ChildRecurseDepth == -1U && !ShowChildren)
182 Opts.ChildRecurseDepth = 0;
183 if (ParentRecurseDepth == -1U && !ShowParents)
184 Opts.ParentRecurseDepth = 0;
182185 return Opts;
183186 }
184187 };
552552
553553 /// Helper to dump a DIE with all of its parents, but no siblings.
554554 static unsigned dumpParentChain(DWARFDie Die, raw_ostream &OS, unsigned Indent,
555 DIDumpOptions DumpOpts) {
555 DIDumpOptions DumpOpts, unsigned Depth = 0) {
556556 if (!Die)
557557 return Indent;
558 Indent = dumpParentChain(Die.getParent(), OS, Indent, DumpOpts);
558 if (DumpOpts.ParentRecurseDepth > 0 && Depth >= DumpOpts.ParentRecurseDepth)
559 return Indent;
560 Indent = dumpParentChain(Die.getParent(), OS, Indent, DumpOpts, Depth + 1);
559561 Die.dump(OS, Indent, DumpOpts);
560562 return Indent + 2;
561563 }
603605 }
604606
605607 DWARFDie child = getFirstChild();
606 if (DumpOpts.ShowChildren && DumpOpts.RecurseDepth > 0 && child) {
607 DumpOpts.RecurseDepth--;
608 if (DumpOpts.ShowChildren && DumpOpts.ChildRecurseDepth > 0 && child) {
609 DumpOpts.ChildRecurseDepth--;
608610 DIDumpOptions ChildDumpOpts = DumpOpts;
609611 ChildDumpOpts.ShowParents = false;
610612 while (child) {
11 # RUN: llvm-dwarfdump --debug-info=0x0000002a -p %t | FileCheck %s --check-prefix=PARENTS
22 # RUN: llvm-dwarfdump --debug-info=0x0000002a -c %t | FileCheck %s --check-prefix=CHILDREN
33 # RUN: llvm-dwarfdump --debug-info=0x0000002a -p -c %t | FileCheck %s --check-prefix=BOTH
4 # RUN: llvm-dwarfdump --debug-info=0x00000032 -p -parent-recurse-depth 1 -c %t | FileCheck %s --check-prefix=ONEPARENT
45
56 # PARENTS: DW_TAG_compile_unit
67 # PARENTS: DW_TAG_enumeration_type
78 # PARENTS-NOT: DW_TAG_enumerator
9
10 # ONEPARENT-NOT: DW_TAG_compile_unit
11 # ONEPARENT: DW_TAG_enumeration_type
12 # ONEPARENT: DW_TAG_enumerator
813
914 # CHILDREN-NOT: DW_TAG_compile_unit
1015 # CHILDREN: DW_TAG_enumerator
1212 HELP: -ignore-case
1313 HELP: -lookup
1414 HELP: -name
15 HELP: -parent-recurse-depth=
1516 HELP: -recurse-depth=
1617 HELP: -regex
1718 HELP: -show-children
226226 return;
227227
228228 DIDumpOptions DumpOpts;
229 DumpOpts.RecurseDepth = 0;
229 DumpOpts.ChildRecurseDepth = 0;
230230 DumpOpts.Verbose = Options.Verbose;
231231
232232 WithColor::note() << " in DIE:\n";
648648
649649 if (Options.Verbose) {
650650 DIDumpOptions DumpOpts;
651 DumpOpts.RecurseDepth = 0;
651 DumpOpts.ChildRecurseDepth = 0;
652652 DumpOpts.Verbose = Options.Verbose;
653653 DIE.dump(outs(), 8 /* Indent */, DumpOpts);
654654 }
684684
685685 if (Options.Verbose) {
686686 DIDumpOptions DumpOpts;
687 DumpOpts.RecurseDepth = 0;
687 DumpOpts.ChildRecurseDepth = 0;
688688 DumpOpts.Verbose = Options.Verbose;
689689 DIE.dump(outs(), 8 /* Indent */, DumpOpts);
690690 }
20952095 Linker.AssignAbbrev(Copy);
20962096 }
20972097
2098 uint32_t DwarfLinker::DIECloner::hashFullyQualifiedName(
2099 DWARFDie DIE, CompileUnit &U, const DebugMapObject &DMO, int RecurseDepth) {
2098 uint32_t
2099 DwarfLinker::DIECloner::hashFullyQualifiedName(DWARFDie DIE, CompileUnit &U,
2100 const DebugMapObject &DMO,
2101 int ChildRecurseDepth) {
21002102 const char *Name = nullptr;
21012103 DWARFUnit *OrigUnit = &U.getOrigUnit();
21022104 CompileUnit *CU = &U;
21302132 // FIXME: dsymutil-classic compatibility. Ignore modules.
21312133 CU->getOrigUnit().getDIEAtIndex(CU->getInfo(Idx).ParentIdx).getTag() ==
21322134 dwarf::DW_TAG_module)
2133 return djbHash(Name ? Name : "", djbHash(RecurseDepth ? "" : "::"));
2135 return djbHash(Name ? Name : "", djbHash(ChildRecurseDepth ? "" : "::"));
21342136
21352137 DWARFDie Die = OrigUnit->getDIEAtIndex(CU->getInfo(Idx).ParentIdx);
21362138 return djbHash(
21372139 (Name ? Name : ""),
21382140 djbHash((Name ? "::" : ""),
2139 hashFullyQualifiedName(Die, *CU, DMO, ++RecurseDepth)));
2141 hashFullyQualifiedName(Die, *CU, DMO, ++ChildRecurseDepth)));
21402142 }
21412143
21422144 static uint64_t getDwoId(const DWARFDie &CUDie, const DWARFUnit &Unit) {
26552657 if (Options.Verbose) {
26562658 outs() << "Input compilation unit:";
26572659 DIDumpOptions DumpOpts;
2658 DumpOpts.RecurseDepth = 0;
2660 DumpOpts.ChildRecurseDepth = 0;
26592661 DumpOpts.Verbose = Options.Verbose;
26602662 CUDie.dump(outs(), 0, DumpOpts);
26612663 }
191191 cat(DwarfDumpCategory));
192192 static alias ShowFormAlias("F", desc("Alias for -show-form."),
193193 aliasopt(ShowForm), cat(DwarfDumpCategory));
194 static opt RecurseDepth(
195 "recurse-depth",
196 desc("Only recurse to a depth of N when displaying debug info entries."),
197 cat(DwarfDumpCategory), init(-1U), value_desc("N"));
198 static alias RecurseDepthAlias("r", desc("Alias for -recurse-depth."),
199 aliasopt(RecurseDepth));
200
194 static opt
195 ChildRecurseDepth("recurse-depth",
196 desc("Only recurse to a depth of N when displaying "
197 "children of debug info entries."),
198 cat(DwarfDumpCategory), init(-1U), value_desc("N"));
199 static alias ChildRecurseDepthAlias("r", desc("Alias for -recurse-depth."),
200 aliasopt(ChildRecurseDepth));
201 static opt
202 ParentRecurseDepth("parent-recurse-depth",
203 desc("Only recurse to a depth of N when displaying "
204 "parents of debug info entries."),
205 cat(DwarfDumpCategory), init(-1U), value_desc("N"));
201206 static opt
202207 SummarizeTypes("summarize-types",
203208 desc("Abbreviate the description of type unit entries."),
232237 static DIDumpOptions getDumpOpts() {
233238 DIDumpOptions DumpOpts;
234239 DumpOpts.DumpType = DumpType;
235 DumpOpts.RecurseDepth = RecurseDepth;
240 DumpOpts.ChildRecurseDepth = ChildRecurseDepth;
241 DumpOpts.ParentRecurseDepth = ParentRecurseDepth;
236242 DumpOpts.ShowAddresses = !Diff;
237243 DumpOpts.ShowChildren = ShowChildren;
238244 DumpOpts.ShowParents = ShowParents;
388394 return false;
389395
390396 DIDumpOptions DumpOpts = getDumpOpts();
391 DumpOpts.RecurseDepth = 0;
397 DumpOpts.ChildRecurseDepth = 0;
392398 DIEsForAddr.CompileUnit->dump(OS, DumpOpts);
393399 if (DIEsForAddr.FunctionDIE) {
394400 DIEsForAddr.FunctionDIE.dump(OS, 2, DumpOpts);