diff --git a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp index 9618a1a4bba..66d5a72ea44 100644 --- a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -35,6 +35,10 @@ static cl::list InputFilenames(cl::Positional, cl::desc(""), cl::ZeroOrMore); +static cl::opt +Address("address", cl::init(-1ULL), + cl::desc("Print line information for a given address")); + static void DumpInput(const StringRef &Filename) { OwningPtr Buff; @@ -45,10 +49,6 @@ static void DumpInput(const StringRef &Filename) { OwningPtr Obj(ObjectFile::createObjectFile(Buff.take())); - outs() << '\n'; - outs() << Filename - << ":\tfile format " << Obj->getFileFormatName() << "\n\n"; - StringRef DebugInfoSection; StringRef DebugAbbrevSection; StringRef DebugLineSection; @@ -85,7 +85,17 @@ static void DumpInput(const StringRef &Filename) { DebugArangesSection, DebugLineSection, DebugStringSection)); - dictx->dump(outs()); + if (Address == -1ULL) { + outs() << Filename + << ":\tfile format " << Obj->getFileFormatName() << "\n\n"; + // Dump the complete DWARF structure. + dictx->dump(outs()); + } else { + // Print line info for the specified address. + DILineInfo dli = dictx->getLineInfoForAddress(Address); + outs() << (dli.getFileName() ? dli.getFileName() : "") << ':' + << dli.getLine() << ':' << dli.getColumn() << '\n'; + } } int main(int argc, char **argv) {