s3: Move setting the name_query timeout
[Samba.git] / selftest / gdb_backtrace
blob553181414992ed5633f315e3eda42f83ece32c70
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}"
34 # On solaris dbx is working way more better than gdb
35 # let's try it first
37 SunOS)
38 DB_LIST="dbx ${DB_LIST}"
41 # FreeBSD comes with a flavor that works gdb66 and one that don't gdb
42 # (gdb 6.1) let's try it first the one that works !
44 FreeBSD)
45 DB_LIST="gdb66 ${DB_LIST}"
47 esac
49 for DB in ${DB_LIST}; do
50 DB_BIN=`which ${DB} 2>/dev/null | grep '^/'`
51 test x"${DB_BIN}" != x"" && {
52 break
54 done
56 test x"${DB_BIN}" = x"" && {
57 echo "${BASENAME}: ERROR: No debugger found."
58 exit 1
62 # we first try to use /proc/${PID}/exe or /proc/{$PID}/path for solaris
63 # then fallback to the binary from the commandline
64 # then we search for the commandline argument with
65 # 'which'
67 test -f "/proc/${PID}/exe" && BINARY="/proc/${PID}/exe"
68 test -f "/proc/${PID}/path/a.out" && BINARY=`ls -l /proc/${PID}/path/a.out |sed 's/.*-> //'`
69 test x"${BINARY}" = x"" && BINARY="/proc/${PID}/exe"
70 test -f "${BINARY}" || BINARY=`which ${BINARY}`
72 test -f "${BINARY}" || {
73 echo "${BASENAME}: ERROR: Cannot find binary '${BINARY}'."
74 exit 1
77 echo "${BASENAME}: Trying to use ${DB_BIN} on ${BINARY} on PID ${PID}"
79 BATCHFILE_PRE=/tmp/gdb_backtrace_pre.$$
80 BATCHFILE_MAIN=/tmp/gdb_backtrace_main.$$
81 case "${DB}" in
82 ladebug)
83 cat << EOF > ${BATCHFILE_PRE}
84 set \$stoponattach
85 EOF
87 cat << EOF > ${BATCHFILE_MAIN}
88 where
89 quit
90 EOF
91 ${DB_BIN} -c "${BATCHFILE_MAIN}" -i "${BATCHFILE_PRE}" -pid "${PID}" "${BINARY}"
93 gdb66)
94 cat << EOF > ${BATCHFILE_MAIN}
95 set height 1000
96 bt full
97 info locals
98 kill
99 quit
101 ${DB_BIN} -x "${BATCHFILE_MAIN}" "${BINARY}" "${PID}"
103 gdb)
104 cat << EOF > ${BATCHFILE_MAIN}
105 set height 0
106 bt full
107 thread apply all bt full
108 info locals
109 quit
111 ${DB_BIN} -batch -x "${BATCHFILE_MAIN}" --pid "${PID}" < /dev/null
113 dbx)
114 ${DB_BIN} "where;dump;kill;quit" "${BINARY}" "${PID}"
116 esac
117 /bin/rm -f ${BATCHFILE_PRE} ${BATCHFILE_MAIN}