File: create-minidebug.sh

package info (click to toggle)
systemtap 5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 47,556 kB
  • sloc: cpp: 81,117; ansic: 54,933; xml: 49,795; exp: 43,595; sh: 11,526; python: 5,003; perl: 2,252; tcl: 1,312; makefile: 1,006; javascript: 149; lisp: 105; awk: 101; asm: 91; java: 70; sed: 16
file content (32 lines) | stat: -rwxr-xr-x 1,345 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash

# Extract the dynamic symbols from the main binary, there is no need
# to also have these in the normal symbol table
nm -D binary --format=posix --defined-only | awk '{ print $1 }' | sort > binary.dynsyms

# Extract all the text (i.e. function) symbols from the debuginfo .
nm binary --format=posix --defined-only | awk '{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 }' | sort > binary.funcsyms

# Keep all the function symbols not already in the dynamic symbol
# table.
comm -13 binary.dynsyms binary.funcsyms > binary.keep_symbols

# We don't have a split executable in advance
# so we need to strip the binary ourselves
strip --strip-all -o binary.strip binary

# Separate full debug info into debug binary.
objcopy --only-keep-debug binary binary.debug

# Copy the full debuginfo, keeping only a minimal set of symbols and
# removing some unnecessary sections.
rm -f binary.mini_debuginfo
objcopy -S --remove-section .gdb_index --remove-section .comment --keep-symbols=binary.keep_symbols binary.debug binary.mini_debuginfo

#compress the binary.mini_debuginfo while keeping original file
rm -f binary.mini_debuginfo.xz
xz -k binary.mini_debuginfo

# Inject the compressed data into the .gnu_debugdata section of the
# original binary
objcopy --add-section .gnu_debugdata=binary.mini_debuginfo.xz binary.strip binary.test