Debian Codegraph @

doc/SystemTap_Beginners_Guide/testsuite/systemtap.base/create-minidebug.sh

raw
1 #!/bin/bash
2
3 # Extract the dynamic symbols from the main binary, there is no need
4 # to also have these in the normal symbol table
5 nm -D binary --format=posix --defined-only | awk '{ print $1 }' | sort > binary.dynsyms
6
7 # Extract all the text (i.e. function) symbols from the debuginfo .
8 nm binary --format=posix --defined-only | awk '{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 }' | sort > binary.funcsyms
9
10 # Keep all the function symbols not already in the dynamic symbol
11 # table.
12 comm -13 binary.dynsyms binary.funcsyms > binary.keep_symbols
13
14 # We don't have a split executable in advance
15 # so we need to strip the binary ourselves
16 strip --strip-all -o binary.strip binary
17
18 # Separate full debug info into debug binary.
19 objcopy --only-keep-debug binary binary.debug
20
21 # Copy the full debuginfo, keeping only a minimal set of symbols and
22 # removing some unnecessary sections.
23 rm -f binary.mini_debuginfo
24 objcopy -S --remove-section .gdb_index --remove-section .comment --keep-symbols=binary.keep_symbols binary.debug binary.mini_debuginfo
25
26 #compress the binary.mini_debuginfo while keeping original file
27 rm -f binary.mini_debuginfo.xz
28 xz -k binary.mini_debuginfo
29
30 # Inject the compressed data into the .gnu_debugdata section of the
31 # original binary
32 objcopy --add-section .gnu_debugdata=binary.mini_debuginfo.xz binary.strip binary.test