summaryrefslogtreecommitdiff
path: root/source3/script/tests
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2006-10-07 10:33:33 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:15:19 -0500
commit78d21c7785ae85649b7356a774787d008285133b (patch)
tree60a65cd87e2152c9065ac0437761ba7d69c8f3ea /source3/script/tests
parent628fc4b53a33b604e1c28d38ff5fd91459434814 (diff)
downloadsamba-78d21c7785ae85649b7356a774787d008285133b.tar.gz
samba-78d21c7785ae85649b7356a774787d008285133b.tar.bz2
samba-78d21c7785ae85649b7356a774787d008285133b.zip
r19164: merge the gdb_backtrace script from samba4
this more portable and try to make use of ladebug on Tru64, but that only works when the binary is passed as 2nd arg to gdb_backtrace as Tru64 doesn't know /proc/${PID}/exe we need to find a way to pass the progname in 'panic action' in samba3 metze (This used to be commit 2f55fd82ff5db82974f91648cc386daa423e38be)
Diffstat (limited to 'source3/script/tests')
-rwxr-xr-xsource3/script/tests/gdb_backtrace96
1 files changed, 71 insertions, 25 deletions
diff --git a/source3/script/tests/gdb_backtrace b/source3/script/tests/gdb_backtrace
index 8a74d1c101..b19a5b2f4b 100755
--- a/source3/script/tests/gdb_backtrace
+++ b/source3/script/tests/gdb_backtrace
@@ -1,41 +1,87 @@
-#! /bin/sh
-#
-# Author: Andrew Tridgell <tridge at samba dot org>
+#!/bin/sh
+
+BASENAME=`basename $0`
+
+if [ -n "$VALGRIND" -o -n "$SMBD_VALGRIND" ]; then
+ echo "${BASENAME}: Not running debugger under valgrind"
+ exit 1
+fi
# we want everything on stderr, so the program is not disturbed
exec 1>&2
BASENAME=`basename $0`
+UNAME=`uname`
PID=$1
-if [ x"$PID" = x"" ]; then
- echo "ERROR: ${BASENAME} needs a PID. "
+BINARY=$2
+
+test x"${PID}" = x"" && {
+ echo "Usage: ${BASENAME} <pid> [<binary>]"
exit 1
-fi
+}
+
+DB_LIST="gdb"
+case "${UNAME}" in
+ #
+ # on Tru64 we need to try ladebug first
+ # because gdb crashes itself...
+ #
+ OSF1)
+ DB_LIST="ladebug ${DB_LIST}"
+ ;;
+esac
-test x"${GDB_BIN}" = x"" && GDB_BIN=`type -p gdb`
-if [ x"${GDB_BIN}" = x"" ]; then
- echo "ERROR: ${BASENAME} needs an installed gdb. "
+for DB in ${DB_LIST}; do
+ DB_BIN=`which ${DB} 2>/dev/null`
+ test x"${DB_BIN}" != x"" && {
+ break
+ }
+done
+
+test x"${DB_BIN}" = x"" && {
+ echo "${BASENAME}: ERROR: No debugger found."
exit 1
-fi
+}
-# use /dev/shm as default temp directory
-test -d /dev/shm && \
- TMP_BASE_DIR=/dev/shm || \
- TMP_BASE_DIR=/var/tmp
-TMPFILE=`mktemp -p ${TMP_BASE_DIR} backtrace.XXXXXX`
-if [ $? -ne 0 ]; then
- echo "ERROR: ${basename} can't create temp file in ${TMP_BASE_DIR}. "
+#
+# we first try to use /proc/${PID}/exe
+# then fallback to the binary from the commandline
+# then we search for the commandline argument with
+# 'which'
+#
+test -f "/proc/${PID}/exe" && BINARY="/proc/${PID}/exe"
+test x"${BINARY}" = x"" && BINARY="/proc/${PID}/exe"
+test -f "${BINARY}" || BINARY=`which ${BINARY}`
+
+test -f "${BINARY}" || {
+ echo "${BASENAME}: ERROR: Cannot find binary '${BINARY}'."
exit 1
-fi
+}
+
+echo "${BASENAME}: Trying to use ${DB_BIN} on ${BINARY} on PID ${PID}"
-cat << EOF > "${TMPFILE}"
-set height 0
-up 8
+BATCHFILE_PRE=/tmp/gdb_backtrace_pre.$$
+BATCHFILE_MAIN=/tmp/gdb_backtrace_main.$$
+case "${DB}" in
+ ladebug)
+cat << EOF > ${BATCHFILE_PRE}
+set \$stoponattach
+EOF
+
+cat << EOF > ${BATCHFILE_MAIN}
+where
+quit
+EOF
+ ${DB_BIN} -c "${BATCHFILE_MAIN}" -i "${BATCHFILE_PRE}" -pid "${PID}" "${BINARY}"
+ ;;
+ gdb)
+cat << EOF > ${BATCHFILE_MAIN}
+set height 1000
bt full
quit
EOF
-
-${GDB_BIN} -x "${TMPFILE}" "/proc/${PID}/exe" "${PID}"
-
-/bin/rm -f "${TMPFILE}"
+ ${DB_BIN} -x "${BATCHFILE_MAIN}" "${BINARY}" "${PID}"
+ ;;
+esac
+/bin/rm -f ${BATCHFILE_PRE} ${BATCHFILE_MAIN}