|
| 1 | +# REQUIRES: system-linux, lzma, xz |
| 2 | + |
| 3 | +# We want to keep the symbol "multiplyByThree" in the .dynamic section and not |
| 4 | +# have it put the default .symtab section. |
| 5 | +# RUN: echo "{multiplyByThree;};" > %T/dynmic-symbols.txt |
| 6 | +# RUN: %clang -Wl,--dynamic-list=%T/dynmic-symbols.txt -g -o %t.binary %p/Inputs/minidebuginfo-main.c |
| 7 | + |
| 8 | +# The following section is adapted from GDB's official documentation: |
| 9 | +# http://sourceware.org/gdb/current/onlinedocs/gdb/MiniDebugInfo.html#MiniDebugInfo |
| 10 | + |
| 11 | +# Extract the dynamic symbols from the main binary, there is no need |
| 12 | +# to also have these in the normal symbol table. |
| 13 | + |
| 14 | +# IGNORE: llvm-nm -D %t.binary --format=posix --defined-only | awk '{ print $1 }' | sort > %t.dynsyms |
| 15 | + |
| 16 | +# Extract all the text (i.e. function) symbols from the debuginfo. |
| 17 | +# (Note that we actually also accept "D" symbols, for the benefit |
| 18 | +# of platforms like PowerPC64 that use function descriptors.) |
| 19 | + |
| 20 | +# IGNORE: llvm-nm %t.binary --format=posix --defined-only | awk '{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 }' | sort > %t.funcsyms |
| 21 | + |
| 22 | +# Keep all the function symbols not already in the dynamic symbol |
| 23 | +# table. |
| 24 | + |
| 25 | +# IGNORE: comm -13 %t.dynsyms %t.funcsyms > %t.keep_symbols |
| 26 | +# The result of the preceeding command can be preprocessed in %p/Inputs/minidebuginfo.keep_symbols |
| 27 | +# because we know what symbol to keep. |
| 28 | +# RUN: echo "multiplyByFour" > %p/Inputs/minidebuginfo.keep_symbols |
| 29 | + |
| 30 | +# Separate full debug info into debug binary. |
| 31 | + |
| 32 | +# RUN: llvm-objcopy --only-keep-debug %t.binary %t.debug |
| 33 | + |
| 34 | +# Copy the full debuginfo, keeping only a minimal set of symbols and |
| 35 | +# removing some unnecessary sections. |
| 36 | + |
| 37 | +# RUN: llvm-objcopy -S --remove-section .gdb_index --remove-section .comment --keep-symbols=%p/Inputs/minidebuginfo.keep_symbols %t.debug %t.mini_debuginfo |
| 38 | + |
| 39 | +# This command is not from the GDB manual but it slims down embedded minidebug |
| 40 | +# info. On top if that, it ensures that we only have the multiplyByThree symbol |
| 41 | +# in the .dynsym section of the main binary. |
| 42 | +# RUN: llvm-objcopy --remove-section=.rela.dyn --remove-section=.gnu.version --remove-section=.gnu.hash --remove-section=.dynsym %t.mini_debuginfo |
| 43 | + |
| 44 | +# Drop the full debug info from the original binary. |
| 45 | + |
| 46 | +# RUN: llvm-strip --strip-all -R .comment %t.binary |
| 47 | + |
| 48 | +# Inject the compressed data into the .gnu_debugdata section of the |
| 49 | +# original binary. |
| 50 | + |
| 51 | +# RUN: xz --force --keep %t.mini_debuginfo |
| 52 | + |
| 53 | +# RUN: llvm-objcopy --add-section .gnu_debugdata=%t.mini_debuginfo.xz %t.binary |
| 54 | + |
| 55 | +# Now run the binary and see that we can set and hit a breakpoint |
| 56 | +# from within the .dynsym section (multiplyByThree) and one from |
| 57 | +# the .symtab section embedded in the .gnu_debugdata section (multiplyByFour). |
| 58 | + |
| 59 | +# RUN: %lldb -b -o 'b multiplyByThree' -o 'b multiplyByFour' -o 'run' -o 'continue' -o 'breakpoint list -v' %t.binary | FileCheck %s |
| 60 | + |
| 61 | +# CHECK: (lldb) b multiplyByThree |
| 62 | +# CHECK-NEXT: Breakpoint 1: where = minidebuginfo-set-and-hit-breakpoint.test.tmp.binary`multiplyByThree, address = 0x{{.*}} |
| 63 | + |
| 64 | +# CHECK: (lldb) b multiplyByFour |
| 65 | +# CHECK-NEXT: Breakpoint 2: where = minidebuginfo-set-and-hit-breakpoint.test.tmp.binary`multiplyByFour, address = 0x{{.*}} |
| 66 | + |
| 67 | +# CHECK: * thread #1, name = 'minidebuginfo-s', stop reason = breakpoint 1.1 |
| 68 | +# CHECK: * thread #1, name = 'minidebuginfo-s', stop reason = breakpoint 2.1 |
| 69 | + |
| 70 | +# CHECK: (lldb) breakpoint list -v |
| 71 | +# CHECK-NEXT: Current breakpoints: |
| 72 | +# CHECK-NEXT: 1: name = 'multiplyByThree' |
| 73 | +# CHECK-NEXT: 1.1: |
| 74 | +# CHECK-NEXT: module = {{.*}}/minidebuginfo-set-and-hit-breakpoint.test.tmp.binary |
| 75 | +# CHECK-NEXT: symbol = multiplyByThree |
| 76 | +# CHECK-NEXT: address = 0x{{.*}} |
| 77 | +# CHECK-NEXT: resolved = true |
| 78 | +# CHECK-NEXT: hit count = 1 |
| 79 | + |
| 80 | +# CHECK: 2: name = 'multiplyByFour' |
| 81 | +# CHECK-NEXT: 2.1: |
| 82 | +# CHECK-NEXT: module = {{.*}}/minidebuginfo-set-and-hit-breakpoint.test.tmp.binary |
| 83 | +# CHECK-NEXT: symbol = multiplyByFour |
| 84 | +# CHECK-NEXT: address = 0x{{.*}} |
| 85 | +# CHECK-NEXT: resolved = true |
| 86 | +# CHECK-NEXT: hit count = 1 |
0 commit comments