author | Claus Gittinger <cg@exept.de> |
Tue, 12 Mar 2019 22:17:03 +0100 | |
changeset 23880 | f366fd5a51b5 |
parent 23651 | 20175dbb7642 |
child 23882 | 4ff5dd3eda16 |
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 |
19390 | 19 |
instanceVariableNames:'inspectedObject commandArg inputStream' |
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 |
|
19390 | 64 |
^ self openOn:anObject input:nil |
65 |
! |
|
66 |
||
67 |
openOn:anObject input:inputStreamOrNil |
|
1 | 68 |
|anInspector| |
14938 | 69 |
|
1 | 70 |
anInspector := (self new) initializeFor:anObject. |
19390 | 71 |
anInspector inputStream:inputStreamOrNil. |
14938 | 72 |
anInspector enter. |
73 |
^ anInspector |
|
1 | 74 |
! ! |
75 |
||
19390 | 76 |
!MiniInspector methodsFor:'accessing'! |
77 |
||
78 |
inputStream:something |
|
79 |
inputStream := something. |
|
80 |
! ! |
|
81 |
||
1 | 82 |
!MiniInspector methodsFor:'private'! |
83 |
||
20735 | 84 |
callInspect:anotherObject message:msg |
20842 | 85 |
msg _errorPrintCR. |
20735 | 86 |
|
87 |
MiniInspector openOn:anotherObject input:inputStream. |
|
88 |
||
20842 | 89 |
'Back in previous inspector on: ' _errorPrint. |
90 |
inspectedObject displayString _errorPrintCR. |
|
20735 | 91 |
! |
92 |
||
1 | 93 |
commandLoop |
23880 | 94 |
|cmd valid lastValue idx| |
1 | 95 |
|
20842 | 96 |
'MiniInspector on ' _errorPrint. |
97 |
inspectedObject displayString _errorPrintCR. |
|
98 |
'' _errorPrintCR. |
|
23880 | 99 |
'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
|
100 |
|
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
4965
diff
changeset
|
101 |
[true] whileTrue:[ |
19390 | 102 |
valid := false. |
103 |
cmd := self getCommand:'inspector> '. |
|
104 |
cmd isNil ifTrue:[ "/ EOF -> quit |
|
105 |
cmd := $q |
|
106 |
]. |
|
107 |
cmd isNumber ifTrue:[ |
|
108 |
valid := true. |
|
109 |
self inspectInstvar:cmd of:inspectedObject |
|
110 |
]. |
|
111 |
(cmd == $i) ifTrue:[ |
|
112 |
valid := true. |
|
113 |
self printInstVarsOf:inspectedObject |
|
114 |
]. |
|
115 |
(cmd == $p) ifTrue:[ |
|
116 |
valid := true. |
|
20842 | 117 |
inspectedObject displayString _errorPrintCR |
19390 | 118 |
]. |
119 |
(cmd == $c) ifTrue:[ |
|
120 |
valid := true. |
|
20842 | 121 |
inspectedObject class displayString _errorPrintCR |
19390 | 122 |
]. |
123 |
(cmd == $C) ifTrue:[ |
|
124 |
valid := true. |
|
20735 | 125 |
self callInspect:inspectedObject class message:'inspecting class...'. |
19390 | 126 |
]. |
127 |
(cmd == $d) ifTrue:[ |
|
128 |
valid := true. |
|
129 |
ObjectMemory dumpObject:inspectedObject |
|
130 |
]. |
|
20735 | 131 |
(cmd == $D) ifTrue:[ |
19390 | 132 |
valid := true. |
20735 | 133 |
ObjectMemory dumpObject:inspectedObject class |
19390 | 134 |
]. |
23651 | 135 |
((cmd == $e) or:[ cmd == $E or:[ cmd == $? ]]) ifTrue:[ |
19390 | 136 |
valid := true. |
20735 | 137 |
lastValue := Parser evaluate:commandArg receiver:inspectedObject. |
138 |
(cmd == $e) ifTrue:[ |
|
20842 | 139 |
lastValue _errorPrintCR. |
20735 | 140 |
]. |
23651 | 141 |
(cmd == $?) ifTrue:[ |
142 |
inspectedObject := lastValue. |
|
143 |
'inspecting ' _errorPrint. |
|
144 |
inspectedObject displayString _errorPrintCR. '' _errorPrintCR. |
|
145 |
]. |
|
19390 | 146 |
]. |
20735 | 147 |
(cmd == $$) ifTrue:[ |
19390 | 148 |
valid := true. |
20735 | 149 |
self callInspect:lastValue message:'inspecting last value...'. |
19390 | 150 |
]. |
151 |
(cmd == $*) ifTrue:[ |
|
152 |
valid := true. |
|
153 |
inspectedObject becomeNil. |
|
154 |
^ cmd. |
|
155 |
]. |
|
156 |
(cmd == $I) ifTrue:[ |
|
157 |
valid := true. |
|
158 |
self interpreterLoopWith:inspectedObject |
|
159 |
]. |
|
23880 | 160 |
(cmd == $N) ifTrue:[ |
161 |
(commandArg withoutSeparators conform:#isDigit) ifTrue:[ |
|
162 |
(idx := Integer readFrom:commandArg) > 0 ifTrue:[ |
|
163 |
(idx <= inspectedObject class instSize) ifFalse:[ |
|
164 |
'bad instvar index' _errorPrintCR |
|
165 |
] ifTrue:[ |
|
166 |
inspectedObject instVarAt:idx put:nil. |
|
167 |
valid := true. |
|
168 |
]. |
|
169 |
]. |
|
170 |
]. |
|
171 |
]. |
|
19390 | 172 |
(cmd == $q) ifTrue:[ |
173 |
^ cmd. |
|
174 |
]. |
|
5802
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
4965
diff
changeset
|
175 |
|
19390 | 176 |
valid ifFalse: [ |
177 |
'valid commands: |
|
15926 | 178 |
p ...... print inspected object |
179 |
i ...... print instvars |
|
180 |
d ...... VM-dump inspected object |
|
20735 | 181 |
P ...... print inspected object''s class |
182 |
D ...... VM-dump inspected object''s class |
|
5804 | 183 |
|
15926 | 184 |
I ...... interpreter |
185 |
e expr evaluate expression & print result ("E" to not print) |
|
23651 | 186 |
? expr evaluate expression & inspect result |
20735 | 187 |
$ inspect the value of the last evaluated expression |
5804 | 188 |
|
15926 | 189 |
C ...... inspect class |
23880 | 190 |
<N> .... inspect instvar <N> (N=1..) |
191 |
N <N> .. nil instvar <N> (N=1..) |
|
5803 | 192 |
|
15926 | 193 |
* ...... becomeNil and quit (dangerous) |
194 |
q ...... quit |
|
20842 | 195 |
' _errorPrintCR |
19390 | 196 |
] |
1 | 197 |
]. |
1426 | 198 |
|
15926 | 199 |
"Modified: / 03-02-2014 / 10:19:46 / cg" |
23880 | 200 |
"Modified: / 12-03-2019 / 22:16:45 / Claus Gittinger" |
1 | 201 |
! |
202 |
||
618 | 203 |
enter |
15904
7b8100b48c7a
AbortSignal -> AbortOperationRequest
Stefan Vogel <sv@exept.de>
parents:
14938
diff
changeset
|
204 |
AbortOperationRequest handle:[:ex | |
20842 | 205 |
'** Abort Signal caught - back in previous debugLevel' _errorPrintCR. |
20721 | 206 |
ex restart |
5805 | 207 |
] do:[ |
20721 | 208 |
Error handle:[:ex | |
209 |
|yesNo| |
|
5805 | 210 |
|
20842 | 211 |
'Error while executing command: ' _errorPrint. |
212 |
ex description _errorPrintCR. |
|
20721 | 213 |
yesNo := self getCommand:'- (i)gnore / (p)roceed / (d)ebug ? '. |
214 |
yesNo == $d ifTrue:[ |
|
215 |
ex reject |
|
216 |
]. |
|
217 |
yesNo == $p ifTrue:[ |
|
218 |
ex proceed |
|
219 |
]. |
|
220 |
ex restart |
|
221 |
] do:[ |
|
222 |
self commandLoop. |
|
223 |
]. |
|
16558 | 224 |
]. |
618 | 225 |
^ nil |
226 |
! |
|
227 |
||
19390 | 228 |
getCharacter |
229 |
inputStream isNil ifTrue:[ |
|
230 |
"/ globally blocking |
|
231 |
^ Character fromUser |
|
232 |
]. |
|
233 |
^ inputStream next |
|
234 |
! |
|
235 |
||
5805 | 236 |
getCommand:prompt |
15926 | 237 |
|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
|
238 |
|
20842 | 239 |
prompt _errorPrint. |
5802
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
4965
diff
changeset
|
240 |
|
19390 | 241 |
c := cmd := self getCharacter. |
16250 | 242 |
c isNil ifTrue:[ |
19390 | 243 |
^ nil. |
16250 | 244 |
]. |
245 |
c isDigit ifTrue:[ |
|
19390 | 246 |
num := 0. |
247 |
[ |
|
248 |
num := (num * 10) + c digitValue. |
|
249 |
c := self getCharacter. |
|
250 |
] doWhile:[c notNil and:[c isDigit]]. |
|
251 |
^ num "/ numeric |
|
5802
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
4965
diff
changeset
|
252 |
]. |
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
4965
diff
changeset
|
253 |
|
19390 | 254 |
c := self getCharacter. |
255 |
[c notNil and:[c isEndOfLineCharacter not and:[c isSeparator ]]] whileTrue:[ c := self getCharacter ]. |
|
15926 | 256 |
arg := ''. |
4965 | 257 |
[c notNil and:[c isEndOfLineCharacter]] whileFalse:[ |
19390 | 258 |
arg := arg copyWith:c. |
259 |
c := self getCharacter |
|
1 | 260 |
]. |
15926 | 261 |
commandArg := arg. |
1 | 262 |
^ cmd |
15926 | 263 |
|
264 |
"Modified: / 03-02-2014 / 10:16:49 / cg" |
|
1 | 265 |
! |
266 |
||
618 | 267 |
initializeFor:anObject |
268 |
inspectedObject := anObject. |
|
269 |
^self |
|
270 |
! |
|
271 |
||
16635 | 272 |
inspect:anObject |
273 |
inspectedObject := anObject. |
|
274 |
! |
|
275 |
||
618 | 276 |
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
|
277 |
|numInsts idx| |
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
4965
diff
changeset
|
278 |
|
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
4965
diff
changeset
|
279 |
numInsts := anObject class instSize. |
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
4965
diff
changeset
|
280 |
|
93748287026d
better Mini- debugging tools (+/- context in debugger); interpreter in inspector.
Claus Gittinger <cg@exept.de>
parents:
4965
diff
changeset
|
281 |
which > numInsts ifTrue:[ |
19390 | 282 |
idx := which - numInsts. |
283 |
idx > anObject basicSize ifTrue:[ |
|
20842 | 284 |
'invalid indexed instvar index: ' _errorPrint. idx _errorPrintCR |
19390 | 285 |
] ifFalse:[ |
20735 | 286 |
self callInspect:(anObject basicAt:idx) message:('Inspecting indexed instVar ',which printString,'...') |
19390 | 287 |
] |
618 | 288 |
] ifFalse: [ |
19390 | 289 |
which < 0 ifTrue:[ |
20842 | 290 |
'invalid instVar # (must be >= 1)' _errorPrintCR |
19390 | 291 |
] ifFalse:[ |
20735 | 292 |
self callInspect:(anObject instVarAt:which) message:('Inspecting instVar ',which printString,'...') |
19390 | 293 |
]. |
618 | 294 |
] |
1426 | 295 |
|
296 |
"Modified: 20.5.1996 / 10:27:40 / cg" |
|
618 | 297 |
! |
298 |
||
7092
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
5805
diff
changeset
|
299 |
interpreterLoopWith:anObject |
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
5805
diff
changeset
|
300 |
|line done rslt| |
16558 | 301 |
|
20842 | 302 |
'read-eval-print loop; exit with empty line' _errorPrintCR. |
303 |
'' _errorPrintCR. |
|
16558 | 304 |
|
7092
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
5805
diff
changeset
|
305 |
done := false. |
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
5805
diff
changeset
|
306 |
[done] whileFalse:[ |
20842 | 307 |
'> ' _errorPrint. |
16558 | 308 |
|
19381 | 309 |
line := Processor activeProcess stdin nextLine. |
310 |
(line size == 0) ifTrue:[ |
|
311 |
done := true |
|
312 |
] ifFalse:[ |
|
313 |
rslt := Compiler |
|
314 |
evaluate:line |
|
315 |
in:nil |
|
316 |
receiver:anObject |
|
317 |
notifying:nil |
|
318 |
ifFail:[]. |
|
20842 | 319 |
rslt _errorPrintCR. |
19381 | 320 |
] |
7092
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
5805
diff
changeset
|
321 |
] |
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
5805
diff
changeset
|
322 |
! |
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
5805
diff
changeset
|
323 |
|
1 | 324 |
printInstVarsOf:anObject |
5805 | 325 |
|n "{ Class: SmallInteger }" names | |
903 | 326 |
|
1 | 327 |
n := anObject class instSize. |
5805 | 328 |
names := anObject class allInstVarNames. |
329 |
||
20842 | 330 |
'number of instvars: ' _errorPrint. n _errorPrintCR. |
1 | 331 |
1 to:n do:[:i | |
20842 | 332 |
(i printStringLeftPaddedTo:2) _errorPrint. |
333 |
' {' _errorPrint. (names at:i) _errorPrint. '}' _errorPrint. |
|
334 |
': ' _errorPrint. |
|
335 |
((anObject instVarAt:i) displayString contractAtEndTo:160) _errorPrintCR |
|
903 | 336 |
]. |
5805 | 337 |
|
903 | 338 |
n := anObject basicSize. |
5805 | 339 |
n > 0 ifTrue:[ |
20842 | 340 |
'number of indexed instvars: ' _errorPrint. n _errorPrintCR. |
20721 | 341 |
n > 10 ifTrue:[n := 10]. |
342 |
1 to:n do:[:i | |
|
20842 | 343 |
' [' _errorPrint. i _errorPrint. ']: ' _errorPrint. |
344 |
((anObject basicAt:i) displayString contractAtEndTo:160) _errorPrintCR |
|
20721 | 345 |
] |
903 | 346 |
]. |
1426 | 347 |
|
348 |
"Modified: 20.5.1996 / 10:27:45 / cg" |
|
618 | 349 |
! ! |
1 | 350 |
|
658 | 351 |
!MiniInspector class methodsFor:'documentation'! |
352 |
||
353 |
version |
|
19381 | 354 |
^ '$Header$' |
19390 | 355 |
! |
356 |
||
357 |
version_CVS |
|
358 |
^ '$Header$' |
|
658 | 359 |
! ! |
16635 | 360 |