7 if [ -n "$VALGRIND" -o -n "$SMBD_VALGRIND" ]; then
8 echo "${BASENAME}: Not running debugger under valgrind"
12 # we want everything on stderr, so the program is not disturbed
16 BASENAME=`basename $0`
22 test x"${PID}" = x"" && {
23 echo "Usage: ${BASENAME} <pid> [<binary>]"
30 # on Tru64 we need to try ladebug first
31 # because gdb crashes itself...
34 DB_LIST="ladebug ${DB_LIST}"
37 # On solaris dbx is working way more better than gdb
41 DB_LIST="dbx ${DB_LIST}"
44 # FreeBSD comes with a flavor that works gdb66 and one that don't gdb
45 # (gdb 6.1) let's try it first the one that works !
48 DB_LIST="gdb66 ${DB_LIST}"
52 for DB in ${DB_LIST}; do
53 DB_BIN=`which ${DB} 2>/dev/null | grep '^/'`
54 test x"${DB_BIN}" != x"" && {
59 test x"${DB_BIN}" = x"" && {
60 echo "${BASENAME}: ERROR: No debugger found."
66 # These debuggers need the process binary specified:
78 echo "METZE... $0: $@"
80 test x"${need_binary}" = x"yes" && {
82 # we first try to use /proc/${PID}/exe or /proc/{$PID}/path for solaris
83 # then fallback to the binary from the commandline
84 # then we search for the commandline argument with
87 test -f "/proc/${PID}/exe" && BINARY="/proc/${PID}/exe"
88 test -f "/proc/${PID}/path/a.out" && BINARY=`ls -l /proc/${PID}/path/a.out |sed 's/.*-> //'`
89 test x"${BINARY}" = x"" && BINARY="/proc/${PID}/exe"
90 test -f "${BINARY}" || BINARY=`which ${BINARY}`
92 test -f "${BINARY}" || {
93 echo "${BASENAME}: ERROR: Cannot find binary '${BINARY}'."
98 BATCHFILE_PRE=`mktemp --tmpdir gdb_backtrace_pre.XXXXXXXXXX`
99 test -n "${BATCHFILE_PRE}" || {
100 echo "mktemp doesn't work" 1>&2
103 BATCHFILE_MAIN=`mktemp --tmpdir gdb_backtrace_main.XXXXXXXXXX`
104 test -n "${BATCHFILE_MAIN}" || {
105 echo "mktemp doesn't work" 1>&2
110 cat << EOF > ${BATCHFILE_PRE}
114 cat << EOF > ${BATCHFILE_MAIN}
118 ${DB_BIN} -c "${BATCHFILE_MAIN}" -i "${BATCHFILE_PRE}" -pid "${PID}" "${BINARY}"
121 cat << EOF > ${BATCHFILE_MAIN}
128 ${DB_BIN} -x "${BATCHFILE_MAIN}" "${BINARY}" "${PID}"
131 cat << EOF > ${BATCHFILE_MAIN}
134 thread apply all bt full
138 ${DB_BIN} -batch -x "${BATCHFILE_MAIN}" --pid "${PID}" < /dev/null
141 ${DB_BIN} "where;dump;kill;quit" "${BINARY}" "${PID}"
144 /bin/rm -f ${BATCHFILE_PRE} ${BATCHFILE_MAIN}