source: trunk/server/selftest/gdb_backtrace@ 752

Last change on this file since 752 was 745, checked in by Silvan Scherrer, 13 years ago

Samba Server: updated trunk to 3.6.0

File size: 2.4 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 ;;
33 #
34 # On solaris dbx is working way more better than gdb
35 # let's try it first
36 #
37 SunOS)
38 DB_LIST="dbx ${DB_LIST}"
39 ;;
40 #
41 # FreeBSD comes with a flavor that works gdb66 and one that don't gdb
42 # (gdb 6.1) let's try it first the one that works !
43 #
44 FreeBSD)
45 DB_LIST="gdb66 ${DB_LIST}"
46 ;;
47esac
48
49for DB in ${DB_LIST}; do
50 DB_BIN=`which ${DB} 2>/dev/null | grep '^/'`
51 test x"${DB_BIN}" != x"" && {
52 break
53 }
54done
55
56test x"${DB_BIN}" = x"" && {
57 echo "${BASENAME}: ERROR: No debugger found."
58 exit 1
59}
60
61#
62# we first try to use /proc/${PID}/exe or /proc/{$PID}/path for solaris
63# then fallback to the binary from the commandline
64# then we search for the commandline argument with
65# 'which'
66#
67test -f "/proc/${PID}/exe" && BINARY="/proc/${PID}/exe"
68test -f "/proc/${PID}/path/a.out" && BINARY=`ls -l /proc/${PID}/path/a.out |sed 's/.*-> //'`
69test x"${BINARY}" = x"" && BINARY="/proc/${PID}/exe"
70test -f "${BINARY}" || BINARY=`which ${BINARY}`
71
72test -f "${BINARY}" || {
73 echo "${BASENAME}: ERROR: Cannot find binary '${BINARY}'."
74 exit 1
75}
76
77echo "${BASENAME}: Trying to use ${DB_BIN} on ${BINARY} on PID ${PID}"
78
79BATCHFILE_PRE=/tmp/gdb_backtrace_pre.$$
80BATCHFILE_MAIN=/tmp/gdb_backtrace_main.$$
81case "${DB}" in
82 ladebug)
83cat << EOF > ${BATCHFILE_PRE}
84set \$stoponattach
85EOF
86
87cat << EOF > ${BATCHFILE_MAIN}
88where
89quit
90EOF
91 ${DB_BIN} -c "${BATCHFILE_MAIN}" -i "${BATCHFILE_PRE}" -pid "${PID}" "${BINARY}"
92 ;;
93 gdb66)
94cat << EOF > ${BATCHFILE_MAIN}
95set height 1000
96bt full
97info locals
98kill
99quit
100EOF
101 ${DB_BIN} -x "${BATCHFILE_MAIN}" "${BINARY}" "${PID}"
102 ;;
103 gdb)
104cat << EOF > ${BATCHFILE_MAIN}
105set height 0
106bt full
107thread apply all bt full
108info locals
109quit
110EOF
111 ${DB_BIN} -batch -x "${BATCHFILE_MAIN}" --pid "${PID}" < /dev/null
112 ;;
113dbx)
114 ${DB_BIN} "where;dump;kill;quit" "${BINARY}" "${PID}"
115 ;;
116esac
117/bin/rm -f ${BATCHFILE_PRE} ${BATCHFILE_MAIN}
Note: See TracBrowser for help on using the repository browser.