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 [-b] [-d crashdir] [-n dumpnr]" \
39 # Find a gdb binary to use and save the value in GDB.
44 for binary in /usr/local/bin/gdb /usr/libexec/gdb /usr/bin/gdb; do
45 if [ -x ${binary} ]; then
52 # Run a single gdb command against a kernel file in batch mode.
53 # The kernel file is specified as the first argument and the command
54 # is given in the remaining arguments.
61 if [ ${GDB} = /usr/local/bin/gdb ]; then
62 ${GDB} -batch -ex "$@" $k
64 echo -e "$@" | ${GDB} -x /dev/stdin -batch $k
79 if ($0 ~ "^ [A-Za-z ]+: ") {
86 # Look for a matching kernel version, handling possible truncation
87 # of the version string recovered from the dump.
88 for k in `sysctl -n kern.bootfile` $(ls -t /boot/*/kernel); do
89 kvers=$(gdb_command $k 'printf " Version String: %s", version' | \
90 awk "{line=line\$0\"\n\"} END{print substr(line,1,${#ivers})}" \
92 if [ "$ivers" = "$kvers" ]; then
104 while getopts "bd:n:k:" opt; do
124 shift $((OPTIND - 1))
126 if [ $# -eq 1 ]; then
127 if [ -n "$DUMPNR" ]; then
128 echo "-n and an explicit vmcore are mutually exclusive"
132 # Figure out the crash directory and number from the vmcore name.
133 CRASHDIR=`dirname $1`
134 DUMPNR=$(expr $(basename $1) : 'vmcore\.\([0-9]*\)$')
135 if [ -z "$DUMPNR" ]; then
136 echo "Unable to determine dump number from vmcore file $1."
139 elif [ $# -gt 1 ]; then
142 # If we don't have an explicit dump number, operate on the most
144 if [ -z "$DUMPNR" ]; then
145 if ! [ -r $CRASHDIR/bounds ]; then
146 echo "No crash dumps in $CRASHDIR."
149 next=`cat $CRASHDIR/bounds`
150 if [ -z "$next" ] || [ "$next" -eq 0 ]; then
151 echo "No crash dumps in $CRASHDIR."
154 DUMPNR=$(($next - 1))
158 VMCORE=$CRASHDIR/vmcore.$DUMPNR
159 INFO=$CRASHDIR/info.$DUMPNR
160 FILE=$CRASHDIR/core.txt.$DUMPNR
164 echo "Writing crash summary to $FILE."
169 if [ -z "$GDB" ]; then
170 echo "Unable to find a kernel debugger."
174 if [ ! -e $VMCORE ]; then
175 echo "$VMCORE not found"
179 if [ ! -e $INFO ]; then
180 echo "$INFO not found"
184 # If the user didn't specify a kernel, then try to find one.
185 if [ -z "$KERNEL" ]; then
187 if [ -z "$KERNEL" ]; then
188 echo "Unable to find matching kernel for $VMCORE"
191 elif [ ! -e $KERNEL ]; then
192 echo "$KERNEL not found"
199 ostype=$(gdb_command $KERNEL 'printf "%s", ostype')
200 osrelease=$(gdb_command $KERNEL 'printf "%s", osrelease')
201 version=$(gdb_command $KERNEL 'printf "%s", version' | tr '\t\n' ' ')
202 machine=$(gdb_command $KERNEL 'printf "%s", machine')
205 echo "Writing crash summary to $FILE."
209 echo "$HOSTNAME dumped core - see $VMCORE"
213 echo "$ostype $HOSTNAME $osrelease $version $machine"
215 sed -ne '/^ Panic String: /{s//panic: /;p;}' $INFO
218 # XXX: /bin/sh on 7.0+ is broken so we can't simply pipe the commands to
219 # kgdb via stdin and have to use a temporary file instead.
220 file=`mktemp /tmp/crashinfo.XXXXXX`
221 if [ $? -eq 0 ]; then
224 ${GDB%gdb}kgdb $KERNEL $VMCORE < $file
230 echo "------------------------------------------------------------------------"
233 ps -M $VMCORE -N $KERNEL -axlww
236 echo "------------------------------------------------------------------------"
239 vmstat -M $VMCORE -N $KERNEL -s
242 echo "------------------------------------------------------------------------"
245 vmstat -M $VMCORE -N $KERNEL -m
248 echo "------------------------------------------------------------------------"
251 vmstat -M $VMCORE -N $KERNEL -z
254 echo "------------------------------------------------------------------------"
257 vmstat -M $VMCORE -N $KERNEL -i
260 echo "------------------------------------------------------------------------"
263 pstat -M $VMCORE -N $KERNEL -T
266 echo "------------------------------------------------------------------------"
269 pstat -M $VMCORE -N $KERNEL -s
272 echo "------------------------------------------------------------------------"
275 iostat -M $VMCORE -N $KERNEL
278 echo "------------------------------------------------------------------------"
281 ipcs -C $VMCORE -N $KERNEL -a
284 echo "------------------------------------------------------------------------"
287 ipcs -C $VMCORE -N $KERNEL -T
290 # XXX: This doesn't actually work in 5.x+
292 echo "------------------------------------------------------------------------"
295 w -M $VMCORE -N $KERNEL -dn
299 echo "------------------------------------------------------------------------"
302 nfsstat -M $VMCORE -N $KERNEL
305 echo "------------------------------------------------------------------------"
308 netstat -M $VMCORE -N $KERNEL -s
311 echo "------------------------------------------------------------------------"
314 netstat -M $VMCORE -N $KERNEL -m
317 echo "------------------------------------------------------------------------"
320 netstat -M $VMCORE -N $KERNEL -anA
323 echo "------------------------------------------------------------------------"
326 netstat -M $VMCORE -N $KERNEL -aL
329 echo "------------------------------------------------------------------------"
332 fstat -M $VMCORE -N $KERNEL
335 echo "------------------------------------------------------------------------"
338 dmesg -a -M $VMCORE -N $KERNEL
341 echo "------------------------------------------------------------------------"
347 echo "------------------------------------------------------------------------"
348 echo "ddb capture buffer"
351 ddb capture -M $VMCORE -N $KERNEL print