📄 gdb_backtrace
字号:
#!/bin/shBASENAME=`basename $0`if [ -n "$VALGRIND" -o -n "$SMBD_VALGRIND" ]; then echo "${BASENAME}: Not running debugger under valgrind" exit 1fi# we want everything on stderr, so the program is not disturbedexec 1>&2BASENAME=`basename $0`UNAME=`uname`PID=$1BINARY=$2test 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}" ;;esacfor DB in ${DB_LIST}; do DB_BIN=`which ${DB} 2>/dev/null` test x"${DB_BIN}" != x"" && { break }donetest 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}echo "${BASENAME}: Trying to use ${DB_BIN} on ${BINARY} on PID ${PID}"BATCHFILE_PRE=/tmp/gdb_backtrace_pre.$$BATCHFILE_MAIN=/tmp/gdb_backtrace_main.$$case "${DB}" in ladebug)cat << EOF > ${BATCHFILE_PRE}set \$stoponattachEOFcat << EOF > ${BATCHFILE_MAIN}wherequitEOF ${DB_BIN} -c "${BATCHFILE_MAIN}" -i "${BATCHFILE_PRE}" -pid "${PID}" "${BINARY}" ;; gdb)cat << EOF > ${BATCHFILE_MAIN}set height 1000bt fullquitEOF ${DB_BIN} -x "${BATCHFILE_MAIN}" "${BINARY}" "${PID}" ;;esac/bin/rm -f ${BATCHFILE_PRE} ${BATCHFILE_MAIN}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -