MiniDebugger.st
changeset 25253 c0422fc32176
parent 25251 61b643937051
child 25293 037a1af56749
equal deleted inserted replaced
25252:826c0e1220af 25253:c0422fc32176
       
     1 "{ Encoding: utf8 }"
       
     2 
     1 "
     3 "
     2  COPYRIGHT (c) 1988 by Claus Gittinger
     4  COPYRIGHT (c) 1988 by Claus Gittinger
     3 	      All Rights Reserved
     5 	      All Rights Reserved
     4 
     6 
     5  This software is furnished under a license and may be used
     7  This software is furnished under a license and may be used
    13 
    15 
    14 "{ NameSpace: Smalltalk }"
    16 "{ NameSpace: Smalltalk }"
    15 
    17 
    16 Object subclass:#MiniDebugger
    18 Object subclass:#MiniDebugger
    17 	instanceVariableNames:'tracing stepping traceBlock command commandArg commandCount
    19 	instanceVariableNames:'tracing stepping traceBlock command commandArg commandCount
    18 		enteringContext dot nesting inputStream'
    20 		enteringContext dotProcess dot nesting inputStream'
    19 	classVariableNames:'NotFirstTimeEntered'
    21 	classVariableNames:'NotFirstTimeEntered'
    20 	poolDictionaries:''
    22 	poolDictionaries:''
    21 	category:'System-Debugging-Support'
    23 	category:'System-Debugging-Support'
    22 !
    24 !
    23 
    25 
    40 documentation
    42 documentation
    41 "
    43 "
    42     a primitive (non graphical) debugger for use on systems without
    44     a primitive (non graphical) debugger for use on systems without
    43     graphics or when the real debugger dies 
    45     graphics or when the real debugger dies 
    44     (i.e. an error occurs in the graphical debugger or the UI/event handler is broken).
    46     (i.e. an error occurs in the graphical debugger or the UI/event handler is broken).
       
    47 
    45     This one is also called for, if an interrupt occurs within the debuger, 
    48     This one is also called for, if an interrupt occurs within the debuger, 
    46     or if CTRL-C is pressed in the controlling tty/console.
    49     or if CTRL-C is pressed in the controlling tty/console.
    47     Needs a console.
    50     Needs a console.
    48 
    51 
       
    52     You can also enter it explicitly with:
    49         MiniDebugger enter
    53         MiniDebugger enter
    50 
    54 
    51     Attention:
    55     Attention:
    52         all printing is done via lowLevel _errorPrint messages,
    56         all printing is done via lowLevel _errorPrint messages,
    53         to ensure that output is to stderr, even if a logger is present, 
    57         to ensure that output is to stderr, even if a logger is present, 
   462 
   466 
   463 moveDotDown
   467 moveDotDown
   464     "/ sigh - must search
   468     "/ sigh - must search
   465     |c|
   469     |c|
   466 
   470 
   467     c := enteringContext.
   471     dotProcess isNil ifTrue:[ 
       
   472         c := enteringContext
       
   473     ] ifFalse:[ 
       
   474         c := dotProcess suspendedContext.
       
   475         c isNil ifTrue:[
       
   476             '** process is not suspended' _errorPrintCR.
       
   477         ].
       
   478     ].
   468     [ c notNil and:[ c sender ~~ dot ] ] whileTrue:[
   479     [ c notNil and:[ c sender ~~ dot ] ] whileTrue:[
   469         c := c sender.
   480         c := c sender.
   470     ].
   481     ].
   471     c notNil ifTrue:[
   482     c notNil ifTrue:[
   472         dot := c.
   483         dot := c.
   679 
   690 
   680 doCommand:cmd
   691 doCommand:cmd
   681     "a single command;
   692     "a single command;
   682      return true, if command loop should be finished"
   693      return true, if command loop should be finished"
   683 
   694 
   684     |id proc bool|
   695     |id proc bool retVal|
   685 
   696 
   686     "/ care for argument after command character (pid or '+' or '-')
   697     "/ care for argument after command character (pid or '+' or '-')
   687     commandArg notEmptyOrNil ifTrue:[
   698     commandArg notEmptyOrNil ifTrue:[
   688         id := Number readFrom:commandArg onError:nil.
   699         id := Number readFrom:commandArg onError:nil.
   689         id notNil ifTrue:[
   700         id notNil ifTrue:[
   700                 ]
   711                 ]
   701             ]
   712             ]
   702         ]
   713         ]
   703     ].
   714     ].
   704 
   715 
   705     ('wbTQ' includes:cmd) ifTrue:[
   716     "/ S -> save
       
   717     (cmd == $S) ifTrue:[
       
   718         'saving "crash.img"...' _errorPrint.
       
   719         ObjectMemory writeCrashImage.
       
   720         'done.' _errorPrintCR.
       
   721         ^ false
       
   722     ].
       
   723 
       
   724     "/ C -> save session changes
       
   725     (cmd == $C) ifTrue:[
       
   726         |changesFilename|
       
   727 
       
   728         changesFilename := Timestamp now
       
   729              printStringFormat:'changes_%(year)-%(month)-%(day)__%h:%m:%s.chg'.
       
   730         OperatingSystem isMSWINDOWSlike ifTrue:[ changesFilename replaceAll:$: with:$_ ].
       
   731 
       
   732         ('saving session changes to "',changesFilename,'"...') _errorPrintCR.
       
   733         ChangeSet current fileOutAs: changesFilename.
       
   734         'done.' _errorPrintCR.
       
   735         ^ false
       
   736     ].
       
   737 
       
   738     "/ B -> print backtrace of all processes
       
   739     (cmd == $B) ifTrue:[
       
   740         self printAllBacktraces.
       
   741         ^ false
       
   742     ].
       
   743 
       
   744     "/ P -> print all processes
       
   745     (cmd == $P) ifTrue:[
       
   746         self showProcesses:#all.
       
   747         ^ false
       
   748     ].
       
   749     "/ c -> continue
       
   750     (cmd == $c) ifTrue:[^ true].
       
   751 
       
   752     "/ s -> single step
       
   753     (cmd == $s) ifTrue:[^ true].
       
   754 
       
   755     "/ t -> continue with trace
       
   756     (cmd == $t) ifTrue:[^ true].
       
   757 
       
   758     "/ a -> abort
       
   759     (cmd == $a) ifTrue:[
       
   760         id isNil ifTrue:[^ true].
       
   761     ].
       
   762 
       
   763     "/ p -> list (alive) processes
       
   764     (cmd == $p) ifTrue:[
       
   765         self showProcesses:#live.
       
   766         ^ false
       
   767     ].
       
   768 
       
   769 
       
   770     ('wbTQa=' includes:cmd) ifTrue:[
   706         (id notNil and:[proc isNil]) ifTrue:[
   771         (id notNil and:[proc isNil]) ifTrue:[
   707             'no process with id: ' _errorPrint. id _errorPrintCR.
   772             'no process with id: ' _errorPrint. id _errorPrintCR.
   708             ^ false.
   773             ^ false.
   709         ].
   774         ].
       
   775     ].
       
   776 
       
   777     "/ = id -> set current process for dot (to inspect chain/receiver of another thread)
       
   778     (cmd == $=) ifTrue:[
       
   779         (dotProcess == proc) ifFalse:[
       
   780             dotProcess := proc.
       
   781             proc isNil ifTrue:[
       
   782                 dot := enteringContext.
       
   783                 'switched back to interrupted process (for dot commands): ' _errorPrint. Processor activeProcess _errorPrintCR.
       
   784             ] ifFalse:[
       
   785                 dot := proc suspendedContext.
       
   786                 'switched to process (for dot commands): ' _errorPrint. proc _errorPrintCR.
       
   787             ].
       
   788         ].
       
   789         ^ false.
       
   790     ].
       
   791 
       
   792     (cmd == $a) ifTrue:[
       
   793         "/ here a with id-arg
       
   794         proc == Processor activeProcess ifTrue:[^ true].
       
   795         proc interruptWith:[ AbortOperationRequest raise ].
       
   796         ^ false.
   710     ].
   797     ].
   711 
   798 
   712     (cmd == $w) ifTrue:[
   799     (cmd == $w) ifTrue:[
   713         proc notNil ifTrue:[
   800         proc notNil ifTrue:[
   714             '-------- walkback of process ' _errorPrint. id _errorPrint. ' -------' _errorPrintCR.
   801             '-------- walkback of process ' _errorPrint. id _errorPrint. ' -------' _errorPrintCR.
   739             ]
   826             ]
   740         ].
   827         ].
   741         ^ false
   828         ^ false
   742     ].
   829     ].
   743 
   830 
   744     (cmd == $S) ifTrue:[
       
   745         'saving "crash.img"...' _errorPrint.
       
   746         ObjectMemory writeCrashImage.
       
   747         'done.' _errorPrintCR.
       
   748         ^ false
       
   749     ].
       
   750     (cmd == $C) ifTrue:[
       
   751         |changesFilename|
       
   752 
       
   753         changesFilename := Timestamp now
       
   754              printStringFormat:'changes_%(year)-%(month)-%(day)__%h:%m:%s.chg'.
       
   755         OperatingSystem isMSWINDOWSlike ifTrue:[ changesFilename replaceAll:$: with:$_ ].
       
   756 
       
   757         ChangeSet current fileOutAs: changesFilename.
       
   758         ('saved session changes to "',changesFilename,'".') _errorPrintCR.
       
   759         ^ false
       
   760     ].
       
   761 
       
   762     (cmd == $B) ifTrue:[
       
   763         self printAllBacktraces.
       
   764         ^ false
       
   765     ].
       
   766 
       
   767     (cmd == $P) ifTrue:[
       
   768         self showProcesses:#all.
       
   769         ^ false
       
   770     ].
       
   771     (cmd == $p) ifTrue:[
       
   772         self showProcesses:#live.
       
   773         ^ false
       
   774     ].
       
   775 
       
   776     (cmd == $r) ifTrue:[
   831     (cmd == $r) ifTrue:[
   777         dot receiver _errorPrintCR.
   832         dot receiver _errorPrintCR.
   778         ^ false
   833         ^ false
   779     ].
   834     ].
   780 
   835 
   792 
   847 
   793     (cmd == $I) ifTrue:[
   848     (cmd == $I) ifTrue:[
   794         self interpreterLoopWith:nil.
   849         self interpreterLoopWith:nil.
   795         ^ false
   850         ^ false
   796     ].
   851     ].
   797     (cmd == $E) ifTrue:[
   852     ((cmd == $E) or:[(cmd == $e)]) ifTrue:[
   798         Parser evaluate:commandArg.
   853         retVal := Parser evaluate:commandArg in:dot receiver:(dot receiver) notifying:nil ifFail:nil.
   799         ^ false
   854         (cmd == $e) ifTrue:[ retVal _errorPrintCR ].
   800     ].
   855         ^ false
   801     (cmd == $e) ifTrue:[
   856     ].
   802         (Parser evaluate:commandArg) _errorPrintCR.
       
   803         ^ false
       
   804     ].
       
   805 
       
   806     (cmd == $c) ifTrue:[^ true].
       
   807     (cmd == $s) ifTrue:[^ true].
       
   808     (cmd == $t) ifTrue:[^ true].
       
   809     (cmd == $a) ifTrue:[^ true].
       
   810 
   857 
   811     (cmd == $u) ifTrue:[
   858     (cmd == $u) ifTrue:[
   812         stepping := false.
   859         stepping := false.
   813         tracing := false.
   860         tracing := false.
   814         Processor activeProcess vmTrace:false.
   861         Processor activeProcess vmTrace:false.
  1144         'valid commands:
  1191         'valid commands:
  1145    c ........ continue
  1192    c ........ continue
  1146    s ........ step
  1193    s ........ step
  1147    t ........ trace (continue with trace)
  1194    t ........ trace (continue with trace)
  1148    a [id] ... abort (i.e. raise abort signal) in (current) process
  1195    a [id] ... abort (i.e. raise abort signal) in (current) process
  1149    T [id] ... terminate (current) process
       
  1150    W [id] ... stop (current) process
  1196    W [id] ... stop (current) process
  1151    R [id] ... resume (current) process
  1197    R [id] ... resume (current) process
       
  1198    T [id] ... terminate (current) process
  1152    Q [id] ... quick terminate (current) process - no unwinds or cleanup
  1199    Q [id] ... quick terminate (current) process - no unwinds or cleanup
  1153 
  1200 
  1154    p ........ list processes ("P" for full list)
  1201    p ........ list processes ("P" for full list)
  1155    w [id] ... walkback (of current/process with id)
  1202    w [id] ... walkback (of current/process with id)
  1156    b [id] ... full (VM) backtrace with more detail
  1203    b [id] ... full (VM) backtrace with more detail
  1166    S ........ save snapshot into "crash.img"
  1213    S ........ save snapshot into "crash.img"
  1167    C ........ save session changes to a separate change file
  1214    C ........ save session changes to a separate change file
  1168    x ........ exit Smalltalk ("X" to exit with core dump)
  1215    x ........ exit Smalltalk ("X" to exit with core dump)
  1169    Y ........ reopen display, reopen launcher
  1216    Y ........ reopen display, reopen launcher
  1170 
  1217 
       
  1218    = [id] ... set current process for dot commands below
  1171    . ........ print dot (the current context)
  1219    . ........ print dot (the current context)
  1172    - ........ move dot up (sender)
  1220    - ........ move dot up (sender)
  1173    + ........ move dot down (called context)
  1221    + ........ move dot down (called context)
  1174    l ........ list dot''s method source around PC ("L" for full list)
  1222    l ........ list dot''s method source around PC ("L" for full list)
  1175 
  1223    r ........ print receiver (in dot)
  1176    r ........ receiver (in dot) printString
       
  1177    i [expr] . inspect expression (or receiver in dot)
  1224    i [expr] . inspect expression (or receiver in dot)
       
  1225 
  1178    I ........ interpreter (expression evaluator)
  1226    I ........ interpreter (expression evaluator)
  1179    e expr ... evaluate expression & print result ("E" to not print)
  1227    e expr ... evaluate expression & print result ("E" to not print)
  1180    ? c [p] .. help on class c (selectors matching p)
  1228    ? c [p] .. help on class c (selectors matching p)
  1181 '  _errorPrintCR.
  1229 '  _errorPrintCR.
  1182 
  1230