7 if [ -n "$VALGRIND" -o -n "$SMBD_VALGRIND" ]; then
8 echo "${BASENAME}: Not running debugger under valgrind"
12 if [ "x$PLEASE_NO_GDB_BACKTRACE" != "x" ]; then
13 echo "${BASENAME}: Not running debugger because PLEASE_NO_GDB_BACKTRACE is set"
18 # we want everything on stderr, so the program is not disturbed
21 BASENAME
=`basename $0`
27 test x
"${PID}" = x
"" && {
28 echo "Usage: ${BASENAME} <pid> [<binary>]"
35 # on Tru64 we need to try ladebug first
36 # because gdb crashes itself...
39 DB_LIST
="ladebug ${DB_LIST}"
42 # On solaris dbx is working way more better than gdb
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 !
53 DB_LIST
="gdb66 ${DB_LIST}"
57 for DB
in ${DB_LIST}; do
58 DB_BIN
=`which ${DB} 2>/dev/null | grep '^/'`
59 test x
"${DB_BIN}" != x
"" && {
64 test x
"${DB_BIN}" = x
"" && {
65 echo "${BASENAME}: ERROR: No debugger found."
71 # These debuggers need the process binary specified:
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
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}'."
101 BATCHFILE_PRE
=`mktemp --tmpdir gdb_backtrace_pre.XXXXXXXXXX`
102 test -n "${BATCHFILE_PRE}" ||
{
103 echo "mktemp doesn't work" 1>&2
106 BATCHFILE_MAIN
=`mktemp --tmpdir gdb_backtrace_main.XXXXXXXXXX`
107 test -n "${BATCHFILE_MAIN}" ||
{
108 echo "mktemp doesn't work" 1>&2
113 cat << EOF > ${BATCHFILE_PRE}
117 cat << EOF > ${BATCHFILE_MAIN}
121 ${DB_BIN} -c "${BATCHFILE_MAIN}" -i "${BATCHFILE_PRE}" -pid "${PID}" "${BINARY}"
124 cat << EOF > ${BATCHFILE_MAIN}
131 ${DB_BIN} -x "${BATCHFILE_MAIN}" "${BINARY}" "${PID}"
134 cat << EOF > ${BATCHFILE_MAIN}
137 thread apply all bt full
141 ${DB_BIN} -batch -x "${BATCHFILE_MAIN}" --pid "${PID}" < /dev/null
144 ${DB_BIN} "where;dump;kill;quit" "${BINARY}" "${PID}"
147 /bin
/rm -f ${BATCHFILE_PRE} ${BATCHFILE_MAIN}