diff options
author | Adrian Prantl <aprantl@apple.com> | 2017-09-15 22:37:56 +0000 |
---|---|---|
committer | Adrian Prantl <aprantl@apple.com> | 2017-09-15 22:37:56 +0000 |
commit | fb5d284e976ed39bd1a0a7d7032a5e77adb2c60e (patch) | |
tree | f58c583c42b66c46f58bcd645042f28c47e6db1b /llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp | |
parent | ad66fefdca18eeb9966d1a0cd426da4a6262765e (diff) | |
download | bcm5719-llvm-fb5d284e976ed39bd1a0a7d7032a5e77adb2c60e.tar.gz bcm5719-llvm-fb5d284e976ed39bd1a0a7d7032a5e77adb2c60e.zip |
llvm-dwarfdump: Add support for -debug-info=<offset>.
This is the first of many commits that enable selectively dumping just
one record from the debug info.
llvm-svn: 313412
Diffstat (limited to 'llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp')
-rw-r--r-- | llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp | 83 |
1 files changed, 73 insertions, 10 deletions
diff --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp index 823eb8e8133..7671bd8adaf 100644 --- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -37,8 +37,59 @@ using namespace llvm; using namespace object; +/// Parser for options that take an optional offest argument. +/// @{ +struct OffsetOption { + uint64_t Val = 0; + bool HasValue = false; + bool IsRequested = false; +}; + +template <> +class cl::parser<OffsetOption> final : public cl::basic_parser<OffsetOption> { +public: + parser(Option &O) : basic_parser(O) {} + + /// Return true on error. + bool parse(Option &O, StringRef ArgName, StringRef Arg, OffsetOption &Val) { + if (Arg == "") { + Val.Val = 0; + Val.HasValue = false; + Val.IsRequested = true; + return false; + } + if (Arg.getAsInteger(0, Val.Val)) + return O.error("'" + Arg + "' value invalid for integer argument!"); + Val.HasValue = true; + Val.IsRequested = true; + return false; + } + + enum ValueExpected getValueExpectedFlagDefault() const { + return ValueOptional; + } + + void printOptionInfo(const Option &O, size_t GlobalWidth) const { + outs() << " -" << O.ArgStr; + Option::printHelpStr(O.HelpStr, GlobalWidth, getOptionWidth(O)); + } + + void printOptionDiff(const Option &O, OffsetOption V, OptVal Default, + size_t GlobalWidth) const { + printOptionName(O, GlobalWidth); + outs() << "[=offset]"; + } + + // An out-of-line virtual method to provide a 'home' for this class. + void anchor() override {}; +}; + +/// @} +/// Command line options. +/// @{ + namespace { -using namespace llvm::cl; +using namespace cl; OptionCategory DwarfDumpCategory("Specific Options"); static opt<bool> Help("h", desc("Alias for -help"), Hidden, @@ -47,20 +98,26 @@ static list<std::string> InputFilenames(Positional, desc("<input object files or .dSYM bundles>"), ZeroOrMore, cat(DwarfDumpCategory)); -cl::OptionCategory - SectionCategory("Section-specific Dump Options", - "These control which sections are dumped."); +cl::OptionCategory SectionCategory("Section-specific Dump Options", + "These control which sections are dumped. " + "Where applicable these parameters take an " + "optional =<offset> argument to dump only " + "the entry at the specified offset."); + static opt<bool> DumpAll("all", desc("Dump all debug info sections"), cat(SectionCategory)); static alias DumpAllAlias("a", desc("Alias for -all"), aliasopt(DumpAll)); +// Options for dumping specific sections. static unsigned DumpType = DIDT_Null; +static std::array<Optional<uint64_t>, DIDT_ID_Count> DumpOffsets; #define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME) \ - static opt<bool> Dump##ENUM_NAME(CMDLINE_NAME, \ - desc("Dump the " ELF_NAME " section"), \ - cat(SectionCategory)); + static opt<OffsetOption> Dump##ENUM_NAME( \ + CMDLINE_NAME, desc("Dump the " ELF_NAME " section"), \ + cat(SectionCategory)); #include "llvm/BinaryFormat/Dwarf.def" #undef HANDLE_DWARF_SECTION + static opt<bool> DumpUUID("uuid", desc("Show the UUID for each architecture"), cat(DwarfDumpCategory)); static alias DumpUUIDAlias("u", desc("Alias for -uuid"), aliasopt(DumpUUID)); @@ -78,6 +135,9 @@ static opt<bool> Verbose("verbose", static alias VerboseAlias("v", desc("Alias for -verbose"), aliasopt(Verbose), cat(DwarfDumpCategory)); } // namespace +/// @} +//===----------------------------------------------------------------------===// + static void error(StringRef Filename, std::error_code EC) { if (!EC) @@ -103,7 +163,7 @@ static bool dumpObjectFile(ObjectFile &Obj, Twine Filename) { outs() << Filename << ":\tfile format " << Obj.getFileFormatName() << '\n'; // Dump the complete DWARF structure. - DICtx->dump(outs(), getDumpOpts()); + DICtx->dump(outs(), getDumpOpts(), DumpOffsets); return true; } @@ -237,8 +297,11 @@ int main(int argc, char **argv) { // Defaults to dumping all sections, unless brief mode is specified in which // case only the .debug_info section in dumped. #define HANDLE_DWARF_SECTION(ENUM_NAME, ELF_NAME, CMDLINE_NAME) \ - if (Dump##ENUM_NAME) \ - DumpType |= DIDT_##ENUM_NAME; + if (Dump##ENUM_NAME.IsRequested) { \ + DumpType |= DIDT_##ENUM_NAME; \ + if (Dump##ENUM_NAME.HasValue) \ + DumpOffsets[DIDT_ID_##ENUM_NAME] = Dump##ENUM_NAME.Val; \ + } #include "llvm/BinaryFormat/Dwarf.def" #undef HANDLE_DWARF_SECTION if (DumpUUID) |