1133123Sjmg#!/bin/sh -
2133123Sjmg#
3133123Sjmg# Copyright 2004 John-Mark Gurney
4133123Sjmg# All rights reserved.
5133123Sjmg#
6133123Sjmg# Redistribution and use in source and binary forms, with or without
7133123Sjmg# modification, are permitted provided that the following conditions
8133123Sjmg# are met:
9133123Sjmg# 1. Redistributions of source code must retain the above copyright
10133123Sjmg#    notice, this list of conditions and the following disclaimer.
11133123Sjmg# 2. Redistributions in binary form must reproduce the above copyright
12133123Sjmg#    notice, this list of conditions and the following disclaimer in the
13133123Sjmg#    documentation and/or other materials provided with the distribution.
14133123Sjmg#
15133123Sjmg# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16133123Sjmg# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17133123Sjmg# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18133123Sjmg# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19133123Sjmg# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20133123Sjmg# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21133123Sjmg# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22133123Sjmg# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23133123Sjmg# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24133123Sjmg# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25133123Sjmg# SUCH DAMAGE.
26133123Sjmg#
27133123Sjmg# $FreeBSD$
28133123Sjmg
29133123Sjmgcrashpath="/var/crash"
30133123Sjmgkld_debpy="kld_deb.py"
31133123Sjmg
32133123Sjmgif [ x"$1" = x"-?" -o x"$1" = x"-h" ]; then
33133123Sjmg	echo "Usage: $0 <corenum> [ <gdbcmdfile> [ <modulepaths> ] ]"
34133123Sjmg	echo ""
35133123Sjmg	echo "Path for crash dumps: $crashpath"
36133123Sjmg	exit 1
37133123Sjmgfi
38133123Sjmg
39133123Sjmgif [ x"$1" = x"" ]; then
40133123Sjmg	echo "Need core number."
41133123Sjmg	exit 1
42133123Sjmgfi
43133123Sjmgcorenum="$1"
44133123Sjmgshift
45133123Sjmg
46133123Sjmgcmd_file=""
47133123Sjmgif [ x"$2" != x"" ]; then
48133123Sjmg	cmd_file="-x $2"
49133123Sjmg	shift
50133123Sjmgfi
51133123Sjmg
52133123Sjmgcore="$crashpath/vmcore.$corenum"
53133123Sjmginfo="$crashpath/info.$corenum"
54133123Sjmg
55133123Sjmg#Get the kernel source compile dir from the info file
56133123Sjmgkernsrc="`awk 'i == 1 { split($0, a, ":"); print a[2]; i = 0 } $1 == "Versionstring:" { i = 1 }' < "$info"`"
57133123Sjmg
58133123Sjmgtmpfile="/tmp/kgdb.asf.$$"
59133123Sjmg# -mapped (broken?)
60133123Sjmg# -x command_file
61133123Sjmgecho "Kernel Source:	$kernsrc"
62133123Sjmgecho "Getting KLD information and locations..."
63133123Sjmgpython $kld_debpy "$kernsrc" "$core" $@ > "$tmpfile" &&
64143864Sjmgecho "Please run the following command to load module symbols:"
65143864Sjmgecho "source $tmpfile"
66143864Sjmg(cd "$kernsrc"; kgdb "$kernsrc/kernel.debug" "$core")
67133123Sjmgrm "$tmpfile"
68