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]"
49 if ($0 ~ "^ [A-Za-z ]+: ") {
56 # Look for a matching kernel version.
57 for k in `sysctl -n kern.bootfile` $(ls -t /boot/*/kernel); do
58 kvers=$(echo 'printf " Version String: %s", version' | \
59 gdb -x /dev/stdin -batch $k 2>/dev/null)
60 if [ "$ivers" = "$kvers" ]; then
71 while getopts "d:n:k:" opt; do
91 if [ -n "$DUMPNR" ]; then
92 echo "-n and an explicit vmcore are mutually exclusive"
96 # Figure out the crash directory and number from the vmcore name.
98 DUMPNR=$(expr $(basename $1) : 'vmcore\.\([0-9]*\)$')
99 if [ -z "$DUMPNR" ]; then
100 echo "Unable to determine dump number from vmcore file $1."
103 elif [ $# -gt 1 ]; then
106 # If we don't have an explicit dump number, operate on the most
108 if [ -z "$DUMPNR" ]; then
109 if ! [ -r $CRASHDIR/bounds ]; then
110 echo "No crash dumps in $CRASHDIR."
113 next=`cat $CRASHDIR/bounds`
114 if [ -z "$next" ] || [ "$next" -eq 0 ]; then
115 echo "No crash dumps in $CRASHDIR."
118 DUMPNR=$(($next - 1))
122 VMCORE=$CRASHDIR/vmcore.$DUMPNR
123 INFO=$CRASHDIR/info.$DUMPNR
124 FILE=$CRASHDIR/core.txt.$DUMPNR
127 if [ ! -e $VMCORE ]; then
128 echo "$VMCORE not found"
132 if [ ! -e $INFO ]; then
133 echo "$INFO not found"
137 # If the user didn't specify a kernel, then try to find one.
138 if [ -z "$KERNEL" ]; then
140 if [ -z "$KERNEL" ]; then
141 echo "Unable to find matching kernel for $VMCORE"
144 elif [ ! -e $KERNEL ]; then
145 echo "$KERNEL not found"
149 echo "Writing crash summary to $FILE."
154 ostype=$(echo -e printf '"%s", ostype' | gdb -x /dev/stdin -batch $KERNEL)
155 osrelease=$(echo -e printf '"%s", osrelease' | gdb -x /dev/stdin -batch $KERNEL)
156 version=$(echo -e printf '"%s", version' | gdb -x /dev/stdin -batch $KERNEL | \
158 machine=$(echo -e printf '"%s", machine' | gdb -x /dev/stdin -batch $KERNEL)
162 echo "$HOSTNAME dumped core - see $VMCORE"
166 echo "$ostype $HOSTNAME $osrelease $version $machine"
168 sed -ne '/^ Panic String: /{s//panic: /;p;}' $INFO
171 # XXX: /bin/sh on 7.0+ is broken so we can't simply pipe the commands to
172 # kgdb via stdin and have to use a temporary file instead.
173 file=`mktemp /tmp/crashinfo.XXXXXX`
174 if [ $? -eq 0 ]; then
177 kgdb $KERNEL $VMCORE < $file
183 echo "------------------------------------------------------------------------"
186 ps -M $VMCORE -N $KERNEL -axl
189 echo "------------------------------------------------------------------------"
192 vmstat -M $VMCORE -N $KERNEL -s
195 echo "------------------------------------------------------------------------"
198 vmstat -M $VMCORE -N $KERNEL -m
201 echo "------------------------------------------------------------------------"
204 vmstat -M $VMCORE -N $KERNEL -z
207 echo "------------------------------------------------------------------------"
210 vmstat -M $VMCORE -N $KERNEL -i
213 echo "------------------------------------------------------------------------"
216 pstat -M $VMCORE -N $KERNEL -T
219 echo "------------------------------------------------------------------------"
222 pstat -M $VMCORE -N $KERNEL -s
225 echo "------------------------------------------------------------------------"
228 iostat -M $VMCORE -N $KERNEL
231 echo "------------------------------------------------------------------------"
234 ipcs -C $VMCORE -N $KERNEL -a
237 echo "------------------------------------------------------------------------"
240 ipcs -C $VMCORE -N $KERNEL -T
243 # XXX: This doesn't actually work in 5.x+
245 echo "------------------------------------------------------------------------"
248 w -M $VMCORE -N $KERNEL -dn
252 echo "------------------------------------------------------------------------"
255 nfsstat -M $VMCORE -N $KERNEL
258 echo "------------------------------------------------------------------------"
261 netstat -M $VMCORE -N $KERNEL -s
264 echo "------------------------------------------------------------------------"
267 netstat -M $VMCORE -N $KERNEL -m
270 echo "------------------------------------------------------------------------"
273 netstat -M $VMCORE -N $KERNEL -idW
276 echo "------------------------------------------------------------------------"
279 netstat -M $VMCORE -N $KERNEL -anr
282 echo "------------------------------------------------------------------------"
285 netstat -M $VMCORE -N $KERNEL -anA
288 echo "------------------------------------------------------------------------"
291 netstat -M $VMCORE -N $KERNEL -aL
294 echo "------------------------------------------------------------------------"
297 fstat -M $VMCORE -N $KERNEL
300 echo "------------------------------------------------------------------------"
303 dmesg -a -M $VMCORE -N $KERNEL
306 echo "------------------------------------------------------------------------"
312 echo "------------------------------------------------------------------------"
313 echo "ddb capture buffer"
316 ddb capture -M $VMCORE -N $KERNEL print