[llvm] r314855 - llvm-dwarfdump: implement the --regex option in combination with --name.
Adrian Prantl via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 3 15:08:23 PDT 2017
Author: adrian
Date: Tue Oct 3 15:08:22 2017
New Revision: 314855
URL: http://llvm.org/viewvc/llvm-project?rev=314855&view=rev
Log:
llvm-dwarfdump: implement the --regex option in combination with --name.
Modified:
llvm/trunk/test/tools/llvm-dwarfdump/X86/name.test
llvm/trunk/test/tools/llvm-dwarfdump/cmdline.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=314855&r1=314854&r2=314855&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/name.test (original)
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/name.test Tue Oct 3 15:08:22 2017
@@ -43,4 +43,21 @@ RUN: | llvm-dwarfdump -name=Main - | F
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
\ No newline at end of file
+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
Modified: llvm/trunk/test/tools/llvm-dwarfdump/cmdline.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/cmdline.test?rev=314855&r1=314854&r2=314855&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-dwarfdump/cmdline.test (original)
+++ llvm/trunk/test/tools/llvm-dwarfdump/cmdline.test Tue Oct 3 15:08:22 2017
@@ -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
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=314855&r1=314854&r2=314855&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp (original)
+++ llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp Tue Oct 3 15:08:22 2017
@@ -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", de
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
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 &O
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);
More information about the llvm-commits
mailing list