]> git.ipfire.org Git - thirdparty/freeswitch.git/blob - scripts/backtrace-from-core
[mod_python3] fix build on Python 3.10+
[thirdparty/freeswitch.git] / scripts / backtrace-from-core
1 #!/bin/sh
2 ##### -*- mode:shell-script; indent-tabs-mode:nil; sh-basic-offset:2 -*-
3 ##### Author: Travis Cross <tc@traviscross.com>
4
5 log1 () { printf '%s' "$1">&2; }
6 log () { printf '%s\n' "$1">&2; }
7 err () { log "$1"; exit 1; }
8
9 usage () {
10 local opt="$1" bs="" be=""
11 $opt && { bs="[ "; be=" ]"; }
12 log "usage: $0 <corefile> ${bs}<path/to/freeswitch>${be}"
13 }
14
15 while getopts "h" o; do
16 case "$o" in
17 h) usage true; exit 0; ;;
18 esac
19 done
20 shift $(($OPTIND-1))
21
22
23 if [ $# -lt 1 ]; then
24 usage true; exit 1
25 fi
26 core="$1"
27 if ! [ $# -lt 2 ]; then
28 fspath="$2"
29 [ -x "$fspath" ] || err "Not executable: $fspath"
30 fi
31 btpath="/tmp/$(date -u +%Y%m%dT%H%M%SZ)-bt.txt"
32 if [ -z "$fspath" ]; then
33 for x in "$(which freeswitch)" \
34 /usr/bin/freeswitch /usr/sbin/freeswitch \
35 /usr/local/bin/freeswitch /usr/local/sbin/freeswitch \
36 /opt/freeswitch/bin/freeswitch; do
37 ! [ -x "$x" ] || { fspath="$x"; break; }
38 done
39 fi
40 if [ -z "$fspath" ]; then
41 log "Couldn't find FS binary"
42 usage false; exit 1
43 fi
44 if test $(id -u) = 0 && test -f /etc/debian_version; then
45 cat >&2 <<'EOF'
46 ### You're running on Debian. Please make sure you have appropriate
47 ### freeswitch-*-dbg packages installed so we get as many symbols in
48 ### this backtrace as possible. I won't install these for you. If
49 ### you're running the freeswitch-all package, then you should install
50 ### freeswitch-all-dbg.
51 EOF
52 log ''
53 fi
54
55 log1 'Generating backtrace...'
56 gdb "$fspath" "$core" > $btpath <<'EOF'
57 set prompt
58 set pagination off
59 printf "\n\n"
60 printf "================================================================================\n"
61 printf "# GDB session generated by FS backtrace-from-core\n"
62 printf "# FreeSWITCH version: %s\n", switch_version_full_str
63 printf "# FreeSWITCH version (human): %s\n", switch_version_full_human_str
64 printf "================================================================================\n"
65 printf "\n\n"
66 printf "================================================================================\n"
67 printf "# info threads\n"
68 printf "================================================================================\n"
69 info threads
70 printf "================================================================================\n"
71 printf "# bt\n"
72 printf "================================================================================\n"
73 bt
74 printf "================================================================================\n"
75 printf "# bt full\n"
76 printf "================================================================================\n"
77 bt full
78 printf "================================================================================\n"
79 printf "# thread apply all bt\n"
80 printf "================================================================================\n"
81 thread apply all bt
82 printf "================================================================================\n"
83 printf "# thread apply all bt full\n"
84 printf "================================================================================\n"
85 thread apply all bt full
86 quit
87 EOF
88 log 'done'
89 log ''
90 log "Please attach the backtrace here:"
91 log "$btpath"