Debian Codegraph @

test/gdb-index-dwarf5.sh

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/bin/bash
2 . $(dirname $0)/common.inc
3
4 on_qemu && skip
5 [ $MACHINE = riscv64 -o $MACHINE = riscv32 -o $MACHINE = sparc64 ] && skip
6 command -v gdb >& /dev/null || skip
7 test_cflags -gdwarf-5 -g || skip
8
9 cat <<EOF > $t/a.c
10 void fn3();
11
12 static void fn2() {
13 fn3();
14 }
15
16 void fn1() {
17 fn2();
18 }
19 EOF
20
21 cat <<EOF > $t/b.c
22 void fn5();
23
24 static void fn4() {
25 fn5();
26 }
27
28 void fn3() {
29 fn4();
30 }
31 EOF
32
33 cat <<EOF > $t/c.c
34 void fn7();
35
36 static void fn6() {
37 fn7();
38 }
39
40 void fn5() {
41 fn6();
42 }
43 EOF
44
45 cat <<EOF > $t/d.c
46 #include <stdio.h>
47 void trap() {}
48
49 static void fn8() {
50 printf("Hello world\n");
51 trap();
52 }
53
54 void fn7() {
55 fn8();
56 }
57 EOF
58
59 $CC -c -o $t/a.o $t/a.c -fPIC -g -ggnu-pubnames -gdwarf-5 -ffunction-sections
60 $CC -c -o $t/b.o $t/b.c -fPIC -g -ggnu-pubnames -gdwarf-4 -ffunction-sections
61 $CC -c -o $t/c.o $t/c.c -fPIC -g -ggnu-pubnames -gdwarf-5
62 $CC -c -o $t/d.o $t/d.c -fPIC -g -ggnu-pubnames -gdwarf-5 -ffunction-sections
63
64 $CC -B. -shared -o $t/e.so $t/a.o $t/b.o $t/c.o $t/d.o -Wl,--gdb-index
65 readelf -WS $t/e.so 2> /dev/null | grep -F .gdb_index
66 readelf --debug=gdb_index $t/e.so 2> /dev/null | grep 'fn1: .* \[global, function\]'
67 readelf --debug=gdb_index $t/e.so 2> /dev/null | grep 'char: .* \[static, type\]'
68
69 cat <<EOF | $CC -c -o $t/f.o -fPIC -g -ggnu-pubnames -gdwarf-5 -xc - -gz
70 void fn1();
71
72 int main() {
73 fn1();
74 }
75 EOF
76
77 $CC -B. -o $t/exe $t/e.so $t/f.o -Wl,--gdb-index
78 readelf -WS $t/exe 2> /dev/null | grep -F .gdb_index
79 readelf --debug=gdb_index $t/exe 2> /dev/null | grep 'main: .* \[global, function\]'
80
81 $QEMU $t/exe | grep 'Hello world'
82
83 DEBUGINFOD_URLS= gdb $t/exe -nx -batch -ex 'b main' -ex r -ex 'b trap' \
84 -ex c -ex bt -ex quit >& $t/log
85
86 grep 'fn8 () at .*/d.c:6' $t/log
87 grep 'fn7 () at .*/d.c:10' $t/log
88 grep 'fn6 () at .*/c.c:4' $t/log
89 grep 'fn5 () at .*/c.c:8' $t/log
90 grep 'fn4 () at .*/b.c:4' $t/log
91 grep 'fn3 () at .*/b.c:8' $t/log
92 grep 'fn2 () at .*/a.c:4' $t/log
93 grep 'fn1 () at .*/a.c:8' $t/log