Author: wmb
Date: Thu Mar 22 01:21:57 2012
New Revision: 2913
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/2913
Log:
Debugger - improved the "up" command so it will skip past the method call machinery to find the caller that the user cares about.
Modified:
forth/lib/debug.fth
forth/lib/rstrace.fth
ofw/core/ofwcore.fth
Modified: forth/lib/debug.fth
==============================================================================
--- forth/lib/debug.fth Wed Mar 21 23:25:54 2012 (r2912)
+++ forth/lib/debug.fth Thu Mar 22 01:21:57 2012 (r2913)
@@ -75,26 +75,28 @@
;
bug definitions
headerless
-\ Go up the return stack until we find the return address left by our caller
-: caller-ip ( rp -- ip )
- begin
- na1+ dup @ dup in-dictionary? if ( rs-adr ip )
- ip>token token@
- dup ['] execute = over defer? or swap <ip @ body> = or
- else
- drop false
- then
- until ( rs-adr )
- @ ip>token
-;
+\ Go up the return stack until we find an interesting caller
: up1 ( rp -- )
- caller-ip
- dup find-cfa ( ip cfa )
- dup ['] catch = if 2drop exit then
- cr ." [ Up to " dup .name ." ]" cr ( ip cfa )
- over token@ .name ( ip cfa )
- >body swap 'unnest (debug)
+ begin na1+ dup rp0 @ <> while ( rs-adr )
+ dup @ ( rs-adr ip )
+ dup in-dictionary? if ( rs-adr ip )
+ find-cfa dup indirect-call? if ( rs-adr xt )
+ drop ( rs-adr )
+ else ( rs-adr xt )
+ nip ( rs-adr )
+ scrolling-debug? if ( xt )
+ cr ." [ Up to " dup .name ." ]" cr
+ then ( xt )
+ (debug ( )
+ exit ( -- )
+ then ( rs-adr )
+ else ( rs-adr ip )
+ drop ( rs-adr )
+ then ( rs-adr )
+ repeat ( rs-adr )
+ drop ( )
;
+
defer to-debug-window ' noop is to-debug-window
defer restore-window ' noop is restore-window
: .debug-short-help ( -- )
@@ -183,19 +185,12 @@
d# 78 rmargin !
.debug-short-help
." Callers: " rp0 @ the-rp na1+ rslist kill-line cr
- \ XXX the following is wrong when popping up
- the-ip <ip @ = if
- #line @ is stack-line \ So the initial stack is displayed in the right place
- then
d# 40 rmargin !
the-ip debug-see
cr
- \ When popping up from an interior word, display the initial stack on
- \ the line where the cursor will be.
- the-ip <ip @ <> if
- the-ip ip>position if ( col row )
- drop is stack-line ( )
- then
+ \ Display the initial stack on the cursor line
+ the-ip ip>position 0= if ( col row )
+ is stack-line drop ( )
then
;
: setup-debug-display ( -- )
Modified: forth/lib/rstrace.fth
==============================================================================
--- forth/lib/rstrace.fth Wed Mar 21 23:25:54 2012 (r2912)
+++ forth/lib/rstrace.fth Thu Mar 22 01:21:57 2012 (r2913)
@@ -103,9 +103,9 @@
\ boring? is a hook for Open Firmware. It recognizes words like
\ $call-method that are essentially indirect calls. Such words
\ just clutter up the stack display and should be elided for clarity.
-defer boring?
-: (boring?) ( ip -- flag ) drop false ;
-' (boring?) is boring?
+defer indirect-call?
+: (indirect-call?) ( xt -- flag ) ['] catch = ;
+' (indirect-call?) is indirect-call?
: rtraceword ( rs-end rs-adr -- rs-end rs-adr' )
@+ ( rs-end rs-adr' ip )
@@ -120,7 +120,7 @@
find-cfa ( rs-end rs-adr xt )
- dup boring? if ( rs-end rs-adr xt )
+ dup indirect-call? if ( rs-end rs-adr xt )
drop exit ( -- rs-end rs-adr )
then ( rs-end rs-adr xt )
Modified: ofw/core/ofwcore.fth
==============================================================================
--- ofw/core/ofwcore.fth Wed Mar 21 23:25:54 2012 (r2912)
+++ ofw/core/ofwcore.fth Thu Mar 22 01:21:57 2012 (r2913)
@@ -4772,20 +4772,21 @@
[then]
also hidden
-: method-call? ( ip -- flag )
- dup ['] $call-self = if drop true exit then ( ip )
- dup ['] $call-method = if drop true exit then ( ip )
- dup ['] $call-parent = if drop true exit then ( ip )
- dup ['] call-package = if drop true exit then ( ip )
- dup ['] $vexecute = if drop true exit then ( ip )
- dup ['] $vexecute? = if drop true exit then ( ip )
- dup ['] $package-execute? = if drop true exit then ( ip )
- dup ['] package-execute = if drop true exit then ( ip )
- dup ['] apply-method = if drop true exit then ( ip )
- dup ['] (apply-method) = if drop true exit then ( ip )
- dup ['] (execute-method) = if drop true exit then ( ip )
- dup ['] execute-device-method = if drop true exit then ( ip )
+: method-call? ( xt -- flag )
+ dup (indirect-call?) if drop true exit then ( xt )
+ dup ['] $call-self = if drop true exit then ( xt )
+ dup ['] $call-method = if drop true exit then ( xt )
+ dup ['] $call-parent = if drop true exit then ( xt )
+ dup ['] call-package = if drop true exit then ( xt )
+ dup ['] $vexecute = if drop true exit then ( xt )
+ dup ['] $vexecute? = if drop true exit then ( xt )
+ dup ['] $package-execute? = if drop true exit then ( xt )
+ dup ['] package-execute = if drop true exit then ( xt )
+ dup ['] apply-method = if drop true exit then ( xt )
+ dup ['] (apply-method) = if drop true exit then ( xt )
+ dup ['] (execute-method) = if drop true exit then ( xt )
+ dup ['] execute-device-method = if drop true exit then ( xt )
drop false
;
-' method-call? to boring?
+' method-call? to indirect-call?
previous
Author: wmb
Date: Wed Mar 21 23:16:33 2012
New Revision: 2911
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/2911
Log:
rstrace - set the default value for boring? so the debugger works before OFW is loaded.
Modified:
forth/lib/rstrace.fth
Modified: forth/lib/rstrace.fth
==============================================================================
--- forth/lib/rstrace.fth Wed Mar 21 23:15:39 2012 (r2910)
+++ forth/lib/rstrace.fth Wed Mar 21 23:16:33 2012 (r2911)
@@ -99,8 +99,14 @@
then ( rs-adr n )
drop ( rs-adr )
;
+
+\ boring? is a hook for Open Firmware. It recognizes words like
+\ $call-method that are essentially indirect calls. Such words
+\ just clutter up the stack display and should be elided for clarity.
defer boring?
: (boring?) ( ip -- flag ) drop false ;
+' (boring?) is boring?
+
: rtraceword ( rs-end rs-adr -- rs-end rs-adr' )
@+ ( rs-end rs-adr' ip )
dup reasonable-ip? 0= if ( rs-end rs-adr ip )
Author: wmb
Date: Wed Mar 21 23:15:39 2012
New Revision: 2910
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/2910
Log:
Debugger - factored (trace so it's not so crazy long, and cleaned up a few minor glitches.
Modified:
forth/lib/debug.fth
Modified: forth/lib/debug.fth
==============================================================================
--- forth/lib/debug.fth Wed Mar 21 23:14:01 2012 (r2909)
+++ forth/lib/debug.fth Wed Mar 21 23:15:39 2012 (r2910)
@@ -37,8 +37,7 @@
variable step? step? on
variable res
headers
-false value first-time?
-d# 10 circular-stack: locations
+false value redisplay?
: (debug) (s low-adr hi-adr -- )
unbug 1 cnt ! ip> ! <ip ! pnext
@@ -47,7 +46,7 @@
slow-next? on
then
step? on
- true is first-time?
+ true is redisplay?
;
headerless
: 'unnest (s pfa -- pfa' )
@@ -116,6 +115,7 @@
." $ Display top of stack as adr,len text string" cr
." \ Display Forth return stack as numbers (like the data stack)" cr
." Q Quit: abandon execution of the debugged word" cr
+ ." V Visual: toggle between 2-D and scrolling" cr
;
d# 24 constant cmd-column
: to-cmd-column ( -- ) cmd-column to-column ;
@@ -141,8 +141,6 @@
: save-result-loc ( -- ) #out @ to result-col #line @ to result-line ;
: to-result-loc ( -- ) result-col result-line at-xy ;
-0 value rp-mark
-
\ set-package is a hook for Open Firmware. When Open Firmware is loaded,
\ set-package should be set to a word that sets the active package to the
\ package corresponding to the current instance. set-package is called
@@ -165,72 +163,82 @@
variable hex-stack \ Show the data stack in hex?
: save# ( -- ) #-buf /#buf - #buf-save d# 72 move hld @ hld-save ! ;
: restore# ( -- ) #buf-save #-buf /#buf - d# 72 move hld-save @ hld ! ;
+0 value the-ip
+0 value the-rp
: (.rs ( -- )
show-rstack @ 0= if exit then
." return-stack: "
push-hex
- rp0 @ rp@ - /n /
- 6 do \ It appears that skipping the first 6 entries on the stack skips the debug goo on the rs
- rp@ i /n * + @ .
- loop
+ \ Skip the debugger's footprint on the return stack
+ rp0 @ the-rp 5 na+ ?do i @ . /n +loop
pop-base
;
-: (trace ( -- )
- first-time? if
+: setup-scrolling-display ( -- )
+ ??cr
+ the-ip <ip @ = if ." : " else ." Inside " then
+ <ip @ find-cfa .name
+;
+: setup-2d-display ( -- )
+ page
+ d# 78 rmargin !
+ .debug-short-help
+ ." Callers: " rp0 @ the-rp na1+ rslist kill-line cr
+ \ XXX the following is wrong when popping up
+ the-ip <ip @ = if
+ #line @ is stack-line \ So the initial stack is displayed in the right place
+ then
+ d# 40 rmargin !
+ the-ip debug-see
+ cr
+ \ When popping up from an interior word, display the initial stack on
+ \ the line where the cursor will be.
+ the-ip <ip @ <> if
+ the-ip ip>position if ( col row )
+ drop is stack-line ( )
+ then
+ then
+;
+: setup-debug-display ( -- )
+ redisplay? if
scrolling-debug? if
- ??cr
- ip@ <ip @ = if ." : " else ." Inside " then
- <ip @ find-cfa .name
+ setup-scrolling-display
else
- page
- d# 78 rmargin !
- ." Callers: " rp0 @ rp@ na1+ rslist kill-line cr
- \ XXX the following is wrong when popping up
- ip@ <ip @ = if
- #line @ is stack-line \ So the initial stack is displayed in the right place
- then
- d# 40 rmargin !
- ip@ debug-see
- cr
-\ ip@ <ip @ <> if
-\ ip@ ip>position if ( col row )
-\ swap
-\ is stack-line
-\ then
-\ #line @ is stack-line \ So the initial stack is displayed in the right place
- \ then
+ setup-2d-display
then
0 show-rstack !
- false is first-time?
- rp@ is rp-mark
+ false is redisplay?
then
-
- begin
- step? @ if to-debug-window then
+;
+: show-debug-stack ( -- )
+ scrolling-debug? if
save#
- scrolling-debug? if
- cmd-column 2+ to-column
+ cmd-column 2+ to-column
- hex-stack @ if push-hex then
- ." ( " .s \ Show data stack
- hex-stack @ if pop-base then
- show-rstack @ if (.rs then \ Show return stack
- ." )"
- restore#
-
- cr
- ['] noop is indent
- ip@ .token drop \ Show word name
- ['] (indent) is indent
- to-cmd-column
- else
- save-result-loc
- show-partial-stack
+ hex-stack @ if push-hex then
+ ." ( " .s \ Show data stack
+ hex-stack @ if pop-base then
+ show-rstack @ if (.rs then \ Show return stack
+ ." )"
+ restore#
+
+ cr
+ ['] noop is indent
+ the-ip .token drop \ Show word name
+ ['] (indent) is indent
+ to-cmd-column
+ else
+ save-result-loc
+ show-partial-stack
- ip@ ip-set-cursor
- #line @ to stack-line
- then
-
+ the-ip ip-set-cursor
+ #line @ to stack-line
+ then
+;
+: debug-interact ( -- )
+ save#
+ begin
+ step? @ if to-debug-window then
+ show-debug-stack
step? @ key? or if
step? on res off
key dup bl < if drop bl then
@@ -238,28 +246,35 @@
restore-window
scrolling-debug? if reset-page then
case
- ascii D of ip@ token@ executer ['] (debug try endof \ Down
- ascii U of rp@ ['] up1 try endof \ Up
- ascii C of step? @ 0= step? ! true endof \ Continue
- ascii F of
+ ascii D of the-ip token@ executer ['] (debug try endof \ Down
+ ascii U of the-rp ['] up1 try endof \ Up
+ ascii C of \ Continue
+ step? @ 0= step? !
+ step? @ 0= if true to scrolling-debug? true to redisplay? then
+ true
+ endof
+
+ ascii F of \ Forth
cr ." Type 'resume' to return to debugger" cr
set-package interact unset-package false
- endof \ Forth
- ascii G of debug-off cr exit endof \ Go
- ascii H of cr .debug-long-help false endof \ Help
- ascii R of cr rp0 @ rp@ na1+ (rstrace false endof \ RSTrace
- ascii S of cr <ip @ body> (see) false endof \ See
- ascii ? of cr .debug-short-help false endof \ Short Help
+ endof
+ ascii G of debug-off cr true endof \ Go
+ ascii H of cr .debug-long-help false endof \ Help
+ ascii R of cr rp0 @ the-rp na1+ (rstrace false endof \ RSTrace
+ ascii S of cr <ip @ body> (see) false endof \ See
+ ascii ? of cr .debug-short-help false endof \ Short Help
ascii $ of space 2dup type cr to-cmd-column false endof \ String
ascii Q of cr ." unbug" abort true endof \ Quit
- ascii ( of ip@ set-<ip false endof
- ascii < of ip@ ta1+ set-<ip 1 cnt ! false endof
- ascii ) of ip@ ip> ! 1 cnt ! false endof
- ascii * of ip@ find-cfa dup <ip ! 'unnest ip> ! false endof
- ascii \ of show-rstack @ 0= show-rstack ! false endof
- ascii X of hex-stack @ 0= hex-stack ! false endof
- ascii V of scrolling-debug? 0= to scrolling-debug?
- scrolling-debug? 0= if true to first-time? then false endof
+ ascii ( of the-ip set-<ip false endof
+ ascii < of the-ip ta1+ set-<ip 1 cnt ! false endof
+ ascii ) of the-ip ip> ! 1 cnt ! false endof
+ ascii * of the-ip find-cfa dup <ip ! 'unnest ip> ! false endof
+ ascii \ of show-rstack @ 0= show-rstack ! false endof \ toggle return stack display
+ ascii X of hex-stack @ 0= hex-stack ! false endof \ toggle heX stack display
+ ascii V of \ toggle Visual (2D) mode
+ scrolling-debug? 0= to scrolling-debug?
+ scrolling-debug? 0= if true to redisplay? then false
+ endof
( default ) true swap
endcase
else
@@ -267,11 +282,17 @@
then
until
restore#
- scrolling-debug? 0= if to-result-loc then
- ip@ token@ dup ['] unnest = swap ['] exit = or if
- cr true is first-time?
+;
+: (trace ( -- )
+ ip@ to the-ip
+ rp@ to the-rp
+ setup-debug-display
+ debug-interact
+\ scrolling-debug? 0= if to-result-loc then
+ the-ip token@ dup ['] unnest = swap ['] exit = or if
+ cr true is redisplay?
then
- pnext
+ slow-next? @ if pnext then
;
' (trace 'debug token!