1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

llvm-dwarfdump: implement the --regex option in combination with --name.

llvm-svn: 314855
This commit is contained in:
Adrian Prantl 2017-10-03 22:08:22 +00:00
parent 3a760e95ad
commit 7d0f59fbef
3 changed files with 49 additions and 9 deletions

View File

@ -43,4 +43,21 @@ RUN: | llvm-dwarfdump -name=Main - | FileCheck %s -check-prefix=EMPTY
RUN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o - \
RUN: | llvm-dwarfdump -name=Main -i - | FileCheck %s
RUN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o - \
RUN: | llvm-dwarfdump -name=MAIN -ignore-case - | FileCheck %s
RUN: | llvm-dwarfdump -name=MAIN -ignore-case - | FileCheck %s
Test the -regex option.
RUN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o - \
RUN: | llvm-dwarfdump -regex -name=m.+n - | FileCheck %s
RUN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o - \
RUN: | llvm-dwarfdump -x -name=m.+n - | FileCheck %s
RUN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o - \
RUN: | llvm-dwarfdump -x -i -name=M.+n - | FileCheck %s
RUN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o - \
RUN: | not llvm-dwarfdump -x -name=+ - 2>&1 | FileCheck %s --check-prefix=ERR
ERR: error
RUN: llvm-dwarfdump %S/../../dsymutil/Inputs/libfat-test.a \
RUN: -x -name=x86_64h_var -name=i386_var \
RUN: | FileCheck %s --check-prefix=MULTI
RUN: llvm-dwarfdump %S/../../dsymutil/Inputs/libfat-test.a \
RUN: -x -name=.*86.*_var \
RUN: | FileCheck %s --check-prefix=MULTI

View File

@ -10,6 +10,7 @@ HELP: -find
HELP: -ignore-case
HELP: -name
HELP: -recurse-depth=<N>
HELP: -regex
HELP: -show-children
HELP: -show-form
HELP: -show-parents

View File

@ -27,6 +27,7 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/ToolOutputFile.h"
@ -149,11 +150,12 @@ static opt<bool>
value_desc("i"), cat(DwarfDumpCategory));
static alias IgnoreCaseAlias("i", desc("Alias for -ignore-case"),
aliasopt(IgnoreCase));
static list<std::string>
Name("name",
desc("Find and print all debug info entries whose name (DW_AT_name "
"attribute) matches the exact text in <name>."),
value_desc("name"), cat(DwarfDumpCategory));
static list<std::string> Name(
"name",
desc("Find and print all debug info entries whose name (DW_AT_name "
"attribute) matches the exact text in <pattern>. When used with the "
"the -regex option <pattern> is interpreted as a regular expression."),
value_desc("pattern"), cat(DwarfDumpCategory));
static alias NameAlias("n", desc("Alias for -name"), aliasopt(Name));
static opt<std::string>
OutputFilename("out-file", cl::init(""),
@ -162,6 +164,12 @@ static opt<std::string>
static alias OutputFilenameAlias("o", desc("Alias for -out-file"),
aliasopt(OutputFilename),
cat(DwarfDumpCategory));
static opt<bool>
UseRegex("regex",
desc("Treat any <pattern> strings as regular expressions when "
"searching instead of just as an exact string match."),
cat(DwarfDumpCategory));
static alias RegexAlias("x", desc("Alias for -regex"), aliasopt(UseRegex));
static opt<bool>
ShowChildren("show-children",
desc("Show a debug info entry's children when selectively "
@ -272,8 +280,22 @@ static void filterByName(const StringSet<> &Names,
for (const auto &Entry : CU->dies()) {
DWARFDie Die = {CU.get(), &Entry};
if (const char *NamePtr = Die.getName(DINameKind::ShortName)) {
std::string Name = IgnoreCase ? StringRef(NamePtr).lower() : NamePtr;
if (Names.count(Name))
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());
}
}
@ -292,7 +314,7 @@ static bool dumpObjectFile(ObjectFile &Obj, DWARFContext &DICtx, Twine Filename,
if (!Name.empty()) {
StringSet<> Names;
for (auto name : Name)
Names.insert(IgnoreCase ? StringRef(name).lower() : name);
Names.insert((IgnoreCase && !UseRegex) ? StringRef(name).lower() : name);
filterByName(Names, DICtx.compile_units(), OS);
filterByName(Names, DICtx.dwo_compile_units(), OS);