author | Claus Gittinger <cg@exept.de> |
Thu, 24 Apr 1997 18:22:58 +0200 | |
changeset 584 | 2da6bb2c8017 |
parent 579 | eabd0d36b0d0 |
child 591 | 430992318747 |
permissions | -rw-r--r-- |
8 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
11 | 3 |
All Rights Reserved |
8 | 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 |
" |
|
12 |
||
120 | 13 |
Object subclass:#MessageTracer |
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
14 |
instanceVariableNames:'traceDetail' |
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
15 |
classVariableNames:'BreakpointSignal CallingLevel BreakBlock TraceSenderBlock |
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
16 |
LeaveBreakBlock LeaveTraceBlock MethodCounts MethodMemoryUsage |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
17 |
MethodTiming TraceFullBlock' |
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
18 |
poolDictionaries:'' |
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
19 |
category:'System-Debugging-Support' |
8 | 20 |
! |
21 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
22 |
!MessageTracer class methodsFor:'documentation'! |
8 | 23 |
|
9 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
11 | 27 |
All Rights Reserved |
9 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
8 | 38 |
documentation |
39 |
" |
|
11 | 40 |
This class provides a common home for the tracing |
41 |
facilities (originally, they where in Object, but have been moved to |
|
8 | 42 |
allow easier separation of development vs. runtime configurations. |
43 |
||
11 | 44 |
tracing execution of a block: |
45 |
||
236 | 46 |
MessageTracer trace:[ ... ] |
11 | 47 |
|
236 | 48 |
MessageTracer traceFull:[ ... ] |
11 | 49 |
|
236 | 50 |
(for system developper only:) |
11 | 51 |
|
236 | 52 |
MessageTracer debugTrace:[ ... ] |
11 | 53 |
|
54 |
||
8 | 55 |
trapping sends to a specific object: |
56 |
||
236 | 57 |
MessageTracer trap:anObject selector:aSelector |
58 |
... |
|
59 |
MessageTracer untrap:anObject selector:aSelector |
|
60 |
or: |
|
61 |
MessageTracer untrap:anObject |
|
11 | 62 |
|
8 | 63 |
|
64 |
||
27 | 65 |
trapping some messages sent to a specific object: |
66 |
||
236 | 67 |
MessageTracer trap:anObject selectors:aCollectionOfSelectors |
68 |
... |
|
69 |
MessageTracer untrap:anObject |
|
27 | 70 |
|
71 |
||
72 |
||
73 |
trapping any message sent to a specific object: |
|
74 |
||
236 | 75 |
MessageTracer trapAll:anObject |
76 |
... |
|
77 |
MessageTracer untrap:anObject |
|
27 | 78 |
|
79 |
||
80 |
||
8 | 81 |
trapping evaluation of a specific method: |
82 |
||
236 | 83 |
MessageTracer trapMethod:aMethod |
84 |
... |
|
85 |
MessageTracer unwrapMethod:aMethod |
|
8 | 86 |
|
87 |
||
88 |
||
12 | 89 |
trapping evaluation of a specific method with |
90 |
receiver being an instance of some class: |
|
91 |
||
236 | 92 |
MessageTracer trapMethod:aMethod forInstancesOf:aClass |
93 |
... |
|
94 |
MessageTracer unwrapMethod:aMethod |
|
12 | 95 |
|
96 |
||
97 |
||
8 | 98 |
tracing sends to a specific object: |
99 |
||
236 | 100 |
MessageTracer trace:anObject selector:aSelector |
101 |
... |
|
102 |
MessageTracer untrace:anObject selector:aSelector |
|
103 |
or: |
|
104 |
MessageTracer untrace:anObject |
|
11 | 105 |
|
8 | 106 |
|
107 |
||
108 |
tracing sender only: |
|
109 |
||
236 | 110 |
MessageTracer traceSender:anObject selector:aSelector |
111 |
... |
|
112 |
MessageTracer untrace:anObject selector:aSelector |
|
113 |
or: |
|
114 |
MessageTracer untrace:anObject |
|
11 | 115 |
|
8 | 116 |
|
117 |
||
118 |
tracing evaluation of a specific method: |
|
119 |
||
236 | 120 |
MessageTracer traceMethod:aMethod |
121 |
... |
|
122 |
MessageTracer unwrapmethod:aMethod |
|
18 | 123 |
|
124 |
see more in examples and in method comments. |
|
236 | 125 |
|
126 |
[author:] |
|
127 |
Claus Gittinger |
|
8 | 128 |
" |
12 | 129 |
! |
130 |
||
131 |
examples |
|
132 |
" |
|
133 |
For the common cases, you will find a menu entry in the SystemBrowser. |
|
134 |
Howeever, more special cases (especially with condition checks) can be |
|
135 |
set up by evaluating the lower level entries. |
|
136 |
||
137 |
||
138 |
trapping specific methods: |
|
139 |
(by class/selector): |
|
244 | 140 |
[exBegin] |
12 | 141 |
MessageTracer trapClass:Collection selector:#select:. |
142 |
Dictionary new select:[:e | ]. 'not cought - Dictionary has its own select'. |
|
143 |
(Array new:10) select:[:e | ]. 'not cought - SeqColl has its own select'. |
|
144 |
Set new select:[:e | ]. 'cought - Set inherits this from Collection'. |
|
145 |
MessageTracer untrapClass:Collection |
|
244 | 146 |
[exEnd] |
12 | 147 |
|
148 |
(by method): |
|
244 | 149 |
[exBegin] |
12 | 150 |
MessageTracer trapMethod:(Collection compiledMethodAt:#select:). |
151 |
Dictionary new select:[:e | ]. 'not cought - Dictionary has its own select'. |
|
152 |
(Array new:10) select:[:e | ]. 'not cought - SeqColl has its own select'. |
|
153 |
Set new select:[:e | ]. 'cought - Set inherits this from Collection'. |
|
154 |
MessageTracer unwrapMethod:(Collection compiledMethodAt:#select:). |
|
244 | 155 |
[exEnd] |
12 | 156 |
|
27 | 157 |
(by method & instance class): |
244 | 158 |
[exBegin] |
27 | 159 |
MessageTracer trapMethod:(SequenceableCollection compiledMethodAt:#select:) |
244 | 160 |
forInstancesOf:SortedCollection. |
27 | 161 |
Dictionary new select:[:e | ]. 'not cought - Dictionary has its own select'. |
162 |
(Array new:10) select:[:e | ]. 'not cought - not a SortedCollection'. |
|
163 |
OrderedCollection new select:[:e | ]. 'not cought - not a SortedCollection'. |
|
164 |
SortedCollection new select:[:e | ]. 'cought - Set inherits this from Collection'. |
|
165 |
MessageTracer unwrapMethod:(SequenceableCollection compiledMethodAt:#select:). |
|
244 | 166 |
[exEnd] |
27 | 167 |
|
12 | 168 |
tracing specific methods: |
169 |
(by class/selector): |
|
244 | 170 |
[exBegin] |
12 | 171 |
MessageTracer traceClass:SequenceableCollection selector:#quickSortFrom:to:. |
172 |
#(6 1 9 66 2 17) copy sort. |
|
173 |
MessageTracer untraceClass:SequenceableCollection |
|
244 | 174 |
[exEnd] |
12 | 175 |
|
176 |
(by method): |
|
244 | 177 |
[exBegin] |
12 | 178 |
MessageTracer traceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
179 |
#(6 1 9 66 2 17) copy sort. |
|
180 |
MessageTracer unwrapMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
244 | 181 |
[exEnd] |
27 | 182 |
|
183 |
object trapping: |
|
244 | 184 |
[exBegin] |
27 | 185 |
|o| |
186 |
||
187 |
o := OrderedCollection new. |
|
188 |
MessageTracer trapAll:o. |
|
189 |
o collect:[:el | el]. |
|
244 | 190 |
[exEnd] |
12 | 191 |
" |
8 | 192 |
! ! |
193 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
194 |
!MessageTracer class methodsFor:'initialization'! |
11 | 195 |
|
196 |
initialize |
|
197 |
BreakpointSignal isNil ifTrue:[ |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
198 |
BreakpointSignal := HaltSignal newSignalMayProceed:true. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
199 |
BreakpointSignal nameClass:self message:#breakpointSignal. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
200 |
BreakpointSignal notifierString:'breakpoint encountered'. |
27 | 201 |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
202 |
BreakBlock := [:con | BreakpointSignal raiseIn:con]. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
203 |
TraceSenderBlock := [:con | MessageTracer printEntrySender:con]. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
204 |
TraceFullBlock := [:con | con fullPrintAll]. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
205 |
LeaveBreakBlock := [:con :retVal | ]. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
206 |
LeaveTraceBlock := [:con :retVal | ]. |
11 | 207 |
] |
156 | 208 |
|
209 |
" |
|
210 |
BreakpointSignal := nil. |
|
211 |
MessageTracer initialize |
|
212 |
" |
|
213 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
214 |
"Modified: 22.10.1996 / 17:39:14 / cg" |
11 | 215 |
! ! |
216 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
217 |
!MessageTracer class methodsFor:'Signal constants'! |
88 | 218 |
|
219 |
breakpointSignal |
|
220 |
^ BreakpointSignal |
|
221 |
! ! |
|
222 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
223 |
!MessageTracer class methodsFor:'class tracing'! |
88 | 224 |
|
225 |
traceClass:aClass selector:aSelector |
|
226 |
"arrange for a trace message to be output on Stderr, when a message with aSelector is |
|
227 |
sent to instances of aClass (or subclass instances). Use untraceClass to remove this." |
|
228 |
||
229 |
self traceMethod:(aClass compiledMethodAt:aSelector) |
|
230 |
||
231 |
" |
|
232 |
MessageTracer traceClass:Integer selector:#factorial. |
|
233 |
5 factorial. |
|
234 |
MessageTracer untraceClass:Integer |
|
235 |
" |
|
236 |
" |
|
237 |
MessageTracer traceClass:SequenceableCollection selector:#quickSortFrom:to:. |
|
238 |
#(6 1 9 66 2 17) copy sort. |
|
239 |
MessageTracer untraceClass:SequenceableCollection |
|
240 |
" |
|
241 |
" |
|
242 |
MessageTracer traceClass:Array selector:#at:. |
|
243 |
MessageTracer traceClass:Array selector:#at:put:. |
|
244 |
#(6 1 9 66 2 17) copy sort. |
|
245 |
MessageTracer untraceClass:Array |
|
246 |
" |
|
247 |
! |
|
248 |
||
249 |
untraceAllClasses |
|
250 |
"remove all traces of messages sent to any class" |
|
251 |
||
252 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
253 |
trace facilities ..." |
|
254 |
||
255 |
^ self untrapAllClasses |
|
256 |
! |
|
257 |
||
258 |
untraceClass:aClass |
|
259 |
"remove all traces of messages sent to instances of aClass" |
|
260 |
||
261 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
262 |
trace facilities ..." |
|
263 |
||
264 |
^ self untrapClass:aClass |
|
265 |
! ! |
|
266 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
267 |
!MessageTracer class methodsFor:'class wrapping'! |
88 | 268 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
269 |
wrapClass:orgClass selector:aSelector onEntry:entryBlock onExit:exitBlock |
88 | 270 |
"arrange for the two blocks entryBlock and exitBlock to be evaluated whenever |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
271 |
aSelector is sent to instances of orgClass or subclasses. |
88 | 272 |
EntryBlock will be called on entry, and get the current context passed as argument. |
273 |
ExitBlock will be called, when the method is left, and get context and the methods return value as arguments. |
|
274 |
" |
|
275 |
||
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
276 |
|myMetaclass trapMethod s spec implClass newClass save dict| |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
277 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
278 |
WrappedMethod autoload. "/ just to make sure ... |
88 | 279 |
|
280 |
" |
|
281 |
create a new method, which calls the original one, |
|
282 |
but only if not already being trapped. |
|
283 |
" |
|
284 |
spec := Parser methodSpecificationForSelector:aSelector. |
|
285 |
||
286 |
s := WriteStream on:String new. |
|
287 |
s nextPutAll:spec. |
|
288 |
s cr. |
|
289 |
s nextPutAll:'|retVal stubClass|'; cr. |
|
290 |
entryBlock notNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
291 |
s nextPutAll:'#literal1 yourself value:thisContext.'; cr. |
88 | 292 |
]. |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
293 |
s nextPutAll:('retVal := #originalMethod. '). "/ just to get a literal to be replaced by theoriginal method |
88 | 294 |
s nextPutAll:('retVal := super ' , spec , '.'); cr. |
295 |
exitBlock notNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
296 |
s nextPutAll:'#literal2 yourself value:thisContext value:retVal.'; cr. |
88 | 297 |
]. |
298 |
s nextPutAll:'^ retVal'; cr. |
|
299 |
||
300 |
save := Compiler stcCompilation. |
|
301 |
Compiler stcCompilation:#never. |
|
302 |
[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
303 |
Class withoutUpdatingChangesDo:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
304 |
trapMethod := Compiler compile:s contents |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
305 |
forClass:orgClass |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
306 |
inCategory:'trapping' |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
307 |
notifying:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
308 |
install:false |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
309 |
skipIfSame:false |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
310 |
silent:true. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
311 |
] |
88 | 312 |
] valueNowOrOnUnwindDo:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
313 |
Compiler stcCompilation:save |
88 | 314 |
]. |
315 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
316 |
implClass := orgClass whichClassIncludesSelector:aSelector. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
317 |
implClass isNil ifTrue:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
318 |
Transcript showCR:aSelector , ' is not understood by ' , orgClass name. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
319 |
] ifFalse:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
320 |
trapMethod changeLiteral:#originalMethod to:(implClass compiledMethodAt:aSelector). |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
321 |
]. |
88 | 322 |
entryBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
323 |
trapMethod changeLiteral:#literal1 to:entryBlock. |
88 | 324 |
]. |
325 |
exitBlock notNil ifTrue:[ |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
326 |
trapMethod changeLiteral:#literal2 to:exitBlock. |
88 | 327 |
]. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
328 |
|
88 | 329 |
" |
330 |
change the source of this new method |
|
331 |
(to avoid confusion in the debugger ...) |
|
332 |
" |
|
333 |
trapMethod source:'this is a wrapper method - not the real one'. |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
334 |
trapMethod changeClassTo:WrappedMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
335 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
336 |
dict := orgClass methodDictionary. |
88 | 337 |
|
338 |
" |
|
339 |
if not already trapping, create a new class |
|
340 |
" |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
341 |
orgClass category == #'* trapping *' ifTrue:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
342 |
dict at:aSelector put:trapMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
343 |
orgClass methodDictionary:dict. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
344 |
newClass := orgClass superclass. |
88 | 345 |
] ifFalse:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
346 |
myMetaclass := orgClass class. |
88 | 347 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
348 |
newClass := myMetaclass copy new. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
349 |
newClass setSuperclass:orgClass superclass. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
350 |
newClass instSize:orgClass instSize. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
351 |
newClass flags:orgClass flags. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
352 |
newClass setClassVariableString:orgClass classVariableString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
353 |
newClass setInstanceVariableString:orgClass instanceVariableString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
354 |
newClass setName:orgClass name. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
355 |
newClass category:orgClass category. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
356 |
newClass methodDictionary:dict. |
88 | 357 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
358 |
orgClass setSuperclass:newClass. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
359 |
orgClass setClassVariableString:''. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
360 |
orgClass setInstanceVariableString:''. |
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
361 |
orgClass category:#'* trapping *'. |
88 | 362 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
363 |
dict := MethodDictionary new:1. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
364 |
dict at:aSelector put:trapMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
365 |
orgClass methodDictionary:dict. |
88 | 366 |
]. |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
367 |
trapMethod changeLiteral:(newClass superclass) to:newClass. |
88 | 368 |
|
369 |
ObjectMemory flushCaches. |
|
370 |
||
371 |
" |
|
372 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
373 |
wrapClass:Point |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
374 |
selector:#scaleBy: |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
375 |
onEntry:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
376 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
377 |
Transcript show:'leave Point>>scaleBy:; returning:'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
378 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
379 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
380 |
]. |
88 | 381 |
(1@2) scaleBy:5. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
382 |
MessageTracer untrapClass:Point selector:#scaleBy:. |
88 | 383 |
(1@2) scaleBy:5. |
384 |
" |
|
385 |
" |
|
386 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
387 |
wrapClass:Integer |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
388 |
selector:#factorial |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
389 |
onEntry:[:con | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
390 |
Transcript showCR:('entering ' , con receiver printString , '>>factorial'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
391 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
392 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
393 |
Transcript show:'leave Integer>>factorial; returning:'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
394 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
395 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
396 |
]. |
258 | 397 |
Transcript showCR:'5 factorial traced'. |
88 | 398 |
5 factorial. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
399 |
MessageTracer untrapClass:Integer selector:#factorial. |
258 | 400 |
Transcript showCR:'5 factorial normal'. |
88 | 401 |
5 factorial. |
402 |
" |
|
403 |
" |
|
404 |
|lvl| |
|
405 |
||
406 |
lvl := 0. |
|
407 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
408 |
wrapClass:Integer |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
409 |
selector:#factorial |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
410 |
onEntry:[:con | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
411 |
Transcript spaces:lvl. lvl := lvl + 2. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
412 |
Transcript showCR:('entering ' , con receiver printString , '>>factorial'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
413 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
414 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
415 |
lvl := lvl - 2. Transcript spaces:lvl. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
416 |
Transcript show:('leave ' , con receiver printString , '>>factorial; returning:'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
417 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
418 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
419 |
]. |
258 | 420 |
Transcript showCR:'5 factorial traced'. |
88 | 421 |
5 factorial. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
422 |
MessageTracer untrapClass:Integer selector:#factorial. |
258 | 423 |
Transcript showCR:'5 factorial normal'. |
88 | 424 |
5 factorial. |
425 |
" |
|
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
426 |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
427 |
"Modified: 25.6.1996 / 22:01:05 / stefan" |
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
428 |
"Modified: 10.9.1996 / 20:07:01 / cg" |
88 | 429 |
! ! |
430 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
431 |
!MessageTracer class methodsFor:'cleanup'! |
27 | 432 |
|
433 |
cleanup |
|
434 |
"if you forgot which classes/methods where wrapped and/or trapped, |
|
435 |
this cleans up everything ..." |
|
436 |
||
437 |
self untrapAllClasses. |
|
438 |
self unwrapAllMethods |
|
439 |
||
440 |
" |
|
441 |
MessageTracer cleanup |
|
442 |
" |
|
443 |
! ! |
|
444 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
445 |
!MessageTracer class methodsFor:'execution trace '! |
88 | 446 |
|
447 |
debugTrace:aBlock |
|
448 |
"trace execution of aBlock. This is for system debugging only" |
|
11 | 449 |
|
196
330cc5c849de
debugOn/Off is now called sendTraceOn/Off
Claus Gittinger <cg@exept.de>
parents:
172
diff
changeset
|
450 |
Smalltalk sendTraceOn. |
88 | 451 |
^ aBlock valueNowOrOnUnwindDo:[ |
196
330cc5c849de
debugOn/Off is now called sendTraceOn/Off
Claus Gittinger <cg@exept.de>
parents:
172
diff
changeset
|
452 |
Smalltalk sendTraceOff. |
88 | 453 |
] |
11 | 454 |
|
88 | 455 |
" |
456 |
MessageTracer debugTrace:[#(6 5 4 3 2 1) sort] |
|
457 |
" |
|
196
330cc5c849de
debugOn/Off is now called sendTraceOn/Off
Claus Gittinger <cg@exept.de>
parents:
172
diff
changeset
|
458 |
|
330cc5c849de
debugOn/Off is now called sendTraceOn/Off
Claus Gittinger <cg@exept.de>
parents:
172
diff
changeset
|
459 |
"Modified: 18.3.1996 / 19:49:36 / cg" |
88 | 460 |
! |
11 | 461 |
|
462 |
trace:aBlock |
|
463 |
"evaluate aBlock sending trace information to stdout. |
|
27 | 464 |
Return the value of the block." |
11 | 465 |
|
17 | 466 |
^ self new trace:aBlock detail:false. |
11 | 467 |
|
468 |
" |
|
469 |
MessageTracer trace:[#(6 5 4 3 2 1) sort] |
|
470 |
" |
|
471 |
! |
|
472 |
||
473 |
traceFull:aBlock |
|
474 |
"evaluate aBlock sending trace information to stdout. |
|
475 |
Return the value of the block. |
|
27 | 476 |
The trace information is more detailed." |
11 | 477 |
|
17 | 478 |
^ self new trace:aBlock detail:true. |
11 | 479 |
|
480 |
" |
|
481 |
MessageTracer traceFull:[#(6 5 4 3 2 1) sort] |
|
482 |
" |
|
88 | 483 |
! ! |
484 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
485 |
!MessageTracer class methodsFor:'method breakpointing'! |
88 | 486 |
|
487 |
trapClass:aClass selector:aSelector |
|
488 |
"arrange for the debugger to be entered when a message with aSelector is |
|
489 |
sent to instances of aClass (or subclass instances). Use untrapClass to remove this trap. |
|
490 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
491 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
492 |
entry/leave blocks." |
|
493 |
||
494 |
self trapMethod:(aClass compiledMethodAt:aSelector) |
|
495 |
||
496 |
" |
|
497 |
MessageTracer trapClass:Collection selector:#select:. |
|
498 |
Dictionary new select:[:e | ]. 'not cought - Dictionary has its own select'. |
|
499 |
(Array new:10) select:[:e | ]. 'not cought - SeqColl has its own select'. |
|
500 |
Set new select:[:e | ]. 'cought - Set inherits this from Collection'. |
|
501 |
MessageTracer untrapClass:Collection |
|
502 |
" |
|
11 | 503 |
! |
504 |
||
88 | 505 |
trapMethod:aMethod |
506 |
"arrange for the debugger to be entered when aMethod is about to be executed. |
|
495 | 507 |
The trap is enabled for any process - see #trapMethodInCurrentProcess: for a more |
508 |
selective breakPoint. |
|
88 | 509 |
Use unwrapMethod or untrapClass to remove this trap. |
510 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
511 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
512 |
entry/leave blocks." |
|
513 |
||
514 |
^ self wrapMethod:aMethod |
|
495 | 515 |
onEntry:BreakBlock |
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
516 |
onExit:LeaveBreakBlock. |
88 | 517 |
|
518 |
" |
|
519 |
MessageTracer trapMethod:(Collection compiledMethodAt:#select:). |
|
520 |
Dictionary new select:[:e | ]. 'not cought - Dictionary has its own select'. |
|
521 |
(Array new:10) select:[:e | ]. 'not cought - SeqColl has its own select'. |
|
522 |
Set new select:[:e | ]. 'cought - Set inherits this from Collection'. |
|
523 |
MessageTracer unwrapMethod:(Collection compiledMethodAt:#select:). |
|
524 |
" |
|
495 | 525 |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
526 |
"Modified: 22.10.1996 / 17:39:58 / cg" |
88 | 527 |
! |
11 | 528 |
|
88 | 529 |
trapMethod:aMethod forInstancesOf:aClass |
530 |
"arrange for the debugger to be entered when aMethod is about to be executed |
|
531 |
for an instance of aClass. |
|
532 |
Use unwrapMethod or untrapClass to remove this trap. |
|
533 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
534 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
535 |
entry/leave blocks." |
|
536 |
||
537 |
^ self wrapMethod:aMethod |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
538 |
onEntry:[:context | |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
539 |
(context receiver isMemberOf:aClass) ifTrue:[ |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
540 |
BreakpointSignal raiseIn:context |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
541 |
] |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
542 |
] |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
543 |
onExit:LeaveBreakBlock. |
88 | 544 |
|
545 |
" |
|
546 |
MessageTracer trapMethod:(View compiledMethodAt:#redraw) forInstancesOf:myView. |
|
547 |
" |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
548 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
549 |
"Modified: 22.10.1996 / 17:40:03 / cg" |
88 | 550 |
! |
551 |
||
496 | 552 |
trapMethod:aMethod inProcess:aProcess |
495 | 553 |
"arrange for the debugger to be entered when aMethod is about to be executed, |
554 |
but only, if executed in the current process. |
|
555 |
This allows for breakpoints to be set on system-critical code. |
|
556 |
The trap is enabled for any process. |
|
557 |
Use unwrapMethod or untrapClass to remove this trap. |
|
558 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
559 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
560 |
entry/leave blocks." |
|
561 |
||
562 |
^ self wrapMethod:aMethod |
|
496 | 563 |
onEntry:[:con | (Processor activeProcess == aProcess) |
495 | 564 |
ifTrue:[ |
565 |
BreakpointSignal raiseIn:con |
|
566 |
] |
|
567 |
] |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
568 |
onExit:LeaveBreakBlock. |
495 | 569 |
|
496 | 570 |
"Created: 14.10.1996 / 15:38:46 / cg" |
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
571 |
"Modified: 22.10.1996 / 17:40:06 / cg" |
495 | 572 |
! |
573 |
||
88 | 574 |
untrapAllClasses |
575 |
"remove any traps on any class" |
|
576 |
||
577 |
Smalltalk allBehaviorsDo:[:aClass | |
|
578 |
self untrapClass:aClass |
|
11 | 579 |
] |
580 |
||
581 |
" |
|
88 | 582 |
MessageTracer untrapAllClasses |
583 |
" |
|
584 |
! |
|
585 |
||
586 |
untrapClass:aClass |
|
587 |
"remove any traps on aClass" |
|
588 |
||
589 |
"this is done by just patching the class back to the original" |
|
590 |
||
591 |
|orgClass| |
|
592 |
||
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
593 |
aClass category == #'* trapping *' ifFalse:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
594 |
^ self |
88 | 595 |
]. |
596 |
orgClass := aClass superclass. |
|
597 |
||
598 |
aClass setSuperclass:orgClass superclass. |
|
599 |
aClass setClassVariableString:orgClass classVariableString. |
|
600 |
aClass setInstanceVariableString:orgClass instanceVariableString. |
|
601 |
aClass category:orgClass category. |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
602 |
aClass methodDictionary:orgClass methodDictionary. |
88 | 603 |
|
604 |
ObjectMemory flushCaches. |
|
605 |
||
606 |
" |
|
607 |
MessageTracer untrapClass:Point |
|
11 | 608 |
" |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
609 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
610 |
"Modified: 5.6.1996 / 13:57:39 / stefan" |
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
611 |
"Modified: 10.9.1996 / 20:06:23 / cg" |
88 | 612 |
! |
613 |
||
614 |
untrapClass:aClass selector:aSelector |
|
615 |
"remove trap of aSelector sent to aClass" |
|
616 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
617 |
|dict| |
88 | 618 |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
619 |
aClass category == #'* trapping *' ifFalse:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
620 |
^ self |
88 | 621 |
]. |
622 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
623 |
dict := aClass methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
624 |
dict at:aSelector ifAbsent:[^ self]. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
625 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
626 |
ObjectMemory flushCaches. "avoid calling the old trap method" |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
627 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
628 |
dict size == 1 ifTrue:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
629 |
"the last trapped method" |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
630 |
^ self untrapClass:aClass |
88 | 631 |
]. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
632 |
dict removeKey:aSelector. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
633 |
aClass methodDictionary:dict. |
88 | 634 |
|
635 |
" |
|
636 |
MessageTracer trapClass:Point selector:#copy. |
|
637 |
(1@2) copy. |
|
638 |
(1@2) deepCopy. |
|
639 |
MessageTracer trapClass:Point selector:#deepCopy. |
|
640 |
(1@2) copy. |
|
641 |
(1@2) deepCopy. |
|
642 |
MessageTracer untrapClass:Point selector:#copy. |
|
643 |
(1@2) copy. |
|
644 |
(1@2) deepCopy. |
|
645 |
MessageTracer untrapClass:Point selector:#deepCopy. |
|
646 |
(1@2) copy. |
|
647 |
(1@2) deepCopy. |
|
648 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
649 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
650 |
"Modified: 5.6.1996 / 14:00:55 / stefan" |
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
651 |
"Modified: 10.9.1996 / 20:06:29 / cg" |
88 | 652 |
! |
653 |
||
654 |
untrapMethod:aMethod |
|
655 |
"remove break on aMethod" |
|
656 |
||
657 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
658 |
trace facilities ..." |
|
659 |
||
660 |
^ self unwrapMethod:aMethod |
|
11 | 661 |
! ! |
662 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
663 |
!MessageTracer class methodsFor:'method counting'! |
155 | 664 |
|
665 |
countMethod:aMethod |
|
666 |
"arrange for a aMethods execution to be counted. |
|
667 |
Use unwrapMethod to remove this." |
|
668 |
||
669 |
MethodCounts isNil ifTrue:[ |
|
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
670 |
MethodCounts := IdentityDictionary new. |
155 | 671 |
]. |
672 |
MethodCounts at:aMethod put:0. |
|
673 |
||
674 |
^ self wrapMethod:aMethod |
|
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
675 |
onEntry:[:con | |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
676 |
|cnt| |
155 | 677 |
|
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
678 |
cnt := MethodCounts at:aMethod ifAbsent:0. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
679 |
MethodCounts at:aMethod put:(cnt + 1). |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
680 |
] |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
681 |
onExit:[:con :retVal | |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
682 |
] |
155 | 683 |
|
684 |
" |
|
685 |
MessageTracer countMethod:(Integer compiledMethodAt:#factorial). |
|
686 |
5 factorial. |
|
687 |
MessageTracer executionCountOf:(Integer compiledMethodAt:#factorial) printNL. |
|
688 |
MessageTracer stopCountingMethod:(Integer compiledMethodAt:#factorial) |
|
689 |
" |
|
690 |
||
691 |
"Created: 15.12.1995 / 10:57:49 / cg" |
|
692 |
"Modified: 15.12.1995 / 15:46:41 / cg" |
|
693 |
! |
|
694 |
||
695 |
executionCountOfMethod:aMethod |
|
696 |
"return the current count" |
|
697 |
||
698 |
|count| |
|
699 |
||
700 |
MethodCounts isNil ifTrue:[^ 0]. |
|
701 |
aMethod isWrapped ifTrue:[ |
|
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
702 |
count := MethodCounts at:aMethod originalMethod ifAbsent:nil. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
703 |
count notNil ifTrue:[^ count]. |
155 | 704 |
]. |
705 |
^ MethodCounts at:aMethod ifAbsent:0 |
|
706 |
||
707 |
"Created: 15.12.1995 / 11:01:56 / cg" |
|
708 |
"Modified: 15.12.1995 / 15:45:15 / cg" |
|
709 |
! |
|
710 |
||
711 |
stopCountingMethod:aMethod |
|
712 |
"remove counting of aMethod" |
|
713 |
||
714 |
^ self unwrapMethod:aMethod |
|
715 |
||
716 |
"Modified: 15.12.1995 / 15:43:53 / cg" |
|
717 |
! ! |
|
718 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
719 |
!MessageTracer class methodsFor:'method memory usage'! |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
720 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
721 |
countMemoryUsageOfMethod:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
722 |
"arrange for aMethods memory usage to be counted. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
723 |
Use unwrapMethod to remove this." |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
724 |
|
501 | 725 |
|oldPriority oldScavengeCount oldNewUsed| |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
726 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
727 |
MethodCounts isNil ifTrue:[ |
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
728 |
MethodCounts := IdentityDictionary new. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
729 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
730 |
MethodMemoryUsage isNil ifTrue:[ |
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
731 |
MethodMemoryUsage := IdentityDictionary new. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
732 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
733 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
734 |
MethodCounts at:aMethod put:0. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
735 |
MethodMemoryUsage at:aMethod put:0. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
736 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
737 |
^ self wrapMethod:aMethod |
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
738 |
onEntry:[:con | |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
739 |
oldPriority := Processor activeProcess changePriority:(Processor userInterruptPriority). |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
740 |
oldNewUsed := ObjectMemory newSpaceUsed. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
741 |
oldScavengeCount := ObjectMemory scavengeCount. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
742 |
] |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
743 |
onExit:[:con :retVal | |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
744 |
|cnt memUse scavenges| |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
745 |
|
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
746 |
memUse := ObjectMemory newSpaceUsed - oldNewUsed. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
747 |
scavenges := ObjectMemory scavengeCount - oldScavengeCount. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
748 |
scavenges ~= 0 ifTrue:[ |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
749 |
memUse := memUse + (ObjectMemory newSpaceSize * scavenges) |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
750 |
]. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
751 |
|
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
752 |
MethodCounts notNil ifTrue:[ |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
753 |
cnt := MethodCounts at:aMethod ifAbsent:0. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
754 |
MethodCounts at:aMethod put:(cnt + 1). |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
755 |
]. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
756 |
MethodMemoryUsage notNil ifTrue:[ |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
757 |
cnt := MethodMemoryUsage at:aMethod ifAbsent:0. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
758 |
MethodMemoryUsage at:aMethod put:(cnt + memUse). |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
759 |
]. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
760 |
Processor activeProcess priority:oldPriority |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
761 |
] |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
762 |
onUnwind:[ |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
763 |
oldPriority notNil ifTrue:[ |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
764 |
Processor activeProcess priority:oldPriority |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
765 |
] |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
766 |
] |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
767 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
768 |
" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
769 |
MessageTracer countMemoryUsageOfMethod:(Integer compiledMethodAt:#factorial). |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
770 |
3 factorial. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
771 |
(MessageTracer memoryUsageOfMethod:(Integer compiledMethodAt:#factorial)) printNL. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
772 |
MessageTracer stopCountingMemoryUsageOfMethod:(Integer compiledMethodAt:#factorial) |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
773 |
" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
774 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
775 |
"Created: 18.12.1995 / 15:41:27 / stefan" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
776 |
"Modified: 18.12.1995 / 21:46:48 / stefan" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
777 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
778 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
779 |
isCountingMemoryUsage:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
780 |
"return true if aMethod is counting memoryUsage" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
781 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
782 |
MethodMemoryUsage isNil ifTrue:[^ false]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
783 |
(MethodMemoryUsage includesKey:aMethod) ifTrue:[^ true]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
784 |
aMethod isWrapped ifTrue:[ |
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
785 |
^ MethodMemoryUsage includesKey:aMethod originalMethod |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
786 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
787 |
^ false |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
788 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
789 |
"Created: 18.12.1995 / 15:51:49 / stefan" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
790 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
791 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
792 |
memoryUsageOfMethod:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
793 |
"return the current count" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
794 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
795 |
|count memUse| |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
796 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
797 |
(MethodCounts isNil or:[MethodMemoryUsage isNil]) ifTrue:[^ 0]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
798 |
aMethod isWrapped ifTrue:[ |
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
799 |
count := MethodCounts at:aMethod originalMethod ifAbsent:nil. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
800 |
memUse := MethodMemoryUsage at:aMethod originalMethod ifAbsent:nil. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
801 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
802 |
memUse isNil ifTrue:[ |
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
803 |
count := MethodCounts at:aMethod ifAbsent:0. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
804 |
memUse := MethodMemoryUsage at:aMethod ifAbsent:0. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
805 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
806 |
count = 0 ifTrue:[^ 0]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
807 |
^ memUse//count |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
808 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
809 |
"Modified: 18.12.1995 / 16:25:51 / stefan" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
810 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
811 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
812 |
stopCountingMemoryUsageOfMethod:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
813 |
"remove counting memory of aMethod" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
814 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
815 |
^ self unwrapMethod:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
816 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
817 |
"Modified: 18.12.1995 / 21:54:36 / stefan" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
818 |
! ! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
819 |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
820 |
!MessageTracer class methodsFor:'method timing'! |
327 | 821 |
|
822 |
executionTimesOfMethod:aMethod |
|
823 |
"return the current times" |
|
824 |
||
825 |
|count info min max avg ret| |
|
826 |
||
827 |
count := min := max := avg := 0. |
|
828 |
MethodTiming notNil ifTrue:[ |
|
829 |
aMethod isWrapped ifTrue:[ |
|
830 |
info := MethodTiming at:aMethod originalMethod ifAbsent:nil. |
|
831 |
info notNil ifTrue:[ |
|
832 |
count := info at:1. |
|
579 | 833 |
count ~~ 0 ifTrue:[ |
834 |
min := info at:2. |
|
835 |
max := info at:3. |
|
836 |
avg := ((info at:4) / count) roundTo:0.01 |
|
837 |
] |
|
327 | 838 |
]. |
839 |
]. |
|
840 |
]. |
|
841 |
||
842 |
ret := IdentityDictionary new. |
|
843 |
ret at:#count put:count. |
|
844 |
ret at:#minTime put:min. |
|
845 |
ret at:#maxTime put:max. |
|
846 |
ret at:#avgTime put:avg. |
|
847 |
^ ret |
|
848 |
||
849 |
"Created: 17.6.1996 / 17:07:30 / cg" |
|
579 | 850 |
"Modified: 11.4.1997 / 17:16:11 / cg" |
327 | 851 |
! |
852 |
||
853 |
stopTimingMethod:aMethod |
|
854 |
"remove timing of aMethod" |
|
855 |
||
856 |
^ self unwrapMethod:aMethod |
|
857 |
||
858 |
"Modified: 15.12.1995 / 15:43:53 / cg" |
|
859 |
"Created: 17.6.1996 / 17:04:03 / cg" |
|
860 |
! |
|
861 |
||
862 |
timeMethod:aMethod |
|
863 |
"arrange for a aMethods execution time to be measured. |
|
864 |
Use unwrapMethod to remove this." |
|
865 |
||
501 | 866 |
|t0| |
327 | 867 |
|
868 |
MethodTiming isNil ifTrue:[ |
|
869 |
MethodTiming := IdentityDictionary new. |
|
870 |
]. |
|
871 |
MethodTiming removeKey:aMethod ifAbsent:nil. |
|
579 | 872 |
MethodTiming at:aMethod put:(Array with:0 |
873 |
with:0 |
|
874 |
with:0 |
|
875 |
with:0). |
|
327 | 876 |
|
877 |
^ self wrapMethod:aMethod |
|
878 |
onEntry:[:con | |
|
879 |
t0 := OperatingSystem getMillisecondTime. |
|
880 |
] |
|
881 |
onExit:[:con :retVal | |
|
882 |
|info t cnt min max sumTimes| |
|
883 |
||
884 |
t := OperatingSystem getMillisecondTime - t0. |
|
885 |
info := MethodTiming at:aMethod ifAbsent:nil. |
|
886 |
info isNil ifTrue:[ |
|
887 |
MethodTiming at:aMethod put:(Array with:1 |
|
888 |
with:t |
|
889 |
with:t |
|
890 |
with:t) |
|
891 |
] ifFalse:[ |
|
892 |
cnt := info at:1. |
|
893 |
min := info at:2. |
|
894 |
max := info at:3. |
|
895 |
sumTimes := info at:4. |
|
896 |
t < min ifTrue:[ |
|
897 |
info at:2 put:t |
|
898 |
] ifFalse:[ |
|
899 |
t > max ifTrue:[ |
|
900 |
info at:3 put:t |
|
901 |
] |
|
902 |
]. |
|
903 |
info at:4 put:(sumTimes + t). |
|
904 |
info at:1 put:cnt + 1 |
|
905 |
]. |
|
906 |
] |
|
907 |
||
908 |
" |
|
909 |
MessageTracer timeMethod:(Integer compiledMethodAt:#factorial). |
|
910 |
5 factorial. |
|
911 |
5 factorial. |
|
912 |
5 factorial. |
|
913 |
(MessageTracer executionTimesOfMethod:(Integer compiledMethodAt:#factorial)) printCR. |
|
914 |
MessageTracer stopTimingMethod:(Integer compiledMethodAt:#factorial) |
|
915 |
" |
|
916 |
||
917 |
"Created: 17.6.1996 / 17:03:50 / cg" |
|
579 | 918 |
"Modified: 11.4.1997 / 17:15:29 / cg" |
327 | 919 |
! ! |
920 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
921 |
!MessageTracer class methodsFor:'method tracing'! |
11 | 922 |
|
88 | 923 |
traceMethod:aMethod |
924 |
"arrange for a trace message to be output on Stderr, when aMethod is executed. |
|
925 |
Use unwrapMethod to remove this." |
|
926 |
||
927 |
|lvl inside| |
|
11 | 928 |
|
88 | 929 |
^ self wrapMethod:aMethod |
930 |
onEntry:[:con | |
|
931 |
inside isNil ifTrue:[ |
|
932 |
inside := true. |
|
933 |
CallingLevel isNil ifTrue:[ |
|
934 |
CallingLevel := 0. |
|
935 |
]. |
|
936 |
lvl notNil ifTrue:[ |
|
937 |
lvl := lvl + 1 |
|
938 |
] ifFalse:[ |
|
939 |
CallingLevel := lvl := CallingLevel + 1. |
|
940 |
]. |
|
941 |
MessageTracer printEntryFull:con level:lvl. |
|
942 |
inside := nil |
|
943 |
] |
|
944 |
] |
|
945 |
onExit:[:con :retVal | |
|
946 |
inside isNil ifTrue:[ |
|
947 |
inside := true. |
|
948 |
MessageTracer printExit:con with:retVal level:lvl. |
|
949 |
CallingLevel := lvl := lvl - 1. |
|
950 |
inside := nil |
|
951 |
] |
|
952 |
] |
|
11 | 953 |
|
954 |
" |
|
88 | 955 |
MessageTracer traceMethod:(Integer compiledMethodAt:#factorial). |
956 |
5 factorial. |
|
957 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial) |
|
958 |
" |
|
959 |
" |
|
960 |
MessageTracer traceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
961 |
#(6 1 9 66 2 17) copy sort. |
|
962 |
MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
963 |
" |
|
964 |
" |
|
965 |
dont do this: |
|
966 |
" |
|
967 |
" |
|
968 |
MessageTracer traceMethod:(Object compiledMethodAt:#at:). |
|
969 |
MessageTracer traceMethod:(Object compiledMethodAt:#at:put:). |
|
970 |
#(6 1 9 66 2 17) copy sort. |
|
971 |
MessageTracer untraceMethod:(Object compiledMethodAt:#at:). |
|
972 |
MessageTracer untraceMethod:(Object compiledMethodAt:#at:put:). |
|
11 | 973 |
" |
974 |
! |
|
975 |
||
162
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
976 |
traceMethodAll:aMethod |
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
977 |
"arrange for a full trace message to be output on Stderr, when amethod is executed. |
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
978 |
Only the sender is traced on entry. |
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
979 |
Use untraceMethod to remove this trace." |
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
980 |
|
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
981 |
^ self wrapMethod:aMethod |
572 | 982 |
onEntry:[:con | ObjectMemory flushCaches. Smalltalk sendTraceOn.] |
983 |
onExit:[:con :val | Smalltalk sendTraceOff.] |
|
162
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
984 |
|
572 | 985 |
"Modified: 22.3.1997 / 17:02:04 / cg" |
162
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
986 |
! |
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
987 |
|
156 | 988 |
traceMethodFull:aMethod |
989 |
"arrange for a full trace message to be output on Stderr, when amethod is executed. |
|
990 |
Only the sender is traced on entry. |
|
991 |
Use untraceMethod to remove this trace." |
|
992 |
||
993 |
^ self wrapMethod:aMethod |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
994 |
onEntry:TraceFullBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
995 |
onExit:LeaveTraceBlock. |
156 | 996 |
|
997 |
"Created: 15.12.1995 / 18:19:31 / cg" |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
998 |
"Modified: 22.10.1996 / 17:39:28 / cg" |
156 | 999 |
! |
1000 |
||
88 | 1001 |
traceMethodSender:aMethod |
1002 |
"arrange for a trace message to be output on Stderr, when amethod is executed. |
|
1003 |
Only the sender is traced on entry. |
|
1004 |
Use untraceMethod to remove this trace." |
|
35 | 1005 |
|
88 | 1006 |
^ self wrapMethod:aMethod |
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1007 |
onEntry:TraceSenderBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1008 |
onExit:LeaveTraceBlock. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1009 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1010 |
"Modified: 22.10.1996 / 17:39:33 / cg" |
88 | 1011 |
! |
1012 |
||
1013 |
untraceMethod:aMethod |
|
1014 |
"remove tracing of aMethod" |
|
1015 |
||
1016 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
1017 |
trace facilities ..." |
|
1018 |
||
1019 |
^ self unwrapMethod:aMethod |
|
11 | 1020 |
! ! |
1021 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1022 |
!MessageTracer class methodsFor:'method wrapping'! |
11 | 1023 |
|
88 | 1024 |
unwrapAllMethods |
1025 |
"just in case you dont know what methods have break/trace-points |
|
1026 |
on them; this removes them all" |
|
1027 |
||
1028 |
WrappedMethod allInstancesDo:[:aMethod | |
|
1029 |
self unwrapMethod:aMethod |
|
1030 |
] |
|
11 | 1031 |
! |
1032 |
||
88 | 1033 |
unwrapMethod:aMethod |
1034 |
"remove any wrapper on aMethod" |
|
1035 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1036 |
|selector class originalMethod dict mthd| |
88 | 1037 |
|
155 | 1038 |
MethodCounts notNil ifTrue:[ |
265 | 1039 |
aMethod isWrapped ifTrue:[ |
1040 |
MethodCounts removeKey:aMethod originalMethod ifAbsent:nil. |
|
1041 |
]. |
|
1042 |
MethodCounts removeKey:aMethod ifAbsent:nil. |
|
1043 |
MethodCounts isEmpty ifTrue:[MethodCounts := nil]. |
|
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
1044 |
]. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
1045 |
MethodMemoryUsage notNil ifTrue:[ |
265 | 1046 |
aMethod isWrapped ifTrue:[ |
1047 |
MethodMemoryUsage removeKey:aMethod originalMethod ifAbsent:nil. |
|
1048 |
]. |
|
1049 |
MethodMemoryUsage removeKey:aMethod ifAbsent:nil. |
|
1050 |
MethodMemoryUsage isEmpty ifTrue:[MethodMemoryUsage := nil]. |
|
155 | 1051 |
]. |
327 | 1052 |
MethodTiming notNil ifTrue:[ |
1053 |
aMethod isWrapped ifTrue:[ |
|
1054 |
MethodTiming removeKey:aMethod originalMethod ifAbsent:nil. |
|
1055 |
]. |
|
1056 |
MethodTiming removeKey:aMethod ifAbsent:nil. |
|
1057 |
MethodTiming isEmpty ifTrue:[MethodTiming := nil]. |
|
1058 |
]. |
|
155 | 1059 |
|
88 | 1060 |
CallingLevel := 0. |
1061 |
||
1062 |
(aMethod isNil or:[aMethod isWrapped not]) ifTrue:[ |
|
265 | 1063 |
^ aMethod |
88 | 1064 |
]. |
1065 |
||
1066 |
" |
|
1067 |
get class/selector |
|
1068 |
" |
|
1069 |
class := aMethod containingClass. |
|
1070 |
class isNil ifTrue:[ |
|
536 | 1071 |
'MessageTracer [info]: no containing class for method found' infoPrintCR. |
265 | 1072 |
^ aMethod |
88 | 1073 |
]. |
1074 |
selector := class selectorAtMethod:aMethod. |
|
1075 |
||
1076 |
originalMethod := aMethod originalMethod. |
|
1077 |
originalMethod isNil ifTrue:[ |
|
265 | 1078 |
self error:'oops, could not find original method'. |
1079 |
^ aMethod |
|
88 | 1080 |
]. |
1081 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1082 |
dict := class methodDictionary. |
506 | 1083 |
mthd := dict at:selector ifAbsent:nil. |
1084 |
mthd notNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1085 |
dict at:selector put:originalMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1086 |
class methodDictionary:dict. |
88 | 1087 |
] ifFalse:[ |
506 | 1088 |
self halt:'oops, unexpected error - cannot remove wrap'. |
265 | 1089 |
^ aMethod |
88 | 1090 |
]. |
1091 |
||
1092 |
ObjectMemory flushCaches. |
|
584
2da6bb2c8017
send out change notifications when a trap is removed
Claus Gittinger <cg@exept.de>
parents:
579
diff
changeset
|
1093 |
class changed:#methodTrap with:selector. "/ tell browsers |
88 | 1094 |
^ originalMethod |
265 | 1095 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1096 |
"Modified: 5.6.1996 / 14:08:08 / stefan" |
584
2da6bb2c8017
send out change notifications when a trap is removed
Claus Gittinger <cg@exept.de>
parents:
579
diff
changeset
|
1097 |
"Modified: 24.4.1997 / 18:20:49 / cg" |
13 | 1098 |
! |
1099 |
||
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1100 |
wrapMethod:aMethod onEntry:entryBlock onExit:exitBlock |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1101 |
^ self wrapMethod:aMethod onEntry:entryBlock onExit:exitBlock onUnwind:nil |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1102 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1103 |
"Modified: 18.12.1995 / 15:58:12 / stefan" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1104 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1105 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1106 |
wrapMethod:aMethod onEntry:entryBlock onExit:exitBlock onUnwind:unwindBlock |
88 | 1107 |
"arrange for the two blocks entryBlock and exitBlock to be evaluated whenever |
1108 |
aMethod is evaluated. |
|
1109 |
EntryBlock will be called on entry, and gets the current context passed as argument. |
|
1110 |
ExitBlock will be called, when the method is left, and gets the context and |
|
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1111 |
the methods return value as arguments. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1112 |
UnwindBlock will be called when the contxt of aMethod is unwound. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1113 |
If there is an unwindBlock, the entry and exitBlocks will be called within the unwind block, |
572 | 1114 |
because allocating the unwindBlock uses memory and some users want to count allocated memory. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1115 |
" |
88 | 1116 |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1117 |
|selector class trapMethod s spec src dict sel save| |
88 | 1118 |
|
1119 |
CallingLevel := 0. |
|
1120 |
||
1121 |
" |
|
1122 |
create a new method, which calls the original one, |
|
1123 |
but only if not already being trapped. |
|
1124 |
" |
|
1125 |
(aMethod isNil or:[aMethod isWrapped]) ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1126 |
^ aMethod |
88 | 1127 |
]. |
1128 |
aMethod isLazyMethod ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1129 |
aMethod makeRealMethod |
88 | 1130 |
]. |
1131 |
||
1132 |
" |
|
1133 |
get class/selector |
|
1134 |
" |
|
1135 |
class := aMethod containingClass. |
|
1136 |
class isNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1137 |
self error:'cannot place trap (no containing class found)'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1138 |
^ aMethod |
88 | 1139 |
]. |
1140 |
selector := class selectorAtMethod:aMethod. |
|
1141 |
||
1142 |
||
1143 |
WrappedMethod autoload. "/ for small systems |
|
1144 |
||
1145 |
" |
|
1146 |
get a new method-spec |
|
1147 |
" |
|
1148 |
spec := Parser methodSpecificationForSelector:selector. |
|
1149 |
||
1150 |
" |
|
1151 |
create a method, executing the trap-blocks and the original method via a direct call |
|
1152 |
" |
|
1153 |
s := WriteStream on:String new. |
|
1154 |
s nextPutAll:spec. |
|
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1155 |
s nextPutAll:' |retVal context| '. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1156 |
s nextPutAll:' context := thisContext.'. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1157 |
unwindBlock notNil ifTrue:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1158 |
s nextPutAll:'['. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1159 |
]. |
88 | 1160 |
entryBlock notNil ifTrue:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1161 |
s nextPutAll:'#entryBlock yourself value:context. '. |
88 | 1162 |
]. |
1163 |
s nextPutAll:'retVal := #originalMethod yourself'; |
|
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1164 |
nextPutAll: ' valueWithReceiver:(context receiver)'; |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1165 |
nextPutAll: ' arguments:(context args)'; |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1166 |
nextPutAll: ' selector:(context selector)'; |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1167 |
nextPutAll: ' search:(context searchClass)'; |
88 | 1168 |
nextPutAll: ' sender:nil. '. |
1169 |
||
1170 |
exitBlock notNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1171 |
s nextPutAll:'#exitBlock yourself value:context value:retVal.'. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1172 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1173 |
unwindBlock notNil ifTrue:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1174 |
s nextPutAll:'] valueOnUnwindDo:#unwindBlock yourself.'. |
88 | 1175 |
]. |
1176 |
s nextPutAll:'^ retVal'; cr. |
|
1177 |
||
1178 |
src := s contents. |
|
1179 |
save := Compiler stcCompilation. |
|
1180 |
Compiler stcCompilation:#never. |
|
1181 |
[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1182 |
Class withoutUpdatingChangesDo:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1183 |
trapMethod := Compiler compile:src |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1184 |
forClass:UndefinedObject |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1185 |
inCategory:aMethod category |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1186 |
notifying:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1187 |
install:false |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1188 |
skipIfSame:false |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1189 |
silent:true. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1190 |
] |
88 | 1191 |
] valueNowOrOnUnwindDo:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1192 |
Compiler stcCompilation:save |
88 | 1193 |
]. |
1194 |
||
1195 |
trapMethod changeClassTo:WrappedMethod. |
|
1196 |
||
1197 |
" |
|
1198 |
raising our eyebrows here ... |
|
1199 |
" |
|
1200 |
entryBlock notNil ifTrue:[ |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1201 |
trapMethod changeLiteral:#entryBlock to:entryBlock. |
88 | 1202 |
]. |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1203 |
trapMethod changeLiteral:#originalMethod to:aMethod. |
88 | 1204 |
exitBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1205 |
trapMethod changeLiteral:#exitBlock to:exitBlock. |
88 | 1206 |
]. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1207 |
unwindBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1208 |
trapMethod changeLiteral:#unwindBlock to:unwindBlock. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1209 |
]. |
88 | 1210 |
" |
1211 |
change the source of this new method |
|
1212 |
(to avoid confusion in the debugger ...) |
|
1213 |
" |
|
1214 |
trapMethod source:'this is a wrapper method - not the real one'. |
|
1215 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1216 |
dict := class methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1217 |
sel := dict at:selector ifAbsent:[0]. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1218 |
sel == 0 ifTrue:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1219 |
self halt:'oops, unexpected error'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1220 |
^ aMethod |
88 | 1221 |
]. |
1222 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1223 |
dict at:selector put:trapMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1224 |
class methodDictionary:dict. |
88 | 1225 |
ObjectMemory flushCaches. |
1226 |
^ trapMethod |
|
1227 |
||
1228 |
" |
|
1229 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1230 |
wrapMethod:(Point compiledMethodAt:#scaleBy:) |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1231 |
onEntry:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1232 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1233 |
Transcript show:'leave Point>>scaleBy:; returning:'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1234 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1235 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1236 |
]. |
88 | 1237 |
(1@2) scaleBy:5. |
1238 |
MessageTracer unwrapMethod:(Point compiledMethodAt:#scaleBy:). |
|
1239 |
(1@2) scaleBy:5. |
|
1240 |
" |
|
1241 |
" |
|
1242 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1243 |
wrapMethod:(Integer compiledMethodAt:#factorial) |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1244 |
onEntry:[:con | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1245 |
Transcript showCR:('entering ' , con receiver printString , '>>factorial'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1246 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1247 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1248 |
Transcript show:'leave Integer>>factorial; returning:'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1249 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1250 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1251 |
]. |
258 | 1252 |
Transcript showCR:'5 factorial traced'. |
88 | 1253 |
5 factorial. |
1254 |
MessageTracer unwrapMethod:(Integer compiledMethodAt:#factorial). |
|
258 | 1255 |
Transcript showCR:'5 factorial normal'. |
88 | 1256 |
5 factorial. |
1257 |
" |
|
1258 |
" |
|
1259 |
|lvl| |
|
1260 |
||
1261 |
lvl := 0. |
|
1262 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1263 |
wrapMethod:(Integer compiledMethodAt:#factorial) |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1264 |
onEntry:[:con | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1265 |
Transcript spaces:lvl. lvl := lvl + 2. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1266 |
Transcript showCR:('entering ' , con receiver printString , '>>factorial'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1267 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1268 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1269 |
lvl := lvl - 2. Transcript spaces:lvl. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1270 |
Transcript show:('leave ' , con receiver printString , '>>factorial; returning:'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1271 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1272 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1273 |
]. |
258 | 1274 |
Transcript showCR:'5 factorial traced'. |
88 | 1275 |
5 factorial. |
1276 |
MessageTracer unwrapMethod:(Integer compiledMethodAt:#factorial). |
|
258 | 1277 |
Transcript showCR:'5 factorial normal'. |
88 | 1278 |
5 factorial. |
1279 |
" |
|
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
1280 |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1281 |
"Modified: 25.6.1996 / 22:04:51 / stefan" |
572 | 1282 |
"Modified: 22.3.1997 / 17:00:43 / cg" |
88 | 1283 |
! ! |
1284 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1285 |
!MessageTracer class methodsFor:'object breakpointing'! |
88 | 1286 |
|
525 | 1287 |
objectHasWraps:anObject |
1288 |
"return true, if anObject has any wraps" |
|
1289 |
||
1290 |
^ anObject class category == #'* trapping *' |
|
1291 |
! |
|
1292 |
||
1293 |
realClassOf:anObject |
|
1294 |
"return anObjects real class" |
|
1295 |
||
1296 |
(anObject class category == #'* trapping *') ifFalse:[ |
|
1297 |
^ anObject class |
|
1298 |
]. |
|
1299 |
^ anObject class superclass |
|
1300 |
! |
|
1301 |
||
88 | 1302 |
trap:anObject selector:aSelector |
1303 |
"arrange for the debugger to be entered when a message with aSelector is |
|
1304 |
sent to anObject. Use untrap to remove this trap. |
|
1305 |
The current implementation does not allow integers or nil to be trapped." |
|
1306 |
||
1307 |
self wrap:anObject |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1308 |
selector:aSelector |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1309 |
onEntry:BreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1310 |
onExit:LeaveBreakBlock. |
88 | 1311 |
|
1312 |
" |
|
1313 |
|p| |
|
1314 |
||
1315 |
p := Point new. |
|
1316 |
MessageTracer trap:p selector:#x:. |
|
1317 |
p x:5 |
|
1318 |
" |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1319 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1320 |
"Modified: 22.10.1996 / 17:39:41 / cg" |
11 | 1321 |
! |
1322 |
||
88 | 1323 |
trap:anObject selectors:aCollection |
1324 |
self wrap:anObject |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1325 |
selectors:aCollection |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1326 |
onEntry:BreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1327 |
onExit:LeaveBreakBlock. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1328 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1329 |
"Modified: 22.10.1996 / 17:39:50 / cg" |
88 | 1330 |
! |
1331 |
||
1332 |
trapAll:anObject |
|
1333 |
"trap on all messages which are understood by anObject" |
|
1334 |
||
1335 |
self wrapAll:anObject |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1336 |
onEntry:BreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1337 |
onExit:LeaveBreakBlock. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1338 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1339 |
"Modified: 22.10.1996 / 17:39:54 / cg" |
88 | 1340 |
! |
1341 |
||
1342 |
trapAll:anObject from:aClass |
|
1343 |
"trap on all messages defined in aClass sent to anObject" |
|
1344 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1345 |
self trap:anObject selectors:aClass selectors |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1346 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1347 |
"Modified: 5.6.1996 / 13:46:06 / stefan" |
88 | 1348 |
! |
1349 |
||
1350 |
untrap:anObject |
|
1351 |
"remove any traps on anObject" |
|
1352 |
||
1353 |
"this is done by just patching the objects class back to the original" |
|
1354 |
||
1355 |
|orgClass| |
|
1356 |
||
1357 |
orgClass := anObject class. |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1358 |
orgClass category == #'* trapping *' ifFalse:[ |
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1359 |
^ self |
88 | 1360 |
]. |
1361 |
||
1362 |
anObject changeClassTo:orgClass superclass |
|
1363 |
||
1364 |
" |
|
1365 |
|p| |
|
1366 |
||
1367 |
p := Point new copy. |
|
1368 |
MessageTracer trace:p selector:#x:. |
|
1369 |
MessageTracer trace:p selector:#y:. |
|
1370 |
p y:1. |
|
1371 |
p x:2. |
|
1372 |
MessageTracer untrap:p |
|
1373 |
p y:2. |
|
1374 |
p x:1. |
|
1375 |
" |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1376 |
|
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1377 |
"Modified: 10.9.1996 / 20:06:07 / cg" |
13 | 1378 |
! |
1379 |
||
88 | 1380 |
untrap:anObject selector:aSelector |
1381 |
"remove trap on aSelector from anObject" |
|
1382 |
||
501 | 1383 |
|orgClass dict| |
88 | 1384 |
|
1385 |
orgClass := anObject class. |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1386 |
orgClass category == #'* trapping *' ifFalse:[^ self]. |
88 | 1387 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1388 |
dict := orgClass methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1389 |
dict at:aSelector ifAbsent:[^ self]. |
88 | 1390 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1391 |
dict size == 1 ifTrue:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1392 |
"the last trap got removed" |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1393 |
anObject changeClassTo:orgClass superclass. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1394 |
^ self |
88 | 1395 |
]. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1396 |
dict removeKey:aSelector. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1397 |
orgClass methodDictionary:dict. |
88 | 1398 |
ObjectMemory flushCaches. "avoid calling the old trap method" |
1399 |
||
1400 |
" |
|
1401 |
|p| |
|
1402 |
||
1403 |
p := Point new copy. |
|
1404 |
MessageTracer trace:p selector:#x:. |
|
1405 |
MessageTracer trace:p selector:#y:. |
|
1406 |
'trace both ...' errorPrintNL. |
|
1407 |
p x:2. |
|
1408 |
p y:1. |
|
1409 |
'trace only y ...' errorPrintNL. |
|
1410 |
MessageTracer untrap:p selector:#x:. |
|
1411 |
p x:2. |
|
1412 |
p y:1. |
|
1413 |
'trace none ...' errorPrintNL. |
|
1414 |
MessageTracer untrap:p selector:#y:. |
|
1415 |
p x:2. |
|
1416 |
p y:1. |
|
1417 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1418 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1419 |
"Modified: 5.6.1996 / 13:56:08 / stefan" |
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1420 |
"Modified: 10.9.1996 / 20:06:14 / cg" |
525 | 1421 |
! |
1422 |
||
1423 |
wrappedSelectorsOf:anObject |
|
1424 |
"return the set of wrapped selectors (if any)" |
|
1425 |
||
1426 |
(anObject class category == #'* trapping *') ifFalse:[ |
|
1427 |
^ #() |
|
1428 |
]. |
|
1429 |
^ anObject class selectors |
|
11 | 1430 |
! ! |
1431 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1432 |
!MessageTracer class methodsFor:'object tracing'! |
88 | 1433 |
|
1434 |
trace:anObject selector:aSelector |
|
1435 |
"arrange for a trace message to be output on Stderr, when a message with |
|
1436 |
aSelector is sent to anObject. Both entry and exit are traced. |
|
1437 |
Use untrap to remove this trace. |
|
1438 |
The current implementation does not allow integers or nil to be traced." |
|
1439 |
||
1440 |
|methodName| |
|
1441 |
||
1442 |
methodName := anObject class name , '>>' , aSelector. |
|
1443 |
self wrap:anObject |
|
538
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1444 |
selector:aSelector |
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1445 |
onEntry:[:con | |
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1446 |
'enter ' errorPrint. methodName errorPrint. |
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1447 |
' receiver=' errorPrint. con receiver printString errorPrint. |
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1448 |
' args=' errorPrint. (con args) printString errorPrint. |
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1449 |
' from:' errorPrint. con sender errorPrintCR. |
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1450 |
] |
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1451 |
onExit:[:con :retVal | |
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1452 |
'leave ' errorPrint. methodName errorPrint. |
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1453 |
' receiver=' errorPrint. con receiver printString errorPrint. |
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1454 |
' returning:' errorPrint. retVal printString errorPrintCR. |
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1455 |
]. |
88 | 1456 |
|
1457 |
" |
|
1458 |
|p| |
|
8 | 1459 |
|
88 | 1460 |
p := Point new. |
1461 |
MessageTracer trace:p selector:#x:. |
|
1462 |
p x:5. |
|
1463 |
p y:1. |
|
1464 |
p x:10. |
|
1465 |
MessageTracer untrap:p. |
|
1466 |
p x:7 |
|
1467 |
" |
|
1468 |
" |
|
1469 |
|a| |
|
1470 |
||
1471 |
a := #(6 1 9 66 2 17) copy. |
|
1472 |
MessageTracer trace:a selector:#at:put:. |
|
1473 |
MessageTracer trace:a selector:#at:. |
|
1474 |
a sort. |
|
1475 |
" |
|
538
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1476 |
|
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1477 |
"Modified: 10.1.1997 / 17:54:50 / cg" |
88 | 1478 |
! |
1479 |
||
1480 |
trace:anObject selectors:aCollection |
|
1481 |
aCollection do:[:aSelector | |
|
1482 |
self trace:anObject selector:aSelector |
|
1483 |
] |
|
1484 |
||
1485 |
" |
|
1486 |
trace all methods in Display, which are implemented |
|
1487 |
in the DisplayWorkstation class. |
|
1488 |
" |
|
1489 |
||
1490 |
" |
|
1491 |
MessageTracer trace:Display selectors:(XWorkstation selectorArray) |
|
1492 |
MessageTracer untrace:Display |
|
1493 |
" |
|
1494 |
! |
|
1495 |
||
1496 |
traceAll:anObject |
|
1497 |
"trace all messages which are understood by anObject" |
|
27 | 1498 |
|
1499 |
|allSelectors| |
|
1500 |
||
1501 |
allSelectors := IdentitySet new. |
|
1502 |
anObject class withAllSuperclasses do:[:aClass | |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1503 |
aClass methodDictionary keys addAllTo:allSelectors |
27 | 1504 |
]. |
88 | 1505 |
self trace:anObject selectors:allSelectors |
1506 |
||
1507 |
" |
|
1508 |
trace all (implemented) messages sent to Display |
|
1509 |
(other messages lead to an error, anyway) |
|
1510 |
" |
|
1511 |
||
1512 |
" |
|
1513 |
MessageTracer traceAll:Display |
|
1514 |
MessageTracer untrace:Display |
|
1515 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1516 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1517 |
"Modified: 5.6.1996 / 13:43:51 / stefan" |
88 | 1518 |
! |
1519 |
||
1520 |
traceAll:anObject from:aClass |
|
1521 |
"trace all messages defined in aClass sent to anObject" |
|
1522 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1523 |
self trace:anObject selectors:aClass selectors |
88 | 1524 |
|
1525 |
" |
|
1526 |
trace all methods in Display, which are implemented |
|
1527 |
in the DisplayWorkstation class. |
|
1528 |
" |
|
1529 |
||
1530 |
" |
|
1531 |
MessageTracer traceAll:Display from:XWorkstation |
|
1532 |
MessageTracer untrace:Display |
|
1533 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1534 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1535 |
"Modified: 5.6.1996 / 13:45:37 / stefan" |
27 | 1536 |
! |
1537 |
||
88 | 1538 |
traceSender:anObject selector:aSelector |
1539 |
"arrange for a trace message to be output on Stderr, when a message with |
|
1540 |
aSelector is sent to anObject. Only the sender is traced on entry. |
|
1541 |
Use untrap to remove this trace. |
|
1542 |
The current implementation does not allow integers or nil to be traced." |
|
1543 |
||
1544 |
|methodName| |
|
1545 |
||
1546 |
methodName := anObject class name , '>>' , aSelector. |
|
1547 |
self wrap:anObject |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1548 |
selector:aSelector |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1549 |
onEntry:[:con | |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1550 |
methodName errorPrint. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1551 |
' from ' errorPrint. |
538
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1552 |
con sender errorPrintCR. |
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1553 |
] |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1554 |
onExit:LeaveTraceBlock. |
88 | 1555 |
|
1556 |
" |
|
1557 |
|p| |
|
27 | 1558 |
|
88 | 1559 |
p := Point new. |
1560 |
MessageTracer traceSender:p selector:#x:. |
|
1561 |
p x:5. |
|
1562 |
p y:1. |
|
1563 |
p x:10. |
|
1564 |
MessageTracer untrap:p. |
|
1565 |
p x:7 |
|
1566 |
" |
|
1567 |
" |
|
1568 |
|a| |
|
1569 |
||
1570 |
a := #(6 1 9 66 2 17) copy. |
|
1571 |
MessageTracer traceSender:a selector:#at:put:. |
|
1572 |
MessageTracer traceSender:a selector:#at:. |
|
1573 |
a sort. |
|
1574 |
" |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1575 |
|
538
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1576 |
"Modified: 10.1.1997 / 17:54:53 / cg" |
11 | 1577 |
! |
1578 |
||
88 | 1579 |
untrace:anObject |
1580 |
"remove any traces on anObject" |
|
1581 |
||
1582 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
1583 |
trace facilities ..." |
|
1584 |
||
1585 |
^ self untrap:anObject |
|
1586 |
! |
|
1587 |
||
1588 |
untrace:anObject selector:aSelector |
|
1589 |
"remove traces of aSelector sent to anObject" |
|
1590 |
||
1591 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
1592 |
trace facilities ..." |
|
1593 |
||
1594 |
^ self untrap:anObject selector:aSelector |
|
1595 |
! ! |
|
1596 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1597 |
!MessageTracer class methodsFor:'object wrapping'! |
88 | 1598 |
|
8 | 1599 |
wrap:anObject selector:aSelector onEntry:entryBlock onExit:exitBlock |
1600 |
"arrange for the two blocks entryBlock and exitBlock to be evaluated whenever |
|
1601 |
a message with aSelector is sent to anObject. EntryBlock will be called on |
|
1602 |
entry, and get the current context passed as argument. ExitBlock will be called, |
|
1603 |
when the method is left, and get the context and the methods return value as arguments. |
|
1604 |
The current implementation does not allow integers or nil to be wrapped." |
|
1605 |
||
1606 |
"I have not yet enough experience, if the wrapped original method should |
|
1607 |
run as an instance of the original, or of the catching class; |
|
1608 |
The latter has the advantage of catching recursive and other sends, while |
|
1609 |
it might lead into trouble when the message is sent from a debugger or a long |
|
1610 |
return is done out of the original method ... |
|
1611 |
Time will show, you can experiment by setting the withOriginalClass: flag to false |
|
1612 |
" |
|
1613 |
^ self wrap:anObject selector:aSelector onEntry:entryBlock onExit:exitBlock withOriginalClass:true |
|
1614 |
! |
|
1615 |
||
1616 |
wrap:anObject selector:aSelector onEntry:entryBlock onExit:exitBlock withOriginalClass:withOriginalClass |
|
1617 |
"arrange for the two blocks entryBlock and exitBlock to be evaluated whenever |
|
1618 |
a message with aSelector is sent to anObject. EntryBlock will be called on |
|
1619 |
entry, and get the current context passed as argument. ExitBlock will be called, |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1620 |
when the method is left, and get the current context and the methods return value as argument. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1621 |
If withOriginalClass is true, the class of anObject will be set to its original class |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1622 |
before the wrapped method will be called. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1623 |
NOTICE: The current implementation does not allow integers or nil to be wrapped." |
8 | 1624 |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1625 |
|newClass orgClass myMetaclass trapMethod s spec implClass save dict| |
8 | 1626 |
|
1627 |
" |
|
27 | 1628 |
some are not allowed (otherwise we get into trouble ...) |
1629 |
" |
|
1630 |
(#(class changeClassTo:) includes:aSelector) ifTrue:[ |
|
256 | 1631 |
Transcript showCR:'sorry, cannot place trap on: ' , aSelector. |
1632 |
^ self |
|
27 | 1633 |
]. |
1634 |
||
1635 |
WrappedMethod autoload. "/ just to make sure ... |
|
1636 |
||
1637 |
" |
|
8 | 1638 |
create a new (anonymous) subclass of the receivers class |
1639 |
but only if not already being trapped. |
|
1640 |
" |
|
1641 |
orgClass := anObject class. |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1642 |
orgClass category == #'* trapping *' ifTrue:[ |
256 | 1643 |
newClass := orgClass |
8 | 1644 |
] ifFalse:[ |
256 | 1645 |
myMetaclass := orgClass class. |
8 | 1646 |
|
256 | 1647 |
newClass := myMetaclass copy new. |
1648 |
newClass setSuperclass:orgClass. |
|
1649 |
newClass instSize:orgClass instSize. |
|
1650 |
newClass flags:orgClass flags. |
|
1651 |
newClass setClassVariableString:''. |
|
1652 |
newClass setInstanceVariableString:''. |
|
1653 |
newClass setName:orgClass name. |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1654 |
newClass category:#'* trapping *'. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1655 |
newClass methodDictionary:MethodDictionary new. |
8 | 1656 |
]. |
1657 |
||
1658 |
" |
|
1659 |
create a method, executing the trap-blocks and the original method via a super-send |
|
1660 |
" |
|
1661 |
spec := Parser methodSpecificationForSelector:aSelector. |
|
1662 |
s := WriteStream on:String new. |
|
1663 |
s nextPutAll:spec. |
|
27 | 1664 |
s nextPutAll:' |retVal stubClass| '. |
8 | 1665 |
withOriginalClass ifTrue:[ |
256 | 1666 |
s nextPutAll:'stubClass := self class. '. |
1667 |
s nextPutAll:'self changeClassTo:(stubClass superclass). '. |
|
8 | 1668 |
]. |
1669 |
entryBlock notNil ifTrue:[ |
|
256 | 1670 |
s nextPutAll:'#literal1 yourself value:thisContext. '. |
8 | 1671 |
]. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1672 |
s nextPutAll:('retVal := #originalMethod. '). "/ just to get a place for the originalMethod |
27 | 1673 |
s nextPutAll:('retVal := super ' , spec , '. '). |
8 | 1674 |
exitBlock notNil ifTrue:[ |
256 | 1675 |
s nextPutAll:'#literal2 yourself value:thisContext value:retVal. '. |
8 | 1676 |
]. |
1677 |
withOriginalClass ifTrue:[ |
|
256 | 1678 |
s nextPutAll:'self changeClassTo:stubClass. '. |
8 | 1679 |
]. |
1680 |
s nextPutAll:'^ retVal'; cr. |
|
1681 |
||
37 | 1682 |
save := Compiler stcCompilation. |
1683 |
Compiler stcCompilation:#never. |
|
1684 |
[ |
|
256 | 1685 |
Class withoutUpdatingChangesDo:[ |
1686 |
trapMethod := Compiler compile:s contents |
|
1687 |
forClass:newClass |
|
1688 |
inCategory:'breakpointed' |
|
1689 |
notifying:nil |
|
1690 |
install:false |
|
1691 |
skipIfSame:false |
|
1692 |
silent:true. |
|
1693 |
] |
|
37 | 1694 |
] valueNowOrOnUnwindDo:[ |
256 | 1695 |
Compiler stcCompilation:save |
37 | 1696 |
]. |
8 | 1697 |
|
29 | 1698 |
implClass := orgClass whichClassIncludesSelector:aSelector. |
1699 |
implClass isNil ifTrue:[ |
|
256 | 1700 |
Transcript showCR:aSelector , ' is not understood by ' , orgClass name. |
29 | 1701 |
] ifFalse:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1702 |
trapMethod changeLiteral:#originalMethod to:(implClass compiledMethodAt:aSelector). |
29 | 1703 |
]. |
8 | 1704 |
entryBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1705 |
trapMethod changeLiteral:#literal1 to:entryBlock. |
8 | 1706 |
]. |
1707 |
exitBlock notNil ifTrue:[ |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1708 |
trapMethod changeLiteral:#literal2 to:exitBlock. |
8 | 1709 |
]. |
1710 |
" |
|
1711 |
change the source of this new method |
|
1712 |
(to avoid confusion in the debugger ...) |
|
1713 |
" |
|
1714 |
trapMethod source:'this is a wrapper method - not the real one'. |
|
27 | 1715 |
trapMethod changeClassTo:WrappedMethod. |
8 | 1716 |
|
1717 |
" |
|
1718 |
install this new method |
|
1719 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1720 |
dict := newClass methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1721 |
dict := dict at:aSelector putOrAppend:trapMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1722 |
newClass methodDictionary:dict. |
8 | 1723 |
|
1724 |
" |
|
1725 |
and finally, the big trick: |
|
1726 |
" |
|
1727 |
anObject changeClassTo:newClass |
|
1728 |
||
1729 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1730 |
[exBegin] |
8 | 1731 |
|p| |
1732 |
||
1733 |
p := Point new copy. |
|
1734 |
MessageTracer |
|
256 | 1735 |
wrap:p |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1736 |
selector:#y: |
256 | 1737 |
onEntry:nil |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1738 |
onExit:[:context :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1739 |
Transcript show:'leave Point>>y:, returning:'. |
256 | 1740 |
Transcript showCR:retVal printString. |
1741 |
Transcript endEntry |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1742 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1743 |
withOriginalClass:true. |
256 | 1744 |
Transcript showCR:'sending x: ...'. |
8 | 1745 |
p x:1. |
256 | 1746 |
Transcript showCR:'sending y: ...'. |
8 | 1747 |
p y:2. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1748 |
MessageTracer untrap:p. |
256 | 1749 |
Transcript showCR:'sending x: ...'. |
8 | 1750 |
p x:2. |
256 | 1751 |
Transcript showCR:'sending y: ...'. |
8 | 1752 |
p y:1. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1753 |
[exEnd] |
8 | 1754 |
" |
1755 |
||
1756 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1757 |
[exBegin] |
8 | 1758 |
|p| |
1759 |
||
1760 |
p := Point new copy. |
|
1761 |
MessageTracer wrap:p |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1762 |
selector:#y: |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1763 |
onEntry:[:context | self halt:'y: you are trapped'] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1764 |
onExit:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1765 |
withOriginalClass:false. |
256 | 1766 |
Transcript showCR:'sending x: ...'. |
8 | 1767 |
p x:1. |
256 | 1768 |
Transcript showCR:'sending y: ...'. |
8 | 1769 |
p y:2. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1770 |
MessageTracer untrap:p. |
256 | 1771 |
Transcript showCR:'sending x: ...'. |
8 | 1772 |
p x:2. |
256 | 1773 |
Transcript showCR:'sending y: ...'. |
8 | 1774 |
p y:1. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1775 |
[exEnd] |
8 | 1776 |
" |
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
1777 |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1778 |
"Modified: 25.6.1996 / 22:11:21 / stefan" |
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1779 |
"Modified: 10.9.1996 / 20:06:54 / cg" |
8 | 1780 |
! |
1781 |
||
88 | 1782 |
wrap:anObject selectors:aCollection onEntry:entryBlock onExit:exitBlock |
1783 |
"install wrappers for anObject on all selectors from aCollection" |
|
8 | 1784 |
|
88 | 1785 |
aCollection do:[:aSelector | |
1786 |
self wrap:anObject selector:aSelector onEntry:entryBlock onExit:exitBlock |
|
1787 |
] |
|
8 | 1788 |
! |
1789 |
||
88 | 1790 |
wrapAll:anObject onEntry:entryBlock onExit:exitBlock |
1791 |
"install wrappers for anObject on all implemented selectors" |
|
27 | 1792 |
|
1793 |
|allSelectors| |
|
1794 |
||
1795 |
allSelectors := IdentitySet new. |
|
1796 |
anObject class withAllSuperclasses do:[:aClass | |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1797 |
aClass methodDictionary keys addAllTo:allSelectors |
27 | 1798 |
]. |
88 | 1799 |
self wrap:anObject selectors:allSelectors onEntry:entryBlock onExit:exitBlock |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1800 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1801 |
"Modified: 5.6.1996 / 14:50:07 / stefan" |
88 | 1802 |
! ! |
1803 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1804 |
!MessageTracer class methodsFor:'queries'! |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1805 |
|
579 | 1806 |
isCounting:aMethod |
1807 |
"return true if aMethod is counted" |
|
1808 |
||
1809 |
MethodCounts isNil ifTrue:[^ false]. |
|
1810 |
(MethodCounts includesKey:aMethod) ifTrue:[^ true]. |
|
1811 |
aMethod isWrapped ifTrue:[ |
|
1812 |
^ MethodCounts includesKey:aMethod originalMethod |
|
1813 |
]. |
|
1814 |
^ false |
|
1815 |
||
1816 |
"Created: 15.12.1995 / 11:07:58 / cg" |
|
1817 |
"Modified: 15.12.1995 / 15:42:10 / cg" |
|
1818 |
! |
|
1819 |
||
1820 |
isTiming:aMethod |
|
1821 |
"return true if aMethod is timed" |
|
1822 |
||
1823 |
MethodTiming isNil ifTrue:[^ false]. |
|
1824 |
(MethodTiming includesKey:aMethod) ifTrue:[^ true]. |
|
1825 |
aMethod isWrapped ifTrue:[ |
|
1826 |
^ MethodTiming includesKey:aMethod originalMethod |
|
1827 |
]. |
|
1828 |
^ false |
|
1829 |
||
1830 |
"Modified: 15.12.1995 / 15:42:10 / cg" |
|
1831 |
"Created: 17.6.1996 / 17:04:29 / cg" |
|
1832 |
! |
|
1833 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1834 |
isTrapped:aMethod |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1835 |
"return true, if a breakpoint is set on aMethod. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1836 |
This only returns true for standard breakpoints (i.e. for user-wraps, |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1837 |
this returns false)" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1838 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1839 |
aMethod isWrapped ifFalse:[^ false]. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1840 |
^ aMethod basicLiterals includesIdentical:LeaveBreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1841 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1842 |
" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1843 |
MessageTracer trapMethod:(Collection compiledMethodAt:#select:). |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1844 |
Transcript showCR:(Collection compiledMethodAt:#select:) isWrapped. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1845 |
Transcript showCR:(MessageTracer isTrapped:(Collection compiledMethodAt:#select:)). |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1846 |
MessageTracer unwrapMethod:(Collection compiledMethodAt:#select:). |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1847 |
" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1848 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1849 |
"Modified: 22.10.1996 / 17:40:37 / cg" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1850 |
! ! |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1851 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1852 |
!MessageTracer class methodsFor:'trace helpers'! |
88 | 1853 |
|
1854 |
printEntryFull:aContext |
|
1855 |
self printEntryFull:aContext level:0 |
|
1856 |
! |
|
27 | 1857 |
|
88 | 1858 |
printEntryFull:aContext level:lvl |
555
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
1859 |
|sender| |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
1860 |
|
88 | 1861 |
(String new:lvl) errorPrint. |
1862 |
'enter ' errorPrint. |
|
1863 |
aContext methodClass name errorPrint. |
|
1864 |
' ' errorPrint. |
|
1865 |
aContext selector errorPrint. |
|
1866 |
' rcvr=' errorPrint. |
|
1867 |
aContext receiver "printString" errorPrint. |
|
1868 |
' args=' errorPrint. |
|
1869 |
(aContext args) "printString" errorPrint. |
|
555
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
1870 |
' from:' errorPrint. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
1871 |
sender := aContext sender. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
1872 |
sender notNil ifTrue:[ |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
1873 |
(sender selector startsWith:'perform:') ifTrue:[ |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
1874 |
sender := sender sender. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
1875 |
]. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
1876 |
]. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
1877 |
sender errorPrintCR. |
538
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1878 |
|
555
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
1879 |
"Modified: 5.3.1997 / 12:40:55 / cg" |
88 | 1880 |
! |
27 | 1881 |
|
88 | 1882 |
printEntrySender:aContext |
555
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
1883 |
|sender| |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
1884 |
|
88 | 1885 |
aContext methodClass name errorPrint. |
1886 |
' ' errorPrint. aContext selector errorPrint. |
|
1887 |
' from ' errorPrint. |
|
538
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1888 |
|
555
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
1889 |
sender := aContext sender. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
1890 |
sender notNil ifTrue:[ |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
1891 |
(sender selector startsWith:'perform:') ifTrue:[ |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
1892 |
sender := sender sender. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
1893 |
]. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
1894 |
]. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
1895 |
sender errorPrintCR. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
1896 |
|
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
1897 |
"Modified: 5.3.1997 / 12:40:42 / cg" |
88 | 1898 |
! |
1899 |
||
1900 |
printExit:aContext with:retVal |
|
1901 |
self printExit:aContext with:retVal level:0 |
|
27 | 1902 |
! |
1903 |
||
88 | 1904 |
printExit:aContext with:retVal level:lvl |
1905 |
(String new:lvl) errorPrint. |
|
1906 |
'leave ' errorPrint. |
|
1907 |
aContext methodClass name errorPrint. |
|
1908 |
' ' errorPrint. |
|
1909 |
aContext selector errorPrint. |
|
1910 |
' rcvr=' errorPrint. |
|
1911 |
aContext receiver "printString" errorPrint. |
|
538
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1912 |
' return:' errorPrint. retVal "printString" errorPrintCR. |
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1913 |
|
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1914 |
"Modified: 10.1.1997 / 17:54:44 / cg" |
88 | 1915 |
! ! |
13 | 1916 |
|
88 | 1917 |
!MessageTracer methodsFor:'trace helpers '! |
1918 |
||
1919 |
stepInterrupt |
|
1920 |
"called for every send while tracing" |
|
13 | 1921 |
|
88 | 1922 |
|con| |
13 | 1923 |
|
88 | 1924 |
StepInterruptPending := nil. |
1925 |
con := thisContext sender. |
|
1926 |
con lineNumber == 1 ifTrue:[ |
|
265 | 1927 |
traceDetail == true ifTrue:[ |
1928 |
self class printEntryFull:con. |
|
1929 |
] ifFalse:[ |
|
1930 |
con printCR. |
|
1931 |
] |
|
88 | 1932 |
]. |
1933 |
ObjectMemory flushInlineCaches. |
|
1934 |
StepInterruptPending := 1. |
|
1935 |
InterruptPending := 1. |
|
1936 |
^ self |
|
265 | 1937 |
|
1938 |
"Modified: 20.5.1996 / 10:28:20 / cg" |
|
13 | 1939 |
! |
1940 |
||
88 | 1941 |
trace:aBlock detail:fullDetail |
1942 |
"trace execution of aBlock." |
|
1943 |
||
1944 |
traceDetail := fullDetail. |
|
1945 |
ObjectMemory stepInterruptHandler:self. |
|
1946 |
^ [ |
|
1947 |
ObjectMemory flushInlineCaches. |
|
1948 |
StepInterruptPending := 1. |
|
1949 |
InterruptPending := 1. |
|
1950 |
aBlock value |
|
1951 |
] valueNowOrOnUnwindDo:[ |
|
1952 |
StepInterruptPending := nil. |
|
1953 |
ObjectMemory stepInterruptHandler:nil. |
|
11 | 1954 |
] |
1955 |
||
1956 |
" |
|
88 | 1957 |
MessageTracer trace:[#(6 5 4 3 2 1) sort] detail:false |
1958 |
MessageTracer trace:[#(6 5 4 3 2 1) sort] detail:true |
|
8 | 1959 |
" |
1960 |
! ! |
|
27 | 1961 |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1962 |
!MessageTracer class methodsFor:'documentation'! |
98 | 1963 |
|
1964 |
version |
|
584
2da6bb2c8017
send out change notifications when a trap is removed
Claus Gittinger <cg@exept.de>
parents:
579
diff
changeset
|
1965 |
^ '$Header: /cvs/stx/stx/libbasic3/MessageTracer.st,v 1.55 1997-04-24 16:22:58 cg Exp $' |
98 | 1966 |
! ! |
27 | 1967 |
MessageTracer initialize! |