stack revision 1.1 1 1.1 jhawk # $NetBSD: stack,v 1.1 2000/06/08 03:15:40 jhawk Exp $
2 1.1 jhawk
3 1.1 jhawk # Copyright (c) 2000 The NetBSD Foundation, Inc.
4 1.1 jhawk # All rights reserved.
5 1.1 jhawk #
6 1.1 jhawk # This code is derived from software contributed to The NetBSD Foundation
7 1.1 jhawk # by John A. Hawkinson.
8 1.1 jhawk #
9 1.1 jhawk # Redistribution and use in source and binary forms, with or without
10 1.1 jhawk # modification, are permitted provided that the following conditions
11 1.1 jhawk # are met:
12 1.1 jhawk # 1. Redistributions of source code must retain the above copyright
13 1.1 jhawk # notice, this list of conditions and the following disclaimer.
14 1.1 jhawk # 2. Redistributions in binary form must reproduce the above copyright
15 1.1 jhawk # notice, this list of conditions and the following disclaimer in the
16 1.1 jhawk # documentation and/or other materials provided with the distribution.
17 1.1 jhawk # 3. All advertising materials mentioning features or use of this software
18 1.1 jhawk # must display the following acknowledgement:
19 1.1 jhawk # This product includes software developed by the NetBSD
20 1.1 jhawk # Foundation, Inc. and its contributors.
21 1.1 jhawk # 4. Neither the name of The NetBSD Foundation nor the names of its
22 1.1 jhawk # contributors may be used to endorse or promote products derived
23 1.1 jhawk # from this software without specific prior written permission.
24 1.1 jhawk #
25 1.1 jhawk # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26 1.1 jhawk # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1 jhawk # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1 jhawk # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29 1.1 jhawk # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1 jhawk # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1 jhawk # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1 jhawk # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1 jhawk # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1 jhawk # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1 jhawk # POSSIBILITY OF SUCH DAMAGE.
36 1.1 jhawk
37 1.1 jhawk
38 1.1 jhawk # Follow an i386 kernel stack trace.
39 1.1 jhawk # This code makes presumptions about the way frames look, consistent
40 1.1 jhawk # with arch/i386/i386/db_trace.c. It also steals algorithms from there.
41 1.1 jhawk
42 1.1 jhawk # Output looks like:
43 1.1 jhawk #
44 1.1 jhawk # 0xc03049cb <cpu_reboot+99>(0x100,0x0,0xc04fd728,0x0,0x6)
45 1.1 jhawk # at 0xc01bc97d <panic+197> (frame at 0xc5633bd0)
46 1.1 jhawk #
47 1.1 jhawk # In this case, the initial hex number and offset should be disregarded,
48 1.1 jhawk # and it should be interprted as if it were:
49 1.1 jhawk #
50 1.1 jhawk # cpu_reboot(0x100,0x0,0xc04fd728,0x0,0x6)
51 1.1 jhawk # at 0xc01bc97d <panic+197> (frame at 0xc5633bd0)
52 1.1 jhawk #
53 1.1 jhawk # due to limitations of gdb scripting.
54 1.1 jhawk
55 1.1 jhawk define stack
56 1.1 jhawk set $frame=$arg0
57 1.1 jhawk set $retaddr=$arg1
58 1.1 jhawk
59 1.1 jhawk while ($frame != 0)
60 1.1 jhawk set $callpc = $retaddr
61 1.1 jhawk set $retaddr = *(long*)($frame+4)
62 1.1 jhawk
63 1.1 jhawk set $inst=*(long*)$retaddr
64 1.1 jhawk if (($inst & 0xff) == 0x59)
65 1.1 jhawk # (popl %ecx)
66 1.1 jhawk set $narg=1
67 1.1 jhawk else if (($inst & 0xffff) == 0xc483)
68 1.1 jhawk # (addl %n, %esp)
69 1.1 jhawk set $narg = (($inst >> 16) & 0xff) / 4
70 1.1 jhawk else
71 1.1 jhawk set $narg = 5
72 1.1 jhawk end
73 1.1 jhawk
74 1.1 jhawk set $argp = $frame+8
75 1.1 jhawk printf " "
76 1.1 jhawk output/a $callpc
77 1.1 jhawk printf "("
78 1.1 jhawk while ($narg != 0)
79 1.1 jhawk printf "0x%lx", *(long*)$argp
80 1.1 jhawk set $argp = $argp+4
81 1.1 jhawk set $narg = $narg-1
82 1.1 jhawk if ($narg != 0)
83 1.1 jhawk printf ","
84 1.1 jhawk end
85 1.1 jhawk end
86 1.1 jhawk printf ")\n at "
87 1.1 jhawk output/a $retaddr
88 1.1 jhawk printf " (frame at %#x)\n", $frame
89 1.1 jhawk
90 1.1 jhawk set $frame=*(long*)($frame+0)
91 1.1 jhawk end
92 1.1 jhawk end
93 1.1 jhawk
94 1.1 jhawk document stack
95 1.1 jhawk ==> (gdb) stack FP IP
96 1.1 jhawk print a backtrace of all stack frames, starting at frame pointer FP,
97 1.1 jhawk and instruction pointer IP. For the default trace, run:
98 1.1 jhawk "stack $ebp $eip"
99 1.1 jhawk end