r8366: Root-level files don't have a slash, but acls need to be settable on
[samba.git] / examples / scripts / debugging / linux / backtrace
1 #! /bin/sh
2 #
3 # Author: Andrew Tridgell <tridge at samba dot org>
4
5 # we want everything on stderr, so the program is not disturbed
6 exec 1>&2
7
8 BASENAME=$( basename $0)
9
10 test -z ${GDB_BIN} && GDB_BIN=$( type -p gdb)
11 if [ -z ${GDB_BIN} ]; then
12         echo "ERROR: ${BASENAME} needs an installed gdb. "
13         exit 1
14 fi
15
16 if [ -z $1 ]; then
17         echo "ERROR: ${BASENAME} needs a PID. "
18         exit 1
19 fi
20 PID=$1
21
22 # use /dev/shm as default temp directory
23 test -d /dev/shm && \
24         TMP_BASE_DIR=/dev/shm || \
25         TMP_BASE_DIR=/var/tmp
26 TMPFILE=$( mktemp -p ${TMP_BASE_DIR} backtrace.XXXXXX)
27 if [ $? -ne 0 ]; then
28         echo "ERROR: ${basename} can't create temp file in ${TMP_BASE_DIR}. "
29         exit 1
30 fi
31
32 cat << EOF  > "${TMPFILE}"
33 set height 0
34 up 8
35 bt full
36 quit
37 EOF
38
39 ${GDB_BIN} -x "${TMPFILE}" "/proc/${PID}/exe" "${PID}"
40
41 /bin/rm -f "${TMPFILE}"