[PATCH] D132887: [llvm-objdump] [debuginfod] Fetch for very-stripped binaries.
Daniel Thornburgh via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 4 10:33:58 PDT 2022
mysterymath updated this revision to Diff 465072.
mysterymath added a comment.
Update the no-section dump syntax.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132887/new/
https://reviews.llvm.org/D132887
Files:
llvm/test/tools/llvm-objdump/debuginfod.test
llvm/tools/llvm-objdump/llvm-objdump.cpp
Index: llvm/tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -1966,6 +1966,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<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
@@ -2069,14 +2085,13 @@
PrettyPrinter &PIP = selectPrettyPrinter(Triple(TripleName));
ObjectFile *DbgObj = Obj;
- OwningBinary<Binary> DebugBinary;
- if (!Obj->hasDebugInfo()) {
+ if (!FetchedBinary.getBinary() && !Obj->hasDebugInfo()) {
if (Optional<OwningBinary<Binary>> DebugBinaryOpt =
fetchBinaryByBuildID(*Obj)) {
if (ObjectFile *FetchedObj =
dyn_cast<ObjectFile>(DebugBinaryOpt->getBinary())) {
if (FetchedObj->hasDebugInfo()) {
- DebugBinary = std::move(*DebugBinaryOpt);
+ FetchedBinary = std::move(*DebugBinaryOpt);
DbgObj = FetchedObj;
}
}
Index: llvm/test/tools/llvm-objdump/debuginfod.test
===================================================================
--- llvm/test/tools/llvm-objdump/debuginfod.test
+++ 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: <main>:
+SECTIONS: <.text>:
+NOSECTIONS: <PT_LOAD#{{[0-9]+}}>:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132887.465072.patch
Type: text/x-patch
Size: 3239 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221004/52602549/attachment.bin>
More information about the llvm-commits
mailing list