diff --git a/llvm/test/tools/llvm-objdump/debuginfod.test b/llvm/test/tools/llvm-objdump/debuginfod.test --- a/llvm/test/tools/llvm-objdump/debuginfod.test +++ b/llvm/test/tools/llvm-objdump/debuginfod.test @@ -61,5 +61,32 @@ RUN: FileCheck %s --check-prefix=NOTFOUND RUN: count 0 < %t.err +# Use debuginfod to recover symbols. +RUN: llvm-strip --strip-sections %t/stripped +RUN: env DEBUGINFOD_CACHE_PATH=%t llvm-objdump -d --debuginfod \ +RUN: %t/stripped | \ +RUN: FileCheck %s --check-prefix=SYMBOLS + +# Use debuginfod to recover section headers, but not symbols. +RUN: mkdir %t/stripped-symbols +RUN: cp %p/Inputs/embedded-source %t/stripped-symbols/llvmcache-7361776989772977641 +RUN: llvm-strip %t/stripped-symbols/llvmcache-7361776989772977641 +RUN: env DEBUGINFOD_CACHE_PATH=%t/stripped-symbols llvm-objdump -d \ +RUN: --debuginfod %t/stripped | \ +RUN: FileCheck %s --check-prefix=SECTIONS + +# Don't use debuginfod if neither section headers nor symbols can be recovered. +RUN: mkdir %t/stripped-sections +RUN: echo "" | llvm-mc -filetype=obj -triple x86_64 > \ +RUN: %t/stripped-sections/llvmcache-7361776989772977641 +RUN: llvm-strip --strip-sections %t/stripped-sections/llvmcache-7361776989772977641 +RUN: env DEBUGINFOD_CACHE_PATH=%t/stripped-sections llvm-objdump -d \ +RUN: --debuginfod %t/stripped | \ +RUN: FileCheck %s --check-prefix=NOSECTIONS + NOTFOUND-NOT: int main(int argc, char *argv[]) { FOUND: int main(int argc, char *argv[]) { + +SYMBOLS:
: +SECTIONS: <.text>: +NOSECTIONS: : diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -1970,6 +1970,22 @@ } static void disassembleObject(ObjectFile *Obj, bool InlineRelocs) { + // If information useful for showing the disassembly is missing, try to find a + // more complete binary and disassemble that instead. + OwningBinary FetchedBinary; + if (Obj->symbols().empty()) { + if (Optional> FetchedBinaryOpt = + fetchBinaryByBuildID(*Obj)) { + if (auto *O = dyn_cast(FetchedBinaryOpt->getBinary())) { + if (!O->symbols().empty() || + (!O->sections().empty() && Obj->sections().empty())) { + FetchedBinary = std::move(*FetchedBinaryOpt); + Obj = O; + } + } + } + } + const Target *TheTarget = getTarget(Obj); // Package up features to be passed to target/subtarget @@ -2074,14 +2090,13 @@ PrettyPrinter &PIP = selectPrettyPrinter(Triple(TripleName)); const ObjectFile *DbgObj = Obj; - OwningBinary DebugBinary; - if (!DbgObj->hasDebugInfo()) { + if (!FetchedBinary.getBinary() && !Obj->hasDebugInfo()) { if (Optional> DebugBinaryOpt = fetchBinaryByBuildID(*Obj)) { if (auto *FetchedObj = dyn_cast(DebugBinaryOpt->getBinary())) { if (FetchedObj->hasDebugInfo()) { - DebugBinary = std::move(*DebugBinaryOpt); + FetchedBinary = std::move(*DebugBinaryOpt); DbgObj = FetchedObj; } }