s3: smbd: Add the definition for SMB2_FIND_POSIX_INFORMATION info level.
[Samba.git] / selftest / gdb_backtrace
blob0aad62f323386feb34efeb5fd76bd9b24c0c02a5
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 UNAME=`uname`
23 PID=$1
24 BINARY=$2
26 test x"${PID}" = x"" && {
27 echo "Usage: ${BASENAME} <pid> [<binary>]"
28 exit 1
31 DB_LIST="gdb"
32 case "${UNAME}" in
34 # on Tru64 we need to try ladebug first
35 # because gdb crashes itself...
37 OSF1)
38 DB_LIST="ladebug ${DB_LIST}"
41 # On solaris dbx is working way more better than gdb
42 # let's try it first
44 SunOS)
45 DB_LIST="dbx ${DB_LIST}"
48 # FreeBSD comes with a flavor that works gdb66 and one that don't gdb
49 # (gdb 6.1) let's try it first the one that works !
51 FreeBSD)
52 DB_LIST="gdb66 ${DB_LIST}"
54 esac
56 for DB in ${DB_LIST}; do
57 DB_BIN=`which ${DB} 2>/dev/null | grep '^/'`
58 test x"${DB_BIN}" != x"" && {
59 break
61 done
63 test x"${DB_BIN}" = x"" && {
64 echo "${BASENAME}: ERROR: No debugger found."
65 exit 1
68 need_binary="no"
69 case "${DB}" in
70 # These debuggers need the process binary specified:
71 ladebug)
72 need_binary="yes"
74 gdb66)
75 need_binary="yes"
77 dbx)
78 need_binary="yes"
80 esac
82 test x"${need_binary}" = x"yes" && {
84 # we first try to use /proc/${PID}/exe or /proc/{$PID}/path for solaris
85 # then fallback to the binary from the commandline
86 # then we search for the commandline argument with
87 # 'which'
89 test -f "/proc/${PID}/exe" && BINARY="/proc/${PID}/exe"
90 test -f "/proc/${PID}/path/a.out" && BINARY=`ls -l /proc/${PID}/path/a.out |sed 's/.*-> //'`
91 test x"${BINARY}" = x"" && BINARY="/proc/${PID}/exe"
92 test -f "${BINARY}" || BINARY=`which ${BINARY}`
94 test -f "${BINARY}" || {
95 echo "${BASENAME}: ERROR: Cannot find binary '${BINARY}'."
96 exit 1
100 BATCHFILE_PRE=`mktemp --tmpdir gdb_backtrace_pre.XXXXXXXXXX`
101 test -n "${BATCHFILE_PRE}" || {
102 echo "mktemp doesn't work" 1>&2
103 exit 1
105 BATCHFILE_MAIN=`mktemp --tmpdir gdb_backtrace_main.XXXXXXXXXX`
106 test -n "${BATCHFILE_MAIN}" || {
107 echo "mktemp doesn't work" 1>&2
108 exit 1
110 case "${DB}" in
111 ladebug)
112 cat << EOF > ${BATCHFILE_PRE}
113 set \$stoponattach
116 cat << EOF > ${BATCHFILE_MAIN}
117 where
118 quit
120 ${DB_BIN} -c "${BATCHFILE_MAIN}" -i "${BATCHFILE_PRE}" -pid "${PID}" "${BINARY}"
122 gdb66)
123 cat << EOF > ${BATCHFILE_MAIN}
124 set height 1000
125 bt full
126 info locals
127 kill
128 quit
130 ${DB_BIN} -x "${BATCHFILE_MAIN}" "${BINARY}" "${PID}"
132 gdb)
133 cat << EOF > ${BATCHFILE_MAIN}
134 set height 0
135 bt full
136 thread apply all bt full
137 info locals
138 quit
140 ${DB_BIN} -batch -x "${BATCHFILE_MAIN}" --pid "${PID}" < /dev/null
142 dbx)
143 ${DB_BIN} "where;dump;kill;quit" "${BINARY}" "${PID}"
145 esac
146 /bin/rm -f ${BATCHFILE_PRE} ${BATCHFILE_MAIN}