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