s4-rpc_server: split out DCERPC_SHARE as a separate subsystem
[Samba.git] / selftest / gdb_backtrace
blob1d8249b08a0378808629bd26ff7ff69f29ebf1ac
1 #!/bin/sh
3 BASENAME=`basename $0`
5 if [ -n "$VALGRIND" -o -n "$SMBD_VALGRIND" ]; then
6 echo "${BASENAME}: Not running debugger under valgrind"
7 exit 1
8 fi
10 # we want everything on stderr, so the program is not disturbed
11 exec 1>&2
13 BASENAME=`basename $0`
14 UNAME=`uname`
16 PID=$1
17 BINARY=$2
19 test x"${PID}" = x"" && {
20 echo "Usage: ${BASENAME} <pid> [<binary>]"
21 exit 1
24 DB_LIST="gdb"
25 case "${UNAME}" in
27 # on Tru64 we need to try ladebug first
28 # because gdb crashes itself...
30 OSF1)
31 DB_LIST="ladebug ${DB_LIST}"
33 esac
35 for DB in ${DB_LIST}; do
36 DB_BIN=`which ${DB} 2>/dev/null | grep '^/'`
37 test x"${DB_BIN}" != x"" && {
38 break
40 done
42 test x"${DB_BIN}" = x"" && {
43 echo "${BASENAME}: ERROR: No debugger found."
44 exit 1
48 # we first try to use /proc/${PID}/exe
49 # then fallback to the binary from the commandline
50 # then we search for the commandline argument with
51 # 'which'
53 test -f "/proc/${PID}/exe" && BINARY="/proc/${PID}/exe"
54 test x"${BINARY}" = x"" && BINARY="/proc/${PID}/exe"
55 test -f "${BINARY}" || BINARY=`which ${BINARY}`
57 test -f "${BINARY}" || {
58 echo "${BASENAME}: ERROR: Cannot find binary '${BINARY}'."
59 exit 1
62 echo "${BASENAME}: Trying to use ${DB_BIN} on ${BINARY} on PID ${PID}"
64 BATCHFILE_PRE=/tmp/gdb_backtrace_pre.$$
65 BATCHFILE_MAIN=/tmp/gdb_backtrace_main.$$
66 case "${DB}" in
67 ladebug)
68 cat << EOF > ${BATCHFILE_PRE}
69 set \$stoponattach
70 EOF
72 cat << EOF > ${BATCHFILE_MAIN}
73 where
74 quit
75 EOF
76 ${DB_BIN} -c "${BATCHFILE_MAIN}" -i "${BATCHFILE_PRE}" -pid "${PID}" "${BINARY}"
78 gdb)
79 cat << EOF > ${BATCHFILE_MAIN}
80 set height 1000
81 bt full
82 info locals
83 quit
84 EOF
85 ${DB_BIN} -x "${BATCHFILE_MAIN}" "${BINARY}" "${PID}"
87 esac
88 /bin/rm -f ${BATCHFILE_PRE} ${BATCHFILE_MAIN}