summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
diff options
context:
space:
mode:
authorAdrian Prantl <aprantl@apple.com>2017-10-03 22:08:22 +0000
committerAdrian Prantl <aprantl@apple.com>2017-10-03 22:08:22 +0000
commite5b93f2e3468cd682dc550f44fe6ee1a24028485 (patch)
tree1541ef70a808eddd03001a29eb5d305ba1586993 /llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
parent2834b006a481758130e3c397f18cefcfdd90ac5d (diff)
downloadbcm5719-llvm-e5b93f2e3468cd682dc550f44fe6ee1a24028485.tar.gz
bcm5719-llvm-e5b93f2e3468cd682dc550f44fe6ee1a24028485.zip
llvm-dwarfdump: implement the --regex option in combination with --name.
llvm-svn: 314855
Diffstat (limited to 'llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp')
-rw-r--r--llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp38
1 files changed, 30 insertions, 8 deletions
diff --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
index 9abc92b7b83..9e6fc773139 100644
--- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
+++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
@@ -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(""),
@@ -163,6 +165,12 @@ 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 "
"printing with the =<offset> option"),
@@ -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);
OpenPOWER on IntegriCloud