Changeset View
Changeset View
Standalone View
Standalone View
head/usr.sbin/crashinfo/crashinfo.sh
Show All 29 Lines | |||||
# $FreeBSD$ | # $FreeBSD$ | ||||
usage() | usage() | ||||
{ | { | ||||
echo "usage: crashinfo [-d crashdir] [-n dumpnr] [-k kernel] [core]" | echo "usage: crashinfo [-d crashdir] [-n dumpnr] [-k kernel] [core]" | ||||
exit 1 | exit 1 | ||||
} | } | ||||
# Find a gdb binary to use and save the value in GDB. | |||||
find_gdb() | |||||
{ | |||||
local binary | |||||
for binary in /usr/local/bin/gdb /usr/libexec/gdb /usr/bin/gdb; do | |||||
if [ -x ${binary} ]; then | |||||
GDB=${binary} | |||||
return | |||||
fi | |||||
done | |||||
} | |||||
# Run a single gdb command against a kernel file in batch mode. | # Run a single gdb command against a kernel file in batch mode. | ||||
# The kernel file is specified as the first argument and the command | # The kernel file is specified as the first argument and the command | ||||
# is given in the remaining arguments. | # is given in the remaining arguments. | ||||
gdb_command() | gdb_command() | ||||
{ | { | ||||
local k | local k | ||||
k=$1 ; shift | k=$1 ; shift | ||||
if [ -x /usr/local/bin/gdb ]; then | if [ ${GDB} = /usr/local/bin/gdb ]; then | ||||
/usr/local/bin/gdb -batch -ex "$@" $k | ${GDB} -batch -ex "$@" $k | ||||
else | else | ||||
echo -e "$@" | /usr/bin/gdb -x /dev/stdin -batch $k | echo -e "$@" | ${GDB} -x /dev/stdin -batch $k | ||||
fi | fi | ||||
} | } | ||||
find_kernel() | find_kernel() | ||||
{ | { | ||||
local ivers k kvers | local ivers k kvers | ||||
ivers=$(awk ' | ivers=$(awk ' | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | else | ||||
fi | fi | ||||
fi | fi | ||||
VMCORE=$CRASHDIR/vmcore.$DUMPNR | VMCORE=$CRASHDIR/vmcore.$DUMPNR | ||||
INFO=$CRASHDIR/info.$DUMPNR | INFO=$CRASHDIR/info.$DUMPNR | ||||
FILE=$CRASHDIR/core.txt.$DUMPNR | FILE=$CRASHDIR/core.txt.$DUMPNR | ||||
HOSTNAME=`hostname` | HOSTNAME=`hostname` | ||||
find_gdb | |||||
if [ -z "$GDB" ]; then | |||||
echo "Unable to find a kernel debugger." | |||||
exit 1 | |||||
fi | |||||
if [ ! -e $VMCORE ]; then | if [ ! -e $VMCORE ]; then | ||||
echo "$VMCORE not found" | echo "$VMCORE not found" | ||||
exit 1 | exit 1 | ||||
fi | fi | ||||
if [ ! -e $INFO ]; then | if [ ! -e $INFO ]; then | ||||
echo "$INFO not found" | echo "$INFO not found" | ||||
exit 1 | exit 1 | ||||
Show All 33 Lines | |||||
echo | echo | ||||
# XXX: /bin/sh on 7.0+ is broken so we can't simply pipe the commands to | # XXX: /bin/sh on 7.0+ is broken so we can't simply pipe the commands to | ||||
# kgdb via stdin and have to use a temporary file instead. | # kgdb via stdin and have to use a temporary file instead. | ||||
file=`mktemp /tmp/crashinfo.XXXXXX` | file=`mktemp /tmp/crashinfo.XXXXXX` | ||||
if [ $? -eq 0 ]; then | if [ $? -eq 0 ]; then | ||||
echo "bt" >> $file | echo "bt" >> $file | ||||
echo "quit" >> $file | echo "quit" >> $file | ||||
if [ -x /usr/local/bin/kgdb ]; then | ${GDB%gdb}kgdb $KERNEL $VMCORE < $file | ||||
/usr/local/bin/kgdb $KERNEL $VMCORE < $file | |||||
else | |||||
kgdb $KERNEL $VMCORE < $file | |||||
fi | |||||
rm -f $file | rm -f $file | ||||
echo | echo | ||||
fi | fi | ||||
echo | echo | ||||
echo "------------------------------------------------------------------------" | echo "------------------------------------------------------------------------" | ||||
echo "ps -axlww" | echo "ps -axlww" | ||||
echo | echo | ||||
▲ Show 20 Lines • Show All 119 Lines • Show Last 20 Lines |