torture: smbtorture test case to verify Compound related handling
[Samba.git] / selftest / gdb_backtrace
blob307a4d1e122f172cdba315b700c30f0fcb224e59
1 #!/bin/sh
3 BASENAME=`basename $0`
5 unset LD_PRELOAD
7 if [ -n "$VALGRIND" -o -n "$SMBD_VALGRIND" ]; then
8 echo "${BASENAME}: Not running debugger under valgrind"
9 exit 1
12 if [ "x$PLEASE_NO_GDB_BACKTRACE" != "x" ]; then
13 echo "${BASENAME}: Not running debugger because PLEASE_NO_GDB_BACKTRACE is set"
14 exit 0
18 # we want everything on stderr, so the program is not disturbed
19 exec 1>&2
21 BASENAME=`basename $0`
22 UNAME=`uname`
24 PID=$1
25 BINARY=$2
27 test x"${PID}" = x"" && {
28 echo "Usage: ${BASENAME} <pid> [<binary>]"
29 exit 1
32 DB_LIST="gdb"
33 case "${UNAME}" in
35 # on Tru64 we need to try ladebug first
36 # because gdb crashes itself...
38 OSF1)
39 DB_LIST="ladebug ${DB_LIST}"
42 # On solaris dbx is working way more better than gdb
43 # let's try it first
45 SunOS)
46 DB_LIST="dbx ${DB_LIST}"
49 # FreeBSD comes with a flavor that works gdb66 and one that don't gdb
50 # (gdb 6.1) let's try it first the one that works !
52 FreeBSD)
53 DB_LIST="gdb66 ${DB_LIST}"
55 esac
57 for DB in ${DB_LIST}; do
58 DB_BIN=`which ${DB} 2>/dev/null | grep '^/'`
59 test x"${DB_BIN}" != x"" && {
60 break
62 done
64 test x"${DB_BIN}" = x"" && {
65 echo "${BASENAME}: ERROR: No debugger found."
66 exit 1
69 need_binary="no"
70 case "${DB}" in
71 # These debuggers need the process binary specified:
72 ladebug)
73 need_binary="yes"
75 gdb66)
76 need_binary="yes"
78 dbx)
79 need_binary="yes"
81 esac
83 test x"${need_binary}" = x"yes" && {
85 # we first try to use /proc/${PID}/exe or /proc/{$PID}/path for solaris
86 # then fallback to the binary from the commandline
87 # then we search for the commandline argument with
88 # 'which'
90 test -f "/proc/${PID}/exe" && BINARY="/proc/${PID}/exe"
91 test -f "/proc/${PID}/path/a.out" && BINARY=`ls -l /proc/${PID}/path/a.out |sed 's/.*-> //'`
92 test x"${BINARY}" = x"" && BINARY="/proc/${PID}/exe"
93 test -f "${BINARY}" || BINARY=`which ${BINARY}`
95 test -f "${BINARY}" || {
96 echo "${BASENAME}: ERROR: Cannot find binary '${BINARY}'."
97 exit 1
101 BATCHFILE_PRE=`mktemp --tmpdir gdb_backtrace_pre.XXXXXXXXXX`
102 test -n "${BATCHFILE_PRE}" || {
103 echo "mktemp doesn't work" 1>&2
104 exit 1
106 BATCHFILE_MAIN=`mktemp --tmpdir gdb_backtrace_main.XXXXXXXXXX`
107 test -n "${BATCHFILE_MAIN}" || {
108 echo "mktemp doesn't work" 1>&2
109 exit 1
111 case "${DB}" in
112 ladebug)
113 cat << EOF > ${BATCHFILE_PRE}
114 set \$stoponattach
117 cat << EOF > ${BATCHFILE_MAIN}
118 where
119 quit
121 ${DB_BIN} -c "${BATCHFILE_MAIN}" -i "${BATCHFILE_PRE}" -pid "${PID}" "${BINARY}"
123 gdb66)
124 cat << EOF > ${BATCHFILE_MAIN}
125 set height 1000
126 bt full
127 info locals
128 kill
129 quit
131 ${DB_BIN} -x "${BATCHFILE_MAIN}" "${BINARY}" "${PID}"
133 gdb)
134 cat << EOF > ${BATCHFILE_MAIN}
135 set height 0
136 bt full
137 thread apply all bt full
138 info locals
139 quit
141 ${DB_BIN} -batch -x "${BATCHFILE_MAIN}" --pid "${PID}" < /dev/null
143 dbx)
144 ${DB_BIN} "where;dump;kill;quit" "${BINARY}" "${PID}"
146 esac
147 /bin/rm -f ${BATCHFILE_PRE} ${BATCHFILE_MAIN}