92 lines · plain
1# REQUIRES: system-linux, lzma, xz2 3# We want to keep the symbol "multiplyByThree" in the .dynamic section and not4# have it put the default .symtab section.5# RUN: echo "{multiplyByThree;};" > %t.dynmic-symbols.txt6# RUN: %clang_host -Wl,--dynamic-list=%t.dynmic-symbols.txt -g -o %t.binary %p/Inputs/minidebuginfo-main.c7 8# The following section is adapted from GDB's official documentation:9# http://sourceware.org/gdb/current/onlinedocs/gdb/MiniDebugInfo.html#MiniDebugInfo10 11# Extract the dynamic symbols from the main binary, there is no need12# 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.dynsyms15 16# Extract all the text (i.e. function) symbols from the debuginfo.17# (Note that we actually also accept "D" symbols, for the benefit18# 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.funcsyms21 22# Keep all the function symbols not already in the dynamic symbol23# table.24 25# IGNORE: comm -13 %t.dynsyms %t.funcsyms > %t.keep_symbols26# The result of the preceeding command can be hardcoded27# because we know what symbol to keep.28# RUN: echo "multiplyByFour" > %t.keep_symbols29 30# Separate full debug info into debug binary.31 32# RUN: llvm-objcopy --only-keep-debug %t.binary %t.debug33 34# Copy the full debuginfo, keeping only a minimal set of symbols and35# removing some unnecessary sections.36 37# RUN: llvm-objcopy -S --remove-section .gdb_index --remove-section .comment --keep-symbols=%t.keep_symbols %t.debug %t.mini_debuginfo38 39# This command is not from the GDB manual but it slims down embedded minidebug40# info. On top if that, it ensures that we only have the multiplyByThree symbol41# in the .dynsym section of the main binary. The bits removing .rela.plt,42# .rela.dyn and .dynsym sections can be removed once llvm-objcopy43# --only-keep-debug starts to work.44# RUN: llvm-objcopy --remove-section=.rela.plt --remove-section=.rela.dyn --remove-section=.rel.plt --remove-section=.rel.dyn \45# RUN: --remove-section=.gnu.version --remove-section=.gnu.hash --remove-section=.hash --remove-section=.dynsym %t.mini_debuginfo46 47# Drop the full debug info from the original binary.48 49# RUN: llvm-strip --strip-all -R .comment %t.binary50 51# Inject the compressed data into the .gnu_debugdata section of the52# original binary.53 54# RUN: xz --force --keep %t.mini_debuginfo55 56# RUN: llvm-objcopy --add-section .gnu_debugdata=%t.mini_debuginfo.xz %t.binary57 58# Now run the binary and see that we can set and hit a breakpoint59# from within the .dynsym section (multiplyByThree) and one from60# the .symtab section embedded in the .gnu_debugdata section (multiplyByFour).61 62# RUN: %lldb -b -o 'b multiplyByThree' -o 'b multiplyByFour' -o 'run' -o 'continue' -o 'breakpoint list -v' %t.binary | FileCheck %s --dump-input-context 2063 64# CHECK: (lldb) b multiplyByThree65# CHECK-NEXT: Breakpoint 1: where = minidebuginfo-set-and-hit-breakpoint.test.tmp.binary`multiplyByThree, address = 0x{{.*}}66 67# CHECK: (lldb) b multiplyByFour68# CHECK-NEXT: Breakpoint 2: where = minidebuginfo-set-and-hit-breakpoint.test.tmp.binary`multiplyByFour, address = 0x{{.*}}69 70# CHECK: * thread #1, name = 'minidebuginfo-s', stop reason = breakpoint 1.171# CHECK: * thread #1, name = 'minidebuginfo-s', stop reason = breakpoint 2.172 73# CHECK: (lldb) breakpoint list -v74# CHECK-NEXT: Current breakpoints:75# CHECK-NEXT: 1: name = 'multiplyByThree'76# CHECK-NEXT: 1.1:77# CHECK-NEXT: module = {{.*}}/minidebuginfo-set-and-hit-breakpoint.test.tmp.binary78# CHECK-NEXT: symbol = multiplyByThree79# CHECK-NEXT: address = 0x{{.*}}80# CHECK-NEXT: resolved = true81# CHECK-NEXT: hardware = false82# CHECK-NEXT: hit count = 183 84# CHECK: 2: name = 'multiplyByFour'85# CHECK-NEXT: 2.1:86# CHECK-NEXT: module = {{.*}}/minidebuginfo-set-and-hit-breakpoint.test.tmp.binary87# CHECK-NEXT: symbol = multiplyByFour88# CHECK-NEXT: address = 0x{{.*}}89# CHECK-NEXT: resolved = true90# CHECK-NEXT: hardware = false91# CHECK-NEXT: hit count = 192