Rob, all,

I just overhauled lyxdbg again, now v0.3

Now if it needs to start lyx it does it in the background and then attaches gdb using 
the pid it obtained. Now loading lyx is just as fast as without the debugger!! So 
lyxdbg is now suitable as a wrapper for betatesters to use whenever. A side benefit is 
separate stdout and stderr from LyX.

Also more info is grabbed by gdb - mainly added the local variables of the bottom four 
frames, although maybe a command line option specifying how many frames would be good. 
I just don't care myself =)

I added "continue" to gdbcmd so that now if LyX segfaults it has a chance to do an 
emergency save - a necessity for betatesters using it all the time.

Please have a good look through the code as I am unable to test on core files, my 
system doesn't save them. Plus I'm still a newbie to sh scripts =)

Oh and I added gzipping of the trace because it was getting a little big at times =) 
To save bandwidth on the list.

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
# 0.3  - More commands to gdbcmd, made LyX async for faster loading, added trace gzipping. By Darren Freeman

version="LyX automatic backtrace generator v0.3"
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"
lyxout="lyx-stdout"
lyxerr="lyx-stderr"

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

# Create stdin for GDB
echo -n >"$gdbcmd"
if ( test -z "$coredump" )
then
	# GDB needs to wait for LyX as we will spawn it below.
        echo "finish" >>"$gdbcmd"
fi
echo "bt"          >>"$gdbcmd"
echo "info locals" >>"$gdbcmd"
echo "up"          >>"$gdbcmd"
echo "info locals" >>"$gdbcmd"
echo "up"          >>"$gdbcmd"
echo "info locals" >>"$gdbcmd"
echo "up"          >>"$gdbcmd"
echo "info locals" >>"$gdbcmd"
if ( test -z "$coredump" )
then
	echo "continue" >>"$gdbcmd" # allow LyX to do an emergency save if necessary
fi
echo "quit"        >>"$gdbcmd"

# Create the trace file with the version string.
echo "$version" >"$trace"

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

echo "----------*---gdb----*----------" >>"$trace"

# If no coredump was provided then spawn LyX and save its PID.
if ( test -z "$coredump" )
then
	# Run LyX with all remaining command line options in the background.
        echo "Executing $lyx"
	"$lyx" "$@" >"$lyxout" 2>"$lyxerr" &
	lyxpid="$!"
	echo "Attaching the debugger."
else
	echo "Executing the debugger on core file $coredump"
fi

# Start GDB and either attach to a newly running LyX or read a core dump. 
gdb <"$gdbcmd" >>"$trace" 2>&1 "$lyx" "$coredump$lyxpid"
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
	
# Clean up temp files.
rm "$gdbcmd" "$lyxout" "$lyxerr"

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

# Compress without removing original.
cat "$trace" | gzip >"$trace.gz"
echo "Compressed the file to $trace.gz for emailing."

# 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