Annotation of gforth/debug.fs, revision 1.15

1.1       anton       1: \ DEBUG.FS     Debugger                                12jun93jaw
                      2: 
1.9       anton       3: \ Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
1.4       anton       4: 
                      5: \ This file is part of Gforth.
                      6: 
                      7: \ Gforth is free software; you can redistribute it and/or
                      8: \ modify it under the terms of the GNU General Public License
                      9: \ as published by the Free Software Foundation; either version 2
                     10: \ of the License, or (at your option) any later version.
                     11: 
                     12: \ This program is distributed in the hope that it will be useful,
                     13: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
                     14: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     15: \ GNU General Public License for more details.
                     16: 
                     17: \ You should have received a copy of the GNU General Public License
                     18: \ along with this program; if not, write to the Free Software
                     19: \ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
                     20: 
1.1       anton      21: decimal
                     22: 
1.14      crook      23: VARIABLE dbg-ip     \ instruction pointer for debugger
1.1       anton      24: 
1.15    ! jwilke     25: \ !! move to see?
        !            26: 
        !            27: : save-see-flags ( -- n* cnt )
        !            28:   C-Output @
        !            29:   C-Formated @ 1 ;
        !            30: 
        !            31: : restore-see-flags ( n* cnt -- )
        !            32:   drop C-Formated !
        !            33:   C-Output ! ;
        !            34: 
1.1       anton      35: : scanword ( body -- )
1.15    ! jwilke     36:         >r save-see-flags r>
1.1       anton      37:         c-init C-Output off
                     38:         ScanMode c-pass !
                     39:         dup MakePass
                     40:         0 Level !
                     41:         0 XPos !
                     42:         DisplayMode c-pass !
                     43:         MakePass
1.15    ! jwilke     44:         restore-see-flags ;
1.1       anton      45: 
                     46: : .n    0 <# # # # # #S #> ctype bl cemit ;
                     47: 
                     48: : d.s   ." [ " depth . ." ] "
                     49:         depth 4 min dup 0 ?DO dup i - pick .n LOOP drop ;
                     50: 
                     51: : NoFine        XPos off YPos off
                     52:                 NLFlag off Level off
                     53:                 C-Formated off
                     54:                 ;
                     55: 
1.15    ! jwilke     56: : Leave-D ;
        !            57: 
        !            58: : disp-step ( -- )
        !            59: \ display step at current dbg-ip
1.1       anton      60:         DisplayMode c-pass !            \ change to displaymode
                     61:         cr
                     62:         c-stop off
1.8       jwilke     63:         Base @ hex dbg-ip @ 8 u.r space dbg-ip @ @ 8 u.r space
1.1       anton      64:         Base !
1.15    ! jwilke     65:         save-see-flags
1.1       anton      66:         NoFine 10 XPos !
1.8       jwilke     67:         dbg-ip @ DisplayMode c-pass ! Analyse drop
1.15    ! jwilke     68:         25 XPos @ - 0 max spaces ." -> " 
        !            69:         restore-see-flags ;
1.1       anton      70: 
                     71: : get-next ( -- n | n n )
                     72:         DebugMode c-pass !
1.8       jwilke     73:         dbg-ip @ Analyse ;
1.1       anton      74: 
                     75: : jump          ( addr -- )
                     76:                 r> drop \ discard last ip
                     77:                 >r ;
                     78: 
                     79: AVARIABLE DebugLoop
                     80: 
