1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
1
|
3 |
All Rights Reserved
|
|
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:''
|
|
17 |
category:'System-Support'
|
|
18 |
!
|
|
19 |
|
|
20 |
MiniDebugger comment:'
|
89
|
21 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
|
22 |
All Rights Reserved
|
93
|
23 |
|
|
24 |
$Header: /cvs/stx/stx/libbasic/MiniDebugger.st,v 1.8 1994-08-05 00:59:02 claus Exp $
|
89
|
25 |
'!
|
1
|
26 |
|
89
|
27 |
!MiniDebugger class methodsFor: 'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1988 by Claus Gittinger
|
1
|
32 |
All Rights Reserved
|
|
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 |
"
|
93
|
45 |
$Header: /cvs/stx/stx/libbasic/MiniDebugger.st,v 1.8 1994-08-05 00:59:02 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:[
|
|
64 |
TheOneAndOnlyDebugger := self basicNew initialize
|
1
|
65 |
].
|
33
|
66 |
^ TheOneAndOnlyDebugger
|
1
|
67 |
!
|
|
68 |
|
|
69 |
singleStep:aBlock
|
|
70 |
|aDebugger|
|
|
71 |
|
|
72 |
aDebugger := self new stepping.
|
2
|
73 |
ObjectMemory flushInlineCaches.
|
|
74 |
ObjectMemory stepInterruptHandler:aDebugger.
|
1
|
75 |
StepInterruptPending := true.
|
|
76 |
InterruptPending := true.
|
|
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.
|
|
88 |
aStream cr]
|
|
89 |
!
|
|
90 |
|
|
91 |
trace:aBlock with:aTraceBlock
|
|
92 |
|aDebugger|
|
|
93 |
|
|
94 |
aDebugger := self new tracingWith:aTraceBlock.
|
|
95 |
ObjectMemory flushInlineCaches.
|
2
|
96 |
ObjectMemory stepInterruptHandler:aDebugger.
|
1
|
97 |
StepInterruptPending := true.
|
|
98 |
InterruptPending := true.
|
|
99 |
aBlock value.
|
2
|
100 |
ObjectMemory stepInterruptHandler:nil.
|
1
|
101 |
StepInterruptPending := nil.
|
|
102 |
^ nil
|
|
103 |
!
|
|
104 |
|
|
105 |
enterWithMessage:aString
|
93
|
106 |
|active|
|
1
|
107 |
|
|
108 |
StepInterruptPending := nil.
|
93
|
109 |
|
|
110 |
aString printNL.
|
|
111 |
active := Processor activeProcess.
|
|
112 |
'process: id=' print. active id print. ' name=' print. active name printNL.
|
|
113 |
self new enter.
|
1
|
114 |
^ nil
|
|
115 |
! !
|
|
116 |
|
|
117 |
!MiniDebugger methodsFor: 'initialization'!
|
|
118 |
|
|
119 |
initialize
|
|
120 |
traceBlock := nil.
|
|
121 |
tracing := false.
|
|
122 |
stepping := false
|
|
123 |
! !
|
|
124 |
|
|
125 |
!MiniDebugger methodsFor: 'private'!
|
|
126 |
|
|
127 |
stepping
|
|
128 |
traceBlock := nil.
|
|
129 |
tracing := false.
|
|
130 |
stepping := true
|
|
131 |
!
|
|
132 |
|
|
133 |
tracingWith:aBlockOrNil
|
|
134 |
traceBlock := aBlockOrNil.
|
|
135 |
stepping := false.
|
|
136 |
tracing := true
|
|
137 |
!
|
|
138 |
|
|
139 |
getContext
|
|
140 |
|backtrace|
|
|
141 |
backtrace := thisContext.
|
|
142 |
(backtrace notNil) ifTrue: [
|
|
143 |
"remove Context getContext frame"
|
|
144 |
backtrace := backtrace sender.
|
|
145 |
"remove Debugger showContext frame"
|
|
146 |
backtrace := backtrace sender.
|
|
147 |
"remove Debugger commandLoop frame"
|
|
148 |
backtrace := backtrace sender.
|
|
149 |
"remove Debugger enter frame"
|
|
150 |
backtrace := backtrace sender
|
|
151 |
].
|
|
152 |
^ backtrace
|
74
|
153 |
!
|
|
154 |
|
|
155 |
findContext:aSelector
|
|
156 |
|con|
|
|
157 |
|
|
158 |
con := thisContext sender.
|
|
159 |
[con notNil] whileTrue:[
|
|
160 |
(con isBlockContext not and:[con selector == aSelector]) ifTrue:[
|
|
161 |
"got it"
|
|
162 |
^ con
|
|
163 |
].
|
|
164 |
con := con sender
|
|
165 |
].
|
|
166 |
^ nil
|
1
|
167 |
! !
|
|
168 |
|
|
169 |
!MiniDebugger methodsFor: 'interrupt handling'!
|
|
170 |
|
|
171 |
stepInterrupt
|
|
172 |
|where|
|
|
173 |
|
|
174 |
where := thisContext. "where is stepInterrupt context"
|
|
175 |
where notNil ifTrue:[
|
|
176 |
where := where sender "where is now interrupted methods context"
|
|
177 |
].
|
|
178 |
stepping ifTrue:[
|
|
179 |
where notNil ifTrue:[
|
|
180 |
where fullPrint
|
|
181 |
] ifFalse:[
|
74
|
182 |
'stepInterrupt: no context' errorPrintNewline
|
1
|
183 |
].
|
|
184 |
self enter
|
|
185 |
] ifFalse:[
|
|
186 |
where notNil ifTrue:[
|
|
187 |
traceBlock notNil ifTrue:[
|
|
188 |
traceBlock value:where
|
|
189 |
]
|
|
190 |
] ifFalse:[
|
74
|
191 |
'traceInterrupt: no context' errorPrintNewline
|
1
|
192 |
].
|
33
|
193 |
ObjectMemory flushInlineCaches.
|
1
|
194 |
StepInterruptPending := true.
|
|
195 |
InterruptPending := true
|
|
196 |
]
|
|
197 |
!
|
|
198 |
|
|
199 |
enter
|
74
|
200 |
|cmd stillHere|
|
|
201 |
|
|
202 |
stillHere := true.
|
|
203 |
[stillHere] whileTrue:[
|
|
204 |
cmd := self commandLoop.
|
1
|
205 |
|
74
|
206 |
(cmd == $s) ifTrue: [
|
|
207 |
self stepping.
|
|
208 |
ObjectMemory flushInlineCaches.
|
|
209 |
ObjectMemory stepInterruptHandler:self.
|
|
210 |
stillHere := false.
|
|
211 |
StepInterruptPending := true.
|
|
212 |
InterruptPending := true
|
|
213 |
].
|
|
214 |
(cmd == $t) ifTrue: [
|
|
215 |
traceBlock := [:where | where fullPrint].
|
|
216 |
ObjectMemory flushInlineCaches.
|
|
217 |
ObjectMemory stepInterruptHandler:self.
|
|
218 |
stillHere := false.
|
|
219 |
StepInterruptPending := true.
|
|
220 |
InterruptPending := true
|
|
221 |
].
|
|
222 |
(cmd == $c) ifTrue: [
|
|
223 |
stillHere := false.
|
|
224 |
stepping := false.
|
|
225 |
tracing := false.
|
|
226 |
StepInterruptPending := nil.
|
|
227 |
InterruptPending := nil
|
|
228 |
].
|
|
229 |
(cmd == $a) ifTrue: [
|
|
230 |
"abort"
|
|
231 |
stepping := false.
|
|
232 |
tracing := false.
|
|
233 |
StepInterruptPending := nil.
|
|
234 |
InterruptPending := nil.
|
|
235 |
self doAbort.
|
|
236 |
stillHere := true.
|
|
237 |
"failed abort"
|
|
238 |
].
|
1
|
239 |
].
|
|
240 |
^ nil
|
|
241 |
! !
|
|
242 |
|
|
243 |
!MiniDebugger methodsFor: 'user commands'!
|
|
244 |
|
74
|
245 |
doAbort
|
|
246 |
|con sig|
|
|
247 |
|
|
248 |
(sig := Object abortSignal) isHandled ifTrue:[
|
|
249 |
sig raise.
|
|
250 |
'abort raise failed' errorPrintNewline.
|
|
251 |
].
|
|
252 |
|
|
253 |
"TEMPORARY kludge - find event handler context
|
|
254 |
this will be removed, once real debugging is possible
|
|
255 |
"
|
|
256 |
con := self findContext:#processEvent.
|
|
257 |
con isNil ifTrue:[
|
|
258 |
con := self findContext:#dispatch.
|
|
259 |
].
|
|
260 |
con notNil ifTrue:[
|
|
261 |
"got it"
|
|
262 |
con return.
|
|
263 |
'return failed' errorPrintNewline.
|
|
264 |
].
|
|
265 |
|
|
266 |
'found no context to resume' errorPrintNewline.
|
|
267 |
!
|
|
268 |
|
|
269 |
showProcesses
|
|
270 |
|active|
|
|
271 |
|
|
272 |
active := Processor activeProcess.
|
|
273 |
'current id=' print. active id print. ' name=' print. active name printNewline.
|
|
274 |
|
|
275 |
Process allInstancesDo:[:p |
|
|
276 |
'proc id=' print. p id print. ' name=' print. p name print. ' state=' print.
|
|
277 |
p state printNewline.
|
|
278 |
]
|
|
279 |
!
|
|
280 |
|
1
|
281 |
commandLoop
|
|
282 |
|cmd done valid context|
|
|
283 |
|
|
284 |
done := false.
|
|
285 |
[done] whileFalse:[
|
|
286 |
valid := false.
|
|
287 |
cmd := self getCommand.
|
|
288 |
(cmd == $p) ifTrue:[
|
|
289 |
valid := true.
|
|
290 |
context isNil ifTrue: [
|
|
291 |
context := self getContext
|
|
292 |
].
|
|
293 |
context notNil ifTrue:[
|
|
294 |
context fullPrintAll
|
|
295 |
] ifFalse:[
|
74
|
296 |
'no context' errorPrintNewline
|
1
|
297 |
]
|
|
298 |
].
|
74
|
299 |
(cmd == $P) ifTrue:[
|
|
300 |
valid := true.
|
|
301 |
self showProcesses.
|
|
302 |
].
|
1
|
303 |
(cmd == $r) ifTrue:[
|
|
304 |
valid := true.
|
|
305 |
context isNil ifTrue: [
|
|
306 |
context := self getContext
|
|
307 |
].
|
|
308 |
context notNil ifTrue:[
|
|
309 |
"remove Debugger stepinterrupt/halt frame"
|
|
310 |
context sender receiver printNewline
|
|
311 |
] ifFalse:[
|
74
|
312 |
'no context - dont know receiver' errorPrintNewline
|
1
|
313 |
]
|
|
314 |
].
|
|
315 |
(cmd == $R) ifTrue:[
|
|
316 |
valid := true.
|
|
317 |
context isNil ifTrue: [
|
|
318 |
context := self getContext
|
|
319 |
].
|
|
320 |
context notNil ifTrue:[
|
|
321 |
"remove Debugger stepinterrupt/halt frame"
|
|
322 |
context sender receiver storeOn:Stdout
|
|
323 |
] ifFalse:[
|
74
|
324 |
'no context - dont know receiver' errorPrintNewline
|
1
|
325 |
]
|
|
326 |
].
|
|
327 |
(cmd == $i) ifTrue:[
|
|
328 |
valid := true.
|
|
329 |
context isNil ifTrue: [
|
|
330 |
context := self getContext
|
|
331 |
].
|
|
332 |
context notNil ifTrue:[
|
|
333 |
"remove Debugger stepinterrupt/halt frame"
|
93
|
334 |
MiniInspector openOn:(context sender receiver)
|
1
|
335 |
] ifFalse:[
|
74
|
336 |
'no context - dont know receiver' errorPrintNewline
|
1
|
337 |
]
|
|
338 |
].
|
|
339 |
(cmd == $I) ifTrue:[
|
|
340 |
valid := true.
|
|
341 |
context isNil ifTrue: [
|
|
342 |
context := self getContext
|
|
343 |
].
|
|
344 |
context notNil ifTrue:[
|
|
345 |
"remove Debugger stepinterrupt/halt frame"
|
|
346 |
self interpreterLoopWith:(context sender receiver)
|
|
347 |
] ifFalse:[
|
74
|
348 |
'no context - dont know receiver' errorPrintNewline.
|
1
|
349 |
self interpreterLoopWith:nil
|
|
350 |
]
|
|
351 |
].
|
33
|
352 |
context := nil.
|
1
|
353 |
(cmd == $c) ifTrue:[valid := true. done := true].
|
|
354 |
(cmd == $s) ifTrue:[valid := true. done := true].
|
|
355 |
(cmd == $t) ifTrue:[valid := true. done := true].
|
74
|
356 |
(cmd == $a) ifTrue:[valid := true. done := true].
|
|
357 |
(cmd == $T) ifTrue:[valid := true. Processor activeProcess terminate].
|
|
358 |
(cmd == $X) ifTrue:[Smalltalk fatalAbort].
|
1
|
359 |
(cmd == $x) ifTrue:[Smalltalk exit].
|
|
360 |
valid ifFalse: [
|
74
|
361 |
'valid commands:
|
|
362 |
(c)ontinue
|
|
363 |
(s)tep
|
|
364 |
(t)race
|
|
365 |
(p)rintContext
|
93
|
366 |
(r)eceiver printString
|
|
367 |
(R)eceiver storeString
|
74
|
368 |
(i)nspect
|
|
369 |
(I)nterpreter
|
|
370 |
(a)bort
|
|
371 |
(P)rocesses
|
93
|
372 |
(T)terminate current process
|
74
|
373 |
(X)exit (+core)
|
|
374 |
(x)exit Smalltalk' errorPrintNewline
|
1
|
375 |
]
|
|
376 |
].
|
|
377 |
^ cmd
|
|
378 |
!
|
|
379 |
|
|
380 |
getCommand
|
|
381 |
|cmd c|
|
93
|
382 |
|
1
|
383 |
'MiniDebugger> ' print.
|
93
|
384 |
|
1
|
385 |
cmd := Character fromUser.
|
93
|
386 |
cmd isNil ifTrue:[
|
|
387 |
"
|
|
388 |
mhmh end-of-file;
|
|
389 |
return a 'c' (for continue); hope thats ok.
|
|
390 |
"
|
|
391 |
cmd := $c
|
|
392 |
].
|
|
393 |
|
|
394 |
"
|
|
395 |
ignore to end-of-line
|
|
396 |
"
|
1
|
397 |
c := cmd.
|
93
|
398 |
[c isNil or:[c isEndOfLineCharacter]] whileFalse: [
|
|
399 |
c := Character fromUser.
|
1
|
400 |
].
|
|
401 |
^ cmd
|
|
402 |
!
|
|
403 |
|
|
404 |
interpreterLoopWith:anObject
|
|
405 |
|line done|
|
|
406 |
'read-eval-print loop; exit with empty line' printNewline.
|
|
407 |
done := false.
|
|
408 |
[done] whileFalse:[
|
|
409 |
line := Stdin nextLine.
|
|
410 |
(line size == 0) ifTrue:[
|
|
411 |
done := true
|
|
412 |
] ifFalse:[
|
|
413 |
(Compiler evaluate:line
|
|
414 |
receiver:anObject
|
|
415 |
notifying:nil) printNewline
|
|
416 |
]
|
|
417 |
]
|
|
418 |
! !
|