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}"
35 for DB
in ${DB_LIST}; do
36 DB_BIN
=`which ${DB} 2>/dev/null | grep '^/'`
37 test x
"${DB_BIN}" != x
"" && {
42 test x
"${DB_BIN}" = x
"" && {
43 echo "${BASENAME}: ERROR: No debugger found."
48 # we first try to use /proc/${PID}/exe
49 # then fallback to the binary from the commandline
50 # then we search for the commandline argument with
53 test -f "/proc/${PID}/exe" && BINARY
="/proc/${PID}/exe"
54 test x
"${BINARY}" = x
"" && BINARY
="/proc/${PID}/exe"
55 test -f "${BINARY}" || BINARY
=`which ${BINARY}`
57 test -f "${BINARY}" ||
{
58 echo "${BASENAME}: ERROR: Cannot find binary '${BINARY}'."
62 echo "${BASENAME}: Trying to use ${DB_BIN} on ${BINARY} on PID ${PID}"
64 BATCHFILE_PRE
=/tmp
/gdb_backtrace_pre.$$
65 BATCHFILE_MAIN
=/tmp
/gdb_backtrace_main.$$
68 cat << EOF > ${BATCHFILE_PRE}
72 cat << EOF > ${BATCHFILE_MAIN}
76 ${DB_BIN} -c "${BATCHFILE_MAIN}" -i "${BATCHFILE_PRE}" -pid "${PID}" "${BINARY}"
79 cat << EOF > ${BATCHFILE_MAIN}
84 ${DB_BIN} -x "${BATCHFILE_MAIN}" "${BINARY}" "${PID}"
87 /bin
/rm -f ${BATCHFILE_PRE} ${BATCHFILE_MAIN}