[llvm] r314576 - llvm-dwarfdump: implement the --name lookup option.
Adrian Prantl via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 29 17:22:25 PDT 2017
Author: adrian
Date: Fri Sep 29 17:22:25 2017
New Revision: 314576
URL: http://llvm.org/viewvc/llvm-project?rev=314576&view=rev
Log:
llvm-dwarfdump: implement the --name lookup option.
Added:
llvm/trunk/test/tools/llvm-dwarfdump/X86/name.test
- copied, changed from r314575, llvm/trunk/test/tools/llvm-dwarfdump/X86/find.test
Modified:
llvm/trunk/test/tools/llvm-dwarfdump/X86/find.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/find.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/find.test?rev=314576&r1=314575&r2=314576&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/find.test (original)
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/find.test Fri Sep 29 17:22:25 2017
@@ -12,7 +12,7 @@ CHECK-NOT: {{:}}
CHECK: DW_AT_name ("main")
CHECK-NOT: {{:}}
-RUN: llvm-dwarfdump --debug-info %S/../../dsymutil/Inputs/libfat-test.a \
+RUN: llvm-dwarfdump %S/../../dsymutil/Inputs/libfat-test.a \
RUN: -find=x86_64h_var -find=i386_var \
RUN: | FileCheck %s --check-prefix=MULTI
MULTI: .debug_info contents:
Copied: llvm/trunk/test/tools/llvm-dwarfdump/X86/name.test (from r314575, llvm/trunk/test/tools/llvm-dwarfdump/X86/find.test)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/name.test?p2=llvm/trunk/test/tools/llvm-dwarfdump/X86/name.test&p1=llvm/trunk/test/tools/llvm-dwarfdump/X86/find.test&r1=314575&r2=314576&rev=314576&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/find.test (original)
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/name.test Fri Sep 29 17:22:25 2017
@@ -1,44 +1,39 @@
RUN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o - \
-RUN: | llvm-dwarfdump -find=not_there_at_all - | \
+RUN: | llvm-dwarfdump -name=not_there_at_all - | \
RUN: FileCheck %s --check-prefix=EMPTY --allow-empty
EMPTY: {{^$}}
RUN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o - \
-RUN: | llvm-dwarfdump -find=main - | FileCheck %s
-CHECK: .debug_info contents:
-CHECK-NOT: {{:}}
+RUN: | llvm-dwarfdump -name=main - | FileCheck %s
CHECK: : DW_TAG_subprogram
CHECK-NOT: {{:}}
CHECK: DW_AT_name ("main")
CHECK-NOT: {{:}}
-RUN: llvm-dwarfdump --debug-info %S/../../dsymutil/Inputs/libfat-test.a \
-RUN: -find=x86_64h_var -find=i386_var \
+RUN: llvm-dwarfdump %S/../../dsymutil/Inputs/libfat-test.a \
+RUN: -name=x86_64h_var -name=i386_var \
RUN: | FileCheck %s --check-prefix=MULTI
-MULTI: .debug_info contents:
+MULTI: Mach-O 32-bit i386
MULTI-NOT: {{: DW}}
MULTI: : DW_TAG_variable
MULTI-NOT: {{: DW}}
MULTI: DW_AT_name ("i386_var")
MULTI-NOT: {{: DW}}
-MULTI: .debug_info contents:
+MULTI: Mach-O 64-bit x86-64
MULTI: : DW_TAG_variable
MULTI-NOT: {{: DW}}
MULTI: DW_AT_name ("x86_64h_var")
MULTI-NOT: {{: DW}}
RUN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o - \
-RUN: | llvm-dwarfdump -find=int - | FileCheck %s --check-prefix=TYPES
-TYPES: .debug_info contents:
-TYPES-NOT: {{:}}
+RUN: | llvm-dwarfdump -name=int - | FileCheck %s --check-prefix=TYPES
TYPES: : DW_TAG_base_type
TYPES-NOT: {{:}}
TYPES: DW_AT_name ("int")
TYPES-NOT: {{:}}
+This is one where --name observably behaves different from --find.
RUN: llvm-dwarfdump %S/../../dsymutil/Inputs/odr-anon-namespace/1.o \
-RUN: -find="(anonymous namespace)" \
-RUN: | FileCheck %s --check-prefix=NAMESPACE
-NAMESPACE-NOT: {{: DW}}
-NAMESPACE: 0x0000005b: DW_TAG_namespace
-NAMESPACE-NOT: {{: DW}}
+RUN: -name="(anonymous namespace)" \
+RUN: | FileCheck %s --check-prefix=EMPTY
+
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=314576&r1=314575&r2=314576&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-dwarfdump/cmdline.test (original)
+++ llvm/trunk/test/tools/llvm-dwarfdump/cmdline.test Fri Sep 29 17:22:25 2017
@@ -7,6 +7,7 @@ HELP: -debug-info - Dump the
HELP: -eh-frame
HELP: Specific Options
HELP: -find
+HELP: -name
HELP: -recurse-depth=<N>
HELP: -show-children
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=314576&r1=314575&r2=314576&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp (original)
+++ llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp Fri Sep 29 17:22:25 2017
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/Triple.h"
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
@@ -137,13 +138,17 @@ static list<std::string>
static list<std::string>
Find("find",
desc("Search for the exact match for <name> in the accelerator tables "
- "and print the matching debug information entries."),
+ "and print the matching debug information entries. When there no "
+ "accelerator tables avilable, the slower but more complete -name "
+ "option can be used."),
value_desc("name"), cat(DwarfDumpCategory));
static alias FindAlias("f", desc("Alias for -find"), aliasopt(Find));
-
-static opt<bool> DumpUUID("uuid", desc("Show the UUID for each architecture"),
- cat(DwarfDumpCategory));
-static alias DumpUUIDAlias("u", desc("Alias for -uuid"), aliasopt(DumpUUID));
+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 alias NameAlias("n", desc("Alias for -name"), aliasopt(Name));
static opt<std::string>
OutputFilename("out-file", cl::init(""),
cl::desc("Redirect output to the specified file"),
@@ -180,6 +185,9 @@ static opt<bool> Verify("verify", desc("
cat(DwarfDumpCategory));
static opt<bool> Quiet("quiet", desc("Use with -verify to not emit to STDOUT."),
cat(DwarfDumpCategory));
+static opt<bool> DumpUUID("uuid", desc("Show the UUID for each architecture"),
+ cat(DwarfDumpCategory));
+static alias DumpUUIDAlias("u", desc("Alias for -uuid"), aliasopt(DumpUUID));
static opt<bool> Verbose("verbose",
desc("Print more low-level encoding details"),
cat(DwarfDumpCategory));
@@ -244,11 +252,37 @@ static bool filterArch(ObjectFile &Obj)
using HandlerFn = std::function<bool(ObjectFile &, DWARFContext &DICtx, Twine,
raw_ostream &)>;
+/// Print only DIEs that have a certain name.
+static void filterByName(const StringSet<> &Names,
+ DWARFContext::cu_iterator_range CUs, raw_ostream &OS) {
+ for (const auto &CU : CUs)
+ for (const auto &Entry : CU->dies()) {
+ DWARFDie Die = {CU.get(), &Entry};
+ if (Names.count(Die.getName(DINameKind::ShortName)))
+ Die.dump(OS, 0, getDumpOpts());
+ }
+}
+
static bool dumpObjectFile(ObjectFile &Obj, DWARFContext &DICtx, Twine Filename,
raw_ostream &OS) {
logAllUnhandledErrors(DICtx.loadRegisterInfo(Obj), errs(),
Filename.str() + ": ");
+ // The UUID dump already contains all the same information.
+ if (!(DumpType & DIDT_UUID) || DumpType == DIDT_All)
+ OS << Filename << ":\tfile format " << Obj.getFileFormatName() << '\n';
+
+ // Handle the --name option.
+ if (!Name.empty()) {
+ StringSet<> Names;
+ for (auto name : Name)
+ Names.insert(name);
+
+ filterByName(Names, DICtx.compile_units(), OS);
+ filterByName(Names, DICtx.dwo_compile_units(), OS);
+ return true;
+ }
+
// Handle the --find option and lower it to --debug-info=<offset>.
if (!Find.empty()) {
DumpOffsets[DIDT_ID_DebugInfo] = [&]() -> llvm::Optional<uint64_t> {
@@ -275,10 +309,6 @@ static bool dumpObjectFile(ObjectFile &O
return true;
}
- // The UUID dump already contains all the same information.
- if (!(DumpType & DIDT_UUID) || DumpType == DIDT_All)
- OS << Filename << ":\tfile format " << Obj.getFileFormatName() << '\n';
-
// Dump the complete DWARF structure.
DICtx.dump(OS, getDumpOpts(), DumpOffsets);
return true;
More information about the llvm-commits
mailing list