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