| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | . $(dirnamescip-shell system . . dirname. $0)/common.inc |
| 3 | |
| 4 | on_qemu && skip |
| 5 | [scip-shell system . . `[`. $MACHINE = riscv64 -o $MACHINE = riscv32 -o $MACHINE = sparc64 ] && skip |
| 6 | command -v gdb >& /dev/null || skip |
| 7 | |
| 8 | catscip-shell system . . cat. <<EOF | $CC -c -o $t/a.o -fPIC -g -ggnu-pubnames -gdwarf-4 -xc - -ffunction-sections |
| 9 | #include <stdio.h> |
| 10 | |
| 11 | void trap() {} |
| 12 | |
| 13 | static void hello() { |
| 14 | printf("Hello world\n"); |
| 15 | trap(); |
| 16 | } |
| 17 | |
| 18 | void greet() { |
| 19 | hello(); |
| 20 | } |
| 21 | EOF |
| 22 | |
| 23 | $CC -B. -shared -o $t/b.so $t/a.o -Wl,--gdb-index -Wl,--compress-debug-sections=zlib-gabi |
| 24 | readelfscip-shell system . . readelf. -WS $t/b.so 2> /dev/nullscip-shell filesystem . . `/dev/null`. | grepscip-shell system . . grep. -F .gdb_index |
| 25 | |
| 26 | catscip-shell system . . cat. <<EOF | $CC -c -o $t/c.o -fPIC -g -ggnu-pubnames -gdwarf-4 -xc - -gz |
| 27 | void greet(); |
| 28 | |
| 29 | int main() { |
| 30 | greet(); |
| 31 | } |
| 32 | EOF |
| 33 | |
| 34 | $CC -B. -o $t/exe $t/b.so $t/c.o -Wl,--gdb-index -Wl,--compress-debug-sections=zlib |
| 35 | readelfscip-shell system . . readelf. -WS $t/exe 2> /dev/nullscip-shell filesystem . . `/dev/null`. | grepscip-shell system . . grep. -F .gdb_index |
| 36 | |
| 37 | $QEMU $t/exe | grepscip-shell system . . grep. 'Hello world' |
| 38 | |
| 39 | DEBUGINFOD_URLS= gdb $t/exe -nx -batch -ex 'b main' -ex r -ex 'b trap' \ |
| 40 | -ex c -ex bt -ex quit >& $t/log |
| 41 | |
| 42 | grepscip-shell system . . grep. 'hello () at .*<stdin>:7' $t/log |
| 43 | grepscip-shell system . . grep. 'greet () at .*<stdin>:11' $t/log |
| 44 | grepscip-shell system . . grep. 'main () at .*<stdin>:4' $t/log |