author | Stefan Vogel <sv@exept.de> |
Tue, 28 Apr 2020 16:22:26 +0200 | |
changeset 25375 | b784fc06a5eb |
parent 25293 | 037a1af56749 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
159 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
5942
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
12 |
"{ Package: 'stx:libbasic' }" |
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
13 |
|
19144 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
720 | 16 |
Object subclass:#MiniDebugger |
5802
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
5054
diff
changeset
|
17 |
instanceVariableNames:'tracing stepping traceBlock command commandArg commandCount |
25253 | 18 |
enteringContext dotProcess dot nesting inputStream' |
16626 | 19 |
classVariableNames:'NotFirstTimeEntered' |
976 | 20 |
poolDictionaries:'' |
21 |
category:'System-Debugging-Support' |
|
1 | 22 |
! |
23 |
||
618 | 24 |
!MiniDebugger class methodsFor:'documentation'! |
89 | 25 |
|
26 |
copyright |
|
27 |
" |
|
28 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
159 | 29 |
All Rights Reserved |
1 | 30 |
|
89 | 31 |
This software is furnished under a license and may be used |
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
38 |
! |
|
1 | 39 |
|
89 | 40 |
documentation |
41 |
" |
|
42 |
a primitive (non graphical) debugger for use on systems without |
|
20501 | 43 |
graphics or when the real debugger dies |
44 |
(i.e. an error occurs in the graphical debugger or the UI/event handler is broken). |
|
25253 | 45 |
|
20501 | 46 |
This one is also called for, if an interrupt occurs within the debuger, |
47 |
or if CTRL-C is pressed in the controlling tty/console. |
|
15927 | 48 |
Needs a console. |
1297 | 49 |
|
25253 | 50 |
You can also enter it explicitly with: |
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 |
|
25253 | 469 |
dotProcess isNil ifTrue:[ |
470 |
c := enteringContext |
|
471 |
] ifFalse:[ |
|
472 |
c := dotProcess suspendedContext. |
|
473 |
c isNil ifTrue:[ |
|
474 |
'** process is not suspended' _errorPrintCR. |
|
475 |
]. |
|
476 |
]. |
|
5942
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
477 |
[ c notNil and:[ c sender ~~ dot ] ] whileTrue:[ |
20496 | 478 |
c := c sender. |
5942
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 |
c notNil ifTrue:[ |
20496 | 481 |
dot := c. |
482 |
"/ dot fullPrint. |
|
5942
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
483 |
] ifFalse:[ |
20843 | 484 |
'** dot is the bottom of the calling chain' _errorPrintCR. |
5942
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
485 |
]. |
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
486 |
! |
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 |
moveDotUp |
20908 | 489 |
|sender| |
490 |
||
491 |
(sender := dot sender) notNil ifTrue:[ |
|
492 |
dot := sender. |
|
20496 | 493 |
"/ dot fullPrint. |
5942
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
494 |
] ifFalse:[ |
20843 | 495 |
'** dot is the top of the calling chain' _errorPrintCR. |
5942
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
496 |
]. |
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
497 |
! |
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
498 |
|
2772 | 499 |
printBacktraceFrom:aContext |
4003
d0f97b9cd4de
added 'S' -> stopp a process
Claus Gittinger <cg@exept.de>
parents:
3814
diff
changeset
|
500 |
|context n| |
d0f97b9cd4de
added 'S' -> stopp a process
Claus Gittinger <cg@exept.de>
parents:
3814
diff
changeset
|
501 |
|
d0f97b9cd4de
added 'S' -> stopp a process
Claus Gittinger <cg@exept.de>
parents:
3814
diff
changeset
|
502 |
aContext isNil ifTrue:[ |
20843 | 503 |
'no context' _errorPrintCR. |
20496 | 504 |
^ self |
4003
d0f97b9cd4de
added 'S' -> stopp a process
Claus Gittinger <cg@exept.de>
parents:
3814
diff
changeset
|
505 |
]. |
d0f97b9cd4de
added 'S' -> stopp a process
Claus Gittinger <cg@exept.de>
parents:
3814
diff
changeset
|
506 |
|
d0f97b9cd4de
added 'S' -> stopp a process
Claus Gittinger <cg@exept.de>
parents:
3814
diff
changeset
|
507 |
context := aContext. |
d0f97b9cd4de
added 'S' -> stopp a process
Claus Gittinger <cg@exept.de>
parents:
3814
diff
changeset
|
508 |
n := commandCount. |
d0f97b9cd4de
added 'S' -> stopp a process
Claus Gittinger <cg@exept.de>
parents:
3814
diff
changeset
|
509 |
[context notNil] whileTrue: [ |
20496 | 510 |
self printContext:context. |
511 |
context := context sender. |
|
512 |
n notNil ifTrue:[ |
|
513 |
n := n - 1. |
|
514 |
n <= 0 ifTrue:[ |
|
515 |
^ self |
|
516 |
] |
|
517 |
] |
|
2772 | 518 |
] |
519 |
! |
|
520 |
||
20496 | 521 |
printContext:aContext |
522 |
"print the receiver, selector and args of the context" |
|
523 |
||
524 |
"/ aContext fullPrint. |
|
525 |
||
20843 | 526 |
aContext receiverPrintString _errorPrint. ' ' _errorPrint. |
527 |
aContext selector asString _errorPrint. |
|
20496 | 528 |
aContext argumentCount ~~ 0 ifTrue: [ |
20843 | 529 |
' ' _errorPrint. aContext argsDisplayString _errorPrint |
20496 | 530 |
]. |
20843 | 531 |
' [' _errorPrint. |
532 |
aContext lineNumber asString _errorPrint. |
|
533 |
']' _errorPrintCR |
|
20496 | 534 |
! |
535 |
||
5942
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
536 |
printDot |
20908 | 537 |
|mthd argNames varNames| |
538 |
||
539 |
'' _errorPrintCR. |
|
540 |
||
20496 | 541 |
self printContext:dot. |
20843 | 542 |
' receiver: ' _errorPrint. dot receiver printString _errorPrintCR. |
543 |
' selector: ' _errorPrint. dot selector _errorPrintCR. |
|
20908 | 544 |
|
545 |
dot isBlockContext ifFalse:[ |
|
546 |
(mthd := dot method) notNil ifTrue:[ |
|
547 |
Error ignoreIn:[ |
|
548 |
argNames := mthd methodArgNames. |
|
549 |
]. |
|
550 |
Error ignoreIn:[ |
|
551 |
varNames := mthd methodVarNames |
|
552 |
]. |
|
553 |
]. |
|
554 |
]. |
|
555 |
"/ ' args: ' _errorPrint. (argNames ? #() asStringWith:$;) _errorPrintCR. |
|
556 |
"/ ' vars: ' _errorPrint. (varNames ? #() asStringWith:$;) _errorPrintCR. |
|
557 |
||
20843 | 558 |
' args: ' _errorPrintCR. |
8717 | 559 |
dot args keysAndValuesDo:[:idx :eachArg | |
20908 | 560 |
' ' _errorPrint. |
561 |
argNames notNil ifTrue:[ |
|
562 |
(argNames at:idx) _errorPrint. |
|
563 |
] ifFalse:[ |
|
564 |
'arg' _errorPrint. idx _errorPrint. |
|
565 |
]. |
|
20843 | 566 |
': ' _errorPrint. eachArg printString _errorPrintCR. |
8717 | 567 |
]. |
20908 | 568 |
|
20843 | 569 |
' vars: ' _errorPrintCR. |
8717 | 570 |
dot vars keysAndValuesDo:[:idx :eachVar | |
23881 | 571 |
|varName| |
572 |
||
20908 | 573 |
varNames notNil ifTrue:[ |
23881 | 574 |
varName := varNames at:idx ifAbsent:nil |
575 |
]. |
|
576 |
||
577 |
' ' _errorPrint. |
|
578 |
varName notNil ifTrue:[ |
|
579 |
varName _errorPrint. |
|
20908 | 580 |
] ifFalse:[ |
581 |
'var' _errorPrint. idx _errorPrint. |
|
582 |
]. |
|
20843 | 583 |
': ' _errorPrint. eachVar printString _errorPrintCR. |
8717 | 584 |
]. |
20908 | 585 |
|
586 |
'' _errorPrintCR. |
|
23881 | 587 |
|
588 |
"Modified: / 12-03-2019 / 22:36:26 / Claus Gittinger" |
|
8717 | 589 |
! |
590 |
||
591 |
printDotsMethodSource |
|
14737 | 592 |
self printDotsMethodSource:false |
593 |
! |
|
594 |
||
595 |
printDotsMethodSource:full |
|
596 |
|home mthd src pcLineNr startLnr stopLnr| |
|
8717 | 597 |
|
598 |
home := dot methodHome. |
|
599 |
mthd := home method. |
|
600 |
mthd isNil ifTrue:[ |
|
20843 | 601 |
'** no source **' _errorPrintCR. |
20496 | 602 |
^ self. |
8717 | 603 |
]. |
604 |
src := mthd source. |
|
605 |
src isNil ifTrue:[ |
|
20843 | 606 |
'** no source **' _errorPrintCR. |
20496 | 607 |
^ self. |
8717 | 608 |
]. |
14737 | 609 |
pcLineNr := dot lineNumber. |
610 |
||
8717 | 611 |
src := src asCollectionOfLines. |
14737 | 612 |
full ifTrue:[ |
20496 | 613 |
startLnr := 1. |
614 |
stopLnr := src size. |
|
14737 | 615 |
] ifFalse:[ |
20496 | 616 |
startLnr := pcLineNr-10 max:1. |
617 |
stopLnr := pcLineNr+10 min:src size. |
|
14737 | 618 |
]. |
619 |
startLnr to:stopLnr do:[:lNr | |
|
20496 | 620 |
lNr == pcLineNr ifTrue:[ |
20843 | 621 |
'>> ' _errorPrint. |
20496 | 622 |
] ifFalse:[ |
20843 | 623 |
' ' _errorPrint. |
20496 | 624 |
]. |
20904 | 625 |
(lNr printStringLeftPaddedTo:3) _errorPrint. '| ' _errorPrint. |
20843 | 626 |
(src at:lNr) asString _errorPrintCR. |
8717 | 627 |
] |
5942
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
628 |
! |
e3431a2c33f1
avoid statements after return
Claus Gittinger <cg@exept.de>
parents:
5921
diff
changeset
|
629 |
|
618 | 630 |
stepping |
631 |
traceBlock := nil. |
|
632 |
tracing := false. |
|
633 |
stepping := true |
|
74 | 634 |
! |
635 |
||
618 | 636 |
tracingWith:aBlockOrNil |
637 |
traceBlock := aBlockOrNil. |
|
638 |
stepping := false. |
|
639 |
tracing := true |
|
640 |
! ! |
|
641 |
||
642 |
!MiniDebugger methodsFor:'user commands'! |
|
643 |
||
1 | 644 |
commandLoop |
16557 | 645 |
"read-eval commands, until one of the continue, abort or single step commands is entered; |
13740 | 646 |
return the last command character" |
647 |
||
648 |
|cmd done| |
|
1 | 649 |
|
650 |
done := false. |
|
651 |
[done] whileFalse:[ |
|
16557 | 652 |
cmd := self getCommand:nil. |
653 |
cmd isNil ifTrue:[ "/ EOF is treated like continue command |
|
654 |
cmd := $c |
|
655 |
]. |
|
656 |
done := self doCommand:cmd. |
|
1 | 657 |
]. |
658 |
^ cmd |
|
1424 | 659 |
|
13740 | 660 |
"Modified (comment): / 29-09-2011 / 09:02:24 / cg" |
1 | 661 |
! |
662 |
||
618 | 663 |
doAbort |
664 |
|con sig| |
|
665 |
||
6204
2bafef9151dd
class based exceptions - abortSignal;
Claus Gittinger <cg@exept.de>
parents:
5942
diff
changeset
|
666 |
(sig := AbortOperationRequest) isHandled ifTrue:[ |
20496 | 667 |
sig raise. |
20843 | 668 |
'abort raise failed' _errorPrintCR. |
618 | 669 |
]. |
670 |
||
671 |
"TEMPORARY kludge - find event handler context |
|
672 |
this will be removed, once real debugging is possible |
|
673 |
" |
|
674 |
con := self findContext:#processEvent. |
|
675 |
con isNil ifTrue:[ |
|
20496 | 676 |
con := self findContext:#dispatch. |
618 | 677 |
]. |
678 |
con notNil ifTrue:[ |
|
20496 | 679 |
"got it" |
680 |
con return. |
|
20843 | 681 |
'return failed' _errorPrintCR. |
618 | 682 |
]. |
683 |
||
20843 | 684 |
'found no context to resume' _errorPrintCR. |
1424 | 685 |
|
6204
2bafef9151dd
class based exceptions - abortSignal;
Claus Gittinger <cg@exept.de>
parents:
5942
diff
changeset
|
686 |
"Modified: / 16.11.2001 / 17:39:14 / cg" |
618 | 687 |
! |
688 |
||
13740 | 689 |
doCommand:cmd |
16557 | 690 |
"a single command; |
14797 | 691 |
return true, if command loop should be finished" |
13740 | 692 |
|
25253 | 693 |
|id proc bool retVal| |
13740 | 694 |
|
25251 | 695 |
"/ care for argument after command character (pid or '+' or '-') |
15860 | 696 |
commandArg notEmptyOrNil ifTrue:[ |
19145 | 697 |
id := Number readFrom:commandArg onError:nil. |
698 |
id notNil ifTrue:[ |
|
699 |
proc := Process allSubInstances detect:[:p | p id == id] ifNone:nil. |
|
700 |
proc == Processor activeProcess ifTrue:[ |
|
701 |
id := proc := nil |
|
702 |
] |
|
703 |
] ifFalse:[ |
|
704 |
commandArg = '-' ifTrue:[ |
|
705 |
bool := false |
|
706 |
] ifFalse:[ |
|
707 |
commandArg = '+' ifTrue:[ |
|
708 |
bool := true |
|
709 |
] |
|
710 |
] |
|
711 |
] |
|
13740 | 712 |
]. |
713 |
||
25253 | 714 |
"/ S -> save |
715 |
(cmd == $S) ifTrue:[ |
|
716 |
'saving "crash.img"...' _errorPrint. |
|
717 |
ObjectMemory writeCrashImage. |
|
718 |
'done.' _errorPrintCR. |
|
719 |
^ false |
|
720 |
]. |
|
721 |
||
722 |
"/ C -> save session changes |
|
723 |
(cmd == $C) ifTrue:[ |
|
724 |
|changesFilename| |
|
725 |
||
726 |
changesFilename := Timestamp now |
|
727 |
printStringFormat:'changes_%(year)-%(month)-%(day)__%h:%m:%s.chg'. |
|
728 |
OperatingSystem isMSWINDOWSlike ifTrue:[ changesFilename replaceAll:$: with:$_ ]. |
|
729 |
||
730 |
('saving session changes to "',changesFilename,'"...') _errorPrintCR. |
|
731 |
ChangeSet current fileOutAs: changesFilename. |
|
732 |
'done.' _errorPrintCR. |
|
733 |
^ false |
|
734 |
]. |
|
735 |
||
736 |
"/ B -> print backtrace of all processes |
|
737 |
(cmd == $B) ifTrue:[ |
|
738 |
self printAllBacktraces. |
|
739 |
^ false |
|
740 |
]. |
|
741 |
||
742 |
"/ P -> print all processes |
|
743 |
(cmd == $P) ifTrue:[ |
|
744 |
self showProcesses:#all. |
|
745 |
^ false |
|
746 |
]. |
|
747 |
"/ c -> continue |
|
748 |
(cmd == $c) ifTrue:[^ true]. |
|
749 |
||
750 |
"/ s -> single step |
|
751 |
(cmd == $s) ifTrue:[^ true]. |
|
752 |
||
753 |
"/ t -> continue with trace |
|
754 |
(cmd == $t) ifTrue:[^ true]. |
|
755 |
||
756 |
"/ a -> abort |
|
757 |
(cmd == $a) ifTrue:[ |
|
758 |
id isNil ifTrue:[^ true]. |
|
759 |
]. |
|
760 |
||
761 |
"/ p -> list (alive) processes |
|
762 |
(cmd == $p) ifTrue:[ |
|
763 |
self showProcesses:#live. |
|
764 |
^ false |
|
765 |
]. |
|
766 |
||
767 |
||
768 |
('wbTQa=' includes:cmd) ifTrue:[ |
|
25251 | 769 |
(id notNil and:[proc isNil]) ifTrue:[ |
770 |
'no process with id: ' _errorPrint. id _errorPrintCR. |
|
771 |
^ false. |
|
772 |
]. |
|
773 |
]. |
|
774 |
||
25253 | 775 |
"/ = id -> set current process for dot (to inspect chain/receiver of another thread) |
776 |
(cmd == $=) ifTrue:[ |
|
777 |
(dotProcess == proc) ifFalse:[ |
|
778 |
dotProcess := proc. |
|
779 |
proc isNil ifTrue:[ |
|
780 |
dot := enteringContext. |
|
781 |
'switched back to interrupted process (for dot commands): ' _errorPrint. Processor activeProcess _errorPrintCR. |
|
782 |
] ifFalse:[ |
|
783 |
dot := proc suspendedContext. |
|
784 |
'switched to process (for dot commands): ' _errorPrint. proc _errorPrintCR. |
|
785 |
]. |
|
786 |
]. |
|
787 |
^ false. |
|
788 |
]. |
|
789 |
||
790 |
(cmd == $a) ifTrue:[ |
|
791 |
"/ here a with id-arg |
|
792 |
proc == Processor activeProcess ifTrue:[^ true]. |
|
793 |
proc interruptWith:[ AbortOperationRequest raise ]. |
|
794 |
^ false. |
|
795 |
]. |
|
796 |
||
14737 | 797 |
(cmd == $w) ifTrue:[ |
19145 | 798 |
proc notNil ifTrue:[ |
20843 | 799 |
'-------- walkback of process ' _errorPrint. id _errorPrint. ' -------' _errorPrintCR. |
19145 | 800 |
self printBacktraceFrom:(proc suspendedContext) |
801 |
] ifFalse:[ |
|
25251 | 802 |
'-------- walkback of current process -------' _errorPrintCR. |
803 |
self printBacktraceFrom:(self getContext) |
|
19145 | 804 |
]. |
805 |
^ false |
|
13740 | 806 |
]. |
807 |
||
808 |
(cmd == $b) ifTrue:[ |
|
19145 | 809 |
proc notNil ifTrue:[ |
20843 | 810 |
'-------- VM walkback of process ' _errorPrint. id _errorPrint. ' -------' _errorPrintCR. |
19389 | 811 |
(Processor activeProcess environmentAt:#Stderr ifAbsent:Stderr) == Stderr ifTrue:[ |
812 |
ObjectMemory printStackBacktraceFrom:(proc suspendedContext) |
|
813 |
] ifFalse:[ |
|
814 |
self printBacktraceFrom:(proc suspendedContext) |
|
815 |
"/ proc suspendedContext fullPrintAllOn:(Processor activeProcess environmentAt:#Stderr) |
|
816 |
]. |
|
19145 | 817 |
] ifFalse:[ |
25251 | 818 |
'-------- VM walkback of current process -------' _errorPrintCR. |
819 |
(Processor activeProcess environmentAt:#Stderr ifAbsent:Stderr) == Stderr ifTrue:[ |
|
820 |
ObjectMemory printStackBacktrace |
|
19145 | 821 |
] ifFalse:[ |
25251 | 822 |
"/ self printBacktraceFrom:(self getContext) |
823 |
thisContext fullPrintAllOn:(Processor activeProcess environmentAt:#Stderr) |
|
19145 | 824 |
] |
825 |
]. |
|
826 |
^ false |
|
13740 | 827 |
]. |
828 |
||
829 |
(cmd == $r) ifTrue:[ |
|
20843 | 830 |
dot receiver _errorPrintCR. |
19145 | 831 |
^ false |
13740 | 832 |
]. |
833 |
||
834 |
(cmd == $i) ifTrue:[ |
|
19389 | 835 |
|inspectedObject| |
836 |
||
19145 | 837 |
(commandArg ? '') withoutSeparators notEmpty ifTrue:[ |
19389 | 838 |
inspectedObject := (Parser evaluate:commandArg). |
19145 | 839 |
] ifFalse:[ |
19389 | 840 |
inspectedObject := (dot receiver). |
19145 | 841 |
]. |
19389 | 842 |
MiniInspector openOn:inspectedObject input:inputStream. |
19145 | 843 |
^ false |
13740 | 844 |
]. |
845 |
||
846 |
(cmd == $I) ifTrue:[ |
|
19145 | 847 |
self interpreterLoopWith:nil. |
848 |
^ false |
|
13740 | 849 |
]. |
25253 | 850 |
((cmd == $E) or:[(cmd == $e)]) ifTrue:[ |
25293 | 851 |
Parser isNil ifTrue:[ |
852 |
'oops - no Compiler class found' _errorPrintCR. |
|
853 |
^ self. |
|
854 |
]. |
|
25253 | 855 |
retVal := Parser evaluate:commandArg in:dot receiver:(dot receiver) notifying:nil ifFail:nil. |
856 |
(cmd == $e) ifTrue:[ retVal _errorPrintCR ]. |
|
19145 | 857 |
^ false |
13740 | 858 |
]. |
859 |
||
860 |
(cmd == $u) ifTrue:[ |
|
19145 | 861 |
stepping := false. |
862 |
tracing := false. |
|
863 |
Processor activeProcess vmTrace:false. |
|
864 |
^ false |
|
13740 | 865 |
]. |
866 |
||
14797 | 867 |
(cmd == $h) ifTrue:[ |
19145 | 868 |
(bool notNil) ifTrue:[ |
869 |
Smalltalk ignoreHalt:bool not. |
|
870 |
]. |
|
20843 | 871 |
'halts are ' _errorPrint. (Smalltalk ignoreHalt ifTrue:['disabled'] ifFalse:['enabled']) _errorPrintCR. |
19145 | 872 |
^ false |
14797 | 873 |
]. |
874 |
||
13740 | 875 |
(cmd == $R) ifTrue:[ |
19145 | 876 |
proc notNil ifTrue:[ |
877 |
proc resume. |
|
878 |
]. |
|
879 |
^ false |
|
13740 | 880 |
]. |
881 |
||
882 |
(cmd == $T) ifTrue:[ |
|
19145 | 883 |
proc notNil ifTrue:[ |
884 |
proc terminate. |
|
885 |
] ifFalse:[ |
|
25251 | 886 |
Processor terminateActive |
19145 | 887 |
]. |
888 |
^ false |
|
13740 | 889 |
]. |
890 |
||
891 |
(cmd == $W) ifTrue:[ |
|
19145 | 892 |
proc notNil ifTrue:[ |
20843 | 893 |
'stopping process id: ' _errorPrint. id _errorPrintCR. |
19145 | 894 |
proc stop. |
895 |
] ifFalse:[ |
|
20843 | 896 |
'invalid process id: ' _errorPrint. id _errorPrintCR. |
19145 | 897 |
]. |
898 |
^ false |
|
13740 | 899 |
]. |
900 |
||
901 |
(cmd == $a) ifTrue:[ |
|
19145 | 902 |
"without id-arg, this is handled by caller" |
903 |
proc notNil ifTrue:[ |
|
20843 | 904 |
'aborting process id: ' _errorPrint. id _errorPrintCR. |
19145 | 905 |
proc interruptWith:[AbortOperationRequest raise] |
906 |
] ifFalse:[ |
|
20843 | 907 |
'aborting' _errorPrintCR. |
19145 | 908 |
]. |
909 |
^ false |
|
13740 | 910 |
]. |
911 |
||
912 |
(cmd == $Q) ifTrue:[ |
|
19145 | 913 |
proc notNil ifTrue:[ |
914 |
proc terminateNoSignal. |
|
915 |
] ifFalse:[ |
|
25251 | 916 |
Processor terminateActiveNoSignal |
19145 | 917 |
]. |
918 |
^ false |
|
13740 | 919 |
]. |
920 |
||
921 |
(cmd == $g) ifTrue:[ |
|
19145 | 922 |
self garbageCollectCommand:id. |
923 |
^ false |
|
13740 | 924 |
]. |
925 |
||
926 |
(cmd == $U) ifTrue:[ |
|
19145 | 927 |
MessageTracer unwrapAllMethods. |
928 |
^ false |
|
13740 | 929 |
]. |
15929 | 930 |
(cmd == $D) ifTrue:[ |
19145 | 931 |
Breakpoint disableAllBreakpoints. |
932 |
^ false |
|
15929 | 933 |
]. |
13740 | 934 |
(cmd == $X) ifTrue:[ |
19145 | 935 |
Smalltalk fatalAbort. |
936 |
"/ not reached |
|
937 |
^ false |
|
13740 | 938 |
]. |
939 |
(cmd == $x) ifTrue:[ |
|
19145 | 940 |
OperatingSystem exit. |
941 |
"/ not reached |
|
942 |
^ false |
|
943 |
]. |
|
19146 | 944 |
(cmd == $Y) ifTrue:[ |
19925 | 945 |
Display := nil. |
19147 | 946 |
Smalltalk openDisplay. |
947 |
NewLauncher open. |
|
948 |
^ true |
|
13740 | 949 |
]. |
950 |
||
14737 | 951 |
(cmd == $l) ifTrue:[self printDotsMethodSource:false. ^ false ]. |
952 |
(cmd == $L) ifTrue:[self printDotsMethodSource:true. ^ false ]. |
|
22256 | 953 |
|
954 |
('.+-' includes:cmd) ifTrue:[ |
|
955 |
(id ? 1) timesRepeat:[ |
|
956 |
(cmd == $-) ifTrue:[ |
|
957 |
self moveDotUp]. |
|
958 |
(cmd == $+) ifTrue:[ |
|
959 |
self moveDotDown]. |
|
960 |
]. |
|
961 |
self printDot. |
|
962 |
^ false. |
|
963 |
]. |
|
964 |
||
15195 | 965 |
(cmd == $?) ifTrue:[ |
19145 | 966 |
commandArg notEmpty ifTrue:[ |
967 |
self helpOn:commandArg. ^ false |
|
968 |
] |
|
15195 | 969 |
]. |
13740 | 970 |
|
971 |
"/ avoid usage print if return was typed ... |
|
972 |
((cmd == Character return) |
|
973 |
or:[cmd == Character linefeed]) ifTrue:[^ false]. |
|
974 |
||
975 |
self showValidCommandHelp. |
|
976 |
^ false. |
|
977 |
||
978 |
"Created: / 29-09-2011 / 08:58:47 / cg" |
|
22256 | 979 |
"Modified: / 15-09-2017 / 14:30:48 / cg" |
13740 | 980 |
! |
981 |
||
5802
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
5054
diff
changeset
|
982 |
getCommand:prompt |
3126
e37ccb66f1b0
onlz ungrab the main Display (remote display could be inoperable)
Claus Gittinger <cg@exept.de>
parents:
3009
diff
changeset
|
983 |
"/ Screen notNil ifTrue:[ |
e37ccb66f1b0
onlz ungrab the main Display (remote display could be inoperable)
Claus Gittinger <cg@exept.de>
parents:
3009
diff
changeset
|
984 |
"/ Screen allScreens do:[:aScreen | |
e37ccb66f1b0
onlz ungrab the main Display (remote display could be inoperable)
Claus Gittinger <cg@exept.de>
parents:
3009
diff
changeset
|
985 |
"/ aScreen ungrabPointer. |
e37ccb66f1b0
onlz ungrab the main Display (remote display could be inoperable)
Claus Gittinger <cg@exept.de>
parents:
3009
diff
changeset
|
986 |
"/ aScreen ungrabKeyboard. |
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 |
"/ ]. |
e37ccb66f1b0
onlz ungrab the main Display (remote display could be inoperable)
Claus Gittinger <cg@exept.de>
parents:
3009
diff
changeset
|
989 |
|
e37ccb66f1b0
onlz ungrab the main Display (remote display could be inoperable)
Claus Gittinger <cg@exept.de>
parents:
3009
diff
changeset
|
990 |
Display notNil ifTrue:[ |
19389 | 991 |
Display ungrabPointer. |
992 |
Display ungrabKeyboard. |
|
852
5c4a0585ba0b
ungrab pointer for every input
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
993 |
]. |
5c4a0585ba0b
ungrab pointer for every input
Claus Gittinger <cg@exept.de>
parents:
720
diff
changeset
|
994 |
|
8840 | 995 |
(prompt |
19389 | 996 |
? (nesting == 0 ifTrue:[ |
997 |
'MiniDebugger> ' |
|
998 |
] ifFalse:[ |
|
999 |
'MiniDebugger' , nesting printString , '>' |
|
20843 | 1000 |
])) _errorPrint. |
93 | 1001 |
|
7706 | 1002 |
UserInterrupt handle:[:ex | |
19389 | 1003 |
ex restart |
159 | 1004 |
] do:[ |
19389 | 1005 |
|c cmd arg cnt| |
3700 | 1006 |
|
19389 | 1007 |
cmd := self getCharacter. |
1008 |
cmd isNil ifTrue:[ |
|
20843 | 1009 |
'<EOF>' _errorPrintCR. |
19389 | 1010 |
" |
1011 |
mhmh end-of-file; |
|
20420 | 1012 |
return a 'c' (for continue); hope that's ok. |
19389 | 1013 |
" |
1014 |
cmd := $c |
|
1015 |
]. |
|
93 | 1016 |
|
19389 | 1017 |
cnt := nil. |
1018 |
(cmd isDigit) ifTrue:[ |
|
1019 |
cnt := 0. |
|
1020 |
[ |
|
1021 |
cnt := (cnt * 10) + cmd digitValue. |
|
1022 |
cmd := self getCharacter |
|
1023 |
] doWhile:[cmd notNil and:[cmd isDigit]]. |
|
1024 |
[cmd notNil and:[cmd == Character space]] whileTrue:[ |
|
1025 |
cmd := self getCharacter |
|
1026 |
]. |
|
20843 | 1027 |
cmd isNil ifTrue:[ '<EOF>' _errorPrintCR ]. |
19389 | 1028 |
]. |
4003
d0f97b9cd4de
added 'S' -> stopp a process
Claus Gittinger <cg@exept.de>
parents:
3814
diff
changeset
|
1029 |
|
19389 | 1030 |
" |
1031 |
collect to end-of-line in arg |
|
1032 |
" |
|
1033 |
c := cmd. |
|
1034 |
arg := ''. |
|
1035 |
[c isNil or:[c isEndOfLineCharacter]] whileFalse: [ |
|
1036 |
arg := arg copyWith:c. |
|
1037 |
c := self getCharacter. |
|
20843 | 1038 |
c isNil ifTrue:[ '<EOF>' _errorPrintCR ]. |
19389 | 1039 |
]. |
1040 |
commandArg := (arg copyFrom:2) withoutSeparators. |
|
1041 |
command := cmd. |
|
1042 |
commandCount := cnt. |
|
1 | 1043 |
]. |
3700 | 1044 |
^ command |
976 | 1045 |
|
3700 | 1046 |
"Modified: / 31.7.1998 / 16:11:01 / cg" |
1 | 1047 |
! |
1048 |
||
15195 | 1049 |
helpOn:commandArg |
1050 |
|args className sym val match showMethod| |
|
1051 |
||
1052 |
commandArg withoutSeparators isEmpty ifTrue:[ |
|
20843 | 1053 |
'usage: H className [methodPattern]' _errorPrintCR. |
20496 | 1054 |
^self |
15195 | 1055 |
]. |
1056 |
args := commandArg asCollectionOfWords. |
|
1057 |
className := args first. |
|
16557 | 1058 |
|
15195 | 1059 |
(sym := className asSymbolIfInterned) isNil ifTrue:[ |
20843 | 1060 |
'no such class' _errorPrintCR. |
20496 | 1061 |
^ self. |
15195 | 1062 |
]. |
20843 | 1063 |
val := Smalltalk at:sym ifAbsent:['no such class' _errorPrintCR. ^ self.]. |
15195 | 1064 |
val isBehavior ifFalse:[ |
20843 | 1065 |
'not a class: ' _errorPrint. className _errorPrintCR. |
20496 | 1066 |
val := val class. |
20843 | 1067 |
'showing help for ' _errorPrint. val name _errorPrintCR. |
15195 | 1068 |
]. |
1069 |
args size > 1 ifTrue:[ |
|
20496 | 1070 |
match := args at:2 |
15195 | 1071 |
] ifFalse:[ |
20496 | 1072 |
match := '*' |
15195 | 1073 |
]. |
1074 |
||
16557 | 1075 |
showMethod := |
20496 | 1076 |
[:sel :cls | |
1077 |
|mthd| |
|
15195 | 1078 |
|
20496 | 1079 |
((match includesMatchCharacters and:[ sel matches:match caseSensitive:false]) |
1080 |
or:[ sel asLowercase startsWith:match asLowercase ]) ifTrue:[ |
|
1081 |
mthd := cls compiledMethodAt:sel. |
|
1082 |
mthd category ~= 'documentation' ifTrue:[ |
|
20843 | 1083 |
sel _errorPrintCR. |
20496 | 1084 |
(mthd comment ? '') asStringCollection do:[:l | |
20843 | 1085 |
' ' _errorPrint. l withoutSeparators _errorPrintCR. |
20496 | 1086 |
]. |
20843 | 1087 |
'' _errorPrintCR |
20496 | 1088 |
]. |
1089 |
]. |
|
1090 |
]. |
|
15195 | 1091 |
|
1092 |
val theMetaclass selectors copy sort do:[:sel | |
|
20496 | 1093 |
showMethod value:sel value:val theMetaclass |
15195 | 1094 |
]. |
1095 |
val theNonMetaclass selectors copy sort do:[:sel | |
|
20496 | 1096 |
showMethod value:sel value:val theNonMetaclass |
15195 | 1097 |
]. |
1098 |
! |
|
1099 |
||
1 | 1100 |
interpreterLoopWith:anObject |
16079 | 1101 |
'MinDebugger read-eval-print loop; exit with "#exit"; help with "?"' printCR. |
16557 | 1102 |
ReadEvalPrintLoop new |
20826 | 1103 |
prompt:'mDBG > '; |
19389 | 1104 |
doChunkFormat:false; |
22830 | 1105 |
errorStream:(Processor activeProcess stderr); |
19389 | 1106 |
readEvalPrintLoop. |
3700 | 1107 |
|
10630 | 1108 |
"/ |line done rslt| |
1109 |
"/ |
|
1110 |
"/ 'read-eval-print loop; exit with empty line' printCR. |
|
1111 |
"/ '' printCR. |
|
1112 |
"/ |
|
1113 |
"/ done := false. |
|
1114 |
"/ [done] whileFalse:[ |
|
1115 |
"/ '> ' print. |
|
1116 |
"/ |
|
1117 |
"/ line := Stdin nextLine. |
|
1118 |
"/ (line size == 0) ifTrue:[ |
|
1119 |
"/ done := true |
|
1120 |
"/ ] ifFalse:[ |
|
1121 |
"/ "/ rslt := Compiler evaluate:line |
|
1122 |
"/ "/ receiver:anObject |
|
1123 |
"/ "/ notifying:nil. |
|
1124 |
"/ |
|
1125 |
"/ rslt := Compiler |
|
1126 |
"/ evaluate:line |
|
1127 |
"/ in:dot |
|
1128 |
"/ receiver:dot receiver |
|
1129 |
"/ notifying:self "/ nil |
|
1130 |
"/ ifFail:[]. |
|
1131 |
"/ rslt printCR. |
|
1132 |
"/ ] |
|
1133 |
"/ ] |
|
1424 | 1134 |
|
3700 | 1135 |
"Modified: / 31.7.1998 / 16:01:47 / cg" |
618 | 1136 |
! |
1137 |
||
2772 | 1138 |
printAllBacktraces |
1139 |
Process allInstancesDo:[:p | |
|
20496 | 1140 |
(p isActive not |
1141 |
and:[p isDead not]) ifTrue:[ |
|
20843 | 1142 |
'---------------------------------------------------------' _errorPrintCR. |
1143 |
' proc id=' _errorPrint. p id asString _errorPrint. |
|
1144 |
' name=''' _errorPrint. p name asString _errorPrint. |
|
1145 |
''' createdBy: ' _errorPrint. p creatorId asString _errorPrint. |
|
1146 |
' state=' _errorPrint. p state asString _errorPrint. |
|
1147 |
' prio=' _errorPrint. p priority asString _errorPrintCR. |
|
1148 |
'' _errorPrintCR. '' _errorPrintCR. |
|
2772 | 1149 |
|
20496 | 1150 |
self printBacktraceFrom:(p suspendedContext) |
1151 |
] |
|
2772 | 1152 |
] |
1153 |
! |
|
1154 |
||
618 | 1155 |
showProcesses |
14797 | 1156 |
self showProcesses:#all |
1157 |
! |
|
1158 |
||
1159 |
showProcesses:how |
|
618 | 1160 |
|active| |
1161 |
||
1162 |
active := Processor activeProcess. |
|
20843 | 1163 |
'current id=' _errorPrint. |
1164 |
active id printString _errorPrint. |
|
1165 |
' name=''' _errorPrint. active name _errorPrint. '''' _errorPrintCR. |
|
618 | 1166 |
|
16094 | 1167 |
(Process allSubInstances sort:[:a :b | (a id ? -1)<(b id ? -1)]) do:[:p | |
20496 | 1168 |
|doShow| |
14797 | 1169 |
|
20849 | 1170 |
doShow := (how == #all) or:[ (how == #dead) == ( p isDead ) ]. |
20496 | 1171 |
doShow ifTrue:[ |
20894 | 1172 |
'id=' _errorPrint. (p id printStringPaddedTo:6) _errorPrint. |
20843 | 1173 |
(p state printStringPaddedTo:10) _errorPrint. |
1174 |
' pri=' _errorPrint. (p priority printStringPaddedTo:2) _errorPrint. |
|
1175 |
' creator:' _errorPrint. (p creatorId printStringPaddedTo:5) _errorPrint. |
|
1176 |
' group:' _errorPrint. (p processGroupId printStringPaddedTo:5) _errorPrint. |
|
20893 | 1177 |
"/ ' sys:' _errorPrint. (p isSystemProcess ifTrue:'y' ifFalse:'n') _errorPrint. |
20894 | 1178 |
"/ ' ui:' _errorPrint. (p isGUIProcess ifTrue:'y' ifFalse:'n') _errorPrint. |
1179 |
(p isGUIProcess |
|
20895 | 1180 |
ifTrue:[' ui'] |
20894 | 1181 |
ifFalse:[p isSystemProcess |
1182 |
ifTrue:['sys'] |
|
1183 |
ifFalse:['usr']]) _errorPrint. |
|
20843 | 1184 |
' name=''' _errorPrint. p name _errorPrint. |
1185 |
'''' _errorPrintCR. |
|
20496 | 1186 |
] |
618 | 1187 |
] |
1424 | 1188 |
|
3700 | 1189 |
"Modified: / 31.7.1998 / 16:30:19 / cg" |
7701 | 1190 |
! |
1191 |
||
1192 |
showValidCommandHelp |
|
19144 | 1193 |
'valid commands: |
16095 | 1194 |
c ........ continue |
1195 |
s ........ step |
|
1196 |
t ........ trace (continue with trace) |
|
1197 |
a [id] ... abort (i.e. raise abort signal) in (current) process |
|
1198 |
W [id] ... stop (current) process |
|
1199 |
R [id] ... resume (current) process |
|
25253 | 1200 |
T [id] ... terminate (current) process |
16095 | 1201 |
Q [id] ... quick terminate (current) process - no unwinds or cleanup |
7701 | 1202 |
|
16095 | 1203 |
p ........ list processes ("P" for full list) |
1204 |
w [id] ... walkback (of current/process with id) |
|
16557 | 1205 |
b [id] ... full (VM) backtrace with more detail |
20825 | 1206 |
B ........ backtrace for all processes |
7701 | 1207 |
|
16095 | 1208 |
U ........ unwrap all traced/breakpointed methods |
1209 |
D ........ disable all line breakpoints |
|
1210 |
h [-/+] .. disable/enable halts |
|
1211 |
g ........ collect all garbage |
|
1212 |
g 2 ...... collect all garbage & reclaim symbols |
|
1213 |
g 3 ...... collect all garbage, reclaim symbols and compress |
|
7701 | 1214 |
|
16095 | 1215 |
S ........ save snapshot into "crash.img" |
1216 |
C ........ save session changes to a separate change file |
|
1217 |
x ........ exit Smalltalk ("X" to exit with core dump) |
|
19149 | 1218 |
Y ........ reopen display, reopen launcher |
7701 | 1219 |
|
25253 | 1220 |
= [id] ... set current process for dot commands below |
16095 | 1221 |
. ........ print dot (the current context) |
1222 |
- ........ move dot up (sender) |
|
1223 |
+ ........ move dot down (called context) |
|
1224 |
l ........ list dot''s method source around PC ("L" for full list) |
|
25253 | 1225 |
r ........ print receiver (in dot) |
1226 |
i [expr] . inspect expression (or receiver in dot) |
|
7701 | 1227 |
|
16095 | 1228 |
I ........ interpreter (expression evaluator) |
19144 | 1229 |
e expr ... evaluate expression & print result ("E" to not print) |
1230 |
? c [p] .. help on class c (selectors matching p) |
|
20843 | 1231 |
' _errorPrintCR. |
7701 | 1232 |
|
14798 | 1233 |
(XWorkstation notNil and:[ Screen default isKindOf:XWorkstation ]) ifTrue:[ |
1234 |
' To repair a broken X-Connection, enter an interpreter (enter "I") and evaluate: |
|
7701 | 1235 |
Display := XWorkstation new. |
14798 | 1236 |
Display initializeFor:''localhost:0''. |
7701 | 1237 |
Display startDispatch. |
1238 |
NewLauncher openOnDevice:Display. |
|
16095 | 1239 |
#exit |
14798 | 1240 |
then enter "c" to continue; a NewLauncher should pop up soon. |
23519 | 1241 |
To repair a frozen XQuartz display, enter the interpreter (with I) |
1242 |
and execute the #qFix command. This is a hack around a race condition |
|
1243 |
inside XQuartz and usually unlocks the deadlock (in its grab/ungrab code). |
|
20843 | 1244 |
' _errorPrintCR |
14798 | 1245 |
] |
15859 | 1246 |
|
15930 | 1247 |
"Modified: / 03-02-2014 / 10:38:36 / cg" |
23519 | 1248 |
"Modified: / 07-11-2018 / 19:55:17 / Claus Gittinger" |
1 | 1249 |
! ! |
618 | 1250 |
|
658 | 1251 |
!MiniDebugger class methodsFor:'documentation'! |
1252 |
||
1253 |
version |
|
18681 | 1254 |
^ '$Header$' |
13113 | 1255 |
! |
1256 |
||
1257 |
version_CVS |
|
18681 | 1258 |
^ '$Header$' |
658 | 1259 |
! ! |
16626 | 1260 |