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
#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"
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(""),
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"),
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());
}
}
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);