summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2006-10-06 13:23:42 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:20:37 -0500
commit40b9cb2dd9fcb379b261c6e4d37f056dcd880ee6 (patch)
treefcd2d178dffc62ca70aca08d37c4589cf0811d77 /source4
parentd544f8a6de2d2150c213406e336ee099d98417d3 (diff)
downloadsamba-40b9cb2dd9fcb379b261c6e4d37f056dcd880ee6.tar.gz
samba-40b9cb2dd9fcb379b261c6e4d37f056dcd880ee6.tar.bz2
samba-40b9cb2dd9fcb379b261c6e4d37f056dcd880ee6.zip
r19128: - make the gdb_backtrace script more portable
- try /proc/${PID}/exe first - fallback to the binary given on the commandline - fallback searching the binary with 'which' from the commandline argument - use 'ladebug' debugger on Tru64 metze (This used to be commit f792a9532d0e263984c37d32bcf059b955e20b2c)
Diffstat (limited to 'source4')
-rwxr-xr-xsource4/script/gdb_backtrace87
1 files changed, 68 insertions, 19 deletions
diff --git a/source4/script/gdb_backtrace b/source4/script/gdb_backtrace
index bff70c389a..0e593764ff 100755
--- a/source4/script/gdb_backtrace
+++ b/source4/script/gdb_backtrace
@@ -1,33 +1,82 @@
#!/bin/sh
+BASENAME=`basename $0`
+
if [ -n "$VALGRIND" -o -n "$SMBD_VALGRIND" ]; then
- echo "Not running gdb under valgrind"
- exit 1
+ 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
-PROG=$2
+BINARY=$2
+
+test x"${PID}" = x"" && {
+ echo "Usage: ${BASENAME} <pid> [<binary>]"
+ exit 1
+}
+
+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
+
+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
+}
+
+#
+# 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
+}
-TMPFILE=/tmp/gdb.$$
-cat << EOF > $TMPFILE
+echo "${BASENAME}: Trying to use ${DB_BIN} on ${BINARY} on PID ${PID}"
+
+BATCHFILE=/tmp/gdb_backtrace.$$
+case "${DB}" in
+ ladebug)
+cat << EOF > ${BATCHFILE}
+where
+quit
+EOF
+ ${DB_BIN} -c "${BATCHFILE}" -pid "${PID}" "${BINARY}"
+ ;;
+ gdb)
+cat << EOF > ${BATCHFILE}
set height 1000
bt full
quit
EOF
-
-if [ ! -f $PROG ]; then
- PROG=`which $PROG`
-fi
-if [ ! -f $PROG ]; then
- PROG=/proc/$PID/exe
-fi
-if [ ! -f $PROG ]; then
- echo "Unable to find binary"
- exit 1
-fi
-
-gdb -batch -x $TMPFILE $PROG $PID < /dev/null
-/bin/rm -f $TMPFILE
+ ${DB_BIN} -x "${BATCHFILE}" "${BINARY}" "${PID}"
+ ;;
+esac
+/bin/rm -f ${BATCHFILE}