1# This test uses the local debuginfod cache to test the llvm-objdump integration 2# with the debuginfod client. 3REQUIRES: x86-registered-target 4 5RUN: rm -rf %t 6RUN: mkdir %t 7 8# Produce a stripped copy of the input binary. 9# Note: See embedded-source.test for details about the input file. 10RUN: llvm-objcopy --strip-debug %p/Inputs/embedded-source %t/stripped 11 12# Printing source for the stripped binary should fail. 13RUN: env DEBUGINFOD_CACHE_PATH=%t llvm-objdump -d --source %t/stripped | \ 14RUN: FileCheck %s --check-prefix=NOTFOUND 15 16# Use cp to write the debug binary to an appropriately-named file in the llvm 17# debuginfod cache. 18RUN: cp %p/Inputs/embedded-source %t/llvmcache-17908201640401622315 19 20# Write a broken "binary" under %t/broken. 21RUN: mkdir %t/broken 22RUN: echo "bad" > %t/broken/llvmcache-17908201640401622315 23 24# Write the stripped binary under %t/stripped-cache. 25RUN: mkdir %t/stripped-cache 26RUN: cp %t/stripped %t/stripped-cache/llvmcache-17908201640401622315 27 28# Write to a debug info directory as well. 29RUN: mkdir -p %t/debug/.build-id/15 30RUN: cp %p/Inputs/embedded-source %t/debug/.build-id/15/12f769114c011387393822af15dd660c080295.debug 31 32# Don't use debuginfod by default without any URLs. 33RUN: env DEBUGINFOD_CACHE_PATH=%t llvm-objdump -d --source %t/stripped | \ 34RUN: FileCheck %s --check-prefix=NOTFOUND 35 36# Don't use debuginfod if disabled. 37RUN: env DEBUGINFOD_CACHE_PATH=%t DEBUGINFOD_URLS=http://foo \ 38RUN: llvm-objdump -d --source --no-debuginfod %t/stripped | \ 39RUN: FileCheck %s --check-prefix=NOTFOUND 40 41# Look up build IDs locally without debuginfod. 42RUN: llvm-objdump -d --source --no-debuginfod --debug-file-directory %t/debug \ 43RUN: %t/stripped | \ 44RUN: FileCheck %s --check-prefix=FOUND 45 46# Use debuginfod without URLs if requested. 47RUN: env DEBUGINFOD_CACHE_PATH=%t llvm-objdump -d --source --debuginfod \ 48RUN: %t/stripped | \ 49RUN: FileCheck %s --check-prefix=FOUND 50 51# Produce a warning if a bad binary is fetched, but do not fail. 52RUN: env DEBUGINFOD_CACHE_PATH=%t/broken llvm-objdump -d --source --debuginfod \ 53RUN: %t/stripped 2> %t.err | \ 54RUN: FileCheck %s --check-prefix=NOTFOUND 55RUN: FileCheck %s --check-prefix=BADBINARYERROR -DPATH=%t --input-file %t.err 56BADBINARYERROR: warning: '[[PATH]]/broken{{[/\\]}}llvmcache-17908201640401622315': The file was not recognized as a valid object file 57 58# Use the original binary if the fetched binary has no debug info. 59RUN: env DEBUGINFOD_CACHE_PATH=%t/stripped-cache llvm-objdump -d --source \ 60RUN: --debuginfod %t/stripped 2> %t.err | \ 61RUN: FileCheck %s --check-prefix=NOTFOUND 62RUN: count 0 < %t.err 63 64# Use debuginfod to look up build IDs. 65RUN: env DEBUGINFOD_CACHE_PATH=%t llvm-objdump -d --source \ 66RUN: --build-id 1512f769114c011387393822af15dd660c080295 | \ 67RUN: FileCheck %s --check-prefix=FOUND 68 69# Produce an error if malformed (not a hex string). 70RUN: not env DEBUGINFOD_CACHE_PATH=%t llvm-objdump -d --source --build-id foo \ 71RUN: 2> %t.err 72RUN: FileCheck %s --check-prefix=MALFORMEDERROR --input-file %t.err 73MALFORMEDERROR: error: --build-id: expected a build ID, but got 'foo' 74 75# Produce an error if not found. 76RUN: not env DEBUGINFOD_CACHE_PATH=%t llvm-objdump -d --source --build-id abc \ 77RUN: 2> %t.err 78RUN: FileCheck %s --check-prefix=NOTFOUNDERROR --input-file %t.err 79NOTFOUNDERROR: error: --build-id: could not find build ID 'abc' 80 81# Use debuginfod to recover symbols. 82RUN: llvm-strip --strip-sections %t/stripped 83RUN: env DEBUGINFOD_CACHE_PATH=%t llvm-objdump -d --debuginfod \ 84RUN: %t/stripped | \ 85RUN: FileCheck %s --check-prefix=SYMBOLS 86 87# Use debuginfod to recover section headers, but not symbols. 88RUN: mkdir %t/stripped-symbols 89RUN: cp %p/Inputs/embedded-source %t/stripped-symbols/llvmcache-17908201640401622315 90RUN: llvm-strip %t/stripped-symbols/llvmcache-17908201640401622315 91RUN: env DEBUGINFOD_CACHE_PATH=%t/stripped-symbols llvm-objdump -d \ 92RUN: --debuginfod %t/stripped | \ 93RUN: FileCheck %s --check-prefix=SECTIONS 94 95# Don't use debuginfod if neither section headers nor symbols can be recovered. 96RUN: mkdir %t/stripped-sections 97RUN: echo "" | llvm-mc -filetype=obj -triple x86_64 > \ 98RUN: %t/stripped-sections/llvmcache-17908201640401622315 99RUN: llvm-strip --strip-sections %t/stripped-sections/llvmcache-17908201640401622315 100RUN: env DEBUGINFOD_CACHE_PATH=%t/stripped-sections llvm-objdump -d \ 101RUN: --debuginfod %t/stripped | \ 102RUN: FileCheck %s --check-prefix=NOSECTIONS 103 104NOTFOUND-NOT: int main(int argc, char *argv[]) { 105FOUND: int main(int argc, char *argv[]) { 106 107SYMBOLS: <main>: 108SECTIONS: <.text>: 109NOSECTIONS: <PT_LOAD#{{[0-9]+}}>: 110