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