author | Claus Gittinger <cg@exept.de> |
Wed, 05 Jun 2019 20:08:48 +0200 | |
changeset 24257 | 3d3652e1f81c |
parent 23884 | 1e08361b4c05 |
permissions | -rw-r--r-- |
23880 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1 | 3 |
" |
5 | 4 |
COPYRIGHT (c) 1989 by Claus Gittinger |
308 | 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 |
" |
|
7092
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
5805
diff
changeset
|
14 |
"{ Package: 'stx:libbasic' }" |
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
5805
diff
changeset
|
15 |
|
19381 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
720 | 18 |
Object subclass:#MiniInspector |
23883 | 19 |
instanceVariableNames:'inspectedObject commandArg inputStream level' |
1297 | 20 |
classVariableNames:'' |
21 |
poolDictionaries:'' |
|
22 |
category:'System-Debugging-Support' |
|
1 | 23 |
! |
24 |
||
89 | 25 |
!MiniInspector class methodsFor:'documentation'! |
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
308 | 30 |
All Rights Reserved |
1 | 31 |
|
89 | 32 |
This software is furnished under a license and may be used |
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
1 | 40 |
|
89 | 41 |
documentation |
42 |
" |
|
43 |
a primitive (non graphical) inspector for use on systems without |
|
15926 | 44 |
graphics or when the real inspector dies (i.e. the UI is locked). |
45 |
Sometimes useful as a last chance to fix a broken UI / event handling. |
|
46 |
Needs a console. |
|
47 |
||
20847 | 48 |
MiniInspector openOn: Display |
49 |
||
50 |
Attention: |
|
51 |
all printing is done via lowLevel _errorPrint messages, |
|
52 |
to ensure that output is to stderr, even if a logger is present, |
|
53 |
or Stderr has been set to some other stream (Transcript). |
|
54 |
Also to avoid the logger's interfering and adding imestamp information. |
|
1297 | 55 |
|
56 |
[author:] |
|
20847 | 57 |
Claus Gittinger |
89 | 58 |
" |
59 |
! ! |
|
1 | 60 |
|
61 |
!MiniInspector class methodsFor:'instance creation'! |
|
62 |
||
63 |
openOn:anObject |
|
23883 | 64 |
^ self openOn:anObject input:nil level:1 |
65 |
||
66 |
"Modified: / 12-03-2019 / 22:43:53 / Claus Gittinger" |
|
19390 | 67 |
! |
68 |
||
69 |
openOn:anObject input:inputStreamOrNil |
|
23883 | 70 |
^ self openOn:anObject input:inputStreamOrNil level:1 |
71 |
||
72 |
"Modified: / 12-03-2019 / 22:44:15 / Claus Gittinger" |
|
73 |
! |
|
74 |
||
75 |
openOn:anObject input:inputStreamOrNil level:level |
|
1 | 76 |
|anInspector| |
14938 | 77 |
|
1 | 78 |
anInspector := (self new) initializeFor:anObject. |
19390 | 79 |
anInspector inputStream:inputStreamOrNil. |
23883 | 80 |
anInspector level:level. |
14938 | 81 |
anInspector enter. |
82 |
^ anInspector |
|
23883 | 83 |
|
84 |
"Created: / 12-03-2019 / 22:43:39 / Claus Gittinger" |
|
1 | 85 |
! ! |
86 |
||
19390 | 87 |
!MiniInspector methodsFor:'accessing'! |
88 |
||
89 |
inputStream:something |
|
90 |
inputStream := something. |
|
23883 | 91 |
! |
92 |
||
93 |
level:anInteger |
|
94 |
level := anInteger. |
|
95 |
||
96 |
"Created: / 12-03-2019 / 22:44:26 / Claus Gittinger" |
|
19390 | 97 |
! ! |
98 |
||
1 | 99 |
!MiniInspector methodsFor:'private'! |
100 |
||
20735 | 101 |
callInspect:anotherObject message:msg |
20842 | 102 |
msg _errorPrintCR. |
20735 | 103 |
|
23884 | 104 |
MiniInspector openOn:anotherObject input:inputStream level:(level?1)+1. |
20735 | 105 |
|
20842 | 106 |
'Back in previous inspector on: ' _errorPrint. |
107 |
inspectedObject displayString _errorPrintCR. |
|
23884 | 108 |
|
109 |
"Modified: / 12-03-2019 / 22:45:50 / Claus Gittinger" |
|
20735 | 110 |
! |
111 |
||
1 | 112 |
commandLoop |
23880 | 113 |
|cmd valid lastValue idx| |
1 | 114 |
|
20842 | 115 |
'MiniInspector on ' _errorPrint. |
116 |
inspectedObject displayString _errorPrintCR. |
|
117 |
'' _errorPrintCR. |
|
23880 | 118 |
'Type "q" to quit, "?" for help ' _errorPrintCR. |
5802
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
4965
diff
changeset
|
119 |
|
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
4965
diff
changeset
|
120 |
[true] whileTrue:[ |
19390 | 121 |
valid := false. |
23884 | 122 |
cmd := self getCommand:'inspector',(level ? 1) printString,'> '. |
19390 | 123 |
cmd isNil ifTrue:[ "/ EOF -> quit |
124 |
cmd := $q |
|
125 |
]. |
|
126 |
cmd isNumber ifTrue:[ |
|
127 |
valid := true. |
|
128 |
self inspectInstvar:cmd of:inspectedObject |
|
129 |
]. |
|
130 |
(cmd == $i) ifTrue:[ |
|
131 |
valid := true. |
|
132 |
self printInstVarsOf:inspectedObject |
|
133 |
]. |
|
134 |
(cmd == $p) ifTrue:[ |
|
135 |
valid := true. |
|
20842 | 136 |
inspectedObject displayString _errorPrintCR |
19390 | 137 |
]. |
138 |
(cmd == $c) ifTrue:[ |
|
139 |
valid := true. |
|
20842 | 140 |
inspectedObject class displayString _errorPrintCR |
19390 | 141 |
]. |
142 |
(cmd == $C) ifTrue:[ |
|
143 |
valid := true. |
|
20735 | 144 |
self callInspect:inspectedObject class message:'inspecting class...'. |
19390 | 145 |
]. |
146 |
(cmd == $d) ifTrue:[ |
|
147 |
valid := true. |
|
148 |
ObjectMemory dumpObject:inspectedObject |
|
149 |
]. |
|
20735 | 150 |
(cmd == $D) ifTrue:[ |
19390 | 151 |
valid := true. |
20735 | 152 |
ObjectMemory dumpObject:inspectedObject class |
19390 | 153 |
]. |
23882 | 154 |
((cmd == $e) or:[ cmd == $E or:[ cmd == $Q ]]) ifTrue:[ |
19390 | 155 |
valid := true. |
20735 | 156 |
lastValue := Parser evaluate:commandArg receiver:inspectedObject. |
157 |
(cmd == $e) ifTrue:[ |
|
20842 | 158 |
lastValue _errorPrintCR. |
20735 | 159 |
]. |
23882 | 160 |
(cmd == $Q) ifTrue:[ |
23651 | 161 |
inspectedObject := lastValue. |
162 |
'inspecting ' _errorPrint. |
|
163 |
inspectedObject displayString _errorPrintCR. '' _errorPrintCR. |
|
164 |
]. |
|
19390 | 165 |
]. |
20735 | 166 |
(cmd == $$) ifTrue:[ |
19390 | 167 |
valid := true. |
20735 | 168 |
self callInspect:lastValue message:'inspecting last value...'. |
19390 | 169 |
]. |
170 |
(cmd == $*) ifTrue:[ |
|
171 |
valid := true. |
|
172 |
inspectedObject becomeNil. |
|
173 |
^ cmd. |
|
174 |
]. |
|
175 |
(cmd == $I) ifTrue:[ |
|
176 |
valid := true. |
|
177 |
self interpreterLoopWith:inspectedObject |
|
178 |
]. |
|
23880 | 179 |
(cmd == $N) ifTrue:[ |
180 |
(commandArg withoutSeparators conform:#isDigit) ifTrue:[ |
|
181 |
(idx := Integer readFrom:commandArg) > 0 ifTrue:[ |
|
182 |
(idx <= inspectedObject class instSize) ifFalse:[ |
|
183 |
'bad instvar index' _errorPrintCR |
|
184 |
] ifTrue:[ |
|
185 |
inspectedObject instVarAt:idx put:nil. |
|
186 |
valid := true. |
|
187 |
]. |
|
188 |
]. |
|
189 |
]. |
|
190 |
]. |
|
19390 | 191 |
(cmd == $q) ifTrue:[ |
192 |
^ cmd. |
|
193 |
]. |
|
5802
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
4965
diff
changeset
|
194 |
|
19390 | 195 |
valid ifFalse: [ |
196 |
'valid commands: |
|
15926 | 197 |
p ...... print inspected object |
198 |
i ...... print instvars |
|
199 |
d ...... VM-dump inspected object |
|
20735 | 200 |
P ...... print inspected object''s class |
201 |
D ...... VM-dump inspected object''s class |
|
5804 | 202 |
|
15926 | 203 |
I ...... interpreter |
204 |
e expr evaluate expression & print result ("E" to not print) |
|
23882 | 205 |
Q expr evaluate expression & inspect result |
20735 | 206 |
$ inspect the value of the last evaluated expression |
5804 | 207 |
|
15926 | 208 |
C ...... inspect class |
23880 | 209 |
<N> .... inspect instvar <N> (N=1..) |
210 |
N <N> .. nil instvar <N> (N=1..) |
|
5803 | 211 |
|
15926 | 212 |
* ...... becomeNil and quit (dangerous) |
23883 | 213 |
q ...... quit (or back to previous level) |
20842 | 214 |
' _errorPrintCR |
19390 | 215 |
] |
1 | 216 |
]. |
1426 | 217 |
|
15926 | 218 |
"Modified: / 03-02-2014 / 10:19:46 / cg" |
23884 | 219 |
"Modified: / 12-03-2019 / 22:46:01 / Claus Gittinger" |
1 | 220 |
! |
221 |
||
618 | 222 |
enter |
15904
7b8100b48c7a
AbortSignal -> AbortOperationRequest
Stefan Vogel <sv@exept.de>
parents:
14938
diff
changeset
|
223 |
AbortOperationRequest handle:[:ex | |
20842 | 224 |
'** Abort Signal caught - back in previous debugLevel' _errorPrintCR. |
20721 | 225 |
ex restart |
5805 | 226 |
] do:[ |
20721 | 227 |
Error handle:[:ex | |
228 |
|yesNo| |
|
5805 | 229 |
|
20842 | 230 |
'Error while executing command: ' _errorPrint. |
231 |
ex description _errorPrintCR. |
|
20721 | 232 |
yesNo := self getCommand:'- (i)gnore / (p)roceed / (d)ebug ? '. |
233 |
yesNo == $d ifTrue:[ |
|
234 |
ex reject |
|
235 |
]. |
|
236 |
yesNo == $p ifTrue:[ |
|
237 |
ex proceed |
|
238 |
]. |
|
239 |
ex restart |
|
240 |
] do:[ |
|
241 |
self commandLoop. |
|
242 |
]. |
|
16558 | 243 |
]. |
618 | 244 |
^ nil |
245 |
! |
|
246 |
||
19390 | 247 |
getCharacter |
248 |
inputStream isNil ifTrue:[ |
|
249 |
"/ globally blocking |
|
250 |
^ Character fromUser |
|
251 |
]. |
|
252 |
^ inputStream next |
|
253 |
! |
|
254 |
||
5805 | 255 |
getCommand:prompt |
15926 | 256 |
|cmd c num arg| |
5802
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
4965
diff
changeset
|
257 |
|
20842 | 258 |
prompt _errorPrint. |
5802
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
4965
diff
changeset
|
259 |
|
19390 | 260 |
c := cmd := self getCharacter. |
16250 | 261 |
c isNil ifTrue:[ |
19390 | 262 |
^ nil. |
16250 | 263 |
]. |
264 |
c isDigit ifTrue:[ |
|
19390 | 265 |
num := 0. |
266 |
[ |
|
267 |
num := (num * 10) + c digitValue. |
|
268 |
c := self getCharacter. |
|
269 |
] doWhile:[c notNil and:[c isDigit]]. |
|
270 |
^ num "/ numeric |
|
5802
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
4965
diff
changeset
|
271 |
]. |
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
4965
diff
changeset
|
272 |
|
19390 | 273 |
c := self getCharacter. |
274 |
[c notNil and:[c isEndOfLineCharacter not and:[c isSeparator ]]] whileTrue:[ c := self getCharacter ]. |
|
15926 | 275 |
arg := ''. |
4965 | 276 |
[c notNil and:[c isEndOfLineCharacter]] whileFalse:[ |
19390 | 277 |
arg := arg copyWith:c. |
278 |
c := self getCharacter |
|
1 | 279 |
]. |
15926 | 280 |
commandArg := arg. |
1 | 281 |
^ cmd |
15926 | 282 |
|
283 |
"Modified: / 03-02-2014 / 10:16:49 / cg" |
|
1 | 284 |
! |
285 |
||
618 | 286 |
initializeFor:anObject |
287 |
inspectedObject := anObject. |
|
288 |
^self |
|
289 |
! |
|
290 |
||
16635 | 291 |
inspect:anObject |
292 |
inspectedObject := anObject. |
|
293 |
! |
|
294 |
||
618 | 295 |
inspectInstvar:which of:anObject |
5802
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
4965
diff
changeset
|
296 |
|numInsts idx| |
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
4965
diff
changeset
|
297 |
|
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
4965
diff
changeset
|
298 |
numInsts := anObject class instSize. |
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
4965
diff
changeset
|
299 |
|
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
4965
diff
changeset
|
300 |
which > numInsts ifTrue:[ |
19390 | 301 |
idx := which - numInsts. |
302 |
idx > anObject basicSize ifTrue:[ |
|
20842 | 303 |
'invalid indexed instvar index: ' _errorPrint. idx _errorPrintCR |
19390 | 304 |
] ifFalse:[ |
20735 | 305 |
self callInspect:(anObject basicAt:idx) message:('Inspecting indexed instVar ',which printString,'...') |
19390 | 306 |
] |
618 | 307 |
] ifFalse: [ |
19390 | 308 |
which < 0 ifTrue:[ |
20842 | 309 |
'invalid instVar # (must be >= 1)' _errorPrintCR |
19390 | 310 |
] ifFalse:[ |
20735 | 311 |
self callInspect:(anObject instVarAt:which) message:('Inspecting instVar ',which printString,'...') |
19390 | 312 |
]. |
618 | 313 |
] |
1426 | 314 |
|
315 |
"Modified: 20.5.1996 / 10:27:40 / cg" |
|
618 | 316 |
! |
317 |
||
7092
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
5805
diff
changeset
|
318 |
interpreterLoopWith:anObject |
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
5805
diff
changeset
|
319 |
|line done rslt| |
16558 | 320 |
|
20842 | 321 |
'read-eval-print loop; exit with empty line' _errorPrintCR. |
322 |
'' _errorPrintCR. |
|
16558 | 323 |
|
7092
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
5805
diff
changeset
|
324 |
done := false. |
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
5805
diff
changeset
|
325 |
[done] whileFalse:[ |
20842 | 326 |
'> ' _errorPrint. |
16558 | 327 |
|
19381 | 328 |
line := Processor activeProcess stdin nextLine. |
329 |
(line size == 0) ifTrue:[ |
|
330 |
done := true |
|
331 |
] ifFalse:[ |
|
332 |
rslt := Compiler |
|
333 |
evaluate:line |
|
334 |
in:nil |
|
335 |
receiver:anObject |
|
336 |
notifying:nil |
|
337 |
ifFail:[]. |
|
20842 | 338 |
rslt _errorPrintCR. |
19381 | 339 |
] |
7092
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
5805
diff
changeset
|
340 |
] |
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
5805
diff
changeset
|
341 |
! |
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
5805
diff
changeset
|
342 |
|
1 | 343 |
printInstVarsOf:anObject |
5805 | 344 |
|n "{ Class: SmallInteger }" names | |
903 | 345 |
|
1 | 346 |
n := anObject class instSize. |
5805 | 347 |
names := anObject class allInstVarNames. |
348 |
||
20842 | 349 |
'number of instvars: ' _errorPrint. n _errorPrintCR. |
1 | 350 |
1 to:n do:[:i | |
20842 | 351 |
(i printStringLeftPaddedTo:2) _errorPrint. |
352 |
' {' _errorPrint. (names at:i) _errorPrint. '}' _errorPrint. |
|
353 |
': ' _errorPrint. |
|
354 |
((anObject instVarAt:i) displayString contractAtEndTo:160) _errorPrintCR |
|
903 | 355 |
]. |
5805 | 356 |
|
903 | 357 |
n := anObject basicSize. |
5805 | 358 |
n > 0 ifTrue:[ |
20842 | 359 |
'number of indexed instvars: ' _errorPrint. n _errorPrintCR. |
20721 | 360 |
n > 10 ifTrue:[n := 10]. |
361 |
1 to:n do:[:i | |
|
20842 | 362 |
' [' _errorPrint. i _errorPrint. ']: ' _errorPrint. |
363 |
((anObject basicAt:i) displayString contractAtEndTo:160) _errorPrintCR |
|
20721 | 364 |
] |
903 | 365 |
]. |
1426 | 366 |
|
367 |
"Modified: 20.5.1996 / 10:27:45 / cg" |
|
618 | 368 |
! ! |
1 | 369 |
|
658 | 370 |
!MiniInspector class methodsFor:'documentation'! |
371 |
||
372 |
version |
|
19381 | 373 |
^ '$Header$' |
19390 | 374 |
! |
375 |
||
376 |
version_CVS |
|
377 |
^ '$Header$' |
|
658 | 378 |
! ! |
16635 | 379 |