1.8       jwilke     81: : breaker      r> 1 cells - dbg-ip ! DebugLoop @ jump ;
1.1       anton      82: 
                     83: CREATE BP 0 , 0 ,
                     84: CREATE DT 0 , 0 ,
                     85: 
                     86: : set-bp        ( 0 n | 0 n n -- )
                     87:                 0. BP 2!
                     88:                 ?dup IF dup BP ! dup @ DT !
                     89:                         ['] Breaker swap !
                     90:                         ?dup IF dup BP cell+ ! dup @ DT cell+ !
                     91:                                 ['] Breaker swap ! drop THEN
                     92:                      THEN ;
                     93: 
                     94: : restore-bp    ( -- )
                     95:                 BP @ ?dup IF DT @ swap ! THEN
                     96:                 BP cell+ @ ?dup IF DT cell+ @ swap ! THEN ;
                     97: 
                     98: VARIABLE Body
                     99: 
                    100: : NestXT        ( xt -- true | body false )
1.10      jwilke    101:                \ special deal for create does> words
                    102:                \ leaves body address on the stack
                    103:                dup >does-code IF dup >body swap THEN
                    104: 
1.1       anton     105:                 DebugMode c-pass ! C-Output off
1.5       anton     106:                 xt-see C-Output on
1.1       anton     107:                 c-pass @ DebugMode = dup
                    108:                 IF      ." Cannot debug" cr
                    109:                 THEN ;         
                    110: 
                    111: VARIABLE Nesting
                    112: 
                    113: VARIABLE Unnest
                    114: 
                    115: : D-KEY         ( -- flag )
                    116:         BEGIN
                    117:                 Unnest @ IF 0 ELSE key THEN
1.8       jwilke    118:                 CASE    [char] n OF     dbg-ip @ @ NestXT EXIT ENDOF
1.1       anton     119:                         [char] s OF     Leave-D
                    120:                                         -128 THROW ENDOF
                    121:                         [char] a OF     Leave-D
                    122:                                         -128 THROW ENDOF
                    123:                         [char] d OF     Leave-D
                    124:                                         cr ." Done..." cr
                    125:                                         Nesting off
1.8       jwilke    126:                                         r> drop dbg-ip @ >r
1.1       anton     127:                                         EXIT ENDOF
                    128:                         [char] ? OF     cr ." Nest Stop Done Unnest" cr
                    129:                                         ENDOF
                    130:                         [char] u OF     Unnest on true EXIT ENDOF
                    131:                         drop true EXIT
                    132:                 ENDCASE
                    133:         AGAIN ;
                    134: 
1.15    ! jwilke    135: : (_debug) ( body ip -- )
1.1       anton     136:         0 Nesting !
                    137:         BEGIN   Unnest off
                    138:                 cr ." Scanning code..." cr C-Formated on
1.15    ! jwilke    139:                 swap scanword dbg-ip !
1.1       anton     140:                 cr ." Nesting debugger ready!" cr
1.10      jwilke    141:                 BEGIN   d.s disp-step D-Key
1.1       anton     142:                 WHILE   C-Stop @ 0=
                    143:                 WHILE   0 get-next set-bp
1.8       jwilke    144:                         dbg-ip @ jump
1.1       anton     145:                         [ here DebugLoop ! ]
                    146:                         restore-bp
                    147:                 REPEAT
1.8       jwilke    148:                 Nesting @ 0= IF EXIT THEN
1.1       anton     149:                 -1 Nesting +! r>
                    150:                 ELSE
1.8       jwilke    151:                 dbg-ip @ 1 cells + >r 1 Nesting +!
1.1       anton     152:                 THEN
1.15    ! jwilke    153:                 dup
1.1       anton     154:         AGAIN ;
                    155: 
1.15    ! jwilke    156: : (debug) dup (_debug) ;
        !           157: 
1.14      crook     158: : dbg ( "name" -- ) \ gforth 
1.11      crook     159:     ' NestXT IF EXIT THEN (debug) Leave-D ;
1.1       anton     160: 
1.15    ! jwilke    161: : break:, ( -- )
        !           162:   lastxt postpone literal ;
        !           163: 
        !           164: : (break:)
        !           165:     r> ['] (_debug) >body >r ;
        !           166:   
1.14      crook     167: : break: ( -- ) \ gforth
1.15    ! jwilke    168:     break:, postpone (break:) ; immediate
1.6       anton     169: 
1.7       jwilke    170: : (break")
1.11      crook     171:     cr
                    172:     ." BREAK AT: " type cr
1.15    ! jwilke    173:     r> ['] (_debug) >body >r ;
1.6       anton     174: 
1.14      crook     175: : break" ( 'ccc"' -- ) \ gforth
1.15    ! jwilke    176:     break:,
1.11      crook     177:     postpone s"
                    178:     postpone (break") ; immediate

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>