author | Claus Gittinger <cg@exept.de> |
Sat, 11 Nov 1995 16:28:41 +0100 | |
changeset 530 | 07d0bce293c9 |
parent 417 | 4e2a6e11345e |
child 618 | 9048d43527d2 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
159 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
Object subclass:#MiniDebugger |
|
14 |
instanceVariableNames:'tracing stepping traceBlock' |
|
33 | 15 |
classVariableNames: 'TheOneAndOnlyDebugger' |
1 | 16 |
poolDictionaries:'' |
308 | 17 |
category:'System-Debugging-Support' |
1 | 18 |
! |
19 |
||
89 | 20 |
!MiniDebugger class methodsFor: 'documentation'! |
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
159 | 25 |
All Rights Reserved |
1 | 26 |
|
89 | 27 |
This software is furnished under a license and may be used |
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
1 | 35 |
|
89 | 36 |
version |
530
07d0bce293c9
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
417
diff
changeset
|
37 |
^ '$Header: /cvs/stx/stx/libbasic/Attic/MiniDebug.st,v 1.18 1995-11-11 15:24:29 cg Exp $' |
89 | 38 |
! |
39 |
||
40 |
documentation |
|
41 |
" |
|
42 |
a primitive (non graphical) debugger for use on systems without |
|
43 |
graphics or when the real debugger dies (i.e. an error occurs in |
|
44 |
the graphical debugger). |
|
93 | 45 |
Also, if an interrupt occurs within the debuger, this one is called |
46 |
for. |
|
89 | 47 |
" |
48 |
! ! |
|
1 | 49 |
|
50 |
!MiniDebugger class methodsFor: 'instance creation'! |
|
51 |
||
52 |
new |
|
33 | 53 |
TheOneAndOnlyDebugger printNL. |
54 |
TheOneAndOnlyDebugger isNil ifTrue:[ |
|
159 | 55 |
TheOneAndOnlyDebugger := self basicNew initialize |
1 | 56 |
]. |
33 | 57 |
^ TheOneAndOnlyDebugger |
1 | 58 |
! |
59 |
||
60 |
singleStep:aBlock |
|
61 |
|aDebugger| |
|
62 |
||
63 |
aDebugger := self new stepping. |
|
241 | 64 |
ObjectMemory stepInterruptHandler:aDebugger. |
2 | 65 |
ObjectMemory flushInlineCaches. |
241 | 66 |
StepInterruptPending := 1. |
67 |
InterruptPending := 1. |
|
1 | 68 |
aBlock value. |
2 | 69 |
StepInterruptPending := nil. |
70 |
ObjectMemory stepInterruptHandler:nil |
|
1 | 71 |
! |
72 |
||
73 |
trace:aBlock |
|
74 |
self trace:aBlock with:[:where | where printNewline] |
|
75 |
! |
|
76 |
||
77 |
trace:aBlock on:aStream |
|
78 |
self trace:aBlock with:[:where | where printString printOn:aStream. |
|
159 | 79 |
aStream cr] |
1 | 80 |
! |
81 |
||
82 |
trace:aBlock with:aTraceBlock |
|
83 |
|aDebugger| |
|
84 |
||
85 |
aDebugger := self new tracingWith:aTraceBlock. |
|
241 | 86 |
ObjectMemory stepInterruptHandler:aDebugger. |
1 | 87 |
ObjectMemory flushInlineCaches. |
241 | 88 |
StepInterruptPending := 1. |
89 |
InterruptPending := 1. |
|
1 | 90 |
aBlock value. |
2 | 91 |
ObjectMemory stepInterruptHandler:nil. |
1 | 92 |
StepInterruptPending := nil. |
93 |
^ nil |
|
94 |
! |
|
95 |
||
216 | 96 |
enter |
97 |
^ self enterWithMessage:'MiniDebugger' |
|
98 |
! |
|
99 |
||
100 |
enter:aContext |
|
101 |
^ self enterWithMessage:'MiniDebugger' |
|
102 |
! |
|
103 |
||
104 |
enter:aContext withMessage:aString |
|
105 |
^ self enterWithMessage:aString |
|
106 |
! |
|
107 |
||
1 | 108 |
enterWithMessage:aString |
93 | 109 |
|active| |
1 | 110 |
|
111 |
StepInterruptPending := nil. |
|
93 | 112 |
|
113 |
aString printNL. |
|
159 | 114 |
Processor notNil ifTrue:[ |
115 |
active := Processor activeProcess. |
|
116 |
'process: id=' print. active id print. ' name=' print. active name printNL. |
|
117 |
]. |
|
93 | 118 |
self new enter. |
1 | 119 |
^ nil |
120 |
! ! |
|
121 |
||
122 |
!MiniDebugger methodsFor: 'initialization'! |
|
123 |
||
124 |
initialize |
|
125 |
traceBlock := nil. |
|
126 |
tracing := false. |
|
127 |
stepping := false |
|
128 |
! ! |
|
129 |
||
130 |
!MiniDebugger methodsFor: 'private'! |
|
131 |
||
132 |
stepping |
|
133 |
traceBlock := nil. |
|
134 |
tracing := false. |
|
135 |
stepping := true |
|
136 |
! |
|
137 |
||
138 |
tracingWith:aBlockOrNil |
|
139 |
traceBlock := aBlockOrNil. |
|
140 |
stepping := false. |
|
141 |
tracing := true |
|
142 |
! |
|
143 |
||
144 |
getContext |
|
145 |
|backtrace| |
|
146 |
backtrace := thisContext. |
|
147 |
(backtrace notNil) ifTrue: [ |
|
159 | 148 |
"remove Context getContext frame" |
149 |
backtrace := backtrace sender. |
|
150 |
"remove Debugger showContext frame" |
|
151 |
backtrace := backtrace sender. |
|
152 |
"remove Debugger commandLoop frame" |
|
153 |
backtrace := backtrace sender. |
|
154 |
"remove Debugger enter frame" |
|
155 |
backtrace := backtrace sender |
|
1 | 156 |
]. |
157 |
^ backtrace |
|
74 | 158 |
! |
159 |
||
160 |
findContext:aSelector |
|
161 |
|con| |
|
162 |
||
163 |
con := thisContext sender. |
|
164 |
[con notNil] whileTrue:[ |
|
159 | 165 |
(con isBlockContext not and:[con selector == aSelector]) ifTrue:[ |
166 |
"got it" |
|
167 |
^ con |
|
168 |
]. |
|
169 |
con := con sender |
|
74 | 170 |
]. |
171 |
^ nil |
|
1 | 172 |
! ! |
173 |
||
174 |
!MiniDebugger methodsFor: 'interrupt handling'! |
|
175 |
||
176 |
stepInterrupt |
|
177 |
|where| |
|
178 |
||
179 |
where := thisContext. "where is stepInterrupt context" |
|
180 |
where notNil ifTrue:[ |
|
159 | 181 |
where := where sender "where is now interrupted methods context" |
1 | 182 |
]. |
183 |
stepping ifTrue:[ |
|
159 | 184 |
where notNil ifTrue:[ |
185 |
where fullPrint |
|
186 |
] ifFalse:[ |
|
187 |
'stepInterrupt: no context' errorPrintNewline |
|
188 |
]. |
|
189 |
self enter |
|
1 | 190 |
] ifFalse:[ |
159 | 191 |
where notNil ifTrue:[ |
192 |
traceBlock notNil ifTrue:[ |
|
193 |
traceBlock value:where |
|
194 |
] |
|
195 |
] ifFalse:[ |
|
196 |
'traceInterrupt: no context' errorPrintNewline |
|
197 |
]. |
|
198 |
ObjectMemory flushInlineCaches. |
|
241 | 199 |
StepInterruptPending := 1. |
200 |
InterruptPending := 1 |
|
1 | 201 |
] |
202 |
! |
|
203 |
||
204 |
enter |
|
159 | 205 |
|leaveCmd stillHere| |
74 | 206 |
|
379 | 207 |
Display notNil ifTrue:[ |
208 |
Display ungrabPointer. |
|
209 |
Display ungrabKeyboard. |
|
210 |
]. |
|
211 |
||
74 | 212 |
stillHere := true. |
213 |
[stillHere] whileTrue:[ |
|
159 | 214 |
leaveCmd := self commandLoop. |
1 | 215 |
|
159 | 216 |
(leaveCmd == $s) ifTrue: [ |
217 |
self stepping. |
|
218 |
ObjectMemory flushInlineCaches. |
|
219 |
ObjectMemory stepInterruptHandler:self. |
|
220 |
stillHere := false. |
|
241 | 221 |
StepInterruptPending := 1. |
222 |
InterruptPending := 1 |
|
159 | 223 |
]. |
224 |
(leaveCmd == $t) ifTrue: [ |
|
225 |
traceBlock := [:where | where fullPrint]. |
|
226 |
ObjectMemory flushInlineCaches. |
|
227 |
ObjectMemory stepInterruptHandler:self. |
|
228 |
stillHere := false. |
|
241 | 229 |
StepInterruptPending := 1. |
230 |
InterruptPending := 1 |
|
159 | 231 |
]. |
232 |
(leaveCmd == $c) ifTrue: [ |
|
233 |
stillHere := false. |
|
234 |
stepping := false. |
|
235 |
tracing := false. |
|
236 |
StepInterruptPending := nil. |
|
237 |
InterruptPending := nil |
|
238 |
]. |
|
239 |
(leaveCmd == $a) ifTrue: [ |
|
240 |
"abort" |
|
241 |
stepping := false. |
|
242 |
tracing := false. |
|
243 |
StepInterruptPending := nil. |
|
244 |
InterruptPending := nil. |
|
245 |
self doAbort. |
|
246 |
stillHere := true. |
|
247 |
"failed abort" |
|
248 |
]. |
|
1 | 249 |
]. |
250 |
^ nil |
|
251 |
! ! |
|
252 |
||
253 |
!MiniDebugger methodsFor: 'user commands'! |
|
254 |
||
74 | 255 |
doAbort |
256 |
|con sig| |
|
257 |
||
258 |
(sig := Object abortSignal) isHandled ifTrue:[ |
|
159 | 259 |
sig raise. |
260 |
'abort raise failed' errorPrintNewline. |
|
74 | 261 |
]. |
262 |
||
263 |
"TEMPORARY kludge - find event handler context |
|
264 |
this will be removed, once real debugging is possible |
|
265 |
" |
|
266 |
con := self findContext:#processEvent. |
|
267 |
con isNil ifTrue:[ |
|
159 | 268 |
con := self findContext:#dispatch. |
74 | 269 |
]. |
270 |
con notNil ifTrue:[ |
|
159 | 271 |
"got it" |
272 |
con return. |
|
273 |
'return failed' errorPrintNewline. |
|
74 | 274 |
]. |
275 |
||
276 |
'found no context to resume' errorPrintNewline. |
|
277 |
! |
|
278 |
||
279 |
showProcesses |
|
280 |
|active| |
|
281 |
||
282 |
active := Processor activeProcess. |
|
283 |
'current id=' print. active id print. ' name=' print. active name printNewline. |
|
284 |
||
285 |
Process allInstancesDo:[:p | |
|
159 | 286 |
'proc id=' print. p id print. ' name=' print. p name print. ' state=' print. |
375 | 287 |
p state print. ' prio=' print. p priority printNL. |
74 | 288 |
] |
289 |
! |
|
290 |
||
1 | 291 |
commandLoop |
292 |
|cmd done valid context| |
|
293 |
||
294 |
done := false. |
|
295 |
[done] whileFalse:[ |
|
159 | 296 |
valid := false. |
297 |
cmd := self getCommand. |
|
298 |
(cmd == $p) ifTrue:[ |
|
299 |
valid := true. |
|
300 |
context isNil ifTrue: [ |
|
301 |
context := self getContext |
|
302 |
]. |
|
303 |
context notNil ifTrue:[ |
|
304 |
context fullPrintAll |
|
305 |
] ifFalse:[ |
|
306 |
'no context' errorPrintNewline |
|
307 |
] |
|
308 |
]. |
|
309 |
(cmd == $P) ifTrue:[ |
|
310 |
valid := true. |
|
311 |
self showProcesses. |
|
312 |
]. |
|
313 |
(cmd == $r) ifTrue:[ |
|
314 |
valid := true. |
|
315 |
context isNil ifTrue: [ |
|
316 |
context := self getContext |
|
317 |
]. |
|
318 |
context notNil ifTrue:[ |
|
319 |
"remove Debugger stepinterrupt/halt frame" |
|
320 |
context sender receiver printNewline |
|
321 |
] ifFalse:[ |
|
322 |
'no context - dont know receiver' errorPrintNewline |
|
323 |
] |
|
324 |
]. |
|
325 |
(cmd == $R) ifTrue:[ |
|
326 |
valid := true. |
|
327 |
context isNil ifTrue: [ |
|
328 |
context := self getContext |
|
329 |
]. |
|
330 |
context notNil ifTrue:[ |
|
331 |
"remove Debugger stepinterrupt/halt frame" |
|
332 |
context sender receiver storeOn:Stdout |
|
333 |
] ifFalse:[ |
|
334 |
'no context - dont know receiver' errorPrintNewline |
|
335 |
] |
|
336 |
]. |
|
337 |
(cmd == $i) ifTrue:[ |
|
338 |
valid := true. |
|
339 |
context isNil ifTrue: [ |
|
340 |
context := self getContext |
|
341 |
]. |
|
342 |
context notNil ifTrue:[ |
|
343 |
"remove Debugger stepinterrupt/halt frame" |
|
344 |
MiniInspector openOn:(context sender receiver) |
|
345 |
] ifFalse:[ |
|
346 |
'no context - dont know receiver' errorPrintNewline |
|
347 |
] |
|
348 |
]. |
|
349 |
(cmd == $I) ifTrue:[ |
|
350 |
valid := true. |
|
351 |
context isNil ifTrue: [ |
|
352 |
context := self getContext |
|
353 |
]. |
|
216 | 354 |
"/ context notNil ifTrue:[ |
355 |
"/ "remove Debugger stepinterrupt/halt frame" |
|
356 |
"/ self interpreterLoopWith:(context sender receiver) |
|
357 |
"/ ] ifFalse:[ |
|
358 |
"/ 'no context - dont know receiver' errorPrintNewline. |
|
159 | 359 |
self interpreterLoopWith:nil |
216 | 360 |
"/ ] |
159 | 361 |
]. |
362 |
context := nil. |
|
363 |
(cmd == $c) ifTrue:[valid := true. done := true]. |
|
364 |
(cmd == $s) ifTrue:[valid := true. done := true]. |
|
365 |
(cmd == $t) ifTrue:[valid := true. done := true]. |
|
366 |
(cmd == $a) ifTrue:[valid := true. done := true]. |
|
367 |
(cmd == $T) ifTrue:[valid := true. Processor terminateActive]. |
|
368 |
(cmd == $Q) ifTrue:[valid := true. Processor terminateActiveNoSignal]. |
|
360 | 369 |
(cmd == $U) ifTrue:[MessageTracer unwrapAllMethods]. |
159 | 370 |
(cmd == $X) ifTrue:[Smalltalk fatalAbort]. |
417 | 371 |
(cmd == $x) ifTrue:[OperatingSystem exit]. |
159 | 372 |
valid ifFalse: [ |
373 |
'valid commands: |
|
74 | 374 |
(c)ontinue |
375 |
(s)tep |
|
216 | 376 |
(t)race (continue with trace) |
377 |
(p)rint context chain |
|
93 | 378 |
(r)eceiver printString |
379 |
(R)eceiver storeString |
|
216 | 380 |
(i)nspect (enter inspector on receiver) |
381 |
(I)nterpreter (expression evaluator) |
|
382 |
(a)bort (raise abort signal) |
|
383 |
(P)rocess list |
|
93 | 384 |
(T)terminate current process |
159 | 385 |
(Q)uick terminate current process (no unwinds) |
360 | 386 |
(U)nwrap all traced/breakpointed methods |
74 | 387 |
(X)exit (+core) |
388 |
(x)exit Smalltalk' errorPrintNewline |
|
159 | 389 |
] |
1 | 390 |
]. |
391 |
^ cmd |
|
392 |
! |
|
393 |
||
394 |
getCommand |
|
395 |
|cmd c| |
|
93 | 396 |
|
1 | 397 |
'MiniDebugger> ' print. |
93 | 398 |
|
159 | 399 |
Object userInterruptSignal handle:[:ex | |
400 |
ex restart |
|
401 |
] do:[ |
|
402 |
cmd := Character fromUser. |
|
403 |
cmd isNil ifTrue:[ |
|
404 |
" |
|
405 |
mhmh end-of-file; |
|
406 |
return a 'c' (for continue); hope thats ok. |
|
407 |
" |
|
408 |
cmd := $c |
|
409 |
]. |
|
93 | 410 |
|
159 | 411 |
" |
412 |
ignore to end-of-line |
|
413 |
" |
|
414 |
c := cmd. |
|
415 |
[c isNil or:[c isEndOfLineCharacter]] whileFalse: [ |
|
416 |
c := Character fromUser. |
|
417 |
]. |
|
1 | 418 |
]. |
419 |
^ cmd |
|
420 |
! |
|
421 |
||
422 |
interpreterLoopWith:anObject |
|
423 |
|line done| |
|
424 |
'read-eval-print loop; exit with empty line' printNewline. |
|
425 |
done := false. |
|
426 |
[done] whileFalse:[ |
|
159 | 427 |
line := Stdin nextLine. |
428 |
(line size == 0) ifTrue:[ |
|
429 |
done := true |
|
430 |
] ifFalse:[ |
|
431 |
(Compiler evaluate:line |
|
432 |
receiver:anObject |
|
433 |
notifying:nil) printNewline |
|
434 |
] |
|
1 | 435 |
] |
436 |
! ! |