3 BASENAME
=$
(basename $0)
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"
17 # we want everything on stderr, so the program is not disturbed
25 test x
"${PID}" = x
"" && {
26 echo "Usage: ${BASENAME} <pid> [<binary>]"
33 # on Tru64 we need to try ladebug first
34 # because gdb crashes itself...
37 DB_LIST
="ladebug ${DB_LIST}"
40 # On solaris dbx is working way more better than gdb
44 DB_LIST
="dbx ${DB_LIST}"
47 # FreeBSD comes with a flavor that works gdb66 and one that don't gdb
48 # (gdb 6.1) let's try it first the one that works !
51 DB_LIST
="gdb66 ${DB_LIST}"
55 for DB
in ${DB_LIST}; do
56 DB_BIN
=$
(which ${DB} 2>/dev
/null |
grep '^/')
57 test x
"${DB_BIN}" != x
"" && {
62 test x
"${DB_BIN}" = x
"" && {
63 echo "${BASENAME}: ERROR: No debugger found."
69 # These debuggers need the process binary specified:
81 test x
"${need_binary}" = x
"yes" && {
83 # we first try to use /proc/${PID}/exe or /proc/{$PID}/path for solaris
84 # then fallback to the binary from the commandline
85 # then we search for the commandline argument with
88 test -f "/proc/${PID}/exe" && BINARY
="/proc/${PID}/exe"
89 test -f "/proc/${PID}/path/a.out" && BINARY
=$
(ls -l /proc
/${PID}/path
/a.out |
sed 's/.*-> //')
90 test x
"${BINARY}" = x
"" && BINARY
="/proc/${PID}/exe"
91 test -f "${BINARY}" || BINARY
=$
(which ${BINARY})
93 test -f "${BINARY}" ||
{
94 echo "${BASENAME}: ERROR: Cannot find binary '${BINARY}'."
99 BATCHFILE_PRE
=$
(mktemp
--tmpdir gdb_backtrace_pre.XXXXXXXXXX
)
100 test -n "${BATCHFILE_PRE}" ||
{
101 echo "mktemp doesn't work" 1>&2
104 BATCHFILE_MAIN
=$
(mktemp
--tmpdir gdb_backtrace_main.XXXXXXXXXX
)
105 test -n "${BATCHFILE_MAIN}" ||
{
106 echo "mktemp doesn't work" 1>&2
111 cat <<EOF >${BATCHFILE_PRE}
115 cat <<EOF >${BATCHFILE_MAIN}
119 ${DB_BIN} -c "${BATCHFILE_MAIN}" -i "${BATCHFILE_PRE}" -pid "${PID}" "${BINARY}"
122 cat <<EOF >${BATCHFILE_MAIN}
129 ${DB_BIN} -x "${BATCHFILE_MAIN}" "${BINARY}" "${PID}"
132 cat <<EOF >${BATCHFILE_MAIN}
134 echo \\n### detailed backtrace\\n\\n
136 init-if-undefined \$_inferior_thread_count = 0
137 if \$_inferior_thread_count != 1
138 echo \\n### info threads\\n\\n
140 echo \\n### backtrace for all threads\\n\\n
141 thread apply all bt full
143 echo \\n### info locals\\n\\n
146 echo \\n### Python traceback\\n\\n
148 echo \\n### Python locals\\n\\n
150 echo \\n### Python full traceback\\n\\n
155 ${DB_BIN} -batch -x "${BATCHFILE_MAIN}" --pid "${PID}" </dev/null
158 ${DB_BIN} "where;dump;kill;quit" "${BINARY}" "${PID}"
161 /bin
/rm -f ${BATCHFILE_PRE} ${BATCHFILE_MAIN}