llvm.org GIT mirror llvm / 0f41067
llvm-dwarfdump: Extend --name to also search DW_AT_linkage_name. rdar://problem/45132695 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@344079 91177308-0d34-0410-b5e6-96231b3b80d8 Adrian Prantl 1 year, 11 days ago
2 changed file(s) with 37 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
6666 RUN: | llvm-dwarfdump -name="brief.c" - | FileCheck %s -check-prefix=NOCHILDREN
6767 NOCHILDREN: DW_AT_name ("brief.c")
6868 NOCHILDREN-NOT: DW_TAG
69
70 Test that --name also searches in DW_AT_linkage_name.
71 RUN: llc -O0 %S/statistics.ll -filetype obj -o - \
72 RUN: | llvm-dwarfdump -name=_Z4cubei - | FileCheck %s --check-prefix=LINKAGE
73 LINKAGE: DW_AT_name ("cube")
280280 raw_ostream &)>;
281281
282282 /// Print only DIEs that have a certain name.
283 static bool filterByName(const StringSet<> &Names, DWARFDie Die,
284 StringRef NameRef, raw_ostream &OS) {
285 std::string Name =
286 (IgnoreCase && !UseRegex) ? NameRef.lower() : NameRef.str();
287 if (UseRegex) {
288 // Match regular expression.
289 for (auto Pattern : Names.keys()) {
290 Regex RE(Pattern, IgnoreCase ? Regex::IgnoreCase : Regex::NoFlags);
291 std::string Error;
292 if (!RE.isValid(Error)) {
293 errs() << "error in regular expression: " << Error << "\n";
294 exit(1);
295 }
296 if (RE.match(Name)) {
297 Die.dump(OS, 0, getDumpOpts());
298 return true;
299 }
300 }
301 } else if (Names.count(Name)) {
302 // Match full text.
303 Die.dump(OS, 0, getDumpOpts());
304 return true;
305 }
306 return false;
307 }
308
309 /// Print only DIEs that have a certain name.
283310 static void filterByName(const StringSet<> &Names,
284311 DWARFContext::unit_iterator_range CUs,
285312 raw_ostream &OS) {
286313 for (const auto &CU : CUs)
287314 for (const auto &Entry : CU->dies()) {
288315 DWARFDie Die = {CU.get(), &Entry};
289 if (const char *NamePtr = Die.getName(DINameKind::ShortName)) {
290 std::string Name =
291 (IgnoreCase && !UseRegex) ? StringRef(NamePtr).lower() : NamePtr;
292 // Match regular expression.
293 if (UseRegex)
294 for (auto Pattern : Names.keys()) {
295 Regex RE(Pattern, IgnoreCase ? Regex::IgnoreCase : Regex::NoFlags);
296 std::string Error;
297 if (!RE.isValid(Error)) {
298 errs() << "error in regular expression: " << Error << "\n";
299 exit(1);
300 }
301 if (RE.match(Name))
302 Die.dump(OS, 0, getDumpOpts());
303 }
304 // Match full text.
305 else if (Names.count(Name))
306 Die.dump(OS, 0, getDumpOpts());
307 }
316 if (const char *Name = Die.getName(DINameKind::ShortName))
317 if (filterByName(Names, Die, Name, OS))
318 continue;
319 if (const char *Name = Die.getName(DINameKind::LinkageName))
320 filterByName(Names, Die, Name, OS);
308321 }
309322 }
310323