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]"
40 local ivers k kvers
file
55 file=`mktemp /tmp/crashinfo.XXXXXX`
57 echo 'printf " Version String: %s", version' > $file
58 # Look for a matching kernel version.
59 for k
in /boot
/kernel
/kernel $
(ls -t $CRASHDIR/kern.
*) $
(ls -t /boot
/*/kernel
); do
60 kvers
=$
(gdb
-x $file -batch $k 2>/dev
/null
)
61 if [ "$ivers" = "$kvers" ]; then
76 while getopts "d:n:k:" opt
; do
96 if [ -n "$DUMPNR" ]; then
97 echo "-n and an explicit vmcore are mutually exclusive"
101 # Figure out the crash directory and number from the vmcore name.
102 CRASHDIR
=`dirname $1`
103 DUMPNR
=$
(expr $
(basename $1) : 'vmcore\.\([0-9]*\)$')
104 if [ -z "$DUMPNR" ]; then
105 echo "Unable to determine dump number from vmcore file $1."
108 elif [ $# -gt 1 ]; then
111 # If we don't have an explicit dump number, operate on the most
113 if [ -z "$DUMPNR" ]; then
114 if ! [ -r $CRASHDIR/bounds
]; then
115 echo "No crash dumps in $CRASHDIR."
118 next
=`cat $CRASHDIR/bounds`
119 if [ -z "$next" ] ||
[ "$next" -eq 0 ]; then
120 echo "No crash dumps in $CRASHDIR."
123 DUMPNR
=$
(($next - 1))
127 VMCORE
=$CRASHDIR/vmcore.
$DUMPNR
128 INFO
=$CRASHDIR/info.
$DUMPNR
129 FILE
=$CRASHDIR/core.txt.
$DUMPNR
132 if [ ! -e $VMCORE ]; then
133 echo "$VMCORE not found"
137 if [ ! -e $INFO ]; then
138 echo "$INFO not found"
142 # If the user didn't specify a kernel, then try to find one.
143 if [ -z "$KERNEL" ]; then
145 if [ -z "$KERNEL" ]; then
146 echo "Unable to find matching kernel for $VMCORE"
149 elif [ ! -e $KERNEL ]; then
150 echo "$KERNEL not found"
154 echo "Writing crash summary to $FILE."
157 #ostype=$(echo -e printf '"%s", ostype' | gdb -x /dev/stdin -batch $KERNEL)
158 #osrelease=$(echo -e printf '"%s", osrelease' | gdb -x /dev/stdin -batch $KERNEL)
159 #version=$(echo -e printf '"%s", version' | gdb -x /dev/stdin -batch $KERNEL | \
161 #machine=$(echo -e printf '"%s", machine' | gdb -x /dev/stdin -batch $KERNEL)
165 echo "$HOSTNAME dumped core - see $VMCORE"
169 #echo "$ostype $HOSTNAME $osrelease $version $machine"
172 sed -ne '/^ Panic String: /{s//panic: /;p;}' $INFO
175 # XXX: /bin/sh on 7.0+ is broken so we can't simply pipe the commands to
176 # kgdb via stdin and have to use a temporary file instead.
177 file=`mktemp /tmp/crashinfo.XXXXXX`
178 if [ $?
-eq 0 ]; then
180 echo "source /usr/share/misc/gdbinit" >> $file
181 echo "lstok" >> $file
183 echo "running_threads" >> $file
184 echo "lsvfs" >> $file
185 echo "lsvfsops" >> $file
186 echo "lsmount" >> $file
187 echo "kldstat" >> $file
189 ( ulimit -t 15; cat $file | kgdb
$KERNEL $VMCORE )
195 echo "------------------------------------------------------------------------"
198 ps
-M $VMCORE -N $KERNEL -axlwR
201 echo "------------------------------------------------------------------------"
204 vmstat
-M $VMCORE -N $KERNEL -s
207 echo "------------------------------------------------------------------------"
210 vmstat
-M $VMCORE -N $KERNEL -m
213 echo "------------------------------------------------------------------------"
216 vmstat
-M $VMCORE -N $KERNEL -z
219 echo "------------------------------------------------------------------------"
222 vmstat
-M $VMCORE -N $KERNEL -i
225 echo "------------------------------------------------------------------------"
228 pstat
-M $VMCORE -N $KERNEL -T
231 echo "------------------------------------------------------------------------"
234 pstat
-M $VMCORE -N $KERNEL -s
237 #echo "------------------------------------------------------------------------"
240 #iostat -M $VMCORE -N $KERNEL
243 echo "------------------------------------------------------------------------"
246 ipcs
-C $VMCORE -N $KERNEL -a
249 echo "------------------------------------------------------------------------"
252 ipcs
-C $VMCORE -N $KERNEL -T
255 # XXX: This doesn't actually work in 5.x+
257 echo "------------------------------------------------------------------------"
260 w
-M $VMCORE -N $KERNEL -dn
264 echo "------------------------------------------------------------------------"
267 nfsstat
-M $VMCORE -N $KERNEL
270 echo "------------------------------------------------------------------------"
273 netstat
-M $VMCORE -N $KERNEL -s
276 echo "------------------------------------------------------------------------"
279 netstat
-M $VMCORE -N $KERNEL -m
282 echo "------------------------------------------------------------------------"
285 netstat
-M $VMCORE -N $KERNEL -id
288 echo "------------------------------------------------------------------------"
291 netstat
-M $VMCORE -N $KERNEL -anr
294 echo "------------------------------------------------------------------------"
297 netstat
-M $VMCORE -N $KERNEL -anA
300 echo "------------------------------------------------------------------------"
303 netstat
-M $VMCORE -N $KERNEL -aL
306 echo "------------------------------------------------------------------------"
309 fstat
-M $VMCORE -N $KERNEL
312 echo "------------------------------------------------------------------------"
315 dmesg
-a -M $VMCORE -N $KERNEL
318 #echo "------------------------------------------------------------------------"
319 #echo "kernel config"