diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2017-10-25 21:56:41 +0000 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2017-10-25 21:56:41 +0000 |
commit | f63ee64c4bd7ca18a492cf329f87afe120f34317 (patch) | |
tree | dff1ce26616555d91c45872dc2486959a32a4831 /llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp | |
parent | a932c8745c778b03ffb8f6e7fb2e7d8134d40be3 (diff) | |
download | bcm5719-llvm-f63ee64c4bd7ca18a492cf329f87afe120f34317.tar.gz bcm5719-llvm-f63ee64c4bd7ca18a492cf329f87afe120f34317.zip |
Re-land "[dwarfdump] Add -lookup option"
Add the option to lookup an address in the debug information and print
out the file, function, block and line table details.
Differential revision: https://reviews.llvm.org/D38409
llvm-svn: 316619
Diffstat (limited to 'llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp')
-rw-r--r-- | llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp index 9dad3b91778..04371b7da84 100644 --- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -157,6 +157,11 @@ static list<std::string> Name( "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<unsigned> + Lookup("lookup", + desc("Lookup <address> in the debug information and print out any" + "available file, function, block and line table details."), + value_desc("address"), cat(DwarfDumpCategory)); static opt<std::string> OutputFilename("out-file", cl::init(""), cl::desc("Redirect output to the specified file."), @@ -303,6 +308,30 @@ static void filterByName(const StringSet<> &Names, Die.dump(OS, 0, getDumpOpts()); } } + +} + +/// Handle the --lookup option and dump the DIEs and line info for the given +/// address. +static bool lookup(DWARFContext &DICtx, uint64_t Address, raw_ostream &OS) { + auto DIEsForAddr = DICtx.getDIEsForAddress(Lookup); + + if (!DIEsForAddr) + return false; + + DIDumpOptions DumpOpts = getDumpOpts(); + DumpOpts.RecurseDepth = 0; + DIEsForAddr.CompileUnit->dump(OS, DumpOpts); + if (DIEsForAddr.FunctionDIE) { + DIEsForAddr.FunctionDIE.dump(OS, 2, DumpOpts); + if (DIEsForAddr.BlockDIE) + DIEsForAddr.BlockDIE.dump(OS, 4, DumpOpts); + } + + if (DILineInfo LineInfo = DICtx.getLineInfoForAddress(Lookup)) + LineInfo.dump(OS); + + return true; } bool collectStatsForObjectFile(ObjectFile &Obj, DWARFContext &DICtx, @@ -312,11 +341,14 @@ 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 --lookup option. + if (Lookup) + return lookup(DICtx, Lookup, OS); + // Handle the --name option. if (!Name.empty()) { StringSet<> Names; |