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