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