On Fri, 2002-11-29 at 22:40, Rob Lahaye wrote:
> Darren,
> 
> Have a look at the attached script.

I'm trying it now, and changing what I want to.

These are my thoughts:

1) Running lyxdbg0.2 with no command line options should try to work out
what lyx to run, or give an error message, not run gdb on nothing and
grab a backtrace =) I've added the ability to check if $1 is executable
and if not, retry on `dirname $0`/lyx which seems to be working.

2) It seems that if running lyx through lyxdbg, that the emergency save
is not performed. I wonder how to modify gdbcmd so that after it
possibly bombs, it does a backtrace and then executes the lyx recovery
code.

3) I can't test reading of coredump because my system is configured not
to generate them (Mandrake 9.0 default). I might have broken it in 0.2b
since I'm not very experienced with shell scripts so please check =)

Apart from that it's looking pretty solid now!

> It can handle what you intended, but also the core file by calling
> "lyxdbg src/lyx lyx.core". It also writes to current working directory,
> instead of LYXDIR, which garantees better the write permission.
> The script also uses /bin/sh (/bin/bash breaks on FreeBSD since there
> it must be /usr/local/bin/bash).

I suspected as much. I started writing it for me, and I use bash =)

Yes it wasn't very finished way back in v0.1 =)

> Rob.

Have fun,
Darren
#!/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  - Initial version by Darren Freeman
# 0.2  - Greatly improved by Rob Lahaye
# 0.2b - Revisited by Darren Freeman

version="LyX automatic backtrace generator v0.2b"
echo "$version"

lyx="$1"

if ( test -x "$lyx" )
then
	# First argument was executable so remove it.
	shift
else
	# Not executable, probably a document or coredump. Try same dir as this file.
	lyx=`dirname "$0"`/lyx

	if ( ! test -x "$lyx" )
	then
		echo You must either supply the path to LyX as the first argument or copy this file to the LyX directory.
		exit
	fi
fi

gdbcmd="lyx-gdb-cmd"
trace="lyx-trace"

echo "# $version" > $gdbcmd

if ( test $# -gt 1 )
then
	coredump=`file -i $1 | grep coredump`
	[ -n "$coredump" ] && coredump=$1
fi

# Create stdin for GDB
if ( test -z "$coredump" )
then
	# GDB needs to run LyX as no coredump was found.
	echo "set arg $@" >> $gdbcmd
	echo "run"        >> $gdbcmd
fi
echo "bt"   >> $gdbcmd
echo "up"   >> $gdbcmd
echo "quit" >> $gdbcmd

# prepend the GDB commands to the trace so we don't need to email it.
cp $gdbcmd $trace
echo "----------*----------*----------" >> $trace

echo "Loading $lyx into debugger."
echo "This may take a while..."
gdb < $gdbcmd >> $trace 2>&1 $lyx $coredump

rm $gdbcmd

echo
echo "Wrote the file $trace with everything GDB and LyX said."


# Extra messages when interesting things are in lyx-trace..
# add more interesting things below!
if ( grep SIGSEGV $trace )
then
  echo
  echo "Whoa! Looks like something nasty happened."
  echo "*Please* email the above file to the LyX team at:"
  echo "[EMAIL PROTECTED]"
  echo "Don't forget to include what you were doing when it bombed!"
fi

Reply via email to