Update crashinfo to work with newer gdb from ports.

If gdb from ports is installed, use it instead of the base system gdb
to extract variables from a kernel.  Note that base gdb and ports gdb
do not support the same options for invoking a single command in batch
mode, so a wrapper shell function is used.  In addition, prefer kgdb
from ports when generating a backtrace if present.

PR:		193335
Reviewed by:	emaste
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D7218
This commit is contained in:
John Baldwin 2016-07-20 18:41:47 +00:00
parent 2dc6ff9b9d
commit 241cf416c9
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=303109

View file

@ -35,6 +35,22 @@ usage()
exit 1
}
# Run a single gdb command against a kernel file in batch mode.
# The kernel file is specified as the first argument and the command
# is given in the remaining arguments.
gdb_command()
{
local k
k=$1 ; shift
if [ -x /usr/local/bin/gdb ]; then
/usr/local/bin/gdb -batch -ex "$@" $k
else
echo -e "$@" | /usr/bin/gdb -x /dev/stdin -batch $k
fi
}
find_kernel()
{
local ivers k kvers
@ -55,8 +71,8 @@ find_kernel()
# Look for a matching kernel version.
for k in `sysctl -n kern.bootfile` $(ls -t /boot/*/kernel); do
kvers=$(echo 'printf " Version String: %s", version' | \
gdb -x /dev/stdin -batch $k 2>/dev/null)
kvers=$(gdb_command $k 'printf " Version String: %s", version' \
2>/dev/null)
if [ "$ivers" = "$kvers" ]; then
KERNEL=$k
break
@ -151,11 +167,10 @@ echo "Writing crash summary to $FILE."
umask 077
# Simulate uname
ostype=$(echo -e printf '"%s", ostype' | gdb -x /dev/stdin -batch $KERNEL)
osrelease=$(echo -e printf '"%s", osrelease' | gdb -x /dev/stdin -batch $KERNEL)
version=$(echo -e printf '"%s", version' | gdb -x /dev/stdin -batch $KERNEL | \
tr '\t\n' ' ')
machine=$(echo -e printf '"%s", machine' | gdb -x /dev/stdin -batch $KERNEL)
ostype=$(gdb_command $KERNEL 'printf "%s", ostype')
osrelease=$(gdb_command $KERNEL 'printf "%s", osrelease')
version=$(gdb_command $KERNEL 'printf "%s", version' | tr '\t\n' ' ')
machine=$(gdb_command $KERNEL 'printf "%s", machine')
exec > $FILE 2>&1
@ -174,7 +189,11 @@ file=`mktemp /tmp/crashinfo.XXXXXX`
if [ $? -eq 0 ]; then
echo "bt" >> $file
echo "quit" >> $file
kgdb $KERNEL $VMCORE < $file
if [ -x /usr/local/bin/kgdb ]; then
/usr/local/bin/kgdb $KERNEL $VMCORE < $file
else
kgdb $KERNEL $VMCORE < $file
fi
rm -f $file
echo
fi