[llvm] r344079 - llvm-dwarfdump: Extend --name to also search DW_AT_linkage_name.
Adrian Prantl via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 9 13:51:33 PDT 2018
Author: adrian
Date: Tue Oct 9 13:51:33 2018
New Revision: 344079
URL: http://llvm.org/viewvc/llvm-project?rev=344079&view=rev
Log:
llvm-dwarfdump: Extend --name to also search DW_AT_linkage_name.
rdar://problem/45132695
Modified:
llvm/trunk/test/tools/llvm-dwarfdump/X86/name.test
llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
Modified: llvm/trunk/test/tools/llvm-dwarfdump/X86/name.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/name.test?rev=344079&r1=344078&r2=344079&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/name.test (original)
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/name.test Tue Oct 9 13:51:33 2018
@@ -67,3 +67,8 @@ RUN: llvm-mc %S/brief.s -filetype obj -t
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")
\ No newline at end of file
Modified: llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp?rev=344079&r1=344078&r2=344079&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp (original)
+++ llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp Tue Oct 9 13:51:33 2018
@@ -281,31 +281,44 @@ using HandlerFn = std::function<bool(Obj
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,
raw_ostream &OS) {
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);
}
}
More information about the llvm-commits
mailing list