3 # SPDX-License-Identifier: BSD-3-Clause
5 # Copyright (c) 2008 Yahoo!, Inc.
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
16 # 3. Neither the name of the author nor the names of any co-contributors
17 # may be used to endorse or promote products derived from this software
18 # without specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 echo "usage: crashinfo [-b] [-d crashdir] [-n dumpnr]" \
40 # Remove an uncompressed copy of a dump
44 [ -e $VMCORE ] && rm -f $VMCORE
47 # Run a single gdb command against a kernel file in batch mode.
48 # The kernel file is specified as the first argument and the command
49 # is given in the remaining arguments.
56 ${GDB} -batch -ex "$@" $k
70 if ($0 ~ "^ [A-Za-z ]+: ") {
77 # Look for a matching kernel version, handling possible truncation
78 # of the version string recovered from the dump.
79 for k in `sysctl -n kern.bootfile` $(ls -t /boot/*/kernel); do
80 kvers=$(gdb_command $k 'printf " Version String: %s", version' | \
81 awk "{line=line\$0\"\n\"} END{print substr(line,1,${#ivers})}" \
83 if [ "$ivers" = "$kvers" ]; then
95 while getopts "bd:n:k:" opt; do
115 shift $((OPTIND - 1))
117 if [ $# -eq 1 ]; then
118 if [ -n "$DUMPNR" ]; then
119 echo "-n and an explicit vmcore are mutually exclusive"
123 # Figure out the crash directory and number from the vmcore name.
124 CRASHDIR=`dirname $1`
125 DUMPNR=$(expr $(basename $1) : 'vmcore\.\([0-9]*\)')
126 if [ -z "$DUMPNR" ]; then
127 echo "Unable to determine dump number from vmcore file $1."
130 elif [ $# -gt 1 ]; then
133 # If we don't have an explicit dump number, operate on the most
135 if [ -z "$DUMPNR" ]; then
136 if ! [ -r $CRASHDIR/bounds ]; then
137 echo "No crash dumps in $CRASHDIR."
140 next=`cat $CRASHDIR/bounds`
141 if [ -z "$next" ] || [ "$next" -eq 0 ]; then
142 echo "No crash dumps in $CRASHDIR."
145 DUMPNR=$(($next - 1))
149 VMCORE=$CRASHDIR/vmcore.$DUMPNR
150 INFO=$CRASHDIR/info.$DUMPNR
151 FILE=$CRASHDIR/core.txt.$DUMPNR
155 echo "Writing crash summary to $FILE."
159 GDB=/usr/local/bin/gdb
160 if [ ! -x "$GDB" ]; then
161 echo "Unable to find a kernel debugger."
162 echo "Please install the devel/gdb port or gdb package."
166 if [ ! -e $VMCORE ]; then
167 if [ -e $VMCORE.gz ]; then
168 trap cleanup EXIT HUP INT QUIT TERM
169 gzcat $VMCORE.gz > $VMCORE
170 elif [ -e $VMCORE.zst ]; then
171 trap cleanup EXIT HUP INT QUIT TERM
172 zstdcat $VMCORE.zst > $VMCORE
174 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
222 echo "bt -full" >> $file
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 netstat -M $VMCORE -N $KERNEL -s
305 echo "------------------------------------------------------------------------"
308 netstat -M $VMCORE -N $KERNEL -m
311 echo "------------------------------------------------------------------------"
314 netstat -M $VMCORE -N $KERNEL -anA
317 echo "------------------------------------------------------------------------"
320 netstat -M $VMCORE -N $KERNEL -aL
323 echo "------------------------------------------------------------------------"
326 fstat -M $VMCORE -N $KERNEL
329 echo "------------------------------------------------------------------------"
332 dmesg -a -M $VMCORE -N $KERNEL
335 echo "------------------------------------------------------------------------"
341 echo "------------------------------------------------------------------------"
342 echo "ddb capture buffer"
345 ddb capture -M $VMCORE -N $KERNEL print