source: branches/samba-3.5.x/selftest/gdb_backtrace

Last change on this file was 414, checked in by Herwig Bauernfeind, 15 years ago

Samba 3.5.0: Initial import

File size: 1.7 KB
Line 
1#!/bin/sh
2
3BASENAME=`basename $0`
4
5if [ -n "$VALGRIND" -o -n "$SMBD_VALGRIND" ]; then
6 echo "${BASENAME}: Not running debugger under valgrind"
7 exit 1
8fi
9
10# we want everything on stderr, so the program is not disturbed
11exec 1>&2
12
13BASENAME=`basename $0`
14UNAME=`uname`
15
16PID=$1
17BINARY=$2
18
19test x"${PID}" = x"" && {
20 echo "Usage: ${BASENAME} <pid> [<binary>]"
21 exit 1
22}
23
24DB_LIST="gdb"
25case "${UNAME}" in
26 #
27 # on Tru64 we need to try ladebug first
28 # because gdb crashes itself...
29 #
30 OSF1)
31 DB_LIST="ladebug ${DB_LIST}"
32 ;;
33esac
34
35for DB in ${DB_LIST}; do
36 DB_BIN=`which ${DB} 2>/dev/null | grep '^/'`
37 test x"${DB_BIN}" != x"" && {
38 break
39 }
40done
41
42test x"${DB_BIN}" = x"" && {
43 echo "${BASENAME}: ERROR: No debugger found."
44 exit 1
45}
46
47#
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
51# 'which'
52#
53test -f "/proc/${PID}/exe" && BINARY="/proc/${PID}/exe"
54test x"${BINARY}" = x"" && BINARY="/proc/${PID}/exe"
55test -f "${BINARY}" || BINARY=`which ${BINARY}`
56
57test -f "${BINARY}" || {
58 echo "${BASENAME}: ERROR: Cannot find binary '${BINARY}'."
59 exit 1
60}
61
62echo "${BASENAME}: Trying to use ${DB_BIN} on ${BINARY} on PID ${PID}"
63
64BATCHFILE_PRE=/tmp/gdb_backtrace_pre.$$
65BATCHFILE_MAIN=/tmp/gdb_backtrace_main.$$
66case "${DB}" in
67 ladebug)
68cat << EOF > ${BATCHFILE_PRE}
69set \$stoponattach
70EOF
71
72cat << EOF > ${BATCHFILE_MAIN}
73where
74quit
75EOF
76 ${DB_BIN} -c "${BATCHFILE_MAIN}" -i "${BATCHFILE_PRE}" -pid "${PID}" "${BINARY}"
77 ;;
78 gdb)
79cat << EOF > ${BATCHFILE_MAIN}
80set height 1000
81bt full
82quit
83EOF
84 ${DB_BIN} -x "${BATCHFILE_MAIN}" "${BINARY}" "${PID}"
85 ;;
86esac
87/bin/rm -f ${BATCHFILE_PRE} ${BATCHFILE_MAIN}
Note: See TracBrowser for help on using the repository browser.