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