1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

llvm-dwarfdump: Extend --name to also search DW_AT_linkage_name.

rdar://problem/45132695

llvm-svn: 344079
This commit is contained in:
Adrian Prantl 2018-10-09 20:51:33 +00:00
parent 0301b4b6ef
commit 4fb6cc95d4
2 changed files with 37 additions and 19 deletions

View File

@ -67,3 +67,8 @@ 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
Test that --name also searches in DW_AT_linkage_name.
RUN: llc -O0 %S/statistics.ll -filetype obj -o - \
RUN: | llvm-dwarfdump -name=_Z4cubei - | FileCheck %s --check-prefix=LINKAGE
LINKAGE: DW_AT_name ("cube")

View File

@ -280,6 +280,33 @@ static bool filterArch(ObjectFile &Obj) {
using HandlerFn = std::function<bool(ObjectFile &, DWARFContext &DICtx, Twine,
raw_ostream &)>;
/// Print only DIEs that have a certain name.
static bool filterByName(const StringSet<> &Names, DWARFDie Die,
StringRef NameRef, raw_ostream &OS) {
std::string Name =
(IgnoreCase && !UseRegex) ? NameRef.lower() : NameRef.str();
if (UseRegex) {
// Match regular expression.
for (auto Pattern : Names.keys()) {
Regex RE(Pattern, IgnoreCase ? Regex::IgnoreCase : Regex::NoFlags);
std::string Error;
if (!RE.isValid(Error)) {
errs() << "error in regular expression: " << Error << "\n";
exit(1);
}
if (RE.match(Name)) {
Die.dump(OS, 0, getDumpOpts());
return true;
}
}
} else if (Names.count(Name)) {
// Match full text.
Die.dump(OS, 0, getDumpOpts());
return true;
}
return false;
}
/// Print only DIEs that have a certain name.
static void filterByName(const StringSet<> &Names,
DWARFContext::unit_iterator_range CUs,
@ -287,25 +314,11 @@ static void filterByName(const StringSet<> &Names,
for (const auto &CU : CUs)
for (const auto &Entry : CU->dies()) {
DWARFDie Die = {CU.get(), &Entry};
if (const char *NamePtr = Die.getName(DINameKind::ShortName)) {
std::string Name =
(IgnoreCase && !UseRegex) ? StringRef(NamePtr).lower() : NamePtr;
// Match regular expression.
if (UseRegex)
for (auto Pattern : Names.keys()) {
Regex RE(Pattern, IgnoreCase ? Regex::IgnoreCase : Regex::NoFlags);
std::string Error;
if (!RE.isValid(Error)) {
errs() << "error in regular expression: " << Error << "\n";
exit(1);
}
if (RE.match(Name))
Die.dump(OS, 0, getDumpOpts());
}
// Match full text.
else if (Names.count(Name))
Die.dump(OS, 0, getDumpOpts());
}
if (const char *Name = Die.getName(DINameKind::ShortName))
if (filterByName(Names, Die, Name, OS))
continue;
if (const char *Name = Die.getName(DINameKind::LinkageName))
filterByName(Names, Die, Name, OS);
}
}