2
0

backtrace-from-core 3.0 KB

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