source: subsurface/subsurface.debug

Mtestandroid_testdcDownloadforatdotdeiosmergeKirigamiPorttestTomaztesting
Last change on this file was f451387, checked in by Dirk Hohndel <dirk@…>, 20 months ago

Add subsurface.debug script to help debugging and install it (for Linux only)

This patch adds subsurface.debug script and install it for Linux.
Instead of running subsurface, you can run subsurface.debug which will launch
subsurface as usual, but will monitor subsurface exit and run gdb automatically
if subsurface crashes and it creates a crashlog in $HOME/.

Signed-off-by: Guillaume GARDET <guillaume.gardet@…>
Signed-off-by: Dirk Hohndel <dirk@…>

  • Property mode set to 100755
File size: 3.5 KB
Line 
1#!/bin/sh
2#
3# This is a wrapper script (based on kodi/xbmc script) to monitor subsurface and get debug information using GDB when a crash happens.
4# Informations are stored in *.log file in CRASHLOG_DIR ($HOME by default)
5
6APP=Subsurface
7bin_name=subsurface
8SAVED_ARGS="$@"
9prefix="/usr"
10CRASHLOG_DIR=${CRASHLOG_DIR:-$HOME}
11APP_VERSION=$(${prefix}/bin/${bin_name} --version)
12
13command_exists()
14{
15  command -pv $1 >/dev/null 2>&1
16}
17
18single_stacktrace()
19{
20  # core filename is either "core.$PID" or "core"
21  find "$1" -maxdepth $2 -name 'core*' | while read core; do
22      LC_ALL=C gdb --core="$core" --batch 2> /dev/null | grep -q "^Core was generated by \`${prefix}/bin/${bin_name}" || continue
23      echo "=====>  Core file: "$core" ($(stat -c%y "$core"))" >> $FILE
24      echo "        =========================================" >> $FILE
25      gdb "${prefix}/bin/${bin_name}" --core="$core" --batch -ex "thread apply all bt" 2> /dev/null >> $FILE
26      rm -f "$core"
27  done
28}
29
30print_crash_report()
31{
32  FILE="$CRASHLOG_DIR/${bin_name}_crashlog-`date +%Y%m%d_%H%M%S`.log"
33  echo "############## $APP CRASH LOG ###############" >> $FILE
34  echo >> $FILE
35  echo "################ SYSTEM INFO ################" >> $FILE
36  echo -n " Date: " >> $FILE
37  LC_ALL=C date >> $FILE
38  echo " $APP Options: $SAVED_ARGS" >> $FILE
39  echo " $APP version: $APP_VERSION" >> $FILE
40  echo -n " Arch: " >> $FILE
41  uname -m >> $FILE
42  echo -n " Kernel: " >> $FILE
43  uname -rvs >> $FILE
44  echo -n " Release: " >> $FILE
45  if [ -f /etc/os-release ]; then
46          . /etc/os-release
47          echo $NAME $VERSION >> $FILE
48  elif command_exists lsb_release; then
49    echo >> $FILE
50    lsb_release -a 2> /dev/null | sed -e 's/^/    /' >> $FILE
51  else
52    echo "lsb_release not available" >> $FILE
53  fi
54  echo "############## END SYSTEM INFO ##############" >> $FILE
55  echo >> $FILE
56  echo "############### STACK TRACE #################" >> $FILE
57  if command_exists gdb; then
58# TODO: systemd needs more test (systemd-coredumpctl exist on openSUSE 13.1 but does not find any core)
59#     if command_exists systemd-coredumpctl; then
60#       systemd-coredumpctl dump -o core ${prefix}/bin/${bin_name} > /dev/null 2>&1
61#     elif command_exists coredumpctl; then
62#       coredumpctl dump -o core ${prefix}/bin/${bin_name} > /dev/null 2>&1
63#     fi
64    # Find in current directory
65    single_stacktrace "$PWD" 1
66    # Find in plugins directories
67    if [ $KODI_HOME ]; then
68      BASEDIR=$KODI_HOME
69    else
70      BASEDIR="$LIBDIR/${bin_name}/"
71    fi
72    single_stacktrace "$BASEDIR" 5
73    # find in userdata dir
74    single_stacktrace "$HOME" 5
75    # try /proc/sys/kernel/core_pattern
76    [ -d "$(dirname $(cat /proc/sys/kernel/core_pattern))" ] && single_stacktrace "$(dirname $(cat /proc/sys/kernel/core_pattern))" 1
77  else
78    echo "gdb not installed, can't get stack trace." >> $FILE
79  fi
80  echo "############# END STACK TRACE ###############" >> $FILE
81  echo >> $FILE
82  echo "############ END $APP CRASH LOG #############" >> $FILE
83  echo "Crash report available at $FILE"
84}
85
86if command_exists gdb; then
87  # Output warning in case ulimit is unsupported by shell
88  eval ulimit -c unlimited
89  if [ ! $? = "0" ]; then
90    echo "${bin_name}: ulimit is unsupported by this shell" 1>&2
91  fi
92fi
93
94LOOP=1
95while [ $(( $LOOP )) = "1" ]
96do
97  LOOP=0
98  "${prefix}/bin/${bin_name}" $SAVED_ARGS
99  RET=$?
100  if [ $(( $RET == 65 )) = "1" ]
101  then # User requested to restart app
102    LOOP=1
103  elif [ $(( ($RET >= 131 && $RET <= 136) || $RET == 139 )) = "1" ]
104  then # Crashed with core dump
105    print_crash_report
106  fi
107#   echo "RET = $RET"
108done
109
110exit $RET
Note: See TracBrowser for help on using the repository browser.