Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / fm / lib / debug.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: debug.fth
4\
5\ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6\
7\ - Do no alter or remove copyright notices
8\
9\ - Redistribution and use of this software in source and binary forms, with
10\ or without modification, are permitted provided that the following
11\ conditions are met:
12\
13\ - Redistribution of source code must retain the above copyright notice,
14\ this list of conditions and the following disclaimer.
15\
16\ - Redistribution in binary form must reproduce the above copyright notice,
17\ this list of conditions and the following disclaimer in the
18\ documentation and/or other materials provided with the distribution.
19\
20\ Neither the name of Sun Microsystems, Inc. or the names of contributors
21\ may be used to endorse or promote products derived from this software
22\ without specific prior written permission.
23\
24\ This software is provided "AS IS," without a warranty of any kind.
25\ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
26\ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
27\ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
28\ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
29\ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
30\ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
31\ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
32\ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
33\ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
34\ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
35\ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
36\
37\ You acknowledge that this software is not designed, licensed or
38\ intended for use in the design, construction, operation or maintenance of
39\ any nuclear facility.
40\
41\ ========== Copyright Header End ============================================
42\ debug.fth 1.15 95/04/19
43\ Copyright 1985-1990 Bradley Forthware
44
45\ Debugger. Thanks, Mike Perry, Henry Laxen, Mark Smeder.
46\
47\ The debugger lets you single step the execution of a high level
48\ definition. To invoke the debugger, type debug xxx where xxx is
49\ the name of the word you wish to trace. When xxx executes, you will
50\ get a single step trace showing you the word within xxx that
51\ is about to execute, and the contents of the parameter stack.
52\ Debugging makes everything run slightly slower, even outside
53\ the word being debugged. see debug-off
54\
55\ debug name Mark that word for debugging
56\ stepping Debug in single step mode
57\ tracing Debug in trace mode
58\ debug-off Turn off the debugger (makes the system run fast again)
59\ resume Exit from a pushed interpreter (see the f keystroke)
60\
61\ Keystroke commands while you're single-stepping:
62\ d go down a level
63\ u go up a level
64\ c continue; trace without single stepping
65\ g go; turn off stepping and continue execution
66\ f push a Forth interpreter; execute "resume" to get back
67\ q abort back to the top level
68
69only forth also definitions
70
71hex
72headerless
73variable slow-next? slow-next? off
74
75only forth hidden also forth also definitions
76bug also definitions
77variable step? step? on
78variable res
79headers
80: (debug) (s low-adr hi-adr -- ) recursive
81 \ Refuse to debug the kernel; it's too dangerous
82 over low-dictionary-adr ['] (debug) between
83 abort" The source debugger cannot debug the Forth kernel."
84
85 unbug 1 cnt ! ip> ! <ip ! pnext
86 slow-next? @ 0= if
87 here low-dictionary-adr slow-next
88 slow-next? on
89 then
90 step? on
91;
92headerless
93: 'unnest (s pfa -- pfa' )
94 begin dup ta1+ swap token@ ['] unnest = until
95;
96
97false value first-time?
98headers
99\ Enter and leave the debugger
100forth definitions
101: (debug ( acf -- )
102 dup colon-cf? 0= abort" Not a colon definition"
103 >body dup 'unnest (debug) true is first-time?
104;
105bug definitions
106headerless
107\ Go up the return stack until we find the return address left by our caller
108: caller-ip ( -- ip )
109 rp@ begin
110 na1+ dup @ dup in-dictionary? if ( rs-adr ip )
111 ip>token token@ <ip @ body> =
112 else
113 drop false
114 then
115 until ( rs-adr )
116 @ ip>token
117;
118: up1 ( ip -- )
119 caller-ip
120 dup find-cfa ( ip cfa )
121 cr ." [ Up to " dup .name ." ]" cr ( ip cfa )
122 over token@ .name ( ip cfa )
123 >body swap 'unnest (debug)
124;
125defer to-debug-window ' noop is to-debug-window
126defer restore-window ' noop is restore-window
127: .debug-short-help ( -- )
128 ." Stepper keys: <space> Down Up Continue Forth Go Help ? See $tring Quit" cr
129;
130: .debug-long-help ( -- )
131 ." Key Action" cr
132 ." <space> Execute displayed word" cr
133 ." D Down: Step down into displayed word" cr
134 ." U Up: Finish current definition and step in its caller" cr
135 ." C Continue: trace current definition without stopping" cr
136 ." F Forth: enter a subordinate Forth interpreter" cr
137 ." G Go: resume normal exection (stop debugging)" cr
138 ." H Help: display this message" cr
139 ." ? Display short list of debug commands" cr
140 ." S See: Decompile definition being debugged" cr
141 ." $ Display top of stack as adr,len text string" cr
142 ." Q Quit: abandon execution of the debugged word" cr
143;
144d# 24 constant cmd-column
1450 value rp-mark
146: to-cmd-column ( -- ) cmd-column to-column ;
147: (trace ( -- )
148 first-time? if
149 ??cr ." : " <ip @ body> .name
150 false is first-time?
151 rp@ is rp-mark
152 then
153 begin
154 step? @ if to-debug-window then
155 cmd-column 2+ to-column ." ( " .s ." )" cr \ Show stack
156
157 ['] noop is indent
158 ip@ .token drop \ Show word name
159 ['] (indent) is indent
160 to-cmd-column
161
162 step? @ key? or if
163 step? on res off
164 key dup bl < if drop bl then dup emit upc
165 restore-window
166 case
167 ascii D of ip@ token@
168 ['] (debug catch if drop false else cr true then
169 endof \ Down
170 ascii U of up1 true endof \ Up
171 ascii C of step? @ 0= step? ! true endof \ Continue
172 ascii F of
173 cr ." Type 'resume' to return to debugger" cr
174 interact false
175 endof \ Forth
176 ascii G of <ip off ip> off cr true endof \ Go
177 ascii H of cr .debug-long-help false endof \ Help
178 ascii S of cr <ip @ body> (see) false endof \ Help
179 ascii ? of cr .debug-short-help false endof \ Help
180 ascii $ of space 2dup type cr to-cmd-column false endof \ String
181 ascii Q of cr ." unbug" abort true endof \ Quit
182 ( default ) true swap
183 endcase
184 else
185 true
186 then
187 until
188 ip@ token@ dup ['] unnest = swap ['] exit = or if
189 cr true is first-time?
190 then
191 pnext
192;
193' (trace 'debug token!
194
195headers
196
197only forth bug also forth definitions
198
199: debug \ name (s -- )
200 .debug-short-help
201 ' (debug
202;
203: resume (s -- ) true is exit-interact? pnext ;
204: stepping (s -- ) step? on ;
205: tracing (s -- ) step? off ;
206: debug-off (s -- )
207 unbug here low-dictionary-adr fast-next slow-next? off
208;
209
210only forth also definitions