]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Add utility to generate backtraces from core files
authorTravis Cross <tc@traviscross.com>
Tue, 21 Jan 2014 03:38:41 +0000 (03:38 +0000)
committerTravis Cross <tc@traviscross.com>
Tue, 21 Jan 2014 03:41:21 +0000 (03:41 +0000)
This should help with getting people reporting issues to provide us
the exact and complete debugging information we need.  In many cases
we'll be able to have them just run this script against their core
file.

scripts/backtrace-from-core [new file with mode: 0755]

diff --git a/scripts/backtrace-from-core b/scripts/backtrace-from-core
new file mode 100755 (executable)
index 0000000..e8f7d98
--- /dev/null
@@ -0,0 +1,89 @@
+#!/bin/sh
+##### -*- mode:shell-script; indent-tabs-mode:nil; sh-basic-offset:2 -*-
+##### Author: Travis Cross <tc@traviscross.com>
+
+log1 () { printf '%s' "$1">&2; }
+log () { printf '%s\n' "$1">&2; }
+err () { log "$1"; exit 1; }
+
+usage () {
+  local opt="$1" bs="" be=""
+  $opt && { bs="[ "; be=" ]"; }
+  log "usage: $0 <corefile> ${bs}<path/to/freeswitch>${be}"
+}
+
+while getopts "h" o; do
+  case "$o" in
+    h) usage true; exit 0; ;;
+  esac
+done
+shift $(($OPTIND-1))
+
+
+if [ $# -lt 1 ]; then
+  usage true; exit 1
+fi
+core="$1"
+if ! [ $# -lt 2 ]; then
+  fspath="$2"
+  [ -x "$fspath" ] || err "Not executable: $fspath"
+fi
+btpath="/tmp/$(date -u +%Y%m%dT%H%M%SZ)-bt.txt"
+if [ -z "$fspath" ]; then
+  for x in "$(which freeswitch)" \
+    /usr/bin/freeswitch /usr/sbin/freeswitch \
+    /usr/local/bin/freeswitch /usr/local/sbin/freeswitch \
+    /opt/freeswitch/bin/freeswitch; do
+    ! [ -x "$x" ] || { fspath="$x"; break; }
+  done
+fi
+if [ -z "$fspath" ]; then
+  log "Couldn't find FS binary"
+  usage false; exit 1
+fi
+if test $(id -u) = 0 && test -f /etc/debian_version; then
+  cat >&2 <<'EOF'
+### You're running on Debian.  Please make sure you have appropriate
+### freeswitch-*-dbg packages installed so we get as many symbols in
+### this backtrace as possible.  I won't install these for you.  If
+### you're running the freeswitch-all package, then you should install
+### freeswitch-all-dbg.
+EOF
+log ''
+fi
+
+log1 'Generating backtrace...'
+gdb "$fspath" "$core" > $btpath <<'EOF'
+set prompt
+set pagination off
+echo \n\n
+echo ================================================================================\n
+echo # GDB session generated by FS backtrace-from-core\n
+echo ================================================================================\n
+echo \n\n
+echo ================================================================================\n
+echo # info threads\n
+echo ================================================================================\n
+info threads
+echo ================================================================================\n
+echo # bt\n
+echo ================================================================================\n
+bt
+echo ================================================================================\n
+echo # bt full\n
+echo ================================================================================\n
+bt full
+echo ================================================================================\n
+echo # thread apply all bt\n
+echo ================================================================================\n
+thread apply all bt
+echo ================================================================================\n
+echo # thread apply all bt full\n
+echo ================================================================================\n
+thread apply all bt full
+quit
+EOF
+log 'done'
+log ''
+log "Please attach the backtrace here:"
+log "$btpath"