smbd: Make store_file_unix_basic[_info2] public
[Samba.git] / selftest / gdb_backtrace
blobec2396a630e34a6de91da5acdb7bd01cc5985920
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
17 # we want everything on stderr, so the program is not disturbed
18 exec 1>&2
20 UNAME=$(uname)
22 PID=$1
23 BINARY=$2
25 test x"${PID}" = x"" && {
26 echo "Usage: ${BASENAME} <pid> [<binary>]"
27 exit 1
30 DB_LIST="gdb"
31 case "${UNAME}" in
33 # on Tru64 we need to try ladebug first
34 # because gdb crashes itself...
36 OSF1)
37 DB_LIST="ladebug ${DB_LIST}"
40 # On solaris dbx is working way more better than gdb
41 # let's try it first
43 SunOS)
44 DB_LIST="dbx ${DB_LIST}"
47 # FreeBSD comes with a flavor that works gdb66 and one that don't gdb
48 # (gdb 6.1) let's try it first the one that works !
50 FreeBSD)
51 DB_LIST="gdb66 ${DB_LIST}"
53 esac
55 for DB in ${DB_LIST}; do
56 DB_BIN=$(which ${DB} 2>/dev/null | grep '^/')
57 test x"${DB_BIN}" != x"" && {
58 break
60 done
62 test x"${DB_BIN}" = x"" && {
63 echo "${BASENAME}: ERROR: No debugger found."
64 exit 1
67 need_binary="no"
68 case "${DB}" in
69 # These debuggers need the process binary specified:
70 ladebug)
71 need_binary="yes"
73 gdb66)
74 need_binary="yes"
76 dbx)
77 need_binary="yes"
79 esac
81 test x"${need_binary}" = x"yes" && {
83 # we first try to use /proc/${PID}/exe or /proc/{$PID}/path for solaris
84 # then fallback to the binary from the commandline
85 # then we search for the commandline argument with
86 # 'which'
88 test -f "/proc/${PID}/exe" && BINARY="/proc/${PID}/exe"
89 test -f "/proc/${PID}/path/a.out" && BINARY=$(ls -l /proc/${PID}/path/a.out | sed 's/.*-> //')
90 test x"${BINARY}" = x"" && BINARY="/proc/${PID}/exe"
91 test -f "${BINARY}" || BINARY=$(which ${BINARY})
93 test -f "${BINARY}" || {
94 echo "${BASENAME}: ERROR: Cannot find binary '${BINARY}'."
95 exit 1
99 BATCHFILE_PRE=$(mktemp --tmpdir gdb_backtrace_pre.XXXXXXXXXX)
100 test -n "${BATCHFILE_PRE}" || {
101 echo "mktemp doesn't work" 1>&2
102 exit 1
104 BATCHFILE_MAIN=$(mktemp --tmpdir gdb_backtrace_main.XXXXXXXXXX)
105 test -n "${BATCHFILE_MAIN}" || {
106 echo "mktemp doesn't work" 1>&2
107 exit 1
109 case "${DB}" in
110 ladebug)
111 cat <<EOF >${BATCHFILE_PRE}
112 set \$stoponattach
115 cat <<EOF >${BATCHFILE_MAIN}
116 where
117 quit
119 ${DB_BIN} -c "${BATCHFILE_MAIN}" -i "${BATCHFILE_PRE}" -pid "${PID}" "${BINARY}"
121 gdb66)
122 cat <<EOF >${BATCHFILE_MAIN}
123 set height 1000
124 bt full
125 info locals
126 kill
127 quit
129 ${DB_BIN} -x "${BATCHFILE_MAIN}" "${BINARY}" "${PID}"
131 gdb)
132 cat <<EOF >${BATCHFILE_MAIN}
133 set height 0
134 bt full
135 thread apply all bt full
136 info locals
137 quit
139 ${DB_BIN} -batch -x "${BATCHFILE_MAIN}" --pid "${PID}" </dev/null
141 dbx)
142 ${DB_BIN} "where;dump;kill;quit" "${BINARY}" "${PID}"
144 esac
145 /bin/rm -f ${BATCHFILE_PRE} ${BATCHFILE_MAIN}