summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2017-10-25 21:56:41 +0000
committerJonas Devlieghere <jonas@devlieghere.com>2017-10-25 21:56:41 +0000
commitc2c04200c880e65910231e6a5120f5c2d7e059ea (patch)
treed68ced6f4e14bf3a195979a30ad250e19961f83e /tools
parent5d1f72d3b59d3c827357eee1ca4fbde0c9d2c55e (diff)
downloadllvm-c2c04200c880e65910231e6a5120f5c2d7e059ea.tar.gz
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316619 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/llvm-dwarfdump/llvm-dwarfdump.cpp34
1 files changed, 33 insertions, 1 deletions
diff --git a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
index 9dad3b917783..04371b7da841 100644
--- a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
+++ b/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;