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