3 # Copyright (c) 2008 Yahoo!, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # 3. Neither the name of the author nor the names of any co-contributors
15 # may be used to endorse or promote products derived from this software
16 # without specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 echo "usage: crashinfo [-d crashdir] [-n dumpnr] [-k kernel] [core]"
38 # Find a gdb binary to use and save the value in GDB.
43 for binary in /usr/local/bin/gdb /usr/libexec/gdb /usr/bin/gdb; do
44 if [ -x ${binary} ]; then
51 # Run a single gdb command against a kernel file in batch mode.
52 # The kernel file is specified as the first argument and the command
53 # is given in the remaining arguments.
60 if [ ${GDB} = /usr/local/bin/gdb ]; then
61 ${GDB} -batch -ex "$@" $k
63 echo -e "$@" | ${GDB} -x /dev/stdin -batch $k
78 if ($0 ~ "^ [A-Za-z ]+: ") {
85 # Look for a matching kernel version.
86 for k in `sysctl -n kern.bootfile` $(ls -t /boot/*/kernel); do
87 kvers=$(gdb_command $k 'printf " Version String: %s", version' \
89 if [ "$ivers" = "$kvers" ]; then
100 while getopts "d:n:k:" opt; do
117 shift $((OPTIND - 1))
119 if [ $# -eq 1 ]; then
120 if [ -n "$DUMPNR" ]; then
121 echo "-n and an explicit vmcore are mutually exclusive"
125 # Figure out the crash directory and number from the vmcore name.
126 CRASHDIR=`dirname $1`
127 DUMPNR=$(expr $(basename $1) : 'vmcore\.\([0-9]*\)$')
128 if [ -z "$DUMPNR" ]; then
129 echo "Unable to determine dump number from vmcore file $1."
132 elif [ $# -gt 1 ]; then
135 # If we don't have an explicit dump number, operate on the most
137 if [ -z "$DUMPNR" ]; then
138 if ! [ -r $CRASHDIR/bounds ]; then
139 echo "No crash dumps in $CRASHDIR."
142 next=`cat $CRASHDIR/bounds`
143 if [ -z "$next" ] || [ "$next" -eq 0 ]; then
144 echo "No crash dumps in $CRASHDIR."
147 DUMPNR=$(($next - 1))
151 VMCORE=$CRASHDIR/vmcore.$DUMPNR
152 INFO=$CRASHDIR/info.$DUMPNR
153 FILE=$CRASHDIR/core.txt.$DUMPNR
157 if [ -z "$GDB" ]; then
158 echo "Unable to find a kernel debugger."
162 if [ ! -e $VMCORE ]; then
163 echo "$VMCORE not found"
167 if [ ! -e $INFO ]; then
168 echo "$INFO not found"
172 # If the user didn't specify a kernel, then try to find one.
173 if [ -z "$KERNEL" ]; then
175 if [ -z "$KERNEL" ]; then
176 echo "Unable to find matching kernel for $VMCORE"
179 elif [ ! -e $KERNEL ]; then
180 echo "$KERNEL not found"
184 echo "Writing crash summary to $FILE."
189 ostype=$(gdb_command $KERNEL 'printf "%s", ostype')
190 osrelease=$(gdb_command $KERNEL 'printf "%s", osrelease')
191 version=$(gdb_command $KERNEL 'printf "%s", version' | tr '\t\n' ' ')
192 machine=$(gdb_command $KERNEL 'printf "%s", machine')
196 echo "$HOSTNAME dumped core - see $VMCORE"
200 echo "$ostype $HOSTNAME $osrelease $version $machine"
202 sed -ne '/^ Panic String: /{s//panic: /;p;}' $INFO
205 # XXX: /bin/sh on 7.0+ is broken so we can't simply pipe the commands to
206 # kgdb via stdin and have to use a temporary file instead.
207 file=`mktemp /tmp/crashinfo.XXXXXX`
208 if [ $? -eq 0 ]; then
211 ${GDB%gdb}kgdb $KERNEL $VMCORE < $file
217 echo "------------------------------------------------------------------------"
220 ps -M $VMCORE -N $KERNEL -axlww
223 echo "------------------------------------------------------------------------"
226 vmstat -M $VMCORE -N $KERNEL -s
229 echo "------------------------------------------------------------------------"
232 vmstat -M $VMCORE -N $KERNEL -m
235 echo "------------------------------------------------------------------------"
238 vmstat -M $VMCORE -N $KERNEL -z
241 echo "------------------------------------------------------------------------"
244 vmstat -M $VMCORE -N $KERNEL -i
247 echo "------------------------------------------------------------------------"
250 pstat -M $VMCORE -N $KERNEL -T
253 echo "------------------------------------------------------------------------"
256 pstat -M $VMCORE -N $KERNEL -s
259 echo "------------------------------------------------------------------------"
262 iostat -M $VMCORE -N $KERNEL
265 echo "------------------------------------------------------------------------"
268 ipcs -C $VMCORE -N $KERNEL -a
271 echo "------------------------------------------------------------------------"
274 ipcs -C $VMCORE -N $KERNEL -T
277 # XXX: This doesn't actually work in 5.x+
279 echo "------------------------------------------------------------------------"
282 w -M $VMCORE -N $KERNEL -dn
286 echo "------------------------------------------------------------------------"
289 nfsstat -M $VMCORE -N $KERNEL
292 echo "------------------------------------------------------------------------"
295 netstat -M $VMCORE -N $KERNEL -s
298 echo "------------------------------------------------------------------------"
301 netstat -M $VMCORE -N $KERNEL -m
304 echo "------------------------------------------------------------------------"
307 netstat -M $VMCORE -N $KERNEL -anA
310 echo "------------------------------------------------------------------------"
313 netstat -M $VMCORE -N $KERNEL -aL
316 echo "------------------------------------------------------------------------"
319 fstat -M $VMCORE -N $KERNEL
322 echo "------------------------------------------------------------------------"
325 dmesg -a -M $VMCORE -N $KERNEL
328 echo "------------------------------------------------------------------------"
334 echo "------------------------------------------------------------------------"
335 echo "ddb capture buffer"
338 ddb capture -M $VMCORE -N $KERNEL print