Home | History | Annotate | Download | only in tests
      1 #!/bin/sh
      2 
      3 # this function is slight modification of the one used in RPM
      4 # found at https://bugzilla.redhat.com/show_bug.cgi?id=834073
      5 # written by Alexander Larsson <alexl (at] redhat.com>
      6 add_minidebug()
      7 {
      8   debuginfo="$1" ## we don't have separate debuginfo file
      9   binary="$1"
     10 
     11   dynsyms=`mktemp`
     12   funcsyms=`mktemp`
     13   keep_symbols=`mktemp`
     14   mini_debuginfo=`mktemp`
     15 
     16   # Extract the dynamic symbols from the main binary, there is no need to also have these
     17   # in the normal symbol table
     18   nm -D "$binary" --format=posix --defined-only | awk '{ print $1 }' | sort > "$dynsyms"
     19   # Extract all the text (i.e. function) symbols from the debuginfo 
     20   nm "$debuginfo" --format=posix --defined-only | awk '{ if ($2 == "T" || $2 == "t") print $1 }' | sort > "$funcsyms"
     21   # Keep all the function symbols not already in the dynamic symbol table
     22   comm -13 "$dynsyms" "$funcsyms" > "$keep_symbols"
     23   # Copy the full debuginfo, keeping only a minumal set of symbols and removing some unnecessary sections
     24   objcopy -S --remove-section .gdb_index --remove-section .comment --keep-symbols="$keep_symbols" "$debuginfo" "$mini_debuginfo" &> /dev/null
     25   #Inject the compressed data into the .gnu_debugdata section of the original binary
     26   xz "$mini_debuginfo"
     27   mini_debuginfo="${mini_debuginfo}.xz"
     28   objcopy --add-section .gnu_debugdata="$mini_debuginfo" "$binary"
     29   rm -f "$dynsyms" "$funcsyms" "$keep_symbols" "$mini_debuginfo"
     30 
     31   strip "$binary" ## throw away the symbol table
     32 }
     33 
     34 
     35 TESTDIR=`pwd`
     36 TEMPDIR=`mktemp --tmpdir -d libunwind-test-XXXXXXXXXX`
     37 trap "rm -r -- $TEMPDIR" EXIT
     38 
     39 cp crasher $TEMPDIR/crasher
     40 if [ "$1" = "-minidebuginfo" ]; then
     41   add_minidebug $TEMPDIR/crasher
     42 fi
     43 
     44 # create core dump
     45 (
     46     cd $TEMPDIR
     47     ulimit -c 10000
     48     ./crasher backing_files
     49 ) 2>/dev/null
     50 COREFILE=$TEMPDIR/core*
     51 
     52 # magic option -testcase enables checking for the specific contents of the stack
     53 ./test-coredump-unwind $COREFILE -testcase `cat $TEMPDIR/backing_files`
     54