author | Claus Gittinger <cg@exept.de> |
Sun, 14 Oct 2018 21:17:58 +0200 | |
changeset 23443 | 405ef3cf813b |
parent 22830 | 00ba7fc7bdca |
child 23519 | 01b8a5b41a2f |
permissions | -rw-r--r-- |
22733 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1 | 3 |
" |
5 | 4 |
COPYRIGHT (c) 1988 by Claus Gittinger |
159 | 5 |
All Rights Reserved |
1 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
5942
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
14 |
"{ Package: 'stx:libbasic' }" |
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
15 |
|
19144 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
720 | 18 |
Object subclass:#MiniDebugger |
5802
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
5054
diff
changeset
|
19 |
instanceVariableNames:'tracing stepping traceBlock command commandArg commandCount |
19389 | 20 |
enteringContext dot nesting inputStream' |
16626 | 21 |
classVariableNames:'NotFirstTimeEntered' |
976 | 22 |
poolDictionaries:'' |
23 |
category:'System-Debugging-Support' |
|
1 | 24 |
! |
25 |
||
618 | 26 |
!MiniDebugger class methodsFor:'documentation'! |
89 | 27 |
|
28 |
copyright |
|
29 |
" |
|
30 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
159 | 31 |
All Rights Reserved |
1 | 32 |
|
89 | 33 |
This software is furnished under a license and may be used |
34 |
only in accordance with the terms of that license and with the |
|
35 |
inclusion of the above copyright notice. This software may not |
|
36 |
be provided or otherwise made available to, or used by, any |
|
37 |
other person. No title to or ownership of the software is |
|
38 |
hereby transferred. |
|
39 |
" |
|
40 |
! |
|
1 | 41 |
|
89 | 42 |
documentation |
43 |
" |
|
44 |
a primitive (non graphical) debugger for use on systems without |
|
20501 | 45 |
graphics or when the real debugger dies |
46 |
(i.e. an error occurs in the graphical debugger or the UI/event handler is broken). |
|
47 |
This one is also called for, if an interrupt occurs within the debuger, |
|
48 |
or if CTRL-C is pressed in the controlling tty/console. |
|
15927 | 49 |
Needs a console. |
1297 | 50 |
|
20846 | 51 |
MiniDebugger enter |
13740 | 52 |
|
20500 | 53 |
Attention: |
20846 | 54 |
all printing is done via lowLevel _errorPrint messages, |
55 |
to ensure that output is to stderr, even if a logger is present, |
|
56 |
or Stderr has been set to some other stream (Transcript). |
|
20500 | 57 |
Also to avoid the logger's interfering and adding imestamp information. |
58 |
||
1297 | 59 |
[author:] |
20500 | 60 |
Claus Gittinger |
89 | 61 |
" |
62 |
! ! |
|
1 | 63 |
|
618 | 64 |
!MiniDebugger class methodsFor:'instance creation'! |
65 |
||
11534 | 66 |
enter |
67 |
"enter a miniDebugger" |
|
68 |
||
16557 | 69 |
^ self |
19389 | 70 |
enter:thisContext sender |
71 |
withMessage:'MiniDebugger' |
|
72 |
mayProceed:true |
|
73 |
input:nil |
|
20496 | 74 |
|
75 |
" |
|
76 |
MiniDebugger enter |
|
77 |
" |
|
11534 | 78 |
! |
79 |
||
4572 | 80 |
enter:aContext withMessage:aString mayProceed:mayProceed |
3814
1227e4690753
allow aborting other threads
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
81 |
"enter a miniDebugger" |
1227e4690753
allow aborting other threads
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
82 |
|
19389 | 83 |
^ self |
84 |
enter:aContext |
|
85 |
withMessage:aString |
|
86 |
mayProceed:mayProceed |
|
87 |
input:nil |
|
88 |
! |
|
89 |
||
90 |
enter:aContext withMessage:aString mayProceed:mayProceed input:inputStreamOrNil |
|
91 |
"enter a miniDebugger" |
|
92 |
||
7839
d6d9fac8b4db
skip recursive contexts when shwing backtrace
Claus Gittinger <cg@exept.de>
parents:
7706
diff
changeset
|
93 |
|active con sender| |
618 | 94 |
|
95 |
StepInterruptPending := nil. |
|
96 |
||
7093
60bad14d38fc
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
6938
diff
changeset
|
97 |
Error handle:[:ex | |
23443 | 98 |
'MiniDebugger caught (& ignored): ' _errorPrintCR. |
99 |
ex _errorPrintCR. |
|
19389 | 100 |
ex return |
2661
fea131f9f062
care for recursive errors in MiniDebugger
Claus Gittinger <cg@exept.de>
parents:
2118
diff
changeset
|
101 |
] do:[ |
19389 | 102 |
thisContext isRecursive ifTrue:[ |
20843 | 103 |
"/ 'recursive _error in debugger ignored' _errorPrintCR. |
19389 | 104 |
^ self |
105 |
]. |
|
14798 | 106 |
|
20843 | 107 |
aString _errorPrintCR. |
19389 | 108 |
Processor notNil ifTrue:[ |
109 |
active := Processor activeProcess. |
|
20843 | 110 |
'process: id=' _errorPrint. active id _errorPrint. |
111 |
' name=' _errorPrint. active name _errorPrintCR. |
|
4960 | 112 |
|
20843 | 113 |
'context: ' _errorPrint. aContext printString _errorPrintCR. |
19389 | 114 |
(con := aContext) notNil ifTrue:[ |
115 |
con := con sender. |
|
20843 | 116 |
' ......: ' _errorPrint. con printString _errorPrintCR. |
19389 | 117 |
[con notNil] whileTrue:[ |
118 |
sender := con sender. |
|
119 |
(sender notNil and:[sender selector == con selector]) ifTrue:[ |
|
20843 | 120 |
' ......: ' _errorPrint. sender printString _errorPrintCR. |
121 |
' ......: [** intermediate recursive contexts skipped **]' _errorPrintCR. |
|
19389 | 122 |
[sender notNil |
123 |
and:[sender selector == con selector |
|
124 |
and:[sender method == con method]]] whileTrue:[ |
|
125 |
con := sender. |
|
126 |
sender := con sender. |
|
127 |
]. |
|
128 |
]. |
|
129 |
con := sender. |
|
20843 | 130 |
' ......: ' _errorPrint. con printString _errorPrintCR. |
19389 | 131 |
] |
132 |
] |
|
133 |
]. |
|
134 |
NotFirstTimeEntered ~~ true ifTrue:[ |
|
135 |
NotFirstTimeEntered := true. |
|
22733 | 136 |
'Type "c" to proceed, "a" to abort, "?" for help' _errorPrintCR. |
19389 | 137 |
]. |
618 | 138 |
]. |
4209
7c1b4df9e555
care for noConsole present (WIN32 only)
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
139 |
|
7c1b4df9e555
care for noConsole present (WIN32 only)
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
140 |
OperatingSystem hasConsole ifFalse:[ |
19389 | 141 |
Error handle:[:ex | |
142 |
ex return |
|
143 |
] do:[ |
|
20843 | 144 |
self warn:('Unexpected _error:\' , aString , '\\No MiniDebugger functionality available') withCRs . |
19389 | 145 |
]. |
4209
7c1b4df9e555
care for noConsole present (WIN32 only)
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
146 |
|
19389 | 147 |
Error handle:[:ex | |
20843 | 148 |
'cannot raise Abort - exiting ...' _errorPrintCR. |
19389 | 149 |
OperatingSystem exit:10. |
150 |
] do:[ |
|
151 |
AbortOperationRequest raise. |
|
152 |
] |
|
4209
7c1b4df9e555
care for noConsole present (WIN32 only)
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
153 |
] ifTrue:[ |
19389 | 154 |
self new |
155 |
inputStream:inputStreamOrNil; |
|
156 |
enter:aContext mayProceed:mayProceed. |
|
4209
7c1b4df9e555
care for noConsole present (WIN32 only)
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
157 |
]. |
4961
5419c9a32316
abort after unproceedable error
Stefan Vogel <sv@exept.de>
parents:
4960
diff
changeset
|
158 |
mayProceed ifFalse:[ |
19389 | 159 |
AbortOperationRequest raise |
4961
5419c9a32316
abort after unproceedable error
Stefan Vogel <sv@exept.de>
parents:
4960
diff
changeset
|
160 |
]. |
618 | 161 |
^ nil |
1424 | 162 |
|
4209
7c1b4df9e555
care for noConsole present (WIN32 only)
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
163 |
"Modified: / 19.5.1999 / 18:14:33 / cg" |
618 | 164 |
! |
1 | 165 |
|
11235 | 166 |
enterException:ex |
167 |
"enter a debugger; if this is a recursive invocation, enter |
|
168 |
a MiniDebugger instead. |
|
169 |
This is the standard way of entering the debugger; |
|
170 |
sent from error- and halt messages." |
|
171 |
||
172 |
^ self |
|
19389 | 173 |
enter:ex returnableSuspendedContext |
174 |
withMessage:(ex creator name,': ',ex descriptionForDebugger) |
|
175 |
mayProceed:(ex mayProceed) |
|
176 |
input:nil |
|
11235 | 177 |
! |
178 |
||
4572 | 179 |
enterWithMessage:aString mayProceed:mayProceed |
180 |
"enter a miniDebugger" |
|
181 |
||
16557 | 182 |
^ self |
19389 | 183 |
enter:thisContext sender |
184 |
withMessage:aString |
|
185 |
mayProceed:mayProceed |
|
186 |
input:nil |
|
4572 | 187 |
|
188 |
"Modified: / 19.5.1999 / 18:14:33 / cg" |
|
189 |
! |
|
190 |
||
1 | 191 |
new |
3814
1227e4690753
allow aborting other threads
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
192 |
"redefined to make certain that there is only one miniDebugger |
1227e4690753
allow aborting other threads
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
193 |
in the system" |
1227e4690753
allow aborting other threads
Claus Gittinger <cg@exept.de>
parents:
3769
diff
changeset
|
194 |
|
5802
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
5054
diff
changeset
|
195 |
^ self basicNew initialize. |
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
5054
diff
changeset
|
196 |
|
5942
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
197 |
"/ TheOneAndOnlyDebugger isNil ifTrue:[ |
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
198 |
"/ TheOneAndOnlyDebugger := self basicNew initialize |
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
199 |
"/ ]. |
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
200 |
"/ ^ TheOneAndOnlyDebugger |
1424 | 201 |
|
3700 | 202 |
" |
203 |
TheOneAndOnlyDebugger := nil |
|
204 |
" |
|
205 |
||
3701 | 206 |
"Modified: / 31.7.1998 / 17:08:07 / cg" |
1 | 207 |
! |
208 |
||
4966 | 209 |
openOn:aProcess |
210 |
"enter a miniDebugger" |
|
211 |
||
8840 | 212 |
^ self |
19389 | 213 |
enter:thisContext sender |
214 |
withMessage:'MiniDebugger [info]: Attention - process debugging not possible.' |
|
215 |
mayProceed:true |
|
216 |
input:nil |
|
4966 | 217 |
|
218 |
"Modified: / 19.5.1999 / 18:14:33 / cg" |
|
219 |
! |
|
220 |
||
1 | 221 |
singleStep:aBlock |
222 |
|aDebugger| |
|
223 |
||
224 |
aDebugger := self new stepping. |
|
241 | 225 |
ObjectMemory stepInterruptHandler:aDebugger. |
2 | 226 |
ObjectMemory flushInlineCaches. |
241 | 227 |
StepInterruptPending := 1. |
228 |
InterruptPending := 1. |
|
1 | 229 |
aBlock value. |
2 | 230 |
StepInterruptPending := nil. |
231 |
ObjectMemory stepInterruptHandler:nil |
|
1 | 232 |
! |
233 |
||
234 |
trace:aBlock |
|
20843 | 235 |
self trace:aBlock with:[:where | where _errorPrintCR] |
1424 | 236 |
|
237 |
"Modified: 20.5.1996 / 10:27:37 / cg" |
|
1 | 238 |
! |
239 |
||
240 |
trace:aBlock on:aStream |
|
241 |
self trace:aBlock with:[:where | where printString printOn:aStream. |
|
159 | 242 |
aStream cr] |
1 | 243 |
! |
244 |
||
245 |
trace:aBlock with:aTraceBlock |
|
246 |
|aDebugger| |
|
247 |
||
248 |
aDebugger := self new tracingWith:aTraceBlock. |
|
241 | 249 |
ObjectMemory stepInterruptHandler:aDebugger. |
1 | 250 |
ObjectMemory flushInlineCaches. |
241 | 251 |
StepInterruptPending := 1. |
252 |
InterruptPending := 1. |
|
1 | 253 |
aBlock value. |
2 | 254 |
ObjectMemory stepInterruptHandler:nil. |
1 | 255 |
StepInterruptPending := nil. |
256 |
^ nil |
|
257 |
! ! |
|
258 |
||
19389 | 259 |
!MiniDebugger methodsFor:'accessing'! |
260 |
||
261 |
inputStream:aStream |
|
262 |
"if non-nil, the debugger will read its input from there. |
|
263 |
This allows for a miniDebugger to be used in a telnet stream (scripting)" |
|
264 |
||
265 |
inputStream := aStream. |
|
266 |
! ! |
|
267 |
||
13740 | 268 |
!MiniDebugger methodsFor:'entering'! |
1 | 269 |
|
5802
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
5054
diff
changeset
|
270 |
enter:aContext mayProceed:mayProceed |
13740 | 271 |
"regular entry, via unhandled exception" |
272 |
||
5802
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
5054
diff
changeset
|
273 |
|c leaveCmd stillHere yesNo| |
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
5054
diff
changeset
|
274 |
|
20498 | 275 |
Display notNil ifTrue:[ |
276 |
Display ungrabKeyboard; ungrabPointer. |
|
277 |
]. |
|
278 |
||
5802
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
5054
diff
changeset
|
279 |
enteringContext := dot := aContext. |
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
5054
diff
changeset
|
280 |
nesting := 0. |
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
5054
diff
changeset
|
281 |
c := aContext. |
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
5054
diff
changeset
|
282 |
[c notNil] whileTrue:[ |
19148 | 283 |
c selector == #enter:mayProceed: ifTrue:[ |
284 |
nesting := nesting + 1. |
|
285 |
]. |
|
286 |
c := c sender. |
|
5802
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
5054
diff
changeset
|
287 |
]. |
74 | 288 |
|
289 |
stillHere := true. |
|
290 |
[stillHere] whileTrue:[ |
|
19148 | 291 |
AbortOperationRequest handle:[:ex | |
20843 | 292 |
'** Abort caught - back in previous debugLevel' _errorPrintCR. |
19148 | 293 |
] do:[ |
294 |
Error handle:[:ex | |
|
295 |
StreamError handle:[:ex| |
|
296 |
"You won't see this probably - but you will see it when doing a syscall trace" |
|
20843 | 297 |
'Error while processing _error in MiniDebugger (Stdout closed?):' _errorPrintCR. |
298 |
ex description _errorPrintCR. |
|
19148 | 299 |
OperatingSystem exit:10. |
300 |
] do:[ |
|
20843 | 301 |
'Error while executing MiniDebugger command: ' _errorPrint. |
302 |
ex description _errorPrintCR. |
|
19148 | 303 |
yesNo := self getCommand:'- (i)gnore / (p)roceed / (d)ebug / b(acktrace) ? '. |
304 |
yesNo == $d ifTrue:[ |
|
305 |
MiniDebugger enterWithMessage:'Debugging debugger' mayProceed:true. |
|
306 |
ex proceed |
|
307 |
]. |
|
308 |
yesNo == $p ifTrue:[ |
|
309 |
ex proceed |
|
310 |
]. |
|
311 |
yesNo == $b ifTrue:[ |
|
312 |
ex suspendedContext fullPrintAll. |
|
313 |
ex proceed |
|
314 |
]. |
|
315 |
]. |
|
316 |
] do:[ |
|
317 |
[ |
|
318 |
leaveCmd := self commandLoop. |
|
319 |
] valueUnpreemptively. |
|
320 |
]. |
|
321 |
]. |
|
1 | 322 |
|
19148 | 323 |
(leaveCmd == $s) ifTrue: [ |
324 |
self stepping. |
|
325 |
ObjectMemory flushInlineCaches. |
|
326 |
ObjectMemory stepInterruptHandler:self. |
|
327 |
stillHere := false. |
|
328 |
StepInterruptPending := 1. |
|
329 |
InterruptPending := 1 |
|
330 |
]. |
|
331 |
(leaveCmd == $t) ifTrue: [ |
|
20496 | 332 |
traceBlock := [:where | self printContext:where]. |
19148 | 333 |
ObjectMemory flushInlineCaches. |
334 |
ObjectMemory stepInterruptHandler:self. |
|
335 |
stillHere := false. |
|
336 |
StepInterruptPending := 1. |
|
337 |
InterruptPending := 1 |
|
338 |
]. |
|
339 |
(leaveCmd == $c) ifTrue: [ |
|
340 |
traceBlock := nil. |
|
341 |
ObjectMemory flushInlineCaches. |
|
342 |
ObjectMemory stepInterruptHandler:nil. |
|
343 |
stillHere := false. |
|
344 |
stepping := false. |
|
345 |
tracing := false. |
|
346 |
StepInterruptPending := nil. |
|
347 |
InterruptPending := nil |
|
348 |
]. |
|
349 |
((leaveCmd == $a) or:[(leaveCmd == $Y)]) ifTrue: [ |
|
350 |
"abort" |
|
351 |
traceBlock := nil. |
|
352 |
ObjectMemory flushInlineCaches. |
|
353 |
ObjectMemory stepInterruptHandler:nil. |
|
354 |
stepping := false. |
|
355 |
tracing := false. |
|
356 |
StepInterruptPending := nil. |
|
357 |
InterruptPending := nil. |
|
358 |
self doAbort. |
|
359 |
stillHere := true. |
|
360 |
"failed abort" |
|
361 |
]. |
|
1 | 362 |
]. |
5802
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
5054
diff
changeset
|
363 |
enteringContext := dot := nil. |
1 | 364 |
^ nil |
3769 | 365 |
|
13740 | 366 |
"Modified (comment): / 29-09-2011 / 09:05:57 / cg" |
618 | 367 |
! |
368 |
||
369 |
stepInterrupt |
|
13740 | 370 |
"entry via single stepinterrupt" |
371 |
||
618 | 372 |
|where| |
373 |
||
374 |
where := thisContext. "where is stepInterrupt context" |
|
375 |
where notNil ifTrue:[ |
|
20496 | 376 |
where := where sender "where is now interrupted methods context" |
618 | 377 |
]. |
378 |
stepping ifTrue:[ |
|
20496 | 379 |
where notNil ifTrue:[ |
380 |
self printContext:where |
|
381 |
] ifFalse:[ |
|
20843 | 382 |
'stepInterrupt: no context' _errorPrintCR |
20496 | 383 |
]. |
384 |
self enter:where mayProceed:true |
|
618 | 385 |
] ifFalse:[ |
20496 | 386 |
where notNil ifTrue:[ |
387 |
traceBlock notNil ifTrue:[ |
|
388 |
traceBlock value:where |
|
389 |
] |
|
390 |
] ifFalse:[ |
|
20843 | 391 |
'traceInterrupt: no context' _errorPrintCR |
20496 | 392 |
]. |
393 |
ObjectMemory flushInlineCaches. |
|
394 |
StepInterruptPending := 1. |
|
395 |
InterruptPending := 1 |
|
618 | 396 |
] |
1424 | 397 |
|
13740 | 398 |
"Modified: / 20-05-1996 / 10:23:11 / cg" |
399 |
"Modified (comment): / 29-09-2011 / 09:06:29 / cg" |
|
400 |
! ! |
|
401 |
||
402 |
!MiniDebugger methodsFor:'initialization'! |
|
403 |
||
404 |
initialize |
|
405 |
traceBlock := nil. |
|
406 |
tracing := false. |
|
407 |
stepping := false |
|
1 | 408 |
! ! |
409 |
||
618 | 410 |
!MiniDebugger methodsFor:'private'! |
74 | 411 |
|
618 | 412 |
findContext:aSelector |
413 |
|con| |
|
74 | 414 |
|
618 | 415 |
con := thisContext sender. |
416 |
[con notNil] whileTrue:[ |
|
417 |
(con isBlockContext not and:[con selector == aSelector]) ifTrue:[ |
|
418 |
"got it" |
|
419 |
^ con |
|
420 |
]. |
|
421 |
con := con sender |
|
74 | 422 |
]. |
618 | 423 |
^ nil |
74 | 424 |
! |
425 |
||
7701 | 426 |
garbageCollectCommand:id |
427 |
id == 3 ifTrue:[ |
|
8840 | 428 |
ObjectMemory reclaimSymbols. |
429 |
ObjectMemory compressOldSpace. |
|
7701 | 430 |
] ifFalse:[ |
8840 | 431 |
id == 2 ifTrue:[ |
432 |
ObjectMemory reclaimSymbols. |
|
433 |
] ifFalse:[ |
|
434 |
ObjectMemory garbageCollect. |
|
435 |
] |
|
7701 | 436 |
] |
437 |
! |
|
438 |
||
19389 | 439 |
getCharacter |
440 |
inputStream isNil ifTrue:[ |
|
441 |
"/ globally blocking |
|
442 |
^ Character fromUser |
|
443 |
]. |
|
444 |
^ inputStream next |
|
445 |
! |
|
446 |
||
618 | 447 |
getContext |
448 |
|backtrace| |
|
13740 | 449 |
|
618 | 450 |
backtrace := thisContext. |
451 |
(backtrace notNil) ifTrue: [ |
|
16557 | 452 |
[backtrace selector ~~ #commandLoop] whileTrue:[ |
453 |
backtrace := backtrace sender. |
|
454 |
]. |
|
455 |
"remove Debugger commandLoop frame" |
|
456 |
backtrace := backtrace sender. |
|
457 |
"remove Debugger enter frame" |
|
458 |
backtrace := backtrace sender |
|
618 | 459 |
]. |
460 |
^ backtrace |
|
13740 | 461 |
|
462 |
"Modified: / 29-09-2011 / 09:00:14 / cg" |
|
618 | 463 |
! |
74 | 464 |
|
5942
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
465 |
moveDotDown |
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
466 |
"/ sigh - must search |
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
467 |
|c| |
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
468 |
|
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
469 |
c := enteringContext. |
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
470 |
[ c notNil and:[ c sender ~~ dot ] ] whileTrue:[ |
20496 | 471 |
c := c sender. |
5942
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
472 |
]. |
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
473 |
c notNil ifTrue:[ |
20496 | 474 |
dot := c. |
475 |
"/ dot fullPrint. |
|
5942
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
476 |
] ifFalse:[ |
20843 | 477 |
'** dot is the bottom of the calling chain' _errorPrintCR. |
5942
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
478 |
]. |
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
479 |
! |
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
480 |
|
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
481 |
moveDotUp |
20908 | 482 |
|sender| |
483 |
||
484 |
(sender := dot sender) notNil ifTrue:[ |
|
485 |
dot := sender. |
|
20496 | 486 |
"/ dot fullPrint. |
5942
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
487 |
] ifFalse:[ |
20843 | 488 |
'** dot is the top of the calling chain' _errorPrintCR. |
5942
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
489 |
]. |
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
490 |
! |
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
491 |
|
2772 | 492 |
printBacktraceFrom:aContext |
4003
d0f97b9cd4de
added 'S' -> stopp a process
Claus Gittinger <cg@exept.de>
parents:
3814
diff
changeset
|
493 |
|context n| |
d0f97b9cd4de
added 'S' -> stopp a process
Claus Gittinger <cg@exept.de>
parents:
3814
diff
changeset
|
494 |
|
d0f97b9cd4de
added 'S' -> stopp a process
Claus Gittinger <cg@exept.de>
parents:
3814
diff
changeset
|
495 |
aContext isNil ifTrue:[ |
20843 | 496 |
'no context' _errorPrintCR. |
20496 | 497 |
^ self |
4003
d0f97b9cd4de
added 'S' -> stopp a process
Claus Gittinger <cg@exept.de>
parents:
3814
diff
changeset
|
498 |
]. |
d0f97b9cd4de
added 'S' -> stopp a process
Claus Gittinger <cg@exept.de>
parents:
3814
diff
changeset
|
499 |
|
d0f97b9cd4de
added 'S' -> stopp a process
Claus Gittinger <cg@exept.de>
parents:
3814
diff
changeset
|
500 |
context := aContext. |
d0f97b9cd4de
added 'S' -> stopp a process
Claus Gittinger <cg@exept.de>
parents:
3814
diff
changeset
|
501 |
n := commandCount. |
d0f97b9cd4de
added 'S' -> stopp a process
Claus Gittinger <cg@exept.de>
parents:
3814
diff
changeset
|
502 |
[context notNil] whileTrue: [ |
20496 | 503 |
self printContext:context. |
504 |
context := context sender. |
|
505 |
n notNil ifTrue:[ |
|
506 |
n := n - 1. |
|
507 |
n <= 0 ifTrue:[ |
|
508 |
^ self |
|
509 |
] |
|
510 |
] |
|
2772 | 511 |
] |
512 |
! |
|
513 |
||
20496 | 514 |
printContext:aContext |
515 |
"print the receiver, selector and args of the context" |
|
516 |
||
517 |
"/ aContext fullPrint. |
|
518 |
||
20843 | 519 |
aContext receiverPrintString _errorPrint. ' ' _errorPrint. |
520 |
aContext selector asString _errorPrint. |
|
20496 | 521 |
aContext argumentCount ~~ 0 ifTrue: [ |
20843 | 522 |
' ' _errorPrint. aContext argsDisplayString _errorPrint |
20496 | 523 |
]. |
20843 | 524 |
' [' _errorPrint. |
525 |
aContext lineNumber asString _errorPrint. |
|
526 |
']' _errorPrintCR |
|
20496 | 527 |
! |
528 |
||
5942
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
529 |
printDot |
20908 | 530 |
|mthd argNames varNames| |
531 |
||
532 |
'' _errorPrintCR. |
|
533 |
||
20496 | 534 |
self printContext:dot. |
20843 | 535 |
' receiver: ' _errorPrint. dot receiver printString _errorPrintCR. |
536 |
' selector: ' _errorPrint. dot selector _errorPrintCR. |
|
20908 | 537 |
|
538 |
dot isBlockContext ifFalse:[ |
|
539 |
(mthd := dot method) notNil ifTrue:[ |
|
540 |
Error ignoreIn:[ |
|
541 |
argNames := mthd methodArgNames. |
|
542 |
]. |
|
543 |
Error ignoreIn:[ |
|
544 |
varNames := mthd methodVarNames |
|
545 |
]. |
|
546 |
]. |
|
547 |
]. |
|
548 |
"/ ' args: ' _errorPrint. (argNames ? #() asStringWith:$;) _errorPrintCR. |
|
549 |
"/ ' vars: ' _errorPrint. (varNames ? #() asStringWith:$;) _errorPrintCR. |
|
550 |
||
20843 | 551 |
' args: ' _errorPrintCR. |
8717 | 552 |
dot args keysAndValuesDo:[:idx :eachArg | |
20908 | 553 |
' ' _errorPrint. |
554 |
argNames notNil ifTrue:[ |
|
555 |
(argNames at:idx) _errorPrint. |
|
556 |
] ifFalse:[ |
|
557 |
'arg' _errorPrint. idx _errorPrint. |
|
558 |
]. |
|
20843 | 559 |
': ' _errorPrint. eachArg printString _errorPrintCR. |
8717 | 560 |
]. |
20908 | 561 |
|
20843 | 562 |
' vars: ' _errorPrintCR. |
8717 | 563 |
dot vars keysAndValuesDo:[:idx :eachVar | |
20908 | 564 |
' ' _errorPrint. |
565 |
varNames notNil ifTrue:[ |
|
566 |
(varNames at:idx) _errorPrint. |
|
567 |
] ifFalse:[ |
|
568 |
'var' _errorPrint. idx _errorPrint. |
|
569 |
]. |
|
20843 | 570 |
': ' _errorPrint. eachVar printString _errorPrintCR. |
8717 | 571 |
]. |
20908 | 572 |
|
573 |
'' _errorPrintCR. |
|
8717 | 574 |
! |
575 |
||
576 |
printDotsMethodSource |
|
14737 | 577 |
self printDotsMethodSource:false |
578 |
! |
|
579 |
||
580 |
printDotsMethodSource:full |
|
581 |
|home mthd src pcLineNr startLnr stopLnr| |
|
8717 | 582 |
|
583 |
home := dot methodHome. |
|
584 |
mthd := home method. |
|
585 |
mthd isNil ifTrue:[ |
|
20843 | 586 |
'** no source **' _errorPrintCR. |
20496 | 587 |
^ self. |
8717 | 588 |
]. |
589 |
src := mthd source. |
|
590 |
src isNil ifTrue:[ |
|
20843 | 591 |
'** no source **' _errorPrintCR. |
20496 | 592 |
^ self. |
8717 | 593 |
]. |
14737 | 594 |
pcLineNr := dot lineNumber. |
595 |
||
8717 | 596 |
src := src asCollectionOfLines. |
14737 | 597 |
full ifTrue:[ |
20496 | 598 |
startLnr := 1. |
599 |
stopLnr := src size. |
|
14737 | 600 |
] ifFalse:[ |
20496 | 601 |
startLnr := pcLineNr-10 max:1. |
602 |
stopLnr := pcLineNr+10 min:src size. |
|
14737 | 603 |
]. |
604 |
startLnr to:stopLnr do:[:lNr | |
|
20496 | 605 |
lNr == pcLineNr ifTrue:[ |
20843 | 606 |
'>> ' _errorPrint. |
20496 | 607 |
] ifFalse:[ |
20843 | 608 |
' ' _errorPrint. |
20496 | 609 |
]. |
20904 | 610 |
(lNr printStringLeftPaddedTo:3) _errorPrint. '| ' _errorPrint. |
20843 | 611 |
(src at:lNr) asString _errorPrintCR. |
8717 | 612 |
] |
5942
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
613 |
! |
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
614 |
|
618 | 615 |
stepping |
616 |
traceBlock := nil. |
|
617 |
tracing := false. |
|
618 |
stepping := true |
|
74 | 619 |
! |
620 |
||
618 | 621 |
tracingWith:aBlockOrNil |
622 |
traceBlock := aBlockOrNil. |
|
623 |
stepping := false. |
|
624 |
tracing := true |
|
625 |
! ! |
|
626 |
||
627 |
!MiniDebugger methodsFor:'user commands'! |
|
628 |
||
1 | 629 |
commandLoop |
16557 | 630 |
"read-eval commands, until one of the continue, abort or single step commands is entered; |
13740 | 631 |
return the last command character" |
632 |
||
633 |
|cmd done| |
|
1 | 634 |
|
635 |
done := false. |
|
636 |
[done] whileFalse:[ |
|
16557 | 637 |
cmd := self getCommand:nil. |
638 |
cmd isNil ifTrue:[ "/ EOF is treated like continue command |
|
639 |
cmd := $c |
|
640 |
]. |
|
641 |
done := self doCommand:cmd. |
|
1 | 642 |
]. |
643 |
^ cmd |
|
1424 | 644 |
|
13740 | 645 |
"Modified (comment): / 29-09-2011 / 09:02:24 / cg" |
1 | 646 |
! |
647 |
||
618 | 648 |
doAbort |
649 |
|con sig| |
|
650 |
||
6204
2bafef9151dd
class based exceptions - abortSignal;
Claus Gittinger <cg@exept.de>
parents:
5942
diff
changeset
|
651 |
(sig := AbortOperationRequest) isHandled ifTrue:[ |
20496 | 652 |
sig raise. |
20843 | 653 |
'abort raise failed' _errorPrintCR. |
618 | 654 |
]. |
655 |
||
656 |
"TEMPORARY kludge - find event handler context |
|
657 |
this will be removed, once real debugging is possible |
|
658 |
" |
|
659 |
con := self findContext:#processEvent. |
|
660 |
con isNil ifTrue:[ |
|
20496 | 661 |
con := self findContext:#dispatch. |
618 | 662 |
]. |
663 |
con notNil ifTrue:[ |
|
20496 | 664 |
"got it" |
665 |
con return. |
|
20843 | 666 |
'return failed' _errorPrintCR. |
618 | 667 |
]. |
668 |
||
20843 | 669 |
'found no context to resume' _errorPrintCR. |
1424 | 670 |
|
6204
2bafef9151dd
class based exceptions - abortSignal;
Claus Gittinger <cg@exept.de>
parents:
5942
diff
changeset
|
671 |
"Modified: / 16.11.2001 / 17:39:14 / cg" |
618 | 672 |
! |
673 |
||
13740 | 674 |
doCommand:cmd |
16557 | 675 |
"a single command; |
14797 | 676 |
return true, if command loop should be finished" |
13740 | 677 |
|
14797 | 678 |
|id proc bool| |
13740 | 679 |
|
15860 | 680 |
commandArg notEmptyOrNil ifTrue:[ |
19145 | 681 |
id := Number readFrom:commandArg onError:nil. |
682 |
id notNil ifTrue:[ |
|
683 |
proc := Process allSubInstances detect:[:p | p id == id] ifNone:nil. |
|
684 |
proc == Processor activeProcess ifTrue:[ |
|
685 |
id := proc := nil |
|
686 |
] |
|
687 |
] ifFalse:[ |
|
688 |
commandArg = '-' ifTrue:[ |
|
689 |
bool := false |
|
690 |
] ifFalse:[ |
|
691 |
commandArg = '+' ifTrue:[ |
|
692 |
bool := true |
|
693 |
] |
|
694 |
] |
|
695 |
] |
|
13740 | 696 |
]. |
697 |
||
14737 | 698 |
(cmd == $w) ifTrue:[ |
19145 | 699 |
proc notNil ifTrue:[ |
20843 | 700 |
'-------- walkback of process ' _errorPrint. id _errorPrint. ' -------' _errorPrintCR. |
19145 | 701 |
self printBacktraceFrom:(proc suspendedContext) |
702 |
] ifFalse:[ |
|
703 |
id notNil ifTrue:[ |
|
20843 | 704 |
'no process with id: ' _errorPrint. id _errorPrintCR. |
19145 | 705 |
] ifFalse:[ |
20843 | 706 |
'-------- walkback of current process -------' _errorPrintCR. |
19145 | 707 |
self printBacktraceFrom:(self getContext) |
708 |
] |
|
709 |
]. |
|
710 |
^ false |
|
13740 | 711 |
]. |
712 |
||
713 |
(cmd == $b) ifTrue:[ |
|
19145 | 714 |
proc notNil ifTrue:[ |
20843 | 715 |
'-------- VM walkback of process ' _errorPrint. id _errorPrint. ' -------' _errorPrintCR. |
19389 | 716 |
(Processor activeProcess environmentAt:#Stderr ifAbsent:Stderr) == Stderr ifTrue:[ |
717 |
ObjectMemory printStackBacktraceFrom:(proc suspendedContext) |
|
718 |
] ifFalse:[ |
|
719 |
self printBacktraceFrom:(proc suspendedContext) |
|
720 |
"/ proc suspendedContext fullPrintAllOn:(Processor activeProcess environmentAt:#Stderr) |
|
721 |
]. |
|
19145 | 722 |
] ifFalse:[ |
723 |
id notNil ifTrue:[ |
|
20843 | 724 |
'no process with id: ' _errorPrint. id _errorPrintCR. |
19145 | 725 |
] ifFalse:[ |
20843 | 726 |
'-------- VM walkback of current process -------' _errorPrintCR. |
19389 | 727 |
(Processor activeProcess environmentAt:#Stderr ifAbsent:Stderr) == Stderr ifTrue:[ |
728 |
ObjectMemory printStackBacktrace |
|
729 |
] ifFalse:[ |
|
730 |
"/ self printBacktraceFrom:(self getContext) |
|
731 |
thisContext fullPrintAllOn:(Processor activeProcess environmentAt:#Stderr) |
|
732 |
] |
|
19145 | 733 |
] |
734 |
]. |
|
735 |
^ false |
|
13740 | 736 |
]. |
737 |
||
738 |
(cmd == $S) ifTrue:[ |
|
20843 | 739 |
'saving "crash.img"...' _errorPrint. |
19145 | 740 |
ObjectMemory writeCrashImage. |
20843 | 741 |
'done.' _errorPrintCR. |
19145 | 742 |
^ false |
13740 | 743 |
]. |
15859 | 744 |
(cmd == $C) ifTrue:[ |
19145 | 745 |
|changesFilename| |
15859 | 746 |
|
19145 | 747 |
changesFilename := Timestamp now |
748 |
printStringFormat:'changes_%(year)-%(month)-%(day)__%h:%m:%s.chg'. |
|
749 |
OperatingSystem isMSWINDOWSlike ifTrue:[ changesFilename replaceAll:$: with:$_ ]. |
|
15861 | 750 |
|
19145 | 751 |
ChangeSet current fileOutAs: changesFilename. |
20843 | 752 |
('saved session changes to "',changesFilename,'".') _errorPrintCR. |
19145 | 753 |
^ false |
15859 | 754 |
]. |
13740 | 755 |
|
756 |
(cmd == $B) ifTrue:[ |
|
19145 | 757 |
self printAllBacktraces. |
758 |
^ false |
|
13740 | 759 |
]. |
760 |
||
761 |
(cmd == $P) ifTrue:[ |
|
19145 | 762 |
self showProcesses:#all. |
763 |
^ false |
|
14797 | 764 |
]. |
765 |
(cmd == $p) ifTrue:[ |
|
19145 | 766 |
self showProcesses:#live. |
767 |
^ false |
|
13740 | 768 |
]. |
769 |
||
770 |
(cmd == $r) ifTrue:[ |
|
20843 | 771 |
dot receiver _errorPrintCR. |
19145 | 772 |
^ false |
13740 | 773 |
]. |
774 |
||
775 |
(cmd == $i) ifTrue:[ |
|
19389 | 776 |
|inspectedObject| |
777 |
||
19145 | 778 |
(commandArg ? '') withoutSeparators notEmpty ifTrue:[ |
19389 | 779 |
inspectedObject := (Parser evaluate:commandArg). |
19145 | 780 |
] ifFalse:[ |
19389 | 781 |
inspectedObject := (dot receiver). |
19145 | 782 |
]. |
19389 | 783 |
MiniInspector openOn:inspectedObject input:inputStream. |
19145 | 784 |
^ false |
13740 | 785 |
]. |
786 |
||
787 |
(cmd == $I) ifTrue:[ |
|
19145 | 788 |
self interpreterLoopWith:nil. |
789 |
^ false |
|
13740 | 790 |
]. |
15705 | 791 |
(cmd == $E) ifTrue:[ |
19145 | 792 |
Parser evaluate:commandArg. |
793 |
^ false |
|
13740 | 794 |
]. |
15705 | 795 |
(cmd == $e) ifTrue:[ |
20843 | 796 |
(Parser evaluate:commandArg) _errorPrintCR. |
19145 | 797 |
^ false |
15691 | 798 |
]. |
13740 | 799 |
|
800 |
(cmd == $c) ifTrue:[^ true]. |
|
801 |
(cmd == $s) ifTrue:[^ true]. |
|
802 |
(cmd == $t) ifTrue:[^ true]. |
|
803 |
(cmd == $a) ifTrue:[^ true]. |
|
804 |
||
805 |
(cmd == $u) ifTrue:[ |
|
19145 | 806 |
stepping := false. |
807 |
tracing := false. |
|
808 |
Processor activeProcess vmTrace:false. |
|
809 |
^ false |
|
13740 | 810 |
]. |
811 |
||
14797 | 812 |
(cmd == $h) ifTrue:[ |
19145 | 813 |
(bool notNil) ifTrue:[ |
814 |
Smalltalk ignoreHalt:bool not. |
|
815 |
]. |
|
20843 | 816 |
'halts are ' _errorPrint. (Smalltalk ignoreHalt ifTrue:['disabled'] ifFalse:['enabled']) _errorPrintCR. |
19145 | 817 |
^ false |
14797 | 818 |
]. |
819 |
||
13740 | 820 |
(cmd == $R) ifTrue:[ |
19145 | 821 |
proc notNil ifTrue:[ |
822 |
proc resume. |
|
823 |
]. |
|
824 |
^ false |
|
13740 | 825 |
]. |
826 |
||
827 |
(cmd == $T) ifTrue:[ |
|
19145 | 828 |
proc notNil ifTrue:[ |
829 |
proc terminate. |
|
830 |
] ifFalse:[ |
|
831 |
id notNil ifTrue:[ |
|
20843 | 832 |
'no process with id: ' _errorPrint. id _errorPrintCR. |
19145 | 833 |
] ifFalse:[ |
834 |
Processor terminateActive |
|
835 |
] |
|
836 |
]. |
|
837 |
^ false |
|
13740 | 838 |
]. |
839 |
||
840 |
(cmd == $W) ifTrue:[ |
|
19145 | 841 |
proc notNil ifTrue:[ |
20843 | 842 |
'stopping process id: ' _errorPrint. id _errorPrintCR. |
19145 | 843 |
proc stop. |
844 |
] ifFalse:[ |
|
20843 | 845 |
'invalid process id: ' _errorPrint. id _errorPrintCR. |
19145 | 846 |
]. |
847 |
^ false |
|
13740 | 848 |
]. |
849 |
||
850 |
(cmd == $a) ifTrue:[ |
|
19145 | 851 |
"without id-arg, this is handled by caller" |
852 |
proc notNil ifTrue:[ |
|
20843 | 853 |
'aborting process id: ' _errorPrint. id _errorPrintCR. |
19145 | 854 |
proc interruptWith:[AbortOperationRequest raise] |
855 |
] ifFalse:[ |
|
20843 | 856 |
'aborting' _errorPrintCR. |
19145 | 857 |
]. |
858 |
^ false |
|
13740 | 859 |
]. |
860 |
||
861 |
(cmd == $Q) ifTrue:[ |
|
19145 | 862 |
proc notNil ifTrue:[ |
863 |
proc terminateNoSignal. |
|
864 |
] ifFalse:[ |
|
865 |
id notNil ifTrue:[ |
|
20843 | 866 |
'no process with id: ' _errorPrint. id _errorPrintCR. |
19145 | 867 |
] ifFalse:[ |
868 |
Processor terminateActiveNoSignal |
|
869 |
] |
|
870 |
]. |
|
871 |
^ false |
|
13740 | 872 |
]. |
873 |
||
874 |
(cmd == $g) ifTrue:[ |
|
19145 | 875 |
self garbageCollectCommand:id. |
876 |
^ false |
|
13740 | 877 |
]. |
878 |
||
879 |
(cmd == $U) ifTrue:[ |
|
19145 | 880 |
MessageTracer unwrapAllMethods. |
881 |
^ false |
|
13740 | 882 |
]. |
15929 | 883 |
(cmd == $D) ifTrue:[ |
19145 | 884 |
Breakpoint disableAllBreakpoints. |
885 |
^ false |
|
15929 | 886 |
]. |
13740 | 887 |
(cmd == $X) ifTrue:[ |
19145 | 888 |
Smalltalk fatalAbort. |
889 |
"/ not reached |
|
890 |
^ false |
|
13740 | 891 |
]. |
892 |
(cmd == $x) ifTrue:[ |
|
19145 | 893 |
OperatingSystem exit. |
894 |
"/ not reached |
|
895 |
^ false |
|
896 |
]. |
|
19146 | 897 |
(cmd == $Y) ifTrue:[ |
19925 | 898 |
Display := nil. |
19147 | 899 |
Smalltalk openDisplay. |
900 |
NewLauncher open. |
|
901 |
^ true |
|
13740 | 902 |
]. |
903 |
||
14737 | 904 |
(cmd == $l) ifTrue:[self printDotsMethodSource:false. ^ false ]. |
905 |
(cmd == $L) ifTrue:[self printDotsMethodSource:true. ^ false ]. |
|
22256 | 906 |
|
907 |
('.+-' includes:cmd) ifTrue:[ |
|
908 |
(id ? 1) timesRepeat:[ |
|
909 |
(cmd == $-) ifTrue:[ |
|
910 |
self moveDotUp]. |
|
911 |
(cmd == $+) ifTrue:[ |
|
912 |
self moveDotDown]. |
|
913 |
]. |
|
914 |
self printDot. |
|
915 |
^ false. |
|
916 |
]. |
|
917 |
||
15195 | 918 |
(cmd == $?) ifTrue:[ |
19145 | 919 |
commandArg notEmpty ifTrue:[ |
920 |
self helpOn:commandArg. ^ false |
|
921 |
] |
|
15195 | 922 |
]. |
13740 | 923 |
|
924 |
"/ avoid usage print if return was typed ... |
|
925 |
((cmd == Character return) |
|
926 |
or:[cmd == Character linefeed]) ifTrue:[^ false]. |
|
927 |
||
928 |
self showValidCommandHelp. |
|
929 |
^ false. |
|
930 |
||
931 |
"Created: / 29-09-2011 / 08:58:47 / cg" |
|
22256 | 932 |
"Modified: / 15-09-2017 / 14:30:48 / cg" |
13740 | 933 |
! |
934 |
||
5802
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
5054
diff
changeset
|
935 |
getCommand:prompt |
3126
e37ccb66f1b0
onlz ungrab the main Display (remote display could be inoperable)
Claus Gittinger <cg@exept.de>
parents:
3009
diff
changeset
|
936 |
"/ Screen notNil ifTrue:[ |
e37ccb66f1b0
onlz ungrab the main Display (remote display could be inoperable)
Claus Gittinger <cg@exept.de>
parents:
3009
diff
changeset
|
937 |
"/ Screen allScreens do:[:aScreen | |
e37ccb66f1b0
onlz ungrab the main Display (remote display could be inoperable)
Claus Gittinger <cg@exept.de>
parents:
3009
diff
changeset
|
938 |
"/ aScreen ungrabPointer. |
e37ccb66f1b0
onlz ungrab the main Display (remote display could be inoperable)
Claus Gittinger <cg@exept.de>
parents:
3009
diff
changeset
|
939 |
"/ aScreen ungrabKeyboard. |
e37ccb66f1b0
onlz ungrab the main Display (remote display could be inoperable)
Claus Gittinger <cg@exept.de>
parents:
3009
diff
changeset
|
940 |
"/ ]. |
e37ccb66f1b0
onlz ungrab the main Display (remote display could be inoperable)
Claus Gittinger <cg@exept.de>
parents:
3009
diff
changeset
|
941 |
"/ ]. |
e37ccb66f1b0
onlz ungrab the main Display (remote display could be inoperable)
Claus Gittinger <cg@exept.de>
parents:
3009
diff
changeset
|
942 |
|
e37ccb66f1b0
onlz ungrab the main Display (remote display could be inoperable)
Claus Gittinger <cg@exept.de>
parents:
3009
diff
changeset
|
943 |
Display notNil ifTrue:[ |
19389 | 944 |
Display ungrabPointer. |
945 |
Display ungrabKeyboard. |
|
852
5c4a0585ba0b
ungrab pointer for every input
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
946 |
]. |
5c4a0585ba0b
ungrab pointer for every input
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
947 |
|
8840 | 948 |
(prompt |
19389 | 949 |
? (nesting == 0 ifTrue:[ |
950 |
'MiniDebugger> ' |
|
951 |
] ifFalse:[ |
|
952 |
'MiniDebugger' , nesting printString , '>' |
|
20843 | 953 |
])) _errorPrint. |
93 | 954 |
|
7706 | 955 |
UserInterrupt handle:[:ex | |
19389 | 956 |
ex restart |
159 | 957 |
] do:[ |
19389 | 958 |
|c cmd arg cnt| |
3700 | 959 |
|
19389 | 960 |
cmd := self getCharacter. |
961 |
cmd isNil ifTrue:[ |
|
20843 | 962 |
'<EOF>' _errorPrintCR. |
19389 | 963 |
" |
964 |
mhmh end-of-file; |
|
20420 | 965 |
return a 'c' (for continue); hope that's ok. |
19389 | 966 |
" |
967 |
cmd := $c |
|
968 |
]. |
|
93 | 969 |
|
19389 | 970 |
cnt := nil. |
971 |
(cmd isDigit) ifTrue:[ |
|
972 |
cnt := 0. |
|
973 |
[ |
|
974 |
cnt := (cnt * 10) + cmd digitValue. |
|
975 |
cmd := self getCharacter |
|
976 |
] doWhile:[cmd notNil and:[cmd isDigit]]. |
|
977 |
[cmd notNil and:[cmd == Character space]] whileTrue:[ |
|
978 |
cmd := self getCharacter |
|
979 |
]. |
|
20843 | 980 |
cmd isNil ifTrue:[ '<EOF>' _errorPrintCR ]. |
19389 | 981 |
]. |
4003
d0f97b9cd4de
added 'S' -> stopp a process
Claus Gittinger <cg@exept.de>
parents:
3814
diff
changeset
|
982 |
|
19389 | 983 |
" |
984 |
collect to end-of-line in arg |
|
985 |
" |
|
986 |
c := cmd. |
|
987 |
arg := ''. |
|
988 |
[c isNil or:[c isEndOfLineCharacter]] whileFalse: [ |
|
989 |
arg := arg copyWith:c. |
|
990 |
c := self getCharacter. |
|
20843 | 991 |
c isNil ifTrue:[ '<EOF>' _errorPrintCR ]. |
19389 | 992 |
]. |
993 |
commandArg := (arg copyFrom:2) withoutSeparators. |
|
994 |
command := cmd. |
|
995 |
commandCount := cnt. |
|
1 | 996 |
]. |
3700 | 997 |
^ command |
976 | 998 |
|
3700 | 999 |
"Modified: / 31.7.1998 / 16:11:01 / cg" |
1 | 1000 |
! |
1001 |
||
15195 | 1002 |
helpOn:commandArg |
1003 |
|args className sym val match showMethod| |
|
1004 |
||
1005 |
commandArg withoutSeparators isEmpty ifTrue:[ |
|
20843 | 1006 |
'usage: H className [methodPattern]' _errorPrintCR. |
20496 | 1007 |
^self |
15195 | 1008 |
]. |
1009 |
args := commandArg asCollectionOfWords. |
|
1010 |
className := args first. |
|
16557 | 1011 |
|
15195 | 1012 |
(sym := className asSymbolIfInterned) isNil ifTrue:[ |
20843 | 1013 |
'no such class' _errorPrintCR. |
20496 | 1014 |
^ self. |
15195 | 1015 |
]. |
20843 | 1016 |
val := Smalltalk at:sym ifAbsent:['no such class' _errorPrintCR. ^ self.]. |
15195 | 1017 |
val isBehavior ifFalse:[ |
20843 | 1018 |
'not a class: ' _errorPrint. className _errorPrintCR. |
20496 | 1019 |
val := val class. |
20843 | 1020 |
'showing help for ' _errorPrint. val name _errorPrintCR. |
15195 | 1021 |
]. |
1022 |
args size > 1 ifTrue:[ |
|
20496 | 1023 |
match := args at:2 |
15195 | 1024 |
] ifFalse:[ |
20496 | 1025 |
match := '*' |
15195 | 1026 |
]. |
1027 |
||
16557 | 1028 |
showMethod := |
20496 | 1029 |
[:sel :cls | |
1030 |
|mthd| |
|
15195 | 1031 |
|
20496 | 1032 |
((match includesMatchCharacters and:[ sel matches:match caseSensitive:false]) |
1033 |
or:[ sel asLowercase startsWith:match asLowercase ]) ifTrue:[ |
|
1034 |
mthd := cls compiledMethodAt:sel. |
|
1035 |
mthd category ~= 'documentation' ifTrue:[ |
|
20843 | 1036 |
sel _errorPrintCR. |
20496 | 1037 |
(mthd comment ? '') asStringCollection do:[:l | |
20843 | 1038 |
' ' _errorPrint. l withoutSeparators _errorPrintCR. |
20496 | 1039 |
]. |
20843 | 1040 |
'' _errorPrintCR |
20496 | 1041 |
]. |
1042 |
]. |
|
1043 |
]. |
|
15195 | 1044 |
|
1045 |
val theMetaclass selectors copy sort do:[:sel | |
|
20496 | 1046 |
showMethod value:sel value:val theMetaclass |
15195 | 1047 |
]. |
1048 |
val theNonMetaclass selectors copy sort do:[:sel | |
|
20496 | 1049 |
showMethod value:sel value:val theNonMetaclass |
15195 | 1050 |
]. |
1051 |
! |
|
1052 |
||
1 | 1053 |
interpreterLoopWith:anObject |
16079 | 1054 |
'MinDebugger read-eval-print loop; exit with "#exit"; help with "?"' printCR. |
16557 | 1055 |
ReadEvalPrintLoop new |
20826 | 1056 |
prompt:'mDBG > '; |
19389 | 1057 |
doChunkFormat:false; |
22830 | 1058 |
errorStream:(Processor activeProcess stderr); |
19389 | 1059 |
readEvalPrintLoop. |
3700 | 1060 |
|
10630 | 1061 |
"/ |line done rslt| |
1062 |
"/ |
|
1063 |
"/ 'read-eval-print loop; exit with empty line' printCR. |
|
1064 |
"/ '' printCR. |
|
1065 |
"/ |
|
1066 |
"/ done := false. |
|
1067 |
"/ [done] whileFalse:[ |
|
1068 |
"/ '> ' print. |
|
1069 |
"/ |
|
1070 |
"/ line := Stdin nextLine. |
|
1071 |
"/ (line size == 0) ifTrue:[ |
|
1072 |
"/ done := true |
|
1073 |
"/ ] ifFalse:[ |
|
1074 |
"/ "/ rslt := Compiler evaluate:line |
|
1075 |
"/ "/ receiver:anObject |
|
1076 |
"/ "/ notifying:nil. |
|
1077 |
"/ |
|
1078 |
"/ rslt := Compiler |
|
1079 |
"/ evaluate:line |
|
1080 |
"/ in:dot |
|
1081 |
"/ receiver:dot receiver |
|
1082 |
"/ notifying:self "/ nil |
|
1083 |
"/ ifFail:[]. |
|
1084 |
"/ rslt printCR. |
|
1085 |
"/ ] |
|
1086 |
"/ ] |
|
1424 | 1087 |
|
3700 | 1088 |
"Modified: / 31.7.1998 / 16:01:47 / cg" |
618 | 1089 |
! |
1090 |
||
2772 | 1091 |
printAllBacktraces |
1092 |
Process allInstancesDo:[:p | |
|
20496 | 1093 |
(p isActive not |
1094 |
and:[p isDead not]) ifTrue:[ |
|
20843 | 1095 |
'---------------------------------------------------------' _errorPrintCR. |
1096 |
' proc id=' _errorPrint. p id asString _errorPrint. |
|
1097 |
' name=''' _errorPrint. p name asString _errorPrint. |
|
1098 |
''' createdBy: ' _errorPrint. p creatorId asString _errorPrint. |
|
1099 |
' state=' _errorPrint. p state asString _errorPrint. |
|
1100 |
' prio=' _errorPrint. p priority asString _errorPrintCR. |
|
1101 |
'' _errorPrintCR. '' _errorPrintCR. |
|
2772 | 1102 |
|
20496 | 1103 |
self printBacktraceFrom:(p suspendedContext) |
1104 |
] |
|
2772 | 1105 |
] |
1106 |
! |
|
1107 |
||
618 | 1108 |
showProcesses |
14797 | 1109 |
self showProcesses:#all |
1110 |
! |
|
1111 |
||
1112 |
showProcesses:how |
|
618 | 1113 |
|active| |
1114 |
||
1115 |
active := Processor activeProcess. |
|
20843 | 1116 |
'current id=' _errorPrint. |
1117 |
active id printString _errorPrint. |
|
1118 |
' name=''' _errorPrint. active name _errorPrint. '''' _errorPrintCR. |
|
618 | 1119 |
|
16094 | 1120 |
(Process allSubInstances sort:[:a :b | (a id ? -1)<(b id ? -1)]) do:[:p | |
20496 | 1121 |
|doShow| |
14797 | 1122 |
|
20849 | 1123 |
doShow := (how == #all) or:[ (how == #dead) == ( p isDead ) ]. |
20496 | 1124 |
doShow ifTrue:[ |
20894 | 1125 |
'id=' _errorPrint. (p id printStringPaddedTo:6) _errorPrint. |
20843 | 1126 |
(p state printStringPaddedTo:10) _errorPrint. |
1127 |
' pri=' _errorPrint. (p priority printStringPaddedTo:2) _errorPrint. |
|
1128 |
' creator:' _errorPrint. (p creatorId printStringPaddedTo:5) _errorPrint. |
|
1129 |
' group:' _errorPrint. (p processGroupId printStringPaddedTo:5) _errorPrint. |
|
20893 | 1130 |
"/ ' sys:' _errorPrint. (p isSystemProcess ifTrue:'y' ifFalse:'n') _errorPrint. |
20894 | 1131 |
"/ ' ui:' _errorPrint. (p isGUIProcess ifTrue:'y' ifFalse:'n') _errorPrint. |
1132 |
(p isGUIProcess |
|
20895 | 1133 |
ifTrue:[' ui'] |
20894 | 1134 |
ifFalse:[p isSystemProcess |
1135 |
ifTrue:['sys'] |
|
1136 |
ifFalse:['usr']]) _errorPrint. |
|
20843 | 1137 |
' name=''' _errorPrint. p name _errorPrint. |
1138 |
'''' _errorPrintCR. |
|
20496 | 1139 |
] |
618 | 1140 |
] |
1424 | 1141 |
|
3700 | 1142 |
"Modified: / 31.7.1998 / 16:30:19 / cg" |
7701 | 1143 |
! |
1144 |
||
1145 |
showValidCommandHelp |
|
19144 | 1146 |
'valid commands: |
16095 | 1147 |
c ........ continue |
1148 |
s ........ step |
|
1149 |
t ........ trace (continue with trace) |
|
1150 |
a [id] ... abort (i.e. raise abort signal) in (current) process |
|
1151 |
T [id] ... terminate (current) process |
|
1152 |
W [id] ... stop (current) process |
|
1153 |
R [id] ... resume (current) process |
|
1154 |
Q [id] ... quick terminate (current) process - no unwinds or cleanup |
|
7701 | 1155 |
|
16095 | 1156 |
p ........ list processes ("P" for full list) |
1157 |
w [id] ... walkback (of current/process with id) |
|
16557 | 1158 |
b [id] ... full (VM) backtrace with more detail |
20825 | 1159 |
B ........ backtrace for all processes |
7701 | 1160 |
|
16095 | 1161 |
U ........ unwrap all traced/breakpointed methods |
1162 |
D ........ disable all line breakpoints |
|
1163 |
h [-/+] .. disable/enable halts |
|
1164 |
g ........ collect all garbage |
|
1165 |
g 2 ...... collect all garbage & reclaim symbols |
|
1166 |
g 3 ...... collect all garbage, reclaim symbols and compress |
|
7701 | 1167 |
|
16095 | 1168 |
S ........ save snapshot into "crash.img" |
1169 |
C ........ save session changes to a separate change file |
|
1170 |
x ........ exit Smalltalk ("X" to exit with core dump) |
|
19149 | 1171 |
Y ........ reopen display, reopen launcher |
7701 | 1172 |
|
16095 | 1173 |
. ........ print dot (the current context) |
1174 |
- ........ move dot up (sender) |
|
1175 |
+ ........ move dot down (called context) |
|
1176 |
l ........ list dot''s method source around PC ("L" for full list) |
|
7701 | 1177 |
|
16095 | 1178 |
r ........ receiver (in dot) printString |
1179 |
i [expr] . inspect expression (or receiver in dot) |
|
1180 |
I ........ interpreter (expression evaluator) |
|
19144 | 1181 |
e expr ... evaluate expression & print result ("E" to not print) |
1182 |
? c [p] .. help on class c (selectors matching p) |
|
20843 | 1183 |
' _errorPrintCR. |
7701 | 1184 |
|
14798 | 1185 |
(XWorkstation notNil and:[ Screen default isKindOf:XWorkstation ]) ifTrue:[ |
1186 |
' To repair a broken X-Connection, enter an interpreter (enter "I") and evaluate: |
|
7701 | 1187 |
Display := XWorkstation new. |
14798 | 1188 |
Display initializeFor:''localhost:0''. |
7701 | 1189 |
Display startDispatch. |
1190 |
NewLauncher openOnDevice:Display. |
|
16095 | 1191 |
#exit |
14798 | 1192 |
then enter "c" to continue; a NewLauncher should pop up soon. |
20843 | 1193 |
' _errorPrintCR |
14798 | 1194 |
] |
15859 | 1195 |
|
15930 | 1196 |
"Modified: / 03-02-2014 / 10:38:36 / cg" |
1 | 1197 |
! ! |
618 | 1198 |
|
658 | 1199 |
!MiniDebugger class methodsFor:'documentation'! |
1200 |
||
1201 |
version |
|
18681 | 1202 |
^ '$Header$' |
13113 | 1203 |
! |
1204 |
||
1205 |
version_CVS |
|
18681 | 1206 |
^ '$Header$' |
658 | 1207 |
! ! |
16626 | 1208 |