MiniDebugger.st
branchjv
changeset 18027 3621469cc5e8
parent 18023 a6d357f1b3d7
parent 14798 a31ff766419e
child 18040 a11a12546f23
equal deleted inserted replaced
18026:fa8a879502cb 18027:3621469cc5e8
    12 "{ Package: 'stx:libbasic' }"
    12 "{ Package: 'stx:libbasic' }"
    13 
    13 
    14 Object subclass:#MiniDebugger
    14 Object subclass:#MiniDebugger
    15 	instanceVariableNames:'tracing stepping traceBlock command commandArg commandCount
    15 	instanceVariableNames:'tracing stepping traceBlock command commandArg commandCount
    16 		enteringContext dot nesting'
    16 		enteringContext dot nesting'
    17 	classVariableNames:'TheOneAndOnlyDebugger'
    17 	classVariableNames:'TheOneAndOnlyDebugger NotFirstTimeEntered'
    18 	poolDictionaries:''
    18 	poolDictionaries:''
    19 	category:'System-Debugging-Support'
    19 	category:'System-Debugging-Support'
    20 !
    20 !
    21 
    21 
    22 !MiniDebugger class methodsFor:'documentation'!
    22 !MiniDebugger class methodsFor:'documentation'!
    67     |active con sender|
    67     |active con sender|
    68 
    68 
    69     StepInterruptPending := nil.
    69     StepInterruptPending := nil.
    70 
    70 
    71     Error handle:[:ex |
    71     Error handle:[:ex |
    72 	ex return
    72         ex return
    73     ] do:[
    73     ] do:[
    74 	thisContext isRecursive ifTrue:[
    74         thisContext isRecursive ifTrue:[
    75 	    "/ 'recursive error in debugger ignored' errorPrintCR.
    75             "/ 'recursive error in debugger ignored' errorPrintCR.
    76 	    ^ self
    76             ^ self
    77 	].
    77         ].
    78 	aString printCR.
    78 
    79 	Processor notNil ifTrue:[
    79         aString printCR.
    80 	    active := Processor activeProcess.
    80         Processor notNil ifTrue:[
    81 	    'process: id=' print. active id print.
    81             active := Processor activeProcess.
    82 	    ' name=' print. active name printCR.
    82             'process: id=' print. active id print.
    83 
    83             ' name=' print. active name printCR.
    84 	    'context: ' print. aContext printString printCR.
    84 
    85 	    (con := aContext) notNil ifTrue:[
    85             'context: ' print. aContext printString printCR.
    86 		con := con sender.
    86             (con := aContext) notNil ifTrue:[
    87 		' ......: ' print. con printString printCR.
    87                 con := con sender.
    88 		[con notNil] whileTrue:[
    88                 ' ......: ' print. con printString printCR.
    89 		    sender := con sender.
    89                 [con notNil] whileTrue:[
    90 		    (sender notNil and:[sender selector == con selector]) ifTrue:[
    90                     sender := con sender.
    91 			' ......: ' print. sender printString printCR.
    91                     (sender notNil and:[sender selector == con selector]) ifTrue:[
    92 			' ......:  [** intermediate recursive contexts skipped **]' printCR.
    92                         ' ......: ' print. sender printString printCR.
    93 			[sender notNil
    93                         ' ......:  [** intermediate recursive contexts skipped **]' printCR.
    94 			 and:[sender selector == con selector
    94                         [sender notNil
    95 			 and:[sender method == con method]]] whileTrue:[
    95                          and:[sender selector == con selector
    96 			    con := sender.
    96                          and:[sender method == con method]]] whileTrue:[
    97 			    sender := con sender.
    97                             con := sender.
    98 			].
    98                             sender := con sender.
    99 		    ].
    99                         ].
   100 		    con := sender.
   100                     ].
   101 		    ' ......: ' print. con printString printCR.
   101                     con := sender.
   102 		]
   102                     ' ......: ' print. con printString printCR.
   103 	    ]
   103                 ]
   104 	].
   104             ]
       
   105         ].
       
   106         NotFirstTimeEntered ~~ true ifTrue:[
       
   107             NotFirstTimeEntered := true.
       
   108             'Type "c" to proceed, "?" for help' printCR.
       
   109         ].
   105     ].
   110     ].
   106 
   111 
   107     OperatingSystem hasConsole ifFalse:[
   112     OperatingSystem hasConsole ifFalse:[
   108 	Error handle:[:ex |
   113         Error handle:[:ex |
   109 	    ex return
   114             ex return
   110 	] do:[
   115         ] do:[
   111 	    self warn:('Unexpected error:\' , aString , '\\No MiniDebugger functionality available') withCRs .
   116             self warn:('Unexpected error:\' , aString , '\\No MiniDebugger functionality available') withCRs .
   112 	].
   117         ].
   113 
   118 
   114 	Error handle:[:ex |
   119         Error handle:[:ex |
   115 	    'cannot raise Abort - exiting ...' errorPrintCR.
   120             'cannot raise Abort - exiting ...' errorPrintCR.
   116 	    Smalltalk exit.
   121             Smalltalk exit.
   117 	] do:[
   122         ] do:[
   118 	    AbortOperationRequest raise.
   123             AbortOperationRequest raise.
   119 	]
   124         ]
   120     ] ifTrue:[
   125     ] ifTrue:[
   121 	self new enter:aContext mayProceed:mayProceed.
   126         self new enter:aContext mayProceed:mayProceed.
   122     ].
   127     ].
   123     mayProceed ifFalse:[
   128     mayProceed ifFalse:[
   124 	AbortOperationRequest raise
   129         AbortOperationRequest raise
   125     ].
   130     ].
   126     ^ nil
   131     ^ nil
   127 
   132 
   128     "Modified: / 19.5.1999 / 18:14:33 / cg"
   133     "Modified: / 19.5.1999 / 18:14:33 / cg"
   129 !
   134 !
   549 
   554 
   550     "Modified: / 16.11.2001 / 17:39:14 / cg"
   555     "Modified: / 16.11.2001 / 17:39:14 / cg"
   551 !
   556 !
   552 
   557 
   553 doCommand:cmd
   558 doCommand:cmd
   554     "a single command; return true, if command loop should be finished"
   559     "a single command; 
   555 
   560      return true, if command loop should be finished"
   556     |id proc|
   561 
       
   562     |id proc bool|
   557 
   563 
   558     commandArg notEmpty ifTrue:[
   564     commandArg notEmpty ifTrue:[
   559         id := Number readFrom:commandArg onError:nil.
   565         id := Number readFrom:commandArg onError:nil.
   560 
       
   561         id notNil ifTrue:[
   566         id notNil ifTrue:[
   562             proc := Process allSubInstances detect:[:p | p id == id] ifNone:nil.
   567             proc := Process allSubInstances detect:[:p | p id == id] ifNone:nil.
   563             proc == Processor activeProcess ifTrue:[
   568             proc == Processor activeProcess ifTrue:[
   564                 id := proc := nil
   569                 id := proc := nil
       
   570             ]
       
   571         ] ifFalse:[
       
   572             commandArg = '-' ifTrue:[
       
   573                 bool := false
       
   574             ] ifFalse:[
       
   575                 commandArg = '+' ifTrue:[
       
   576                     bool := true
       
   577                 ] 
   565             ]
   578             ]
   566         ]
   579         ]
   567     ].
   580     ].
   568 
   581 
   569     (cmd == $w) ifTrue:[
   582     (cmd == $w) ifTrue:[
   607         self printAllBacktraces.
   620         self printAllBacktraces.
   608         ^ false
   621         ^ false
   609     ].
   622     ].
   610 
   623 
   611     (cmd == $P) ifTrue:[
   624     (cmd == $P) ifTrue:[
   612         self showProcesses.
   625         self showProcesses:#all.
       
   626         ^ false
       
   627     ].
       
   628     (cmd == $p) ifTrue:[
       
   629         self showProcesses:#live.
   613         ^ false
   630         ^ false
   614     ].
   631     ].
   615 
   632 
   616     (cmd == $r) ifTrue:[
   633     (cmd == $r) ifTrue:[
   617         dot receiver printCR.
   634         dot receiver printCR.
   639 
   656 
   640     (cmd == $u) ifTrue:[
   657     (cmd == $u) ifTrue:[
   641         stepping := false.
   658         stepping := false.
   642         tracing := false.
   659         tracing := false.
   643         Processor activeProcess vmTrace:false.
   660         Processor activeProcess vmTrace:false.
       
   661         ^ false
       
   662     ].
       
   663 
       
   664     (cmd == $h) ifTrue:[
       
   665         (bool notNil) ifTrue:[
       
   666             Smalltalk ignoreHalt:bool not.
       
   667         ].
       
   668         'halts are ' print. (Smalltalk ignoreHalt ifTrue:['disabled'] ifFalse:['enabled']) printCR.
   644         ^ false
   669         ^ false
   645     ].
   670     ].
   646 
   671 
   647     (cmd == $R) ifTrue:[
   672     (cmd == $R) ifTrue:[
   648         proc notNil ifTrue:[
   673         proc notNil ifTrue:[
   788         arg := ''.
   813         arg := ''.
   789         [c isNil or:[c isEndOfLineCharacter]] whileFalse: [
   814         [c isNil or:[c isEndOfLineCharacter]] whileFalse: [
   790             arg := arg copyWith:c.
   815             arg := arg copyWith:c.
   791             c := Character fromUser.
   816             c := Character fromUser.
   792         ].
   817         ].
   793         commandArg := arg copyFrom:2.
   818         commandArg := (arg copyFrom:2) withoutSeparators.
   794         command := cmd.
   819         command := cmd.
   795         commandCount := cnt.
   820         commandCount := cnt.
   796     ].
   821     ].
   797     ^ command
   822     ^ command
   798 
   823 
   849         ]
   874         ]
   850     ]
   875     ]
   851 !
   876 !
   852 
   877 
   853 showProcesses
   878 showProcesses
       
   879     self showProcesses:#all
       
   880 !
       
   881 
       
   882 showProcesses:how
   854     |active|
   883     |active|
   855 
   884 
   856     active := Processor activeProcess.
   885     active := Processor activeProcess.
   857     'current id=' print. active id print. ' name=''' print. active name print. '''' printCR.
   886     'current id=' print. active id print. ' name=''' print. active name print. '''' printCR.
   858 
   887 
   859     Process allSubInstancesDo:[:p |
   888     Process allSubInstancesDo:[:p |
   860 	'proc id=' print. (p id printStringPaddedTo:5) print.
   889         |doShow|
   861 	(p state printStringPaddedTo:10) print.
   890 
   862 	' pri=' print. (p priority printStringPaddedTo:2) print.
   891         doShow := (how == #all).
   863 	' creator:' print. (p creatorId printStringPaddedTo:5) print.
   892         doShow := doShow or:[ (how == #dead) and:[ p isDead ]].
   864 	' name=''' print. p name print.
   893         doShow := doShow or:[ (how ~~ #dead) and:[ p isDead not ]].
   865 	'''' printCR.
   894         doShow ifTrue:[
       
   895             'proc id=' print. (p id printStringPaddedTo:5) print.
       
   896             (p state printStringPaddedTo:10) print.
       
   897             ' pri=' print. (p priority printStringPaddedTo:2) print.
       
   898             ' creator:' print. (p creatorId printStringPaddedTo:5) print.
       
   899             ' name=''' print. p name print.
       
   900             '''' printCR.
       
   901         ]
   866     ]
   902     ]
   867 
   903 
   868     "Modified: / 31.7.1998 / 16:30:19 / cg"
   904     "Modified: / 31.7.1998 / 16:30:19 / cg"
   869 !
   905 !
   870 
   906 
   871 showValidCommandHelp
   907 showValidCommandHelp
   872         'valid commands:
   908         'valid commands:
   873    c ..... continue
   909    c ...... continue
   874    s ..... step
   910    s ...... step
   875    t ..... trace (continue with trace)
   911    t ...... trace (continue with trace)
   876    a [id]. abort (i.e. raise abort signal) in (current) process
   912    a [id]   abort (i.e. raise abort signal) in (current) process
   877    T [id]. terminate (current) process
   913    T [id]   terminate (current) process
   878    W [id]. stop (current) process
   914    W [id]   stop (current) process
   879    R [id]. resume (current) process
   915    R [id]   resume (current) process
   880    Q [id]. quick terminate (current) process - no unwinds or cleanup
   916    Q [id]   quick terminate (current) process - no unwinds or cleanup
   881 
   917 
   882    P ..... list processes
   918    p ...... list processes ("P" for full list)
   883    w [id]. walkback (of process with id)
   919    w [id]   walkback (of process with id)
   884    b [id]. full (VM) backtrace (more detail)
   920    b [id]   full (VM) backtrace (more detail)
   885    B ..... backtrace of all other processes
   921    B ...... backtrace of all other processes
   886 
   922 
   887    U ..... unwrap all traced/breakpointed methods
   923    U ...... unwrap all traced/breakpointed methods
   888    g ..... collect all garbage
   924    h [-/+]  disable/enable halts
   889    g 2.... collect all garbage & reclaim symbols
   925    g ...... collect all garbage
   890    g 3.... collect all garbage, reclaim symbols and compress
   926    g 2 .... collect all garbage & reclaim symbols
   891 
   927    g 3 .... collect all garbage, reclaim symbols and compress
   892    S ..... save snapshot into crash.img
   928 
   893    x ..... exit Smalltalk
   929    S ...... save snapshot into crash.img
   894    X ..... exit Smalltalk (+core dump)
   930    x ...... exit Smalltalk ("X" to exit with core dump)
   895 
   931 
   896    . ..... print dot (the current context)
   932    . ...... print dot (the current context)
   897    - ..... move dot up (sender)
   933    - ...... move dot up (sender)
   898    + ..... move dot down (called context)
   934    + ...... move dot down (called context)
   899    l ..... list method source around dot''s
   935    l ...... list dot''s method source around PC ("L" for full list)
   900    L ..... list dot''s method source code
   936 
   901 
   937    r ...... receiver (in dot) printString
   902    r ..... receiver (in dot) printString
   938    i ...... inspect receiver (in dot)
   903    i ..... inspect receiver (in dot)
   939    I ...... interpreter (expression evaluator)
   904    I ..... interpreter (expression evaluator)
   940    e expr   evaluate expression
   905    e expr  evaluate expression
   941 '  errorPrintCR.
   906 
   942 
   907    To repair a broken X-Connection, enter an interpreter and evaluate:
   943    (XWorkstation notNil and:[ Screen default isKindOf:XWorkstation ]) ifTrue:[
       
   944 '   To repair a broken X-Connection, enter an interpreter (enter "I") and evaluate:
   908       Display := XWorkstation new.
   945       Display := XWorkstation new.
   909       Display initializeFor:''hostName:0''.
   946       Display initializeFor:''localhost:0''.
   910       Display startDispatch.
   947       Display startDispatch.
   911       NewLauncher openOnDevice:Display.
   948       NewLauncher openOnDevice:Display.
   912       <empty line>
   949       <empty line>
   913    then enter ''c'' to continue; a NewLauncher should pop up soon.
   950     then enter "c" to continue; a NewLauncher should pop up soon.
   914 
       
   915 '  errorPrintCR
   951 '  errorPrintCR
       
   952     ]
   916 ! !
   953 ! !
   917 
   954 
   918 !MiniDebugger class methodsFor:'documentation'!
   955 !MiniDebugger class methodsFor:'documentation'!
   919 
   956 
   920 version
   957 version
   921     ^ '$Header: /cvs/stx/stx/libbasic/MiniDebugger.st,v 1.80 2013-02-01 14:47:44 cg Exp $'
   958     ^ '$Header: /cvs/stx/stx/libbasic/MiniDebugger.st,v 1.82 2013-02-23 11:14:32 cg Exp $'
   922 !
   959 !
   923 
   960 
   924 version_CVS
   961 version_CVS
   925     ^ '$Header: /cvs/stx/stx/libbasic/MiniDebugger.st,v 1.80 2013-02-01 14:47:44 cg Exp $'
   962     ^ '$Header: /cvs/stx/stx/libbasic/MiniDebugger.st,v 1.82 2013-02-23 11:14:32 cg Exp $'
   926 ! !
   963 ! !
   927 
   964