aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/llvm-objdump.cpp
diff options
context:
space:
mode:
authorDaniel Thornburgh <dthorn@google.com>2022-07-15 14:14:13 -0700
committerDaniel Thornburgh <dthorn@google.com>2022-10-04 11:40:36 -0700
commit410c6ca9a4ed7090a3960d960cdfd09f7d08db68 (patch)
tree04c395a2e9f727222472c32a139f2326af31c6d8 /llvm/tools/llvm-objdump/llvm-objdump.cpp
parent2c43cd883c20b603bc7d9461bfa2591e80a36a3b (diff)
downloadllvm-410c6ca9a4ed7090a3960d960cdfd09f7d08db68.zip
llvm-410c6ca9a4ed7090a3960d960cdfd09f7d08db68.tar.gz
llvm-410c6ca9a4ed7090a3960d960cdfd09f7d08db68.tar.bz2
[llvm-objdump] [debuginfod] Fetch for very-stripped binaries.
When a binary is missing section headers or symbols, objdump can't provide as good of a disassembly. This change makes objdump try to fetch a better verion of the binary by its build ID. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D132887
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r--llvm/tools/llvm-objdump/llvm-objdump.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 0c1bb0b..689aa0a 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -1970,6 +1970,22 @@ static void disassembleObject(const Target *TheTarget, ObjectFile &Obj,
}
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<Binary> FetchedBinary;
+ if (Obj->symbols().empty()) {
+ if (Optional<OwningBinary<Binary>> FetchedBinaryOpt =
+ fetchBinaryByBuildID(*Obj)) {
+ if (auto *O = dyn_cast<ObjectFile>(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 @@ static void disassembleObject(ObjectFile *Obj, bool InlineRelocs) {
PrettyPrinter &PIP = selectPrettyPrinter(Triple(TripleName));
const ObjectFile *DbgObj = Obj;
- OwningBinary<Binary> DebugBinary;
- if (!DbgObj->hasDebugInfo()) {
+ if (!FetchedBinary.getBinary() && !Obj->hasDebugInfo()) {
if (Optional<OwningBinary<Binary>> DebugBinaryOpt =
fetchBinaryByBuildID(*Obj)) {
if (auto *FetchedObj =
dyn_cast<const ObjectFile>(DebugBinaryOpt->getBinary())) {
if (FetchedObj->hasDebugInfo()) {
- DebugBinary = std::move(*DebugBinaryOpt);
+ FetchedBinary = std::move(*DebugBinaryOpt);
DbgObj = FetchedObj;
}
}