diff options
| author | Adrian Prantl <aprantl@apple.com> | 2017-09-30 00:22:25 +0000 |
|---|---|---|
| committer | Adrian Prantl <aprantl@apple.com> | 2017-09-30 00:22:25 +0000 |
| commit | 61913a1ffa313c24953959badf1967119333dfe0 (patch) | |
| tree | 57472700fb4c7f3632e88b2231f52bda5873c8b2 | |
| parent | a01c38b7a3d2a38a32ab995dfcce0f9c30d87a5e (diff) | |
| download | bcm5719-llvm-61913a1ffa313c24953959badf1967119333dfe0.tar.gz bcm5719-llvm-61913a1ffa313c24953959badf1967119333dfe0.zip | |
llvm-dwarfdump: implement the --name lookup option.
llvm-svn: 314576
| -rw-r--r-- | llvm/test/tools/llvm-dwarfdump/X86/find.test | 2 | ||||
| -rw-r--r-- | llvm/test/tools/llvm-dwarfdump/X86/name.test | 39 | ||||
| -rw-r--r-- | llvm/test/tools/llvm-dwarfdump/cmdline.test | 1 | ||||
| -rw-r--r-- | llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp | 48 |
4 files changed, 80 insertions, 10 deletions
diff --git a/llvm/test/tools/llvm-dwarfdump/X86/find.test b/llvm/test/tools/llvm-dwarfdump/X86/find.test index 2d308b7973d..0606c674f91 100644 --- a/llvm/test/tools/llvm-dwarfdump/X86/find.test +++ b/llvm/test/tools/llvm-dwarfdump/X86/find.test @@ -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: diff --git a/llvm/test/tools/llvm-dwarfdump/X86/name.test b/llvm/test/tools/llvm-dwarfdump/X86/name.test new file mode 100644 index 00000000000..d1cdc40639c --- /dev/null +++ b/llvm/test/tools/llvm-dwarfdump/X86/name.test @@ -0,0 +1,39 @@ +RUN: llvm-mc %S/brief.s -filetype obj -triple x86_64-apple-darwin -o - \ +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 -name=main - | FileCheck %s +CHECK: : DW_TAG_subprogram +CHECK-NOT: {{:}} +CHECK: DW_AT_name ("main") +CHECK-NOT: {{:}} + +RUN: llvm-dwarfdump %S/../../dsymutil/Inputs/libfat-test.a \ +RUN: -name=x86_64h_var -name=i386_var \ +RUN: | FileCheck %s --check-prefix=MULTI +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: 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 -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: -name="(anonymous namespace)" \ +RUN: | FileCheck %s --check-prefix=EMPTY + diff --git a/llvm/test/tools/llvm-dwarfdump/cmdline.test b/llvm/test/tools/llvm-dwarfdump/cmdline.test index 467282457d0..fd06f77dda3 100644 --- a/llvm/test/tools/llvm-dwarfdump/cmdline.test +++ b/llvm/test/tools/llvm-dwarfdump/cmdline.test @@ -7,6 +7,7 @@ HELP: -debug-info - Dump the .debug_info section HELP: -eh-frame HELP: Specific Options HELP: -find +HELP: -name HELP: -recurse-depth=<N> HELP: -show-children HELP: -show-parents diff --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp index c61169626c5..28abe05e889 100644 --- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -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("Verify the DWARF debug info"), 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 &Obj, DWARFContext &DICtx, Twine Filename, 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; |

