--- /dev/null
+#!/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"