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