From a369f0ecaf35fb49652873c4c1ddcaf28629c26e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 21 Jul 2005 12:11:52 +0000 Subject: r8678: setup for gdb backtrace in 'make test' (This used to be commit acf8c8fd4995acef47390df5a7d4e611c597367d) --- source4/script/gdb_backtrace | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 source4/script/gdb_backtrace (limited to 'source4/script/gdb_backtrace') diff --git a/source4/script/gdb_backtrace b/source4/script/gdb_backtrace new file mode 100755 index 0000000000..0ba8c0eaad --- /dev/null +++ b/source4/script/gdb_backtrace @@ -0,0 +1,17 @@ +#!/bin/sh + +# we want everything on stderr, so the program is not disturbed +exec 1>&2 + +PID=$1 +PROG=$2 + +TMPFILE=/tmp/gdb.$$ +cat << EOF > $TMPFILE +set height 1000 +bt full +quit +EOF + +gdb -batch -x $TMPFILE $PROG $PID < /dev/null +/bin/rm -f $TMPFILE -- cgit From 563794083834b8e63c7f00ab2986a482adc5fd0c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 21 Jul 2005 12:35:00 +0000 Subject: r8680: try harder to find the binary for gdb in the backtrace (This used to be commit e84871dd3232de73104bee81dd877cc329cd1970) --- source4/script/gdb_backtrace | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'source4/script/gdb_backtrace') diff --git a/source4/script/gdb_backtrace b/source4/script/gdb_backtrace index 0ba8c0eaad..72d1f75be9 100755 --- a/source4/script/gdb_backtrace +++ b/source4/script/gdb_backtrace @@ -13,5 +13,16 @@ 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 -- cgit From 190683f3e8fd04c12b2a930b51393dbef546773d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 Sep 2005 07:11:33 +0000 Subject: r10527: don't attempt self gdb attach if running under valgrind. This was causing fort to get rather unhappy (This used to be commit cc3e15e19cfde45fdfa63ca0a44dbbbefa723d6a) --- source4/script/gdb_backtrace | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source4/script/gdb_backtrace') diff --git a/source4/script/gdb_backtrace b/source4/script/gdb_backtrace index 72d1f75be9..bff70c389a 100755 --- a/source4/script/gdb_backtrace +++ b/source4/script/gdb_backtrace @@ -1,5 +1,10 @@ #!/bin/sh +if [ -n "$VALGRIND" -o -n "$SMBD_VALGRIND" ]; then + echo "Not running gdb under valgrind" + exit 1 +fi + # we want everything on stderr, so the program is not disturbed exec 1>&2 -- cgit From 40b9cb2dd9fcb379b261c6e4d37f056dcd880ee6 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 6 Oct 2006 13:23:42 +0000 Subject: 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) --- source4/script/gdb_backtrace | 87 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 68 insertions(+), 19 deletions(-) (limited to 'source4/script/gdb_backtrace') 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} []" + 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} -- cgit From 9db9ce6087d93d9d8b7d262b9df3b81ae624181c Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 6 Oct 2006 17:55:17 +0000 Subject: r19149: ladebug needs to have the stoponattach flag set to generate the current backtrace without waiting for a signal... metze (This used to be commit d86100289a3a857456e2d4441c290ca2ea2330ff) --- source4/script/gdb_backtrace | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'source4/script/gdb_backtrace') diff --git a/source4/script/gdb_backtrace b/source4/script/gdb_backtrace index 0e593764ff..b19a5b2f4b 100755 --- a/source4/script/gdb_backtrace +++ b/source4/script/gdb_backtrace @@ -61,22 +61,27 @@ test -f "${BINARY}" || { echo "${BASENAME}: Trying to use ${DB_BIN} on ${BINARY} on PID ${PID}" -BATCHFILE=/tmp/gdb_backtrace.$$ +BATCHFILE_PRE=/tmp/gdb_backtrace_pre.$$ +BATCHFILE_MAIN=/tmp/gdb_backtrace_main.$$ case "${DB}" in ladebug) -cat << EOF > ${BATCHFILE} +cat << EOF > ${BATCHFILE_PRE} +set \$stoponattach +EOF + +cat << EOF > ${BATCHFILE_MAIN} where quit EOF - ${DB_BIN} -c "${BATCHFILE}" -pid "${PID}" "${BINARY}" + ${DB_BIN} -c "${BATCHFILE_MAIN}" -i "${BATCHFILE_PRE}" -pid "${PID}" "${BINARY}" ;; gdb) -cat << EOF > ${BATCHFILE} +cat << EOF > ${BATCHFILE_MAIN} set height 1000 bt full quit EOF - ${DB_BIN} -x "${BATCHFILE}" "${BINARY}" "${PID}" + ${DB_BIN} -x "${BATCHFILE_MAIN}" "${BINARY}" "${PID}" ;; esac -/bin/rm -f ${BATCHFILE} +/bin/rm -f ${BATCHFILE_PRE} ${BATCHFILE_MAIN} -- cgit From d3f30cab1e97d2d05d4e99645076ae8508fc177d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 18 May 2007 09:47:53 +0000 Subject: r22997: only if the output of which has a leading '/' the output is useful... metze (This used to be commit 34968bef6dc673374c6d017df87a99a60905d3b7) --- source4/script/gdb_backtrace | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/script/gdb_backtrace') diff --git a/source4/script/gdb_backtrace b/source4/script/gdb_backtrace index b19a5b2f4b..826381e900 100755 --- a/source4/script/gdb_backtrace +++ b/source4/script/gdb_backtrace @@ -33,7 +33,7 @@ case "${UNAME}" in esac for DB in ${DB_LIST}; do - DB_BIN=`which ${DB} 2>/dev/null` + DB_BIN=`which ${DB} 2>/dev/null | grep '^/'` test x"${DB_BIN}" != x"" && { break } -- cgit