5 if [ -n "$VALGRIND" -o -n "$SMBD_VALGRIND" ]; then
6 echo "${BASENAME}: Not running debugger under valgrind"
10 # we want everything on stderr, so the program is not disturbed
13 BASENAME
=`basename $0`
19 test x
"${PID}" = x
"" && {
20 echo "Usage: ${BASENAME} <pid> [<binary>]"
27 # on Tru64 we need to try ladebug first
28 # because gdb crashes itself...
31 DB_LIST
="ladebug ${DB_LIST}"
34 # On solaris dbx is working way more better than gdb
38 DB_LIST
="dbx ${DB_LIST}"
41 # FreeBSD comes with a flavor that works gdb66 and one that don't gdb
42 # (gdb 6.1) let's try it first the one that works !
45 DB_LIST
="gdb66 ${DB_LIST}"
49 for DB
in ${DB_LIST}; do
50 DB_BIN
=`which ${DB} 2>/dev/null | grep '^/'`
51 test x
"${DB_BIN}" != x
"" && {
56 test x
"${DB_BIN}" = x
"" && {
57 echo "${BASENAME}: ERROR: No debugger found."
62 # we first try to use /proc/${PID}/exe or /proc/{$PID}/path for solaris
63 # then fallback to the binary from the commandline
64 # then we search for the commandline argument with
67 test -f "/proc/${PID}/exe" && BINARY
="/proc/${PID}/exe"
68 test -f "/proc/${PID}/path/a.out" && BINARY
=`ls -l /proc/${PID}/path/a.out |sed 's/.*-> //'`
69 test x
"${BINARY}" = x
"" && BINARY
="/proc/${PID}/exe"
70 test -f "${BINARY}" || BINARY
=`which ${BINARY}`
72 test -f "${BINARY}" ||
{
73 echo "${BASENAME}: ERROR: Cannot find binary '${BINARY}'."
77 echo "${BASENAME}: Trying to use ${DB_BIN} on ${BINARY} on PID ${PID}"
79 BATCHFILE_PRE
=/tmp
/gdb_backtrace_pre.$$
80 BATCHFILE_MAIN
=/tmp
/gdb_backtrace_main.$$
83 cat << EOF > ${BATCHFILE_PRE}
87 cat << EOF > ${BATCHFILE_MAIN}
91 ${DB_BIN} -c "${BATCHFILE_MAIN}" -i "${BATCHFILE_PRE}" -pid "${PID}" "${BINARY}"
94 cat << EOF > ${BATCHFILE_MAIN}
101 ${DB_BIN} -x "${BATCHFILE_MAIN}" "${BINARY}" "${PID}"
104 cat << EOF > ${BATCHFILE_MAIN}
110 ${DB_BIN} -x "${BATCHFILE_MAIN}" "${BINARY}" "${PID}"
113 ${DB_BIN} "where;dump;kill;quit" "${BINARY}" "${PID}"
116 /bin
/rm -f ${BATCHFILE_PRE} ${BATCHFILE_MAIN}