r8680: try harder to find the binary for gdb in the backtrace
[bbaumbach/samba-autobuild/.git] / source4 / script / gdb_backtrace
1 #!/bin/sh
2
3 # we want everything on stderr, so the program is not disturbed
4 exec 1>&2
5
6 PID=$1
7 PROG=$2
8
9 TMPFILE=/tmp/gdb.$$
10 cat << EOF  > $TMPFILE
11 set height 1000
12 bt full
13 quit
14 EOF
15
16 if [ ! -f $PROG ]; then
17     PROG=`which $PROG`
18 fi
19 if [ ! -f $PROG ]; then
20     PROG=/proc/$PID/exe
21 fi
22 if [ ! -f $PROG ]; then
23     echo "Unable to find binary"
24     exit 1
25 fi
26
27 gdb -batch -x $TMPFILE $PROG $PID < /dev/null 
28 /bin/rm -f $TMPFILE