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
26 test x
"${PID}" = x
"" && {
27 echo "Usage: ${BASENAME} <pid> [<binary>]"
34 # on Tru64 we need to try ladebug first
35 # because gdb crashes itself...
38 DB_LIST
="ladebug ${DB_LIST}"
41 # On solaris dbx is working way more better than gdb
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 !
52 DB_LIST
="gdb66 ${DB_LIST}"
56 for DB
in ${DB_LIST}; do
57 DB_BIN
=`which ${DB} 2>/dev/null | grep '^/'`
58 test x
"${DB_BIN}" != x
"" && {
63 test x
"${DB_BIN}" = x
"" && {
64 echo "${BASENAME}: ERROR: No debugger found."
70 # These debuggers need the process binary specified:
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
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}'."
100 BATCHFILE_PRE
=`mktemp --tmpdir gdb_backtrace_pre.XXXXXXXXXX`
101 test -n "${BATCHFILE_PRE}" ||
{
102 echo "mktemp doesn't work" 1>&2
105 BATCHFILE_MAIN
=`mktemp --tmpdir gdb_backtrace_main.XXXXXXXXXX`
106 test -n "${BATCHFILE_MAIN}" ||
{
107 echo "mktemp doesn't work" 1>&2
112 cat << EOF > ${BATCHFILE_PRE}
116 cat << EOF > ${BATCHFILE_MAIN}
120 ${DB_BIN} -c "${BATCHFILE_MAIN}" -i "${BATCHFILE_PRE}" -pid "${PID}" "${BINARY}"
123 cat << EOF > ${BATCHFILE_MAIN}
130 ${DB_BIN} -x "${BATCHFILE_MAIN}" "${BINARY}" "${PID}"
133 cat << EOF > ${BATCHFILE_MAIN}
136 thread apply all bt full
140 ${DB_BIN} -batch -x "${BATCHFILE_MAIN}" --pid "${PID}" < /dev/null
143 ${DB_BIN} "where;dump;kill;quit" "${BINARY}" "${PID}"
146 /bin
/rm -f ${BATCHFILE_PRE} ${BATCHFILE_MAIN}