Dear list,
a little while ago I started work on a script to assist users who want
to provide a comprehensive crash report, say on the latest version of
LyX.
Essentially you run lyxdbg instead of lyx, and it will run lyx for you
and attach the debugger. Every message generated is logged and finally a
backtrace is generated in the case of a crash. There is plenty of
information in that logfile, but nothing too sensitive (just what
libraries were used, some pathnames etc.). The logfile is ideal for
posting on lyx-devel if there is a crash and you can explain how it
occurred.
Lyxdbg should also be able to analyse a core dump and provide a
backtrace, but there will be less information available than running
lyxdbg instead of LyX. But hey, if the crash is totally unexpected you
probably only have a core file, right?
While I have only tested on my own system, Mandrake 9.0, I am confident
that it will work most of the time. Rob Lahaye pitched in some
development and testing on a completely different system so I think it
should be working well enough for beta testing. I certainly don't see
anybody losing documents as the LyX emergency save feature still
succeeds on my box.
This script is for anyone and everyone, it's GPLd. Actually it would be
handy for testing other software too. If it comes in handy testing LyX,
then I will know because you posted a trace on lyx-devel! If you have
anything to contribute to the script, please do, as I'm not an expert on
shell scripts and there must be a few things that could be done better.
Have fun,
Darren Freeman
#!/bin/sh
#
# This file is copyright 2002 Darren Freeman and Rob Lahaye.
# It is covered by the GNU General Public License which was supplied with LyX.
# 0.1 - 2002/11/28 Initial version by Darren Freeman
# 0.2 - 2002/11/29 Greatly improved by Rob Lahaye
# 0.2b - 2002/11/30 Revisited by Darren Freeman
# 0.3 - 2002/12/01 More commands to gdbcmd, made LyX async for faster loading, added trace gzipping. By Darren Freeman
# 0.3b - 2002/12/01 Prettifying by Rob Lahaye.
# 0.3c - 2002/12/07 Minor fixes and more messages by Darren Freeman.
# 0.3d - 2002/12/08 Repair work and extra checking by Darren Freeman.
version="LyX automatic testing assistant v0.3d"
echo "$version"
# Define file names for output.
gdbcmd="lyx-gdb-cmd"
trace="lyx-trace"
lyxout="lyx-stdout"
lyxerr="lyx-stderr"
# Number of stack frames to investigate further.
listframes=16
# Verify the existence of GDB. Without that, we're toast.
if ( test -z `which gdb 2>/dev/null` )
then
echo
echo "Sorry, GDB (the GNU Debugger) was not found in your path."
echo "You will need to install or fix it before this script can run."
exit
fi
# Start the trace file with the version string.
echo "$version" >$trace
# Find the LyX executable - it is either the first argument if it's an executable file,
# or we search in order through some possibilities, finishing up with asking which
# to find LyX in the executable path.
if ( test -x "$1" -a ! -d "$1" )
then
lyx=$1
shift
else
for i in `dirname $0`/src/lyx `dirname $0`/lyx ./src/lyx ./lyx `which lyx 2>/dev/null`
do
if ( test -x "$i" -a ! -d "$i" )
then
lyx=$i
break
fi
done
fi
if ( test -z "$lyx" )
then
echo "Cannot find the LyX executable."
echo "Either supply the full path of the LyX executable as the"
echo "first argument, copy this script into the LyX build"
echo "directory, 'cd' into there, or add LyX to your path."
exit
fi
# Dump compiled-in LyX version information to the trace.
echo "----------*-version--*----------" >>$trace
$lyx --version >> $trace 2>&1
# Check next argument for coredump file.
[ -n "`file -i $1 2> /dev/null | grep coredump`" ] && { coredump=$1; shift; }
# Create stdin for GDB. It starts as an empty file.
echo -n > $gdbcmd
# GDB needs to wait for LyX as we will spawn it below.
[ -z "$coredump" ] && echo "finish" >> $gdbcmd
# First grab a backtrace if LyX had problems. Include local variables.
echo "bt" >> $gdbcmd
echo "info locals" >> $gdbcmd
# Rise through the stack dumping local variables.
while (( --listframes > 0 ))
do
echo "up" >> $gdbcmd
echo "info locals" >> $gdbcmd
done
# Allow LyX to continue with an emergency save in case of crash.
[ -z "$coredump" ] && echo "continue" >> $gdbcmd
# Append the GDB commands to the trace.
echo "----------*-commands-*----------" >> $trace
cat "$gdbcmd" >> $trace
echo "----------*---gdb----*----------" >> $trace
if ( test -z "$coredump" )
then
# Spawn LyX in the background and save its PID.
echo "Starting $lyx ..."
$lyx $@ > $lyxout 2> $lyxerr &
lyxpid=$!
echo "Attaching the debugger..."
else
echo "Executing the debugger on core file $coredump ..."
fi
# Start GDB; either attach to running LyX PID or read the core dump.
gdb < $gdbcmd >> $trace 2>&1 $lyx $lyxpid$coredump
echo >> $trace
# If we started LyX ourselves we can append the output of LyX.
if ( test -z "$coredump" )
then
# Append the stdout and stderr from LyX.
echo "----------*--stdout--*----------" >> $trace
cat $lyxout >> $trace
echo "----------*--stderr--*----------" >> $trace
cat $lyxerr >> $trace
fi
# Compress without removing original.
gzip -c $trace > ${trace}.gz
echo
echo "The file $trace contains everything GDB and LyX have said"
echo "plus other useful information intended for the developers."
echo "${trace}.gz is the compressed version for emailing."
# Extra messages when interesting things are in the trace files.
# Add more interesting things below!
# echo "desired line length of messages below---------------------60"
email=""
if ( grep "SIGSEGV" $trace &>/dev/null )
then
echo
echo "Whoa! It appears that a segmentation fault occurred. This is"
echo "probably a very serious fault in LyX that may be hard for"
echo "the developers to find without your help."
email=true
fi
if ( grep "Phew." $lyxerr &>/dev/null )
then
echo
echo "It appears that LyX performed a successful autosave. LyX"
echo "should remind you about this recovery file the next time"
echo "you open the document(s). Most of the time you will not"
echo "lose your work even if you haven't saved it for a while."
fi
if ( ! test -z "$email" )
then
echo
echo "Please email the compressed trace file to the LyX team at"
echo "[EMAIL PROTECTED] (LyX Developers List)"
echo "Don't forget to mention what you were doing before the"
echo "error, and remember that:"
echo
echo "--- THIS SCRIPT REPLACES OLD TRACE FILES AUTOMATICALLY ---"
fi
# Clean up files.
rm -f $gdbcmd $lyxout $lyxerr