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