author | Stefan Vogel <sv@exept.de> |
Fri, 03 Apr 2009 14:29:29 +0200 | |
changeset 2085 | 21d40e42e3fa |
parent 2004 | 9fb45e84f02c |
child 2243 | 886bcbcd310e |
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 |
" |
|
950 | 12 |
"{ Package: 'stx:libbasic3' }" |
13 |
||
120 | 14 |
Object subclass:#MessageTracer |
735 | 15 |
instanceVariableNames:'traceDetail tracedBlock' |
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
16 |
classVariableNames:'BreakpointSignal CallingLevel BreakBlock TraceSenderBlock |
664 | 17 |
TraceSenderBlock2 LeaveBreakBlock LeaveTraceBlock MethodCounts |
18 |
MethodMemoryUsage MethodTiming TraceFullBlock TraceFullBlock2 |
|
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
19 |
ObjectWrittenBreakpointSignal ObjectCopyHolders TimeForWrappers' |
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
20 |
poolDictionaries:'' |
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
21 |
category:'System-Debugging-Support' |
8 | 22 |
! |
23 |
||
1008
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
24 |
MessageTracer subclass:#InteractionCollector |
735 | 25 |
instanceVariableNames:'' |
26 |
classVariableNames:'' |
|
27 |
poolDictionaries:'' |
|
28 |
privateIn:MessageTracer |
|
29 |
! |
|
30 |
||
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
31 |
Object subclass:#MethodTimingInfo |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
32 |
instanceVariableNames:'count minTime maxTime sumTimes avgTime' |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
33 |
classVariableNames:'' |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
34 |
poolDictionaries:'' |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
35 |
privateIn:MessageTracer |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
36 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
37 |
|
1008
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
38 |
MessageTracer subclass:#PrintingMessageTracer |
735 | 39 |
instanceVariableNames:'' |
734 | 40 |
classVariableNames:'' |
41 |
poolDictionaries:'' |
|
42 |
privateIn:MessageTracer |
|
43 |
! |
|
44 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
45 |
!MessageTracer class methodsFor:'documentation'! |
8 | 46 |
|
9 | 47 |
copyright |
48 |
" |
|
49 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
11 | 50 |
All Rights Reserved |
9 | 51 |
|
52 |
This software is furnished under a license and may be used |
|
53 |
only in accordance with the terms of that license and with the |
|
54 |
inclusion of the above copyright notice. This software may not |
|
55 |
be provided or otherwise made available to, or used by, any |
|
56 |
other person. No title to or ownership of the software is |
|
57 |
hereby transferred. |
|
58 |
" |
|
59 |
! |
|
60 |
||
8 | 61 |
documentation |
62 |
" |
|
11 | 63 |
This class provides a common home for the tracing |
64 |
facilities (originally, they where in Object, but have been moved to |
|
8 | 65 |
allow easier separation of development vs. runtime configurations. |
66 |
||
11 | 67 |
tracing execution of a block: |
68 |
||
236 | 69 |
MessageTracer trace:[ ... ] |
11 | 70 |
|
236 | 71 |
MessageTracer traceFull:[ ... ] |
11 | 72 |
|
825 | 73 |
(for system developer only:) |
11 | 74 |
|
236 | 75 |
MessageTracer debugTrace:[ ... ] |
11 | 76 |
|
77 |
||
8 | 78 |
trapping sends to a specific object: |
79 |
||
236 | 80 |
MessageTracer trap:anObject selector:aSelector |
81 |
... |
|
82 |
MessageTracer untrap:anObject selector:aSelector |
|
83 |
or: |
|
84 |
MessageTracer untrap:anObject |
|
11 | 85 |
|
8 | 86 |
|
87 |
||
27 | 88 |
trapping some messages sent to a specific object: |
89 |
||
236 | 90 |
MessageTracer trap:anObject selectors:aCollectionOfSelectors |
91 |
... |
|
92 |
MessageTracer untrap:anObject |
|
27 | 93 |
|
94 |
||
95 |
||
96 |
trapping any message sent to a specific object: |
|
97 |
||
236 | 98 |
MessageTracer trapAll:anObject |
99 |
... |
|
100 |
MessageTracer untrap:anObject |
|
27 | 101 |
|
102 |
||
103 |
||
8 | 104 |
trapping evaluation of a specific method: |
105 |
||
236 | 106 |
MessageTracer trapMethod:aMethod |
107 |
... |
|
108 |
MessageTracer unwrapMethod:aMethod |
|
8 | 109 |
|
110 |
||
111 |
||
12 | 112 |
trapping evaluation of a specific method with |
113 |
receiver being an instance of some class: |
|
114 |
||
236 | 115 |
MessageTracer trapMethod:aMethod forInstancesOf:aClass |
116 |
... |
|
117 |
MessageTracer unwrapMethod:aMethod |
|
12 | 118 |
|
119 |
||
120 |
||
8 | 121 |
tracing sends to a specific object: |
122 |
||
236 | 123 |
MessageTracer trace:anObject selector:aSelector |
124 |
... |
|
125 |
MessageTracer untrace:anObject selector:aSelector |
|
126 |
or: |
|
127 |
MessageTracer untrace:anObject |
|
11 | 128 |
|
8 | 129 |
|
130 |
||
131 |
tracing sender only: |
|
132 |
||
236 | 133 |
MessageTracer traceSender:anObject selector:aSelector |
134 |
... |
|
135 |
MessageTracer untrace:anObject selector:aSelector |
|
136 |
or: |
|
137 |
MessageTracer untrace:anObject |
|
11 | 138 |
|
8 | 139 |
|
140 |
||
141 |
tracing evaluation of a specific method: |
|
142 |
||
236 | 143 |
MessageTracer traceMethod:aMethod |
144 |
... |
|
145 |
MessageTracer unwrapmethod:aMethod |
|
18 | 146 |
|
147 |
see more in examples and in method comments. |
|
236 | 148 |
|
149 |
[author:] |
|
150 |
Claus Gittinger |
|
8 | 151 |
" |
12 | 152 |
! |
153 |
||
154 |
examples |
|
155 |
" |
|
156 |
For the common cases, you will find a menu entry in the SystemBrowser. |
|
157 |
Howeever, more special cases (especially with condition checks) can be |
|
158 |
set up by evaluating the lower level entries. |
|
159 |
||
160 |
||
161 |
trapping specific methods: |
|
162 |
(by class/selector): |
|
244 | 163 |
[exBegin] |
12 | 164 |
MessageTracer trapClass:Collection selector:#select:. |
591 | 165 |
Dictionary new select:[:e | ]. 'not caught - Dictionary has its own select'. |
166 |
(Array new:10) select:[:e | ]. 'not caught - SeqColl has its own select'. |
|
167 |
Set new select:[:e | ]. 'caught - Set inherits this from Collection'. |
|
12 | 168 |
MessageTracer untrapClass:Collection |
244 | 169 |
[exEnd] |
12 | 170 |
|
171 |
(by method): |
|
244 | 172 |
[exBegin] |
12 | 173 |
MessageTracer trapMethod:(Collection compiledMethodAt:#select:). |
591 | 174 |
Dictionary new select:[:e | ]. 'not caught - Dictionary has its own select'. |
175 |
(Array new:10) select:[:e | ]. 'not caught - SeqColl has its own select'. |
|
176 |
Set new select:[:e | ]. 'caught - Set inherits this from Collection'. |
|
12 | 177 |
MessageTracer unwrapMethod:(Collection compiledMethodAt:#select:). |
244 | 178 |
[exEnd] |
12 | 179 |
|
27 | 180 |
(by method & instance class): |
244 | 181 |
[exBegin] |
27 | 182 |
MessageTracer trapMethod:(SequenceableCollection compiledMethodAt:#select:) |
244 | 183 |
forInstancesOf:SortedCollection. |
591 | 184 |
Dictionary new select:[:e | ]. 'not caught - Dictionary has its own select'. |
185 |
(Array new:10) select:[:e | ]. 'not caught - not a SortedCollection'. |
|
186 |
OrderedCollection new select:[:e | ]. 'not caught - not a SortedCollection'. |
|
187 |
SortedCollection new select:[:e | ]. 'caught - Set inherits this from Collection'. |
|
27 | 188 |
MessageTracer unwrapMethod:(SequenceableCollection compiledMethodAt:#select:). |
244 | 189 |
[exEnd] |
27 | 190 |
|
12 | 191 |
tracing specific methods: |
192 |
(by class/selector): |
|
244 | 193 |
[exBegin] |
12 | 194 |
MessageTracer traceClass:SequenceableCollection selector:#quickSortFrom:to:. |
195 |
#(6 1 9 66 2 17) copy sort. |
|
196 |
MessageTracer untraceClass:SequenceableCollection |
|
244 | 197 |
[exEnd] |
12 | 198 |
|
199 |
(by method): |
|
244 | 200 |
[exBegin] |
12 | 201 |
MessageTracer traceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
202 |
#(6 1 9 66 2 17) copy sort. |
|
203 |
MessageTracer unwrapMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
244 | 204 |
[exEnd] |
27 | 205 |
|
206 |
object trapping: |
|
244 | 207 |
[exBegin] |
27 | 208 |
|o| |
209 |
||
210 |
o := OrderedCollection new. |
|
211 |
MessageTracer trapAll:o. |
|
212 |
o collect:[:el | el]. |
|
244 | 213 |
[exEnd] |
661 | 214 |
|
215 |
trapping modifications to an objects instVars: |
|
216 |
[exBegin] |
|
217 |
|o| |
|
218 |
||
219 |
o := Point new. |
|
220 |
MessageTracer trapModificationsIn:o. |
|
221 |
o x:1. |
|
222 |
o y:2. |
|
223 |
o x:1. |
|
224 |
o y:2. |
|
225 |
MessageTracer untrap:o |
|
226 |
[exEnd] |
|
227 |
||
228 |
trapping modifications of a particular instVar: |
|
229 |
[exBegin] |
|
230 |
|o| |
|
231 |
||
232 |
o := Point new. |
|
233 |
MessageTracer trapModificationsIn:o filter:[:old :new | old x ~~ new x]. |
|
234 |
o x:1. |
|
235 |
o y:2. |
|
236 |
o x:1. |
|
237 |
o y:2. |
|
238 |
MessageTracer untrap:o |
|
239 |
[exEnd] |
|
12 | 240 |
" |
8 | 241 |
! ! |
242 |
||
664 | 243 |
!MessageTracer class methodsFor:'Signal constants'! |
244 |
||
245 |
breakpointSignal |
|
246 |
^ BreakpointSignal |
|
247 |
! |
|
248 |
||
249 |
objectWrittenBreakpointSignal |
|
250 |
^ ObjectWrittenBreakpointSignal |
|
251 |
||
252 |
"Created: / 21.4.1998 / 14:38:49 / cg" |
|
253 |
! ! |
|
254 |
||
255 |
!MessageTracer class methodsFor:'class initialization'! |
|
11 | 256 |
|
257 |
initialize |
|
258 |
BreakpointSignal isNil ifTrue:[ |
|
1072 | 259 |
"/ BreakpointSignal := HaltSignal newSignalMayProceed:true. |
260 |
"/ BreakpointSignal nameClass:self message:#breakpointSignal. |
|
261 |
BreakpointSignal := BreakPointInterrupt. |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
262 |
BreakpointSignal notifierString:'breakpoint encountered'. |
1072 | 263 |
]. |
264 |
||
265 |
ObjectWrittenBreakpointSignal isNil ifTrue:[ |
|
660 | 266 |
ObjectWrittenBreakpointSignal := BreakpointSignal newSignalMayProceed:true. |
267 |
ObjectWrittenBreakpointSignal nameClass:self message:#objectWrittenBreakpointSignal. |
|
268 |
ObjectWrittenBreakpointSignal notifierString:'object modified'. |
|
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
269 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
270 |
|
1072 | 271 |
"/ the following have been written as cheapBlocks (by purpose) |
272 |
BreakBlock := [:con | BreakpointSignal raiseRequestWith:nil errorString:nil in:con]. |
|
273 |
TraceSenderBlock := [:con | MessageTracer printEntrySender:con on:(Smalltalk at:#Stderr) ]. |
|
274 |
TraceSenderBlock2 := [:con | MessageTracer printEntrySender:con on:(Smalltalk at:#Transcript) ]. |
|
275 |
TraceFullBlock := [:con | MessageTracer traceEntryFull:con on:(Smalltalk at:#Stderr) ]. |
|
276 |
TraceFullBlock2 := [:con | MessageTracer traceEntryFull:con on:(Smalltalk at:#Transcript) ]. |
|
277 |
LeaveBreakBlock := [:con :retVal | ]. |
|
278 |
LeaveTraceBlock := [:con :retVal | ]. |
|
279 |
||
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
280 |
ObjectMemory addDependent:self. |
156 | 281 |
|
282 |
" |
|
283 |
BreakpointSignal := nil. |
|
284 |
MessageTracer initialize |
|
285 |
" |
|
286 |
||
695 | 287 |
"Modified: / 30.7.1998 / 20:41:29 / cg" |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
288 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
289 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
290 |
update:something with:parameter from:changedObject |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
291 |
"sent when restarted after a snapIn" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
292 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
293 |
(something == #restarted) ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
294 |
TimeForWrappers := nil |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
295 |
] |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
296 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
297 |
"Created: / 30.7.1998 / 17:00:09 / cg" |
11 | 298 |
! ! |
299 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
300 |
!MessageTracer class methodsFor:'class tracing'! |
88 | 301 |
|
302 |
untraceAllClasses |
|
303 |
"remove all traces of messages sent to any class" |
|
304 |
||
305 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
306 |
trace facilities ..." |
|
307 |
||
308 |
^ self untrapAllClasses |
|
309 |
! |
|
310 |
||
311 |
untraceClass:aClass |
|
312 |
"remove all traces of messages sent to instances of aClass" |
|
313 |
||
314 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
315 |
trace facilities ..." |
|
316 |
||
317 |
^ self untrapClass:aClass |
|
318 |
! ! |
|
319 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
320 |
!MessageTracer class methodsFor:'class wrapping'! |
88 | 321 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
322 |
wrapClass:orgClass selector:aSelector onEntry:entryBlock onExit:exitBlock |
88 | 323 |
"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
|
324 |
aSelector is sent to instances of orgClass or subclasses. |
88 | 325 |
EntryBlock will be called on entry, and get the current context passed as argument. |
326 |
ExitBlock will be called, when the method is left, and get context and the methods return value as arguments. |
|
327 |
" |
|
328 |
||
1452 | 329 |
|myMetaclass trapMethod s spec implClass newClass dict| |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
330 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
331 |
WrappedMethod autoload. "/ just to make sure ... |
88 | 332 |
|
333 |
" |
|
334 |
create a new method, which calls the original one, |
|
335 |
but only if not already being trapped. |
|
336 |
" |
|
337 |
spec := Parser methodSpecificationForSelector:aSelector. |
|
338 |
||
339 |
s := WriteStream on:String new. |
|
340 |
s nextPutAll:spec. |
|
341 |
s cr. |
|
342 |
s nextPutAll:'|retVal stubClass|'; cr. |
|
343 |
entryBlock notNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
344 |
s nextPutAll:'#literal1 yourself value:thisContext.'; cr. |
88 | 345 |
]. |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
346 |
s nextPutAll:('retVal := #originalMethod. '). "/ just to get a literal to be replaced by theoriginal method |
88 | 347 |
s nextPutAll:('retVal := super ' , spec , '.'); cr. |
348 |
exitBlock notNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
349 |
s nextPutAll:'#literal2 yourself value:thisContext value:retVal.'; cr. |
88 | 350 |
]. |
351 |
s nextPutAll:'^ retVal'; cr. |
|
352 |
||
1452 | 353 |
ParserFlags |
354 |
withSTCCompilation:#never |
|
355 |
do:[ |
|
356 |
Class withoutUpdatingChangesDo:[ |
|
357 |
trapMethod := Compiler compile:s contents |
|
358 |
forClass:orgClass |
|
359 |
inCategory:'trapping' |
|
360 |
notifying:nil |
|
361 |
install:false |
|
362 |
skipIfSame:false |
|
363 |
silent:true. |
|
364 |
] |
|
365 |
]. |
|
88 | 366 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
367 |
implClass := orgClass whichClassIncludesSelector:aSelector. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
368 |
implClass isNil ifTrue:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
369 |
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
|
370 |
] ifFalse:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
371 |
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
|
372 |
]. |
88 | 373 |
entryBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
374 |
trapMethod changeLiteral:#literal1 to:entryBlock. |
88 | 375 |
]. |
376 |
exitBlock notNil ifTrue:[ |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
377 |
trapMethod changeLiteral:#literal2 to:exitBlock. |
88 | 378 |
]. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
379 |
|
88 | 380 |
" |
381 |
change the source of this new method |
|
382 |
(to avoid confusion in the debugger ...) |
|
383 |
" |
|
384 |
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
|
385 |
trapMethod changeClassTo:WrappedMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
386 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
387 |
dict := orgClass methodDictionary. |
88 | 388 |
|
389 |
" |
|
390 |
if not already trapping, create a new class |
|
391 |
" |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
392 |
orgClass category == #'* trapping *' ifTrue:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
393 |
dict at:aSelector put:trapMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
394 |
orgClass methodDictionary:dict. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
395 |
newClass := orgClass superclass. |
88 | 396 |
] ifFalse:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
397 |
myMetaclass := orgClass class. |
88 | 398 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
399 |
newClass := myMetaclass copy new. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
400 |
newClass setSuperclass:orgClass superclass. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
401 |
newClass instSize:orgClass instSize. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
402 |
newClass flags:orgClass flags. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
403 |
newClass setClassVariableString:orgClass classVariableString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
404 |
newClass setInstanceVariableString:orgClass instanceVariableString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
405 |
newClass setName:orgClass name. |
1320
f346fa1fdb3a
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
406 |
newClass setCategory:orgClass category. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
407 |
newClass methodDictionary:dict. |
88 | 408 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
409 |
orgClass setSuperclass:newClass. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
410 |
orgClass setClassVariableString:''. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
411 |
orgClass setInstanceVariableString:''. |
1320
f346fa1fdb3a
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
412 |
orgClass setCategory:#'* trapping *'. |
88 | 413 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
414 |
dict := MethodDictionary new:1. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
415 |
dict at:aSelector put:trapMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
416 |
orgClass methodDictionary:dict. |
88 | 417 |
]. |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
418 |
trapMethod changeLiteral:(newClass superclass) to:newClass. |
88 | 419 |
|
420 |
ObjectMemory flushCaches. |
|
421 |
||
422 |
" |
|
423 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
424 |
wrapClass:Point |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
425 |
selector:#scaleBy: |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
426 |
onEntry:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
427 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
428 |
Transcript show:'leave Point>>scaleBy:; returning:'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
429 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
430 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
431 |
]. |
88 | 432 |
(1@2) scaleBy:5. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
433 |
MessageTracer untrapClass:Point selector:#scaleBy:. |
88 | 434 |
(1@2) scaleBy:5. |
435 |
" |
|
436 |
" |
|
437 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
438 |
wrapClass:Integer |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
439 |
selector:#factorial |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
440 |
onEntry:[:con | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
441 |
Transcript showCR:('entering ' , con receiver printString , '>>factorial'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
442 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
443 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
444 |
Transcript show:'leave Integer>>factorial; returning:'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
445 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
446 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
447 |
]. |
258 | 448 |
Transcript showCR:'5 factorial traced'. |
88 | 449 |
5 factorial. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
450 |
MessageTracer untrapClass:Integer selector:#factorial. |
258 | 451 |
Transcript showCR:'5 factorial normal'. |
88 | 452 |
5 factorial. |
453 |
" |
|
454 |
" |
|
455 |
|lvl| |
|
456 |
||
457 |
lvl := 0. |
|
458 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
459 |
wrapClass:Integer |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
460 |
selector:#factorial |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
461 |
onEntry:[:con | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
462 |
Transcript spaces:lvl. lvl := lvl + 2. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
463 |
Transcript showCR:('entering ' , con receiver printString , '>>factorial'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
464 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
465 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
466 |
lvl := lvl - 2. Transcript spaces:lvl. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
467 |
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
|
468 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
469 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
470 |
]. |
258 | 471 |
Transcript showCR:'5 factorial traced'. |
88 | 472 |
5 factorial. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
473 |
MessageTracer untrapClass:Integer selector:#factorial. |
258 | 474 |
Transcript showCR:'5 factorial normal'. |
88 | 475 |
5 factorial. |
476 |
" |
|
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
477 |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
478 |
"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
|
479 |
"Modified: 10.9.1996 / 20:07:01 / cg" |
88 | 480 |
! ! |
481 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
482 |
!MessageTracer class methodsFor:'cleanup'! |
27 | 483 |
|
484 |
cleanup |
|
485 |
"if you forgot which classes/methods where wrapped and/or trapped, |
|
486 |
this cleans up everything ..." |
|
487 |
||
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
488 |
ObjectCopyHolders := nil. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
489 |
MethodCounts := MethodMemoryUsage := MethodTiming := TimeForWrappers := nil. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
490 |
|
27 | 491 |
self untrapAllClasses. |
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
492 |
self unwrapAllMethods. |
27 | 493 |
|
494 |
" |
|
495 |
MessageTracer cleanup |
|
496 |
" |
|
497 |
! ! |
|
498 |
||
1082 | 499 |
!MessageTracer class methodsFor:'execution trace'! |
88 | 500 |
|
501 |
debugTrace:aBlock |
|
699
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
502 |
"trace execution of aBlock. This is for system debugging only; |
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
503 |
The trace output is a low level trace generated in the VM." |
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
504 |
|
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
505 |
ObjectMemory sendTraceOn. |
1139
56861678ff27
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
1082
diff
changeset
|
506 |
^ aBlock ensure:[ObjectMemory sendTraceOff] |
11 | 507 |
|
88 | 508 |
" |
509 |
MessageTracer debugTrace:[#(6 5 4 3 2 1) sort] |
|
510 |
" |
|
196
330cc5c849de
debugOn/Off is now called sendTraceOn/Off
Claus Gittinger <cg@exept.de>
parents:
172
diff
changeset
|
511 |
|
699
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
512 |
"Modified: / 31.7.1998 / 16:39:43 / cg" |
88 | 513 |
! |
11 | 514 |
|
515 |
trace:aBlock |
|
516 |
"evaluate aBlock sending trace information to stdout. |
|
27 | 517 |
Return the value of the block." |
11 | 518 |
|
734 | 519 |
^ PrintingMessageTracer new trace:aBlock detail:false. |
11 | 520 |
|
521 |
" |
|
522 |
MessageTracer trace:[#(6 5 4 3 2 1) sort] |
|
523 |
" |
|
524 |
! |
|
525 |
||
526 |
traceFull:aBlock |
|
527 |
"evaluate aBlock sending trace information to stdout. |
|
528 |
Return the value of the block. |
|
27 | 529 |
The trace information is more detailed." |
11 | 530 |
|
734 | 531 |
^ PrintingMessageTracer new trace:aBlock detail:true. |
11 | 532 |
|
533 |
" |
|
534 |
MessageTracer traceFull:[#(6 5 4 3 2 1) sort] |
|
535 |
" |
|
734 | 536 |
! |
537 |
||
538 |
traceFullIndented:aBlock |
|
539 |
"evaluate aBlock sending trace information to stdout. |
|
540 |
Return the value of the block. |
|
541 |
The trace information is more detailed." |
|
542 |
||
543 |
^ PrintingMessageTracer new trace:aBlock detail:#fullIndent. |
|
544 |
||
545 |
" |
|
546 |
MessageTracer traceFullIndented:[ #(6 5 4 3 2 1) sort ] |
|
547 |
" |
|
548 |
! |
|
549 |
||
550 |
traceIndented:aBlock |
|
551 |
"evaluate aBlock sending trace information to stdout. |
|
552 |
Return the value of the block." |
|
553 |
||
554 |
^ PrintingMessageTracer new trace:aBlock detail:#indent. |
|
555 |
||
556 |
" |
|
557 |
MessageTracer traceIndented:[ #(6 5 4 3 2 1) sort ] |
|
558 |
" |
|
88 | 559 |
! ! |
560 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
561 |
!MessageTracer class methodsFor:'method breakpointing'! |
88 | 562 |
|
563 |
trapClass:aClass selector:aSelector |
|
564 |
"arrange for the debugger to be entered when a message with aSelector is |
|
565 |
sent to instances of aClass (or subclass instances). Use untrapClass to remove this trap. |
|
566 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
567 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
568 |
entry/leave blocks." |
|
569 |
||
570 |
self trapMethod:(aClass compiledMethodAt:aSelector) |
|
571 |
||
572 |
" |
|
573 |
MessageTracer trapClass:Collection selector:#select:. |
|
591 | 574 |
Dictionary new select:[:e | ]. 'not caught - Dictionary has its own select'. |
575 |
(Array new:10) select:[:e | ]. 'not caught - SeqColl has its own select'. |
|
576 |
Set new select:[:e | ]. 'caught - Set inherits this from Collection'. |
|
88 | 577 |
MessageTracer untrapClass:Collection |
578 |
" |
|
11 | 579 |
! |
580 |
||
88 | 581 |
trapMethod:aMethod |
582 |
"arrange for the debugger to be entered when aMethod is about to be executed. |
|
495 | 583 |
The trap is enabled for any process - see #trapMethodInCurrentProcess: for a more |
584 |
selective breakPoint. |
|
88 | 585 |
Use unwrapMethod or untrapClass to remove this trap. |
586 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
587 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
588 |
entry/leave blocks." |
|
589 |
||
590 |
^ self wrapMethod:aMethod |
|
495 | 591 |
onEntry:BreakBlock |
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
592 |
onExit:LeaveBreakBlock. |
88 | 593 |
|
594 |
" |
|
595 |
MessageTracer trapMethod:(Collection compiledMethodAt:#select:). |
|
591 | 596 |
Dictionary new select:[:e | ]. 'not caught - Dictionary has its own select'. |
597 |
(Array new:10) select:[:e | ]. 'not caught - SeqColl has its own select'. |
|
598 |
Set new select:[:e | ]. 'caught - Set inherits this from Collection'. |
|
88 | 599 |
MessageTracer unwrapMethod:(Collection compiledMethodAt:#select:). |
600 |
" |
|
495 | 601 |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
602 |
"Modified: 22.10.1996 / 17:39:58 / cg" |
88 | 603 |
! |
11 | 604 |
|
908 | 605 |
trapMethod:aMethod after:countInvocations |
606 |
"arrange for the debugger to be entered when aMethod has been invoked countInvocations times. |
|
607 |
The trap is enabled for any process. |
|
608 |
Use unwrapMethod or untrapClass to remove this trap. |
|
609 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
610 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
611 |
entry/leave blocks." |
|
612 |
||
613 |
|n| |
|
614 |
||
615 |
n := 0. |
|
616 |
^ self wrapMethod:aMethod |
|
617 |
onEntry:[:con | n := n + 1. |
|
618 |
n > countInvocations |
|
619 |
ifTrue:[ |
|
620 |
BreakpointSignal raiseRequestWith:nil errorString:nil in:con |
|
621 |
] |
|
622 |
] |
|
623 |
onExit:LeaveBreakBlock. |
|
624 |
||
625 |
! |
|
626 |
||
88 | 627 |
trapMethod:aMethod forInstancesOf:aClass |
628 |
"arrange for the debugger to be entered when aMethod is about to be executed |
|
629 |
for an instance of aClass. |
|
630 |
Use unwrapMethod or untrapClass to remove this trap. |
|
631 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
632 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
633 |
entry/leave blocks." |
|
634 |
||
635 |
^ self wrapMethod:aMethod |
|
809 | 636 |
onEntry:[:con | |
637 |
(con receiver isMemberOf:aClass) ifTrue:[ |
|
638 |
BreakpointSignal raiseRequestWith:nil errorString:nil in:con |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
639 |
] |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
640 |
] |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
641 |
onExit:LeaveBreakBlock. |
88 | 642 |
|
643 |
" |
|
644 |
MessageTracer trapMethod:(View compiledMethodAt:#redraw) forInstancesOf:myView. |
|
645 |
" |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
646 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
647 |
"Modified: 22.10.1996 / 17:40:03 / cg" |
88 | 648 |
! |
649 |
||
950 | 650 |
trapMethod:aMethod if:conditionBlock |
651 |
"arrange for the debugger to be entered when aMethod has been invoked and conditionBlock |
|
652 |
evaluates to true. |
|
653 |
The trap is enabled for any process. |
|
654 |
Use unwrapMethod or untrapClass to remove this trap. |
|
655 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
656 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
657 |
entry/leave blocks." |
|
658 |
||
659 |
^ self wrapMethod:aMethod |
|
660 |
onEntry:[:con | |conditionFires| |
|
661 |
||
662 |
conditionBlock numArgs == 1 ifTrue:[ |
|
663 |
conditionFires := conditionBlock value:con |
|
664 |
] ifFalse:[ |
|
665 |
conditionFires := conditionBlock value:con value:aMethod |
|
666 |
]. |
|
667 |
conditionFires ifTrue:[ |
|
668 |
BreakpointSignal raiseRequestWith:nil errorString:nil in:con |
|
669 |
] |
|
670 |
] |
|
671 |
onExit:LeaveBreakBlock. |
|
672 |
||
673 |
"Created: / 18.8.2000 / 22:09:10 / cg" |
|
674 |
! |
|
675 |
||
496 | 676 |
trapMethod:aMethod inProcess:aProcess |
495 | 677 |
"arrange for the debugger to be entered when aMethod is about to be executed, |
678 |
but only, if executed in the current process. |
|
679 |
This allows for breakpoints to be set on system-critical code. |
|
680 |
The trap is enabled for any process. |
|
681 |
Use unwrapMethod or untrapClass to remove this trap. |
|
682 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
683 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
684 |
entry/leave blocks." |
|
685 |
||
686 |
^ self wrapMethod:aMethod |
|
496 | 687 |
onEntry:[:con | (Processor activeProcess == aProcess) |
495 | 688 |
ifTrue:[ |
809 | 689 |
BreakpointSignal raiseRequestWith:nil errorString:nil in:con |
495 | 690 |
] |
691 |
] |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
692 |
onExit:LeaveBreakBlock. |
495 | 693 |
|
496 | 694 |
"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
|
695 |
"Modified: 22.10.1996 / 17:40:06 / cg" |
495 | 696 |
! |
697 |
||
88 | 698 |
untrapAllClasses |
699 |
"remove any traps on any class" |
|
700 |
||
970 | 701 |
Smalltalk allClassesDo:[:aClass | |
702 |
self untrapClass:aClass |
|
11 | 703 |
] |
704 |
||
705 |
" |
|
88 | 706 |
MessageTracer untrapAllClasses |
707 |
" |
|
708 |
! |
|
709 |
||
710 |
untrapClass:aClass |
|
711 |
"remove any traps on aClass" |
|
712 |
||
713 |
"this is done by just patching the class back to the original" |
|
714 |
||
715 |
|orgClass| |
|
716 |
||
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
717 |
aClass category == #'* trapping *' ifFalse:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
718 |
^ self |
88 | 719 |
]. |
720 |
orgClass := aClass superclass. |
|
721 |
||
722 |
aClass setSuperclass:orgClass superclass. |
|
723 |
aClass setClassVariableString:orgClass classVariableString. |
|
724 |
aClass setInstanceVariableString:orgClass instanceVariableString. |
|
1320
f346fa1fdb3a
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
725 |
aClass setCategory:orgClass category. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
726 |
aClass methodDictionary:orgClass methodDictionary. |
88 | 727 |
|
728 |
ObjectMemory flushCaches. |
|
729 |
||
730 |
" |
|
731 |
MessageTracer untrapClass:Point |
|
11 | 732 |
" |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
733 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
734 |
"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
|
735 |
"Modified: 10.9.1996 / 20:06:23 / cg" |
88 | 736 |
! |
737 |
||
738 |
untrapClass:aClass selector:aSelector |
|
739 |
"remove trap of aSelector sent to aClass" |
|
740 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
741 |
|dict| |
88 | 742 |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
743 |
aClass category == #'* trapping *' ifFalse:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
744 |
^ self |
88 | 745 |
]. |
746 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
747 |
dict := aClass methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
748 |
dict at:aSelector ifAbsent:[^ self]. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
749 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
750 |
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
|
751 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
752 |
dict size == 1 ifTrue:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
753 |
"the last trapped method" |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
754 |
^ self untrapClass:aClass |
88 | 755 |
]. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
756 |
dict removeKey:aSelector. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
757 |
aClass methodDictionary:dict. |
88 | 758 |
|
759 |
" |
|
760 |
MessageTracer trapClass:Point selector:#copy. |
|
761 |
(1@2) copy. |
|
762 |
(1@2) deepCopy. |
|
763 |
MessageTracer trapClass:Point selector:#deepCopy. |
|
764 |
(1@2) copy. |
|
765 |
(1@2) deepCopy. |
|
766 |
MessageTracer untrapClass:Point selector:#copy. |
|
767 |
(1@2) copy. |
|
768 |
(1@2) deepCopy. |
|
769 |
MessageTracer untrapClass:Point selector:#deepCopy. |
|
770 |
(1@2) copy. |
|
771 |
(1@2) deepCopy. |
|
772 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
773 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
774 |
"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
|
775 |
"Modified: 10.9.1996 / 20:06:29 / cg" |
88 | 776 |
! |
777 |
||
778 |
untrapMethod:aMethod |
|
779 |
"remove break on aMethod" |
|
780 |
||
781 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
782 |
trace facilities ..." |
|
783 |
||
784 |
^ self unwrapMethod:aMethod |
|
11 | 785 |
! ! |
786 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
787 |
!MessageTracer class methodsFor:'method counting'! |
155 | 788 |
|
789 |
countMethod:aMethod |
|
790 |
"arrange for a aMethods execution to be counted. |
|
791 |
Use unwrapMethod to remove this." |
|
792 |
||
793 |
MethodCounts isNil ifTrue:[ |
|
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
794 |
MethodCounts := IdentityDictionary new. |
155 | 795 |
]. |
796 |
MethodCounts at:aMethod put:0. |
|
797 |
||
798 |
^ self wrapMethod:aMethod |
|
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
799 |
onEntry:[:con | |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
800 |
|cnt| |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
801 |
|
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
802 |
cnt := MethodCounts at:aMethod ifAbsent:0. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
803 |
MethodCounts at:aMethod put:(cnt + 1). |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
804 |
aMethod changed:#statistics |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
805 |
] |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
806 |
onExit:[:con :retVal | |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
807 |
] |
155 | 808 |
|
809 |
" |
|
810 |
MessageTracer countMethod:(Integer compiledMethodAt:#factorial). |
|
811 |
5 factorial. |
|
812 |
MessageTracer executionCountOf:(Integer compiledMethodAt:#factorial) printNL. |
|
813 |
MessageTracer stopCountingMethod:(Integer compiledMethodAt:#factorial) |
|
814 |
" |
|
815 |
||
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
816 |
"Created: / 15.12.1995 / 10:57:49 / cg" |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
817 |
"Modified: / 27.7.1998 / 10:47:46 / cg" |
155 | 818 |
! |
819 |
||
820 |
executionCountOfMethod:aMethod |
|
821 |
"return the current count" |
|
822 |
||
823 |
|count| |
|
824 |
||
825 |
MethodCounts isNil ifTrue:[^ 0]. |
|
826 |
aMethod isWrapped ifTrue:[ |
|
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
827 |
count := MethodCounts at:aMethod originalMethod ifAbsent:nil. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
828 |
count notNil ifTrue:[^ count]. |
155 | 829 |
]. |
830 |
^ MethodCounts at:aMethod ifAbsent:0 |
|
831 |
||
832 |
"Created: 15.12.1995 / 11:01:56 / cg" |
|
833 |
"Modified: 15.12.1995 / 15:45:15 / cg" |
|
834 |
! |
|
835 |
||
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
836 |
resetCountOfMethod:aMethod |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
837 |
"return the current count" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
838 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
839 |
MethodCounts notNil ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
840 |
aMethod isWrapped ifTrue:[ |
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
841 |
MethodCounts at:aMethod originalMethod put:0. |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
842 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
843 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
844 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
845 |
"Created: / 30.7.1998 / 17:42:08 / cg" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
846 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
847 |
|
155 | 848 |
stopCountingMethod:aMethod |
849 |
"remove counting of aMethod" |
|
850 |
||
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
851 |
MethodCounts notNil ifTrue:[ |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
852 |
aMethod isWrapped ifTrue:[ |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
853 |
MethodCounts removeKey:aMethod originalMethod ifAbsent:nil. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
854 |
]. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
855 |
]. |
155 | 856 |
^ self unwrapMethod:aMethod |
857 |
||
858 |
"Modified: 15.12.1995 / 15:43:53 / cg" |
|
859 |
! ! |
|
860 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
861 |
!MessageTracer class methodsFor:'method memory usage'! |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
862 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
863 |
countMemoryUsageOfMethod:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
864 |
"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
|
865 |
Use unwrapMethod to remove this." |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
866 |
|
501 | 867 |
|oldPriority oldScavengeCount oldNewUsed| |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
868 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
869 |
MethodCounts isNil ifTrue:[ |
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
870 |
MethodCounts := IdentityDictionary new. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
871 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
872 |
MethodMemoryUsage isNil ifTrue:[ |
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
873 |
MethodMemoryUsage := IdentityDictionary new. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
874 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
875 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
876 |
MethodCounts at:aMethod put:0. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
877 |
MethodMemoryUsage at:aMethod put:0. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
878 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
879 |
^ self wrapMethod:aMethod |
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
880 |
onEntry:[:con | |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
881 |
oldPriority := Processor activeProcess changePriority:(Processor userInterruptPriority). |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
882 |
oldNewUsed := ObjectMemory newSpaceUsed. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
883 |
oldScavengeCount := ObjectMemory scavengeCount. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
884 |
] |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
885 |
onExit:[:con :retVal | |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
886 |
|cnt memUse scavenges| |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
887 |
|
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
888 |
memUse := ObjectMemory newSpaceUsed - oldNewUsed. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
889 |
scavenges := ObjectMemory scavengeCount - oldScavengeCount. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
890 |
scavenges ~= 0 ifTrue:[ |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
891 |
memUse := memUse + (ObjectMemory newSpaceSize * scavenges) |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
892 |
]. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
893 |
|
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
894 |
MethodCounts notNil ifTrue:[ |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
895 |
cnt := MethodCounts at:aMethod ifAbsent:0. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
896 |
MethodCounts at:aMethod put:(cnt + 1). |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
897 |
]. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
898 |
MethodMemoryUsage notNil ifTrue:[ |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
899 |
cnt := MethodMemoryUsage at:aMethod ifAbsent:0. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
900 |
MethodMemoryUsage at:aMethod put:(cnt + memUse). |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
901 |
]. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
902 |
Processor activeProcess priority:oldPriority. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
903 |
aMethod changed:#statistics |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
904 |
] |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
905 |
onUnwind:[ |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
906 |
oldPriority notNil ifTrue:[ |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
907 |
Processor activeProcess priority:oldPriority |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
908 |
] |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
909 |
] |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
910 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
911 |
" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
912 |
MessageTracer countMemoryUsageOfMethod:(Integer compiledMethodAt:#factorial). |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
913 |
3 factorial. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
914 |
(MessageTracer memoryUsageOfMethod:(Integer compiledMethodAt:#factorial)) printNL. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
915 |
MessageTracer stopCountingMemoryUsageOfMethod:(Integer compiledMethodAt:#factorial) |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
916 |
" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
917 |
|
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
918 |
"Created: / 18.12.1995 / 15:41:27 / stefan" |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
919 |
"Modified: / 18.12.1995 / 21:46:48 / stefan" |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
920 |
"Modified: / 27.7.1998 / 10:47:38 / cg" |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
921 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
922 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
923 |
isCountingMemoryUsage:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
924 |
"return true if aMethod is counting memoryUsage" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
925 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
926 |
MethodMemoryUsage isNil ifTrue:[^ false]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
927 |
(MethodMemoryUsage includesKey:aMethod) ifTrue:[^ true]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
928 |
aMethod isWrapped ifTrue:[ |
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
929 |
^ MethodMemoryUsage includesKey:aMethod originalMethod |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
930 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
931 |
^ false |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
932 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
933 |
"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
|
934 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
935 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
936 |
memoryUsageOfMethod:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
937 |
"return the current count" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
938 |
|
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
939 |
|count memUse orgMethod| |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
940 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
941 |
(MethodCounts isNil or:[MethodMemoryUsage isNil]) ifTrue:[^ 0]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
942 |
aMethod isWrapped ifTrue:[ |
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
943 |
orgMethod := aMethod originalMethod. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
944 |
count := MethodCounts at:orgMethod ifAbsent:nil. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
945 |
memUse := MethodMemoryUsage at:orgMethod ifAbsent:nil. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
946 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
947 |
memUse isNil ifTrue:[ |
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
948 |
count := MethodCounts at:aMethod ifAbsent:0. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
949 |
memUse := MethodMemoryUsage at:aMethod ifAbsent:0. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
950 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
951 |
count = 0 ifTrue:[^ 0]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
952 |
^ memUse//count |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
953 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
954 |
"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
|
955 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
956 |
|
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
957 |
resetMemoryUsageOfMethod:aMethod |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
958 |
"reset the current usage" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
959 |
|
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
960 |
|orgMethod| |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
961 |
|
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
962 |
MethodCounts notNil ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
963 |
MethodMemoryUsage notNil ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
964 |
aMethod isWrapped ifTrue:[ |
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
965 |
orgMethod := aMethod originalMethod. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
966 |
MethodCounts at:orgMethod put:0. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
967 |
MethodMemoryUsage at:orgMethod put:nil. |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
968 |
] |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
969 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
970 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
971 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
972 |
"Created: / 30.7.1998 / 17:43:07 / cg" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
973 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
974 |
|
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
975 |
stopCountingMemoryUsageOfMethod:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
976 |
"remove counting memory of aMethod" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
977 |
|
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
978 |
|orgMethod| |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
979 |
|
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
980 |
MethodCounts notNil ifTrue:[ |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
981 |
MethodMemoryUsage notNil ifTrue:[ |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
982 |
aMethod isWrapped ifTrue:[ |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
983 |
orgMethod := aMethod originalMethod. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
984 |
MethodCounts removeKey:orgMethod ifAbsent:nil. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
985 |
MethodMemoryUsage removeKey:orgMethod ifAbsent:nil. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
986 |
] |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
987 |
]. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
988 |
]. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
989 |
^ self unwrapMethod:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
990 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
991 |
"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
|
992 |
! ! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
993 |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
994 |
!MessageTracer class methodsFor:'method timing'! |
327 | 995 |
|
996 |
executionTimesOfMethod:aMethod |
|
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
997 |
"return the current gathered execution time statistics" |
327 | 998 |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
999 |
|info| |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1000 |
|
327 | 1001 |
MethodTiming notNil ifTrue:[ |
1002 |
aMethod isWrapped ifTrue:[ |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1003 |
info := ( MethodTiming at:(aMethod originalMethod) ifAbsent:nil ) copy. |
327 | 1004 |
]. |
1005 |
]. |
|
1006 |
||
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1007 |
info isNil ifTrue:[ info := MethodTimingInfo new ]. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1008 |
^ info |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1009 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1010 |
"Created: / 17-06-1996 / 17:07:30 / cg" |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1011 |
"Modified: / 05-03-2007 / 15:46:17 / cg" |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1012 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1013 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1014 |
resetExecutionTimesOfMethod:aMethod |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1015 |
"reset the gathered execution times statistics for aMethod; |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1016 |
the method remains wrapped." |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1017 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1018 |
MethodTiming notNil ifTrue:[ |
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1019 |
MethodTiming removeKey:aMethod. |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1020 |
aMethod isWrapped ifTrue:[ |
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1021 |
MethodTiming removeKey:aMethod originalMethod. |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1022 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1023 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1024 |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1025 |
"Created: / 30-07-1998 / 17:12:35 / cg" |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1026 |
"Modified: / 05-03-2007 / 15:36:59 / cg" |
327 | 1027 |
! |
1028 |
||
1029 |
stopTimingMethod:aMethod |
|
1030 |
"remove timing of aMethod" |
|
1031 |
||
1032 |
^ self unwrapMethod:aMethod |
|
1033 |
||
1034 |
"Modified: 15.12.1995 / 15:43:53 / cg" |
|
1035 |
"Created: 17.6.1996 / 17:04:03 / cg" |
|
1036 |
! |
|
1037 |
||
1038 |
timeMethod:aMethod |
|
1039 |
"arrange for a aMethods execution time to be measured. |
|
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1040 |
Use unwrapMethod: or stopTimingMethod: to remove this." |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1041 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1042 |
|t0| |
327 | 1043 |
|
1044 |
MethodTiming isNil ifTrue:[ |
|
1045 |
MethodTiming := IdentityDictionary new. |
|
1046 |
]. |
|
1047 |
MethodTiming removeKey:aMethod ifAbsent:nil. |
|
1048 |
||
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1049 |
TimeForWrappers isNil ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1050 |
self getTimeForWrappers |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1051 |
]. |
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1052 |
|
327 | 1053 |
^ self wrapMethod:aMethod |
1054 |
onEntry:[:con | |
|
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1055 |
t0 := OperatingSystem getMicrosecondTime. |
327 | 1056 |
] |
1057 |
onExit:[:con :retVal | |
|
668
7cd41a86e7b2
renamed min/max - bad names on NeXT
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
1058 |
|info t cnt minT maxT sumTimes| |
327 | 1059 |
|
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1060 |
t := OperatingSystem getMicrosecondTime - t0. |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1061 |
t := t - TimeForWrappers. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1062 |
t < 0 ifTrue:[t := 0]. |
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1063 |
t := t / 1000.0. |
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1064 |
|
2004 | 1065 |
MethodTiming isNil ifTrue:[ |
1066 |
MethodTiming := IdentityDictionary new. |
|
1067 |
]. |
|
327 | 1068 |
info := MethodTiming at:aMethod ifAbsent:nil. |
1069 |
info isNil ifTrue:[ |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1070 |
MethodTiming at:aMethod put:(info := MethodTimingInfo new) |
327 | 1071 |
] ifFalse:[ |
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1072 |
info rememberExecutionTime:t. |
327 | 1073 |
]. |
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1074 |
aMethod changed:#statistics |
327 | 1075 |
] |
1076 |
||
1077 |
" |
|
1078 |
MessageTracer timeMethod:(Integer compiledMethodAt:#factorial). |
|
1079 |
5 factorial. |
|
1080 |
5 factorial. |
|
1081 |
5 factorial. |
|
1082 |
(MessageTracer executionTimesOfMethod:(Integer compiledMethodAt:#factorial)) printCR. |
|
1083 |
MessageTracer stopTimingMethod:(Integer compiledMethodAt:#factorial) |
|
1084 |
" |
|
1085 |
||
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1086 |
"Created: / 17-06-1996 / 17:03:50 / cg" |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1087 |
"Modified: / 05-03-2007 / 15:34:01 / cg" |
327 | 1088 |
! ! |
1089 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1090 |
!MessageTracer class methodsFor:'method tracing'! |
11 | 1091 |
|
664 | 1092 |
traceClass:aClass selector:aSelector |
1093 |
"arrange for a trace message to be output on Stderr, when a message with aSelector is |
|
1094 |
sent to instances of aClass (or subclass instances). Use untraceClass to remove this." |
|
1095 |
||
1096 |
self traceClass:aClass selector:aSelector on:Stderr |
|
1097 |
||
1098 |
" |
|
1099 |
MessageTracer traceClass:Integer selector:#factorial. |
|
1100 |
5 factorial. |
|
1101 |
MessageTracer untraceClass:Integer |
|
1102 |
" |
|
1103 |
" |
|
1104 |
MessageTracer traceClass:SequenceableCollection selector:#quickSortFrom:to:. |
|
1105 |
#(6 1 9 66 2 17) copy sort. |
|
1106 |
MessageTracer untraceClass:SequenceableCollection |
|
1107 |
" |
|
1108 |
" |
|
1109 |
MessageTracer traceClass:Array selector:#at:. |
|
1110 |
MessageTracer traceClass:Array selector:#at:put:. |
|
1111 |
#(6 1 9 66 2 17) copy sort. |
|
1112 |
MessageTracer untraceClass:Array |
|
1113 |
" |
|
1114 |
! |
|
1115 |
||
1116 |
traceClass:aClass selector:aSelector on:aStream |
|
1117 |
"arrange for a trace message to be output on aStream, when a message with aSelector is |
|
1118 |
sent to instances of aClass (or subclass instances). Use untraceClass to remove this." |
|
1119 |
||
1120 |
self traceMethod:(aClass compiledMethodAt:aSelector) on:aStream |
|
1121 |
||
1122 |
" |
|
1123 |
MessageTracer traceClass:Integer selector:#factorial on:Transcript. |
|
1124 |
5 factorial. |
|
1125 |
MessageTracer untraceClass:Integer |
|
1126 |
" |
|
1127 |
" |
|
1128 |
MessageTracer traceClass:Integer selector:#factorialR on:Transcript. |
|
1129 |
5 factorialR. |
|
1130 |
MessageTracer untraceClass:Integer |
|
1131 |
" |
|
1132 |
||
1133 |
! |
|
1134 |
||
88 | 1135 |
traceMethod:aMethod |
664 | 1136 |
"arrange for a trace message to be output on Stderr, |
1137 |
when aMethod is executed. Traces both entry and exit. |
|
88 | 1138 |
Use unwrapMethod to remove this." |
1139 |
||
664 | 1140 |
^ self traceMethod:aMethod on:Stderr |
11 | 1141 |
|
1142 |
" |
|
88 | 1143 |
MessageTracer traceMethod:(Integer compiledMethodAt:#factorial). |
1144 |
5 factorial. |
|
1145 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial) |
|
1146 |
" |
|
1147 |
" |
|
664 | 1148 |
MessageTracer traceMethod:(Integer compiledMethodAt:#factorialR). |
1149 |
5 factorialR. |
|
1150 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorialR) |
|
1151 |
" |
|
1152 |
" |
|
88 | 1153 |
MessageTracer traceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
1154 |
#(6 1 9 66 2 17) copy sort. |
|
1155 |
MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
1156 |
" |
|
1157 |
" |
|
1158 |
dont do this: |
|
1159 |
" |
|
1160 |
" |
|
1161 |
MessageTracer traceMethod:(Object compiledMethodAt:#at:). |
|
1162 |
MessageTracer traceMethod:(Object compiledMethodAt:#at:put:). |
|
1163 |
#(6 1 9 66 2 17) copy sort. |
|
1164 |
MessageTracer untraceMethod:(Object compiledMethodAt:#at:). |
|
1165 |
MessageTracer untraceMethod:(Object compiledMethodAt:#at:put:). |
|
11 | 1166 |
" |
1167 |
! |
|
1168 |
||
664 | 1169 |
traceMethod:aMethod on:aStream |
1170 |
"arrange for a trace message to be output on aStream, |
|
1171 |
when aMethod is executed. Traces both entry and exit. |
|
1172 |
Use unwrapMethod to remove this." |
|
1173 |
||
1174 |
|lvl inside| |
|
1175 |
||
1176 |
^ self wrapMethod:aMethod |
|
1177 |
onEntry:[:con | |
|
1178 |
inside isNil ifTrue:[ |
|
1179 |
inside := true. |
|
1180 |
CallingLevel isNil ifTrue:[ |
|
1181 |
CallingLevel := 0. |
|
1182 |
]. |
|
1183 |
lvl notNil ifTrue:[ |
|
1184 |
lvl := lvl + 1 |
|
1185 |
] ifFalse:[ |
|
1186 |
CallingLevel := lvl := CallingLevel + 1. |
|
1187 |
]. |
|
1188 |
MessageTracer printEntryFull:con level:lvl on:aStream. |
|
1189 |
inside := nil |
|
1190 |
] |
|
1191 |
] |
|
1192 |
onExit:[:con :retVal | |
|
1193 |
inside isNil ifTrue:[ |
|
1194 |
inside := true. |
|
1195 |
MessageTracer printExit:con with:retVal level:lvl on:aStream. |
|
1196 |
CallingLevel := lvl := lvl - 1. |
|
1197 |
inside := nil |
|
1198 |
] |
|
1199 |
] |
|
1200 |
||
1201 |
" |
|
1202 |
MessageTracer traceMethod:(Integer compiledMethodAt:#factorial) on:Transcript. |
|
1203 |
5 factorial. |
|
1204 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial) |
|
1205 |
" |
|
1206 |
" |
|
1207 |
MessageTracer traceMethod:(Integer compiledMethodAt:#factorialR) on:Transcript. |
|
1208 |
5 factorialR. |
|
1209 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorialR) |
|
1210 |
" |
|
1211 |
" |
|
1212 |
MessageTracer traceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:) on:Transcript. |
|
1213 |
#(6 1 9 66 2 17) copy sort. |
|
1214 |
MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
1215 |
" |
|
1216 |
! |
|
1217 |
||
162
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1218 |
traceMethodAll:aMethod |
699
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1219 |
"arrange for a full trace message to be output on Stderr, when aMethod is executed. |
162
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1220 |
Only the sender is traced on entry. |
699
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1221 |
Use untraceMethod to remove this trace. |
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1222 |
This is for system debugging only; |
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1223 |
The trace output is a low level trace generated in the VM." |
162
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1224 |
|
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1225 |
^ self wrapMethod:aMethod |
699
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1226 |
onEntry:[:con | ObjectMemory flushCaches. ObjectMemory sendTraceOn.] |
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1227 |
onExit:[:con :val | ObjectMemory sendTraceOff.] |
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1228 |
|
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1229 |
"Modified: / 31.7.1998 / 16:40:07 / cg" |
162
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1230 |
! |
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1231 |
|
664 | 1232 |
traceMethodEntry:aMethod |
1233 |
"arrange for a trace message to be output on stdErr, |
|
1234 |
when aMethod is executed. Only entry is traced. |
|
1235 |
Use unwrapMethod to remove this." |
|
1236 |
||
1237 |
^ self traceMethodEntry:aMethod on:Stderr |
|
1238 |
||
1239 |
" |
|
1240 |
MessageTracer traceMethodEntry:(Integer compiledMethodAt:#factorial). |
|
1241 |
5 factorial. |
|
1242 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial) |
|
1243 |
" |
|
1244 |
" |
|
1245 |
MessageTracer traceMethodEntry:(Integer compiledMethodAt:#factorialR). |
|
1246 |
5 factorialR. |
|
1247 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorialR) |
|
1248 |
" |
|
1249 |
" |
|
1250 |
MessageTracer traceMethodEntry:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
1251 |
#(6 1 9 66 2 17) copy sort. |
|
1252 |
MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
1253 |
" |
|
1254 |
! |
|
1255 |
||
1256 |
traceMethodEntry:aMethod on:aStream |
|
1257 |
"arrange for a trace message to be output on aStream, |
|
1258 |
when aMethod is executed. Only entry is traced. |
|
1259 |
Use unwrapMethod to remove this." |
|
1260 |
||
1261 |
|lvl inside| |
|
1262 |
||
1263 |
^ self wrapMethod:aMethod |
|
1264 |
onEntry:[:con | |
|
1265 |
inside isNil ifTrue:[ |
|
1266 |
inside := true. |
|
1267 |
CallingLevel isNil ifTrue:[ |
|
1268 |
CallingLevel := 0. |
|
1269 |
]. |
|
1270 |
lvl notNil ifTrue:[ |
|
1271 |
lvl := lvl + 1 |
|
1272 |
] ifFalse:[ |
|
1273 |
CallingLevel := lvl := CallingLevel + 1. |
|
1274 |
]. |
|
1275 |
MessageTracer printEntryFull:con level:lvl on:aStream. |
|
1276 |
inside := nil |
|
1277 |
] |
|
1278 |
] |
|
1279 |
onExit:[:con :retVal |] |
|
1280 |
||
1281 |
" |
|
1282 |
MessageTracer traceMethodEntry:(Integer compiledMethodAt:#factorial) on:Transcript. |
|
1283 |
5 factorial. |
|
1284 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial) |
|
1285 |
" |
|
1286 |
" |
|
1287 |
MessageTracer traceMethodEntry:(Integer compiledMethodAt:#factorialR) on:Transcript. |
|
1288 |
5 factorialR. |
|
1289 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorialR) |
|
1290 |
" |
|
1291 |
" |
|
1292 |
MessageTracer traceMethodEntry:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:) on:Transcript. |
|
1293 |
#(6 1 9 66 2 17) copy sort. |
|
1294 |
MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
1295 |
" |
|
1296 |
! |
|
1297 |
||
156 | 1298 |
traceMethodFull:aMethod |
1299 |
"arrange for a full trace message to be output on Stderr, when amethod is executed. |
|
1300 |
Only the sender is traced on entry. |
|
1301 |
Use untraceMethod to remove this trace." |
|
1302 |
||
664 | 1303 |
^ self traceMethodFull:aMethod on:Stderr |
1304 |
||
1305 |
"Created: 15.12.1995 / 18:19:31 / cg" |
|
1306 |
"Modified: 22.10.1996 / 17:39:28 / cg" |
|
1307 |
! |
|
1308 |
||
1309 |
traceMethodFull:aMethod on:aStream |
|
1310 |
"arrange for a full trace message to be output on Stderr, when aMethod is executed. |
|
1311 |
Only the sender is traced on entry. |
|
1312 |
Use untraceMethod to remove this trace." |
|
1313 |
||
1314 |
^ self |
|
1315 |
wrapMethod:aMethod |
|
1316 |
onEntry:(self traceFullBlockFor:aStream) |
|
1317 |
onExit:LeaveTraceBlock. |
|
156 | 1318 |
|
1319 |
"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
|
1320 |
"Modified: 22.10.1996 / 17:39:28 / cg" |
156 | 1321 |
! |
1322 |
||
88 | 1323 |
traceMethodSender:aMethod |
664 | 1324 |
"arrange for a trace message to be output on Stderr, |
1325 |
when amethod is executed. |
|
1326 |
Only the sender is traced on entry. |
|
1327 |
Use untraceMethod to remove this trace." |
|
1328 |
||
1329 |
^ self traceMethodSender:aMethod on:Stderr |
|
1330 |
! |
|
1331 |
||
1332 |
traceMethodSender:aMethod on:aStream |
|
88 | 1333 |
"arrange for a trace message to be output on Stderr, when amethod is executed. |
1334 |
Only the sender is traced on entry. |
|
1335 |
Use untraceMethod to remove this trace." |
|
35 | 1336 |
|
664 | 1337 |
^ self |
1338 |
wrapMethod:aMethod |
|
1339 |
onEntry:(self traceSenderBlockFor:aStream) |
|
1340 |
onExit:LeaveTraceBlock. |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1341 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1342 |
"Modified: 22.10.1996 / 17:39:33 / cg" |
88 | 1343 |
! |
1344 |
||
1071 | 1345 |
traceUpdateMethod:aMethod on:aStream |
1346 |
"arrange for a trace message to be output on aStream, |
|
1347 |
when aMethod is executed. |
|
1348 |
Traces both entry and exit. |
|
1349 |
Use unwrapMethod to remove this. |
|
1350 |
This one is specialized for change-update calling i.e. it traces from the update |
|
1351 |
back to the origial change message." |
|
1352 |
||
1353 |
|lvl inside| |
|
1354 |
||
1355 |
^ self |
|
1356 |
wrapMethod:aMethod |
|
1357 |
onEntry:[:con | |
|
1358 |
inside isNil ifTrue:[ |
|
1359 |
inside := true. |
|
1360 |
CallingLevel isNil ifTrue:[ |
|
1361 |
CallingLevel := 0. |
|
1362 |
]. |
|
1363 |
lvl notNil ifTrue:[ |
|
1364 |
lvl := lvl + 1 |
|
1365 |
] ifFalse:[ |
|
1366 |
CallingLevel := lvl := CallingLevel + 1. |
|
1367 |
]. |
|
1368 |
MessageTracer printUpdateEntryFull:con level:lvl on:aStream. |
|
1369 |
inside := nil |
|
1370 |
] |
|
1371 |
] |
|
1372 |
onExit:[:con :retVal | |
|
1373 |
inside isNil ifTrue:[ |
|
1374 |
inside := true. |
|
1375 |
MessageTracer printExit:con with:retVal level:lvl on:aStream. |
|
1376 |
CallingLevel := lvl := lvl - 1. |
|
1377 |
inside := nil |
|
1378 |
] |
|
1379 |
] |
|
1380 |
! |
|
1381 |
||
88 | 1382 |
untraceMethod:aMethod |
1383 |
"remove tracing of aMethod" |
|
1384 |
||
1385 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
1386 |
trace facilities ..." |
|
1387 |
||
1388 |
^ self unwrapMethod:aMethod |
|
11 | 1389 |
! ! |
1390 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1391 |
!MessageTracer class methodsFor:'method wrapping'! |
11 | 1392 |
|
88 | 1393 |
unwrapAllMethods |
1394 |
"just in case you dont know what methods have break/trace-points |
|
1395 |
on them; this removes them all" |
|
1396 |
||
1397 |
WrappedMethod allInstancesDo:[:aMethod | |
|
1145 | 1398 |
self unwrapMethod:aMethod |
88 | 1399 |
] |
1145 | 1400 |
|
1401 |
" |
|
1402 |
MessageTracer unwrapAllMethods |
|
1403 |
" |
|
11 | 1404 |
! |
1405 |
||
88 | 1406 |
unwrapMethod:aMethod |
1407 |
"remove any wrapper on aMethod" |
|
1408 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1409 |
|selector class originalMethod dict mthd| |
88 | 1410 |
|
1970 | 1411 |
aMethod isWrapped ifTrue:[ |
1412 |
originalMethod := aMethod originalMethod. |
|
1413 |
]. |
|
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1414 |
|
155 | 1415 |
MethodCounts notNil ifTrue:[ |
265 | 1416 |
aMethod isWrapped ifTrue:[ |
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1417 |
MethodCounts removeKey:originalMethod ifAbsent:nil. |
265 | 1418 |
]. |
1419 |
MethodCounts removeKey:aMethod ifAbsent:nil. |
|
1420 |
MethodCounts isEmpty ifTrue:[MethodCounts := nil]. |
|
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
1421 |
]. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
1422 |
MethodMemoryUsage notNil ifTrue:[ |
265 | 1423 |
aMethod isWrapped ifTrue:[ |
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1424 |
MethodMemoryUsage removeKey:originalMethod ifAbsent:nil. |
265 | 1425 |
]. |
1426 |
MethodMemoryUsage removeKey:aMethod ifAbsent:nil. |
|
1427 |
MethodMemoryUsage isEmpty ifTrue:[MethodMemoryUsage := nil]. |
|
155 | 1428 |
]. |
327 | 1429 |
MethodTiming notNil ifTrue:[ |
1430 |
aMethod isWrapped ifTrue:[ |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1431 |
MethodTiming removeKey:originalMethod ifAbsent:nil. |
327 | 1432 |
]. |
1433 |
MethodTiming removeKey:aMethod ifAbsent:nil. |
|
1434 |
MethodTiming isEmpty ifTrue:[MethodTiming := nil]. |
|
1435 |
]. |
|
155 | 1436 |
|
88 | 1437 |
CallingLevel := 0. |
1438 |
||
1439 |
(aMethod isNil or:[aMethod isWrapped not]) ifTrue:[ |
|
265 | 1440 |
^ aMethod |
88 | 1441 |
]. |
1442 |
||
1443 |
" |
|
1444 |
get class/selector |
|
1445 |
" |
|
1446 |
class := aMethod containingClass. |
|
1447 |
class isNil ifTrue:[ |
|
536 | 1448 |
'MessageTracer [info]: no containing class for method found' infoPrintCR. |
265 | 1449 |
^ aMethod |
88 | 1450 |
]. |
1451 |
selector := class selectorAtMethod:aMethod. |
|
1452 |
||
1453 |
originalMethod isNil ifTrue:[ |
|
808 | 1454 |
self error:'oops, could not find original method' mayProceed:true. |
265 | 1455 |
^ aMethod |
88 | 1456 |
]. |
1457 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1458 |
dict := class methodDictionary. |
506 | 1459 |
mthd := dict at:selector ifAbsent:nil. |
1460 |
mthd notNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1461 |
dict at:selector put:originalMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1462 |
class methodDictionary:dict. |
88 | 1463 |
] ifFalse:[ |
667 | 1464 |
'MessageTracer [info]: no containing class for method found' infoPrintCR. |
1465 |
"/ self halt:'oops, unexpected error - cannot remove wrap'. |
|
1466 |
aMethod becomeSameAs:originalMethod. |
|
265 | 1467 |
^ aMethod |
88 | 1468 |
]. |
1469 |
||
1470 |
ObjectMemory flushCaches. |
|
1144
001b374a2431
change notification when traps are added/removed
Claus Gittinger <cg@exept.de>
parents:
1139
diff
changeset
|
1471 |
|
584
2da6bb2c8017
send out change notifications when a trap is removed
Claus Gittinger <cg@exept.de>
parents:
579
diff
changeset
|
1472 |
class changed:#methodTrap with:selector. "/ tell browsers |
1008
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
1473 |
Smalltalk changed:#methodTrap with:(Array with:class with:selector). |
1144
001b374a2431
change notification when traps are added/removed
Claus Gittinger <cg@exept.de>
parents:
1139
diff
changeset
|
1474 |
|
88 | 1475 |
^ originalMethod |
265 | 1476 |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1477 |
"Modified: / 05-06-1996 / 14:08:08 / stefan" |
1970 | 1478 |
"Modified: / 04-10-2007 / 16:41:01 / cg" |
13 | 1479 |
! |
1480 |
||
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1481 |
wrapMethod:aMethod onEntry:entryBlock onExit:exitBlock |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1482 |
^ 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
|
1483 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1484 |
"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
|
1485 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1486 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1487 |
wrapMethod:aMethod onEntry:entryBlock onExit:exitBlock onUnwind:unwindBlock |
88 | 1488 |
"arrange for the two blocks entryBlock and exitBlock to be evaluated whenever |
1489 |
aMethod is evaluated. |
|
1490 |
EntryBlock will be called on entry, and gets the current context passed as argument. |
|
1491 |
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
|
1492 |
the methods return value as arguments. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1493 |
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
|
1494 |
If there is an unwindBlock, the entry and exitBlocks will be called within the unwind block, |
572 | 1495 |
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
|
1496 |
" |
88 | 1497 |
|
1452 | 1498 |
|selector class trapMethod s spec src dict sel saveUS xselector| |
88 | 1499 |
|
1500 |
CallingLevel := 0. |
|
1501 |
||
1502 |
" |
|
1503 |
create a new method, which calls the original one, |
|
1504 |
but only if not already being trapped. |
|
1505 |
" |
|
1506 |
(aMethod isNil or:[aMethod isWrapped]) ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1507 |
^ aMethod |
88 | 1508 |
]. |
1509 |
aMethod isLazyMethod ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1510 |
aMethod makeRealMethod |
88 | 1511 |
]. |
1512 |
||
1513 |
" |
|
1514 |
get class/selector |
|
1515 |
" |
|
1516 |
class := aMethod containingClass. |
|
1517 |
class isNil ifTrue:[ |
|
808 | 1518 |
self error:'cannot place trap (no containing class found)' mayProceed:true. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1519 |
^ aMethod |
88 | 1520 |
]. |
1521 |
selector := class selectorAtMethod:aMethod. |
|
1522 |
||
1523 |
||
1524 |
WrappedMethod autoload. "/ for small systems |
|
1525 |
||
1526 |
" |
|
1527 |
get a new method-spec |
|
1528 |
" |
|
730 | 1529 |
xselector := '_x'. |
729 | 1530 |
aMethod numArgs timesRepeat:[ |
1531 |
xselector := xselector , '_:' |
|
1532 |
]. |
|
1533 |
spec := Parser methodSpecificationForSelector:xselector. |
|
88 | 1534 |
|
1535 |
" |
|
1536 |
create a method, executing the trap-blocks and the original method via a direct call |
|
1537 |
" |
|
1538 |
s := WriteStream on:String new. |
|
1539 |
s nextPutAll:spec. |
|
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1540 |
s nextPutAll:' |retVal context| '. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1541 |
s nextPutAll:' context := thisContext.'. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1542 |
unwindBlock notNil ifTrue:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1543 |
s nextPutAll:'['. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1544 |
]. |
88 | 1545 |
entryBlock notNil ifTrue:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1546 |
s nextPutAll:'#entryBlock yourself value:context. '. |
88 | 1547 |
]. |
1548 |
s nextPutAll:'retVal := #originalMethod yourself'; |
|
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1549 |
nextPutAll: ' valueWithReceiver:(context receiver)'; |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1550 |
nextPutAll: ' arguments:(context args)'; |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1551 |
nextPutAll: ' selector:(context selector)'; |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1552 |
nextPutAll: ' search:(context searchClass)'; |
88 | 1553 |
nextPutAll: ' sender:nil. '. |
1554 |
||
1555 |
exitBlock notNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1556 |
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
|
1557 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1558 |
unwindBlock notNil ifTrue:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1559 |
s nextPutAll:'] valueOnUnwindDo:#unwindBlock yourself.'. |
88 | 1560 |
]. |
1561 |
s nextPutAll:'^ retVal'; cr. |
|
1562 |
||
1563 |
src := s contents. |
|
1452 | 1564 |
saveUS := Compiler allowUnderscoreInIdentifier. |
1565 |
ParserFlags |
|
1566 |
withSTCCompilation:#never |
|
1567 |
do:[ |
|
1568 |
[ |
|
1569 |
Compiler allowUnderscoreInIdentifier:true. |
|
1570 |
Class withoutUpdatingChangesDo:[ |
|
1571 |
trapMethod := Compiler compile:src |
|
1572 |
forClass:UndefinedObject |
|
1573 |
inCategory:aMethod category |
|
1574 |
notifying:nil |
|
1575 |
install:false |
|
1576 |
skipIfSame:false |
|
1577 |
silent:false. "/ true. |
|
1578 |
] |
|
1579 |
] ensure:[ |
|
1580 |
Compiler allowUnderscoreInIdentifier:saveUS. |
|
1581 |
]. |
|
1582 |
]. |
|
88 | 1583 |
|
955
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
1584 |
trapMethod setPackage:aMethod package. |
88 | 1585 |
trapMethod changeClassTo:WrappedMethod. |
1586 |
" |
|
1587 |
raising our eyebrows here ... |
|
1588 |
" |
|
1589 |
entryBlock notNil ifTrue:[ |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1590 |
trapMethod changeLiteral:#entryBlock to:entryBlock. |
88 | 1591 |
]. |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1592 |
trapMethod changeLiteral:#originalMethod to:aMethod. |
88 | 1593 |
exitBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1594 |
trapMethod changeLiteral:#exitBlock to:exitBlock. |
88 | 1595 |
]. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1596 |
unwindBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1597 |
trapMethod changeLiteral:#unwindBlock to:unwindBlock. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1598 |
]. |
88 | 1599 |
" |
1600 |
change the source of this new method |
|
1601 |
(to avoid confusion in the debugger ...) |
|
1602 |
" |
|
840
5ec82d6c2e55
care for the wrappers source info (to allow source access in browser)
Claus Gittinger <cg@exept.de>
parents:
825
diff
changeset
|
1603 |
"/ trapMethod source:'this is a wrapper method - not the real one'. |
5ec82d6c2e55
care for the wrappers source info (to allow source access in browser)
Claus Gittinger <cg@exept.de>
parents:
825
diff
changeset
|
1604 |
trapMethod sourceFilename:(aMethod getSource) position:(aMethod getSourcePosition). |
88 | 1605 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1606 |
dict := class methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1607 |
sel := dict at:selector ifAbsent:[0]. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1608 |
sel == 0 ifTrue:[ |
808 | 1609 |
self error:'oops, unexpected error' mayProceed:true. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1610 |
^ aMethod |
88 | 1611 |
]. |
1612 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1613 |
dict at:selector put:trapMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1614 |
class methodDictionary:dict. |
88 | 1615 |
ObjectMemory flushCaches. |
1144
001b374a2431
change notification when traps are added/removed
Claus Gittinger <cg@exept.de>
parents:
1139
diff
changeset
|
1616 |
|
001b374a2431
change notification when traps are added/removed
Claus Gittinger <cg@exept.de>
parents:
1139
diff
changeset
|
1617 |
class changed:#methodTrap with:selector. "/ tell browsers |
001b374a2431
change notification when traps are added/removed
Claus Gittinger <cg@exept.de>
parents:
1139
diff
changeset
|
1618 |
Smalltalk changed:#methodTrap with:(Array with:class with:selector). |
001b374a2431
change notification when traps are added/removed
Claus Gittinger <cg@exept.de>
parents:
1139
diff
changeset
|
1619 |
|
88 | 1620 |
^ trapMethod |
1621 |
||
1622 |
" |
|
1623 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1624 |
wrapMethod:(Point compiledMethodAt:#scaleBy:) |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1625 |
onEntry:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1626 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1627 |
Transcript show:'leave Point>>scaleBy:; returning:'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1628 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1629 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1630 |
]. |
88 | 1631 |
(1@2) scaleBy:5. |
1632 |
MessageTracer unwrapMethod:(Point compiledMethodAt:#scaleBy:). |
|
1633 |
(1@2) scaleBy:5. |
|
1634 |
" |
|
1635 |
" |
|
1636 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1637 |
wrapMethod:(Integer compiledMethodAt:#factorial) |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1638 |
onEntry:[:con | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1639 |
Transcript showCR:('entering ' , con receiver printString , '>>factorial'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1640 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1641 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1642 |
Transcript show:'leave Integer>>factorial; returning:'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1643 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1644 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1645 |
]. |
258 | 1646 |
Transcript showCR:'5 factorial traced'. |
88 | 1647 |
5 factorial. |
1648 |
MessageTracer unwrapMethod:(Integer compiledMethodAt:#factorial). |
|
258 | 1649 |
Transcript showCR:'5 factorial normal'. |
88 | 1650 |
5 factorial. |
1651 |
" |
|
1652 |
" |
|
1653 |
|lvl| |
|
1654 |
||
1655 |
lvl := 0. |
|
1656 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1657 |
wrapMethod:(Integer compiledMethodAt:#factorial) |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1658 |
onEntry:[:con | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1659 |
Transcript spaces:lvl. lvl := lvl + 2. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1660 |
Transcript showCR:('entering ' , con receiver printString , '>>factorial'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1661 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1662 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1663 |
lvl := lvl - 2. Transcript spaces:lvl. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1664 |
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
|
1665 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1666 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1667 |
]. |
258 | 1668 |
Transcript showCR:'5 factorial traced'. |
88 | 1669 |
5 factorial. |
1670 |
MessageTracer unwrapMethod:(Integer compiledMethodAt:#factorial). |
|
258 | 1671 |
Transcript showCR:'5 factorial normal'. |
88 | 1672 |
5 factorial. |
1673 |
" |
|
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
1674 |
|
729 | 1675 |
"Modified: / 25.6.1996 / 22:04:51 / stefan" |
730 | 1676 |
"Modified: / 16.11.1998 / 16:45:30 / cg" |
88 | 1677 |
! ! |
1678 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1679 |
!MessageTracer class methodsFor:'object breakpointing'! |
88 | 1680 |
|
525 | 1681 |
objectHasWraps:anObject |
1682 |
"return true, if anObject has any wraps" |
|
1683 |
||
1684 |
^ anObject class category == #'* trapping *' |
|
1685 |
! |
|
1686 |
||
1687 |
realClassOf:anObject |
|
1688 |
"return anObjects real class" |
|
1689 |
||
1690 |
(anObject class category == #'* trapping *') ifFalse:[ |
|
1691 |
^ anObject class |
|
1692 |
]. |
|
1693 |
^ anObject class superclass |
|
1694 |
! |
|
1695 |
||
88 | 1696 |
trap:anObject selector:aSelector |
1697 |
"arrange for the debugger to be entered when a message with aSelector is |
|
1698 |
sent to anObject. Use untrap to remove this trap. |
|
1699 |
The current implementation does not allow integers or nil to be trapped." |
|
1700 |
||
1701 |
self wrap:anObject |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1702 |
selector:aSelector |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1703 |
onEntry:BreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1704 |
onExit:LeaveBreakBlock. |
88 | 1705 |
|
1706 |
" |
|
1707 |
|p| |
|
1708 |
||
1709 |
p := Point new. |
|
1710 |
MessageTracer trap:p selector:#x:. |
|
1711 |
p x:5 |
|
1712 |
" |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1713 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1714 |
"Modified: 22.10.1996 / 17:39:41 / cg" |
11 | 1715 |
! |
1716 |
||
88 | 1717 |
trap:anObject selectors:aCollection |
1718 |
self wrap:anObject |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1719 |
selectors:aCollection |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1720 |
onEntry:BreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1721 |
onExit:LeaveBreakBlock. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1722 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1723 |
"Modified: 22.10.1996 / 17:39:50 / cg" |
88 | 1724 |
! |
1725 |
||
1726 |
trapAll:anObject |
|
1727 |
"trap on all messages which are understood by anObject" |
|
1728 |
||
1729 |
self wrapAll:anObject |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1730 |
onEntry:BreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1731 |
onExit:LeaveBreakBlock. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1732 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1733 |
"Modified: 22.10.1996 / 17:39:54 / cg" |
88 | 1734 |
! |
1735 |
||
1736 |
trapAll:anObject from:aClass |
|
1737 |
"trap on all messages defined in aClass sent to anObject" |
|
1738 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1739 |
self trap:anObject selectors:aClass selectors |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1740 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1741 |
"Modified: 5.6.1996 / 13:46:06 / stefan" |
88 | 1742 |
! |
1743 |
||
1744 |
untrap:anObject |
|
1745 |
"remove any traps on anObject" |
|
1746 |
||
1747 |
"this is done by just patching the objects class back to the original" |
|
1748 |
||
1749 |
|orgClass| |
|
1750 |
||
1751 |
orgClass := anObject class. |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1752 |
orgClass category == #'* trapping *' ifFalse:[ |
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1753 |
^ self |
88 | 1754 |
]. |
1755 |
||
660 | 1756 |
anObject changeClassTo:orgClass superclass. |
662 | 1757 |
ObjectCopyHolders notNil ifTrue:[ |
1758 |
ObjectCopyHolders removeKey:anObject ifAbsent:nil. |
|
1759 |
]. |
|
88 | 1760 |
|
1761 |
" |
|
1762 |
|p| |
|
1763 |
||
1764 |
p := Point new copy. |
|
1765 |
MessageTracer trace:p selector:#x:. |
|
1766 |
MessageTracer trace:p selector:#y:. |
|
1767 |
p y:1. |
|
1768 |
p x:2. |
|
1769 |
MessageTracer untrap:p |
|
1770 |
p y:2. |
|
1771 |
p x:1. |
|
1772 |
" |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1773 |
|
660 | 1774 |
"Modified: / 21.4.1998 / 15:43:33 / cg" |
13 | 1775 |
! |
1776 |
||
88 | 1777 |
untrap:anObject selector:aSelector |
1778 |
"remove trap on aSelector from anObject" |
|
1779 |
||
501 | 1780 |
|orgClass dict| |
88 | 1781 |
|
1782 |
orgClass := anObject class. |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1783 |
orgClass category == #'* trapping *' ifFalse:[^ self]. |
88 | 1784 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1785 |
dict := orgClass methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1786 |
dict at:aSelector ifAbsent:[^ self]. |
88 | 1787 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1788 |
dict size == 1 ifTrue:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1789 |
"the last trap got removed" |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1790 |
anObject changeClassTo:orgClass superclass. |
662 | 1791 |
ObjectCopyHolders notNil ifTrue:[ |
1792 |
ObjectCopyHolders removeKey:anObject ifAbsent:nil. |
|
1793 |
]. |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1794 |
^ self |
88 | 1795 |
]. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1796 |
dict removeKey:aSelector. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1797 |
orgClass methodDictionary:dict. |
88 | 1798 |
ObjectMemory flushCaches. "avoid calling the old trap method" |
1799 |
||
1800 |
" |
|
1801 |
|p| |
|
1802 |
||
1803 |
p := Point new copy. |
|
1804 |
MessageTracer trace:p selector:#x:. |
|
1805 |
MessageTracer trace:p selector:#y:. |
|
1806 |
'trace both ...' errorPrintNL. |
|
1807 |
p x:2. |
|
1808 |
p y:1. |
|
1809 |
'trace only y ...' errorPrintNL. |
|
1810 |
MessageTracer untrap:p selector:#x:. |
|
1811 |
p x:2. |
|
1812 |
p y:1. |
|
1813 |
'trace none ...' errorPrintNL. |
|
1814 |
MessageTracer untrap:p selector:#y:. |
|
1815 |
p x:2. |
|
1816 |
p y:1. |
|
1817 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1818 |
|
660 | 1819 |
"Modified: / 5.6.1996 / 13:56:08 / stefan" |
1820 |
"Modified: / 21.4.1998 / 15:43:55 / cg" |
|
525 | 1821 |
! |
1822 |
||
1823 |
wrappedSelectorsOf:anObject |
|
1824 |
"return the set of wrapped selectors (if any)" |
|
1825 |
||
1826 |
(anObject class category == #'* trapping *') ifFalse:[ |
|
1827 |
^ #() |
|
1828 |
]. |
|
1829 |
^ anObject class selectors |
|
11 | 1830 |
! ! |
1831 |
||
660 | 1832 |
!MessageTracer class methodsFor:'object modification traps'! |
1833 |
||
1834 |
trapModificationsIn:anObject |
|
1835 |
"trap modifications in anObject" |
|
1836 |
||
1837 |
self |
|
663 | 1838 |
trapModificationsIn:anObject filter:[:old :new | true] |
660 | 1839 |
|
1840 |
" |
|
1841 |
|a| |
|
1842 |
||
1843 |
a := Array new:10. |
|
1844 |
MessageTracer trapModificationsIn:a. |
|
1845 |
||
1846 |
a size. |
|
1847 |
a at:1. |
|
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1848 |
a at:2 put:nil. ' no trap here (nil already there) '. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1849 |
a at:2 put:2. ' expect trap here (changing nil to 2) '. |
660 | 1850 |
a at:2. |
1851 |
a at:3. |
|
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1852 |
a at:2 put:2. ' no trap here (2 already there) '. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1853 |
a at:2 put:3. ' expect trap here (changing 2 to 3) '. |
660 | 1854 |
MessageTracer untrace:a. |
1855 |
a at:3 put:5. |
|
1856 |
" |
|
1857 |
||
1858 |
"Created: / 21.4.1998 / 14:32:34 / cg" |
|
1859 |
"Modified: / 21.4.1998 / 14:58:24 / cg" |
|
1860 |
! |
|
1861 |
||
1862 |
trapModificationsIn:anObject filter:aFilterBlock |
|
1863 |
"trap modifications in anObject" |
|
1864 |
||
1865 |
|allSelectors| |
|
1866 |
||
1867 |
allSelectors := IdentitySet new. |
|
972 | 1868 |
anObject class withAllSuperclassesDo:[:aClass | |
660 | 1869 |
aClass methodDictionary keys addAllTo:allSelectors |
1870 |
]. |
|
1871 |
||
1872 |
self trapModificationsIn:anObject selectors:allSelectors filter:aFilterBlock |
|
1873 |
||
1874 |
"trap if arrays 5th slot is modified: |
|
1875 |
||
1876 |
|a| |
|
1877 |
||
1878 |
a := Array new:10. |
|
1879 |
MessageTracer trapModificationsIn:a filter:[:old :new | (old at:5) ~~ (new at:5)]. |
|
1880 |
||
1881 |
a size. |
|
1882 |
a at:1. |
|
1883 |
a at:2 put:nil. |
|
1884 |
a at:2 put:2. |
|
1885 |
a at:2. |
|
1886 |
a at:3. |
|
1887 |
a at:2 put:2. |
|
1888 |
a at:2 put:3. |
|
1889 |
a at:5 put:3. |
|
1890 |
a at:5 put:3. |
|
1891 |
MessageTracer untrace:a. |
|
1892 |
a at:3 put:5. |
|
1893 |
" |
|
1894 |
||
1895 |
"Modified: / 21.4.1998 / 15:53:38 / cg" |
|
1896 |
! |
|
1897 |
||
1898 |
trapModificationsIn:anObject selector:aSelector filter:aFilterBlock |
|
1899 |
"install a trap for modifications in anObject by aSelector-messages. |
|
1900 |
the filterBlock will be invoked (after a modification) with the old and |
|
1901 |
new values as arguments and should return true, |
|
1902 |
if the debugger is really wanted." |
|
1903 |
||
1904 |
self |
|
1905 |
trapModificationsIn:anObject |
|
1906 |
selectors:(Array with:aSelector) |
|
1907 |
filter:aFilterBlock |
|
1908 |
||
1909 |
"Modified: / 21.4.1998 / 15:34:44 / cg" |
|
1910 |
! |
|
1911 |
||
1912 |
trapModificationsIn:anObject selectors:aCollectionOfSelectors filter:aFilterBlock |
|
1913 |
"install a trap for modifications in anObject by aSelector-messages. |
|
1914 |
the filterBlock will be invoked (after a modification) with the old and |
|
1915 |
new values as arguments and should return true, |
|
1916 |
if the debugger is really wanted." |
|
1917 |
||
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1918 |
|copyHolder sels checkBlock| |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1919 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1920 |
(anObject isNil |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1921 |
or:[anObject isSymbol |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1922 |
or:[anObject class == SmallInteger |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1923 |
or:[anObject == true |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1924 |
or:[anObject == false]]]]) |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1925 |
ifTrue:[ |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1926 |
self error:'cannot place trap on this object' mayProceed:true. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1927 |
^ self. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1928 |
]. |
660 | 1929 |
|
1930 |
ObjectCopyHolders isNil ifTrue:[ |
|
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1931 |
ObjectCopyHolders := WeakIdentityDictionary new. |
660 | 1932 |
]. |
1933 |
copyHolder := ObjectCopyHolders at:anObject ifAbsent:nil. |
|
1934 |
copyHolder isNil ifTrue:[ |
|
1935 |
ObjectCopyHolders at:anObject put:(copyHolder := ValueHolder new). |
|
1936 |
]. |
|
1937 |
||
1938 |
copyHolder value:(anObject shallowCopy). |
|
1939 |
||
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1940 |
"/ some required ones, which are used in the wrapped code and are known to |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1941 |
"/ do no harm to the object ... consider this a kludge |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1942 |
sels := aCollectionOfSelectors copy. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1943 |
sels removeAll:#(#class #species #yourself #'sameContentsAs:' |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1944 |
#'instVarAt:' #'at:' #'basicAt:' |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1945 |
#'shallowCopy' #'copy' |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1946 |
#'=' #'==' #'~=' #'~~' |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1947 |
#'size' |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1948 |
). |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1949 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1950 |
checkBlock := |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1951 |
[:con :retVal | |
660 | 1952 |
|oldValue| |
1953 |
||
1954 |
oldValue := copyHolder value. |
|
1955 |
||
1956 |
"/ compare with copy ... |
|
1957 |
(anObject sameContentsAs:oldValue) ifFalse:[ |
|
1958 |
"/ see oldValue vs. anObject |
|
1959 |
(aFilterBlock value:oldValue value:anObject) ifTrue:[ |
|
1960 |
copyHolder value:(anObject shallowCopy). |
|
1961 |
ObjectWrittenBreakpointSignal |
|
1962 |
raiseRequestWith:(oldValue -> anObject) |
|
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1963 |
errorString:('object was modififed in: ' , con sender selector) |
660 | 1964 |
in:con sender |
1965 |
] |
|
1966 |
] |
|
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1967 |
]. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1968 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1969 |
sels do:[:aSelector | |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1970 |
self |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1971 |
wrap:anObject |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1972 |
selector:aSelector |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1973 |
onEntry:[:con | ] |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1974 |
onExit:checkBlock |
660 | 1975 |
withOriginalClass:true |
1976 |
flushCaches:false. |
|
1977 |
]. |
|
1978 |
ObjectMemory flushCaches |
|
1979 |
||
1980 |
"Created: / 21.4.1998 / 15:34:05 / cg" |
|
1981 |
"Modified: / 21.4.1998 / 16:00:39 / cg" |
|
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1982 |
! |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1983 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1984 |
trapModificationsOf:anInstVarOrOffset in:anObject |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1985 |
"trap modifications in anObject" |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1986 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1987 |
|idx selectors definingClass| |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1988 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1989 |
anInstVarOrOffset isInteger ifTrue:[ |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1990 |
"/ indexed slot |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1991 |
self |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1992 |
trapModificationsIn:anObject filter:[:old :new | (old at:anInstVarOrOffset) ~~ (new at:anInstVarOrOffset)] |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1993 |
] ifFalse:[ |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1994 |
"/ instVar by name |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1995 |
selectors := IdentitySet new. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1996 |
definingClass := anObject class whichClassDefinesInstVar:anInstVarOrOffset. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1997 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1998 |
definingClass withAllSuperclassesDo:[:aClass | |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1999 |
aClass methodDictionary keys addAllTo:selectors |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2000 |
]. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2001 |
idx := anObject class instVarOffsetOf:anInstVarOrOffset. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2002 |
self |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2003 |
trapModificationsIn:anObject selectors:selectors filter:[:old :new | (old instVarAt:idx) ~~ (new instVarAt:idx)] |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2004 |
] |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2005 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2006 |
" |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2007 |
|a| |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2008 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2009 |
a := Array new:10. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2010 |
MessageTracer trapModificationsOf:2 in:a. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2011 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2012 |
a size. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2013 |
a at:1. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2014 |
a at:2 put:nil. ' no trap here (nil already there) '. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2015 |
a at:2 put:2. ' expect trap here (changing nil to 2) '. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2016 |
a at:2. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2017 |
a at:3. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2018 |
a at:2 put:2. ' no trap here (2 already there) '. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2019 |
a at:2 put:3. ' expect trap here (changing nil to 2) '. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2020 |
a at:3. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2021 |
a at:3 put:3. ' no trap here (index is different) '. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2022 |
MessageTracer untrace:a. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2023 |
a at:3 put:5. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2024 |
" |
660 | 2025 |
! ! |
2026 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2027 |
!MessageTracer class methodsFor:'object tracing'! |
88 | 2028 |
|
2029 |
trace:anObject selector:aSelector |
|
2030 |
"arrange for a trace message to be output on Stderr, when a message with |
|
2031 |
aSelector is sent to anObject. Both entry and exit are traced. |
|
2032 |
Use untrap to remove this trace. |
|
2033 |
The current implementation does not allow integers or nil to be traced." |
|
2034 |
||
664 | 2035 |
self trace:anObject selector:aSelector on:Stderr |
88 | 2036 |
|
2037 |
" |
|
2038 |
|p| |
|
8 | 2039 |
|
88 | 2040 |
p := Point new. |
2041 |
MessageTracer trace:p selector:#x:. |
|
2042 |
p x:5. |
|
2043 |
p y:1. |
|
2044 |
p x:10. |
|
2045 |
MessageTracer untrap:p. |
|
2046 |
p x:7 |
|
2047 |
" |
|
2048 |
" |
|
2049 |
|a| |
|
2050 |
||
2051 |
a := #(6 1 9 66 2 17) copy. |
|
2052 |
MessageTracer trace:a selector:#at:put:. |
|
2053 |
MessageTracer trace:a selector:#at:. |
|
2054 |
a sort. |
|
2055 |
" |
|
538
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
2056 |
|
660 | 2057 |
"Modified: / 21.4.1998 / 15:37:05 / cg" |
88 | 2058 |
! |
2059 |
||
664 | 2060 |
trace:anObject selector:aSelector on:aStream |
2061 |
"arrange for a trace message to be output on Stderr, when a message with |
|
2062 |
aSelector is sent to anObject. Both entry and exit are traced. |
|
2063 |
Use untrap to remove this trace. |
|
2064 |
The current implementation does not allow integers or nil to be traced." |
|
2065 |
||
2066 |
self |
|
2067 |
trace:anObject |
|
2068 |
selectors:(Array with:aSelector) |
|
2069 |
on:aStream |
|
2070 |
||
2071 |
" |
|
2072 |
|p| |
|
2073 |
||
2074 |
p := Point new. |
|
2075 |
MessageTracer trace:p selector:#x: on:Stderr. |
|
2076 |
p x:5. |
|
2077 |
p y:1. |
|
2078 |
p x:10. |
|
2079 |
MessageTracer untrap:p. |
|
2080 |
p x:7 |
|
2081 |
" |
|
2082 |
" |
|
2083 |
|a| |
|
2084 |
||
2085 |
a := #(6 1 9 66 2 17) copy. |
|
2086 |
MessageTracer trace:a selector:#at:put: on:Stderr. |
|
2087 |
MessageTracer trace:a selector:#at:. on:Stderr |
|
2088 |
a sort. |
|
2089 |
" |
|
2090 |
||
2091 |
"Modified: / 21.4.1998 / 15:37:05 / cg" |
|
2092 |
! |
|
2093 |
||
660 | 2094 |
trace:anObject selectors:aCollectionOfSelectors |
2095 |
"arrange for a trace message to be output on Stderr, when any message |
|
2096 |
from aCollectionOfSelectors is sent to anObject. |
|
2097 |
Both entry and exit are traced. |
|
2098 |
Use untrap:/untrace: to remove this trace. |
|
2099 |
The current implementation does not allow integers or nil to be traced." |
|
2100 |
||
664 | 2101 |
self trace:anObject selectors:aCollectionOfSelectors on:Stderr |
88 | 2102 |
|
2103 |
" |
|
660 | 2104 |
|p| |
2105 |
||
2106 |
p := Point new. |
|
2107 |
MessageTracer trace:p selector:#x:. |
|
2108 |
p x:5. |
|
2109 |
p y:1. |
|
2110 |
p x:10. |
|
2111 |
MessageTracer untrap:p. |
|
2112 |
p x:7 |
|
2113 |
" |
|
2114 |
" |
|
2115 |
|a| |
|
2116 |
||
2117 |
a := #(6 1 9 66 2 17) copy. |
|
2118 |
MessageTracer trace:a selector:#at:put:. |
|
2119 |
MessageTracer trace:a selector:#at:. |
|
2120 |
a sort. |
|
88 | 2121 |
" |
2122 |
||
660 | 2123 |
"Modified: / 21.4.1998 / 15:41:57 / cg" |
88 | 2124 |
! |
2125 |
||
664 | 2126 |
trace:anObject selectors:aCollectionOfSelectors on:aStream |
2127 |
"arrange for a trace message to be output on Stderr, when any message |
|
2128 |
from aCollectionOfSelectors is sent to anObject. |
|
2129 |
Both entry and exit are traced. |
|
2130 |
Use untrap:/untrace: to remove this trace. |
|
2131 |
The current implementation does not allow integers or nil to be traced." |
|
2132 |
||
2133 |
|methodName| |
|
2134 |
||
2135 |
aCollectionOfSelectors do:[:aSelector | |
|
2136 |
methodName := anObject class name , '>>' , aSelector. |
|
2137 |
self |
|
2138 |
wrap:anObject |
|
2139 |
selector:aSelector |
|
2140 |
onEntry:[:con | |
|
2141 |
aStream nextPutAll:'enter '; nextPutAll:methodName. |
|
2142 |
aStream nextPutAll:' receiver='. |
|
2143 |
con receiver printOn:aStream. |
|
2144 |
aStream nextPutAll:' args='. (con args) printOn:aStream. |
|
2145 |
aStream nextPutAll:' from:'. con sender printOn:aStream. |
|
2146 |
aStream cr; flush |
|
2147 |
] |
|
2148 |
onExit:[:con :retVal | |
|
2149 |
aStream nextPutAll:'leave '; nextPutAll:methodName. |
|
2150 |
aStream nextPutAll:' receiver='. con receiver printOn:aStream. |
|
2151 |
aStream nextPutAll:' returning:'. retVal printOn:aStream. |
|
2152 |
aStream cr; flush |
|
2153 |
] |
|
2154 |
withOriginalClass:true |
|
2155 |
flushCaches:false |
|
2156 |
]. |
|
2157 |
ObjectMemory flushCaches |
|
2158 |
||
2159 |
" |
|
2160 |
|p| |
|
2161 |
||
2162 |
p := Point new. |
|
2163 |
MessageTracer trace:p selectors:#(x:) on:Transcript. |
|
2164 |
p x:5. |
|
2165 |
p y:1. |
|
2166 |
p x:10. |
|
2167 |
MessageTracer untrap:p. |
|
2168 |
p x:7 |
|
2169 |
" |
|
2170 |
" |
|
2171 |
|a| |
|
2172 |
||
2173 |
a := #(6 1 9 66 2 17) copy. |
|
2174 |
MessageTracer trace:a selectors:#( at:put: at:) on:Transcript. |
|
2175 |
a sort. |
|
2176 |
" |
|
2177 |
||
2178 |
"Modified: / 21.4.1998 / 15:41:57 / cg" |
|
2179 |
! |
|
2180 |
||
88 | 2181 |
traceAll:anObject |
2182 |
"trace all messages which are understood by anObject" |
|
27 | 2183 |
|
664 | 2184 |
self traceAll:anObject on:Stderr |
88 | 2185 |
|
2186 |
" |
|
2187 |
trace all (implemented) messages sent to Display |
|
2188 |
(other messages lead to an error, anyway) |
|
2189 |
" |
|
2190 |
||
2191 |
" |
|
2192 |
MessageTracer traceAll:Display |
|
2193 |
MessageTracer untrace:Display |
|
2194 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2195 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2196 |
"Modified: 5.6.1996 / 13:43:51 / stefan" |
88 | 2197 |
! |
2198 |
||
2199 |
traceAll:anObject from:aClass |
|
2200 |
"trace all messages defined in aClass sent to anObject" |
|
2201 |
||
664 | 2202 |
self traceAll:anObject from:aClass on:Stderr |
88 | 2203 |
|
2204 |
" |
|
2205 |
trace all methods in Display, which are implemented |
|
2206 |
in the DisplayWorkstation class. |
|
2207 |
" |
|
2208 |
||
2209 |
" |
|
2210 |
MessageTracer traceAll:Display from:XWorkstation |
|
2211 |
MessageTracer untrace:Display |
|
2212 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2213 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2214 |
"Modified: 5.6.1996 / 13:45:37 / stefan" |
27 | 2215 |
! |
2216 |
||
664 | 2217 |
traceAll:anObject from:aClass on:aStream |
2218 |
"trace all messages defined in aClass sent to anObject" |
|
2219 |
||
2220 |
self trace:anObject selectors:aClass selectors on:aStream |
|
2221 |
||
2222 |
" |
|
2223 |
trace all methods in Display, which are implemented |
|
2224 |
in the DisplayWorkstation class. |
|
2225 |
" |
|
2226 |
||
2227 |
" |
|
2228 |
MessageTracer traceAll:Display from:XWorkstation on:Transcript |
|
2229 |
MessageTracer untrace:Display |
|
2230 |
" |
|
2231 |
||
2232 |
"Modified: 5.6.1996 / 13:45:37 / stefan" |
|
2233 |
! |
|
2234 |
||
2235 |
traceAll:anObject on:aStream |
|
2236 |
"trace all messages which are understood by anObject" |
|
2237 |
||
2238 |
|allSelectors| |
|
2239 |
||
2240 |
allSelectors := IdentitySet new. |
|
972 | 2241 |
anObject class withAllSuperclassesDo:[:aClass | |
664 | 2242 |
aClass methodDictionary keys addAllTo:allSelectors |
2243 |
]. |
|
2244 |
self trace:anObject selectors:allSelectors on:aStream |
|
2245 |
||
2246 |
" |
|
2247 |
trace all (implemented) messages sent to Display |
|
2248 |
(other messages lead to an error, anyway) |
|
2249 |
" |
|
2250 |
||
2251 |
" |
|
2252 |
MessageTracer traceAll:Display on:Transcript |
|
2253 |
MessageTracer untrace:Display |
|
2254 |
" |
|
2255 |
||
2256 |
"Modified: 5.6.1996 / 13:43:51 / stefan" |
|
2257 |
! |
|
2258 |
||
2259 |
traceEntry:anObject selectors:aCollectionOfSelectors on:aStream |
|
2260 |
"arrange for a trace message to be output on Stderr, when any message |
|
2261 |
from aCollectionOfSelectors is sent to anObject. |
|
2262 |
Only entry is traced. |
|
2263 |
Use untrap:/untrace: to remove this trace. |
|
2264 |
The current implementation does not allow integers or nil to be traced." |
|
2265 |
||
2266 |
self |
|
2267 |
traceEntry:anObject selectors:aCollectionOfSelectors on:Stderr |
|
2268 |
||
2269 |
" |
|
2270 |
|p| |
|
2271 |
||
2272 |
p := Point new. |
|
2273 |
MessageTracer traceEntry:p selectors:#(x:). |
|
2274 |
p x:5. |
|
2275 |
p y:1. |
|
2276 |
p x:10. |
|
2277 |
MessageTracer untrap:p. |
|
2278 |
p x:7 |
|
2279 |
" |
|
2280 |
" |
|
2281 |
|a| |
|
2282 |
||
2283 |
a := #(6 1 9 66 2 17) copy. |
|
2284 |
MessageTracer traceEntry:a selectors:#( at:put: at:). |
|
2285 |
a sort. |
|
2286 |
" |
|
2287 |
||
2288 |
"Modified: / 21.4.1998 / 15:41:57 / cg" |
|
2289 |
! |
|
2290 |
||
88 | 2291 |
traceSender:anObject selector:aSelector |
2292 |
"arrange for a trace message to be output on Stderr, when a message with |
|
2293 |
aSelector is sent to anObject. Only the sender is traced on entry. |
|
2294 |
Use untrap to remove this trace. |
|
2295 |
The current implementation does not allow integers or nil to be traced." |
|
2296 |
||
664 | 2297 |
^ self traceSender:anObject selector:aSelector on:Stderr |
88 | 2298 |
|
2299 |
" |
|
2300 |
|p| |
|
27 | 2301 |
|
88 | 2302 |
p := Point new. |
2303 |
MessageTracer traceSender:p selector:#x:. |
|
2304 |
p x:5. |
|
2305 |
p y:1. |
|
2306 |
p x:10. |
|
2307 |
MessageTracer untrap:p. |
|
2308 |
p x:7 |
|
2309 |
" |
|
2310 |
" |
|
2311 |
|a| |
|
2312 |
||
2313 |
a := #(6 1 9 66 2 17) copy. |
|
2314 |
MessageTracer traceSender:a selector:#at:put:. |
|
2315 |
MessageTracer traceSender:a selector:#at:. |
|
2316 |
a sort. |
|
2317 |
" |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2318 |
|
538
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
2319 |
"Modified: 10.1.1997 / 17:54:53 / cg" |
11 | 2320 |
! |
2321 |
||
664 | 2322 |
traceSender:anObject selector:aSelector on:aStream |
2323 |
"arrange for a trace message to be output on Stderr, when a message with |
|
2324 |
aSelector is sent to anObject. Only the sender is traced on entry. |
|
2325 |
Use untrap to remove this trace. |
|
2326 |
The current implementation does not allow integers or nil to be traced." |
|
2327 |
||
2328 |
|methodName| |
|
2329 |
||
2330 |
methodName := anObject class name , '>>' , aSelector. |
|
2331 |
self wrap:anObject |
|
2332 |
selector:aSelector |
|
2333 |
onEntry:[:con | |
|
2334 |
aStream nextPutAll:methodName. |
|
2335 |
aStream nextPutAll:' from '. |
|
2336 |
con sender printOn:aStream. |
|
2337 |
aStream cr; flush. |
|
2338 |
] |
|
2339 |
onExit:LeaveTraceBlock. |
|
2340 |
||
2341 |
" |
|
2342 |
|p| |
|
2343 |
||
2344 |
p := Point new. |
|
2345 |
MessageTracer traceSender:p selector:#x: on:Transcript. |
|
2346 |
p x:5. |
|
2347 |
p y:1. |
|
2348 |
p x:10. |
|
2349 |
MessageTracer untrap:p. |
|
2350 |
p x:7 |
|
2351 |
" |
|
2352 |
" |
|
2353 |
|a| |
|
2354 |
||
2355 |
a := #(6 1 9 66 2 17) copy. |
|
2356 |
MessageTracer traceSender:a selector:#at:put: on:Transcript. |
|
2357 |
MessageTracer traceSender:a selector:#at:. on:Transcript |
|
2358 |
a sort. |
|
2359 |
" |
|
2360 |
||
2361 |
"Modified: 10.1.1997 / 17:54:53 / cg" |
|
2362 |
! |
|
2363 |
||
88 | 2364 |
untrace:anObject |
2365 |
"remove any traces on anObject" |
|
2366 |
||
2367 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
2368 |
trace facilities ..." |
|
2369 |
||
2370 |
^ self untrap:anObject |
|
2371 |
! |
|
2372 |
||
2373 |
untrace:anObject selector:aSelector |
|
2374 |
"remove traces of aSelector sent to anObject" |
|
2375 |
||
2376 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
2377 |
trace facilities ..." |
|
2378 |
||
2379 |
^ self untrap:anObject selector:aSelector |
|
2380 |
! ! |
|
2381 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2382 |
!MessageTracer class methodsFor:'object wrapping'! |
88 | 2383 |
|
8 | 2384 |
wrap:anObject selector:aSelector onEntry:entryBlock onExit:exitBlock |
2385 |
"arrange for the two blocks entryBlock and exitBlock to be evaluated whenever |
|
2386 |
a message with aSelector is sent to anObject. EntryBlock will be called on |
|
2387 |
entry, and get the current context passed as argument. ExitBlock will be called, |
|
2388 |
when the method is left, and get the context and the methods return value as arguments. |
|
2389 |
The current implementation does not allow integers or nil to be wrapped." |
|
2390 |
||
2391 |
"I have not yet enough experience, if the wrapped original method should |
|
2392 |
run as an instance of the original, or of the catching class; |
|
2393 |
The latter has the advantage of catching recursive and other sends, while |
|
2394 |
it might lead into trouble when the message is sent from a debugger or a long |
|
2395 |
return is done out of the original method ... |
|
2396 |
Time will show, you can experiment by setting the withOriginalClass: flag to false |
|
2397 |
" |
|
660 | 2398 |
^ self |
2399 |
wrap:anObject |
|
2400 |
selector:aSelector |
|
2401 |
onEntry:entryBlock |
|
2402 |
onExit:exitBlock |
|
2403 |
withOriginalClass:true |
|
2404 |
flushCaches:true |
|
2405 |
||
2406 |
"Modified: / 21.4.1998 / 15:29:50 / cg" |
|
8 | 2407 |
! |
2408 |
||
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2409 |
wrap:anObject selector:aSelector onEntry:entryBlock onExit:exitBlock additionalEntryCode:additionalEntryCode additionalExitCode:additionalExitCode additionalVariables:additionalVariables withOriginalClass:withOriginalClass flushCaches:flushCaches |
8 | 2410 |
"arrange for the two blocks entryBlock and exitBlock to be evaluated whenever |
2411 |
a message with aSelector is sent to anObject. EntryBlock will be called on |
|
2412 |
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
|
2413 |
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
|
2414 |
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
|
2415 |
before the wrapped method will be called. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2416 |
NOTICE: The current implementation does not allow integers or nil to be wrapped." |
8 | 2417 |
|
1452 | 2418 |
|newClass orgClass myMetaclass trapMethod s spec implClass dict |
955
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
2419 |
originalMethod| |
8 | 2420 |
|
2421 |
" |
|
27 | 2422 |
some are not allowed (otherwise we get into trouble ...) |
2423 |
" |
|
660 | 2424 |
(aSelector == #class |
2425 |
or:[aSelector == #changeClassTo:]) ifTrue:[ |
|
256 | 2426 |
Transcript showCR:'sorry, cannot place trap on: ' , aSelector. |
2427 |
^ self |
|
27 | 2428 |
]. |
2429 |
||
2430 |
WrappedMethod autoload. "/ just to make sure ... |
|
2431 |
||
2432 |
" |
|
8 | 2433 |
create a new (anonymous) subclass of the receivers class |
2434 |
but only if not already being trapped. |
|
2435 |
" |
|
2436 |
orgClass := anObject class. |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
2437 |
orgClass category == #'* trapping *' ifTrue:[ |
256 | 2438 |
newClass := orgClass |
8 | 2439 |
] ifFalse:[ |
256 | 2440 |
myMetaclass := orgClass class. |
8 | 2441 |
|
256 | 2442 |
newClass := myMetaclass copy new. |
2443 |
newClass setSuperclass:orgClass. |
|
2444 |
newClass instSize:orgClass instSize. |
|
2445 |
newClass flags:orgClass flags. |
|
667 | 2446 |
newClass isMeta ifFalse:[newClass setClassVariableString:'']. |
256 | 2447 |
newClass setInstanceVariableString:''. |
2448 |
newClass setName:orgClass name. |
|
1320
f346fa1fdb3a
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2449 |
newClass setCategory:#'* trapping *'. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2450 |
newClass methodDictionary:MethodDictionary new. |
8 | 2451 |
]. |
2452 |
||
2453 |
" |
|
2454 |
create a method, executing the trap-blocks and the original method via a super-send |
|
2455 |
" |
|
2456 |
spec := Parser methodSpecificationForSelector:aSelector. |
|
2457 |
s := WriteStream on:String new. |
|
2458 |
s nextPutAll:spec. |
|
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2459 |
s nextPutAll:' |retVal stubClass '. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2460 |
additionalVariables notNil ifTrue:[ |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2461 |
s nextPutAll:additionalVariables. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2462 |
]. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2463 |
s nextPutAll:'| '. |
8 | 2464 |
withOriginalClass ifTrue:[ |
256 | 2465 |
s nextPutAll:'stubClass := self class. '. |
2466 |
s nextPutAll:'self changeClassTo:(stubClass superclass). '. |
|
8 | 2467 |
]. |
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2468 |
additionalEntryCode notNil ifTrue:[ |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2469 |
s nextPutAll:additionalEntryCode. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2470 |
]. |
8 | 2471 |
entryBlock notNil ifTrue:[ |
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2472 |
s nextPutAll:'#literal1 yourself value:thisContext. '. "/ #literal1 will be replaced by the entryBlock |
8 | 2473 |
]. |
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2474 |
s nextPutAll:('retVal := #originalMethod. '). "/ just to get a place for the originalMethod |
27 | 2475 |
s nextPutAll:('retVal := super ' , spec , '. '). |
8 | 2476 |
exitBlock notNil ifTrue:[ |
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2477 |
s nextPutAll:'#literal2 yourself value:thisContext value:retVal. '. "/ #literal2 will be replaced by the exitBlock |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2478 |
]. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2479 |
additionalExitCode notNil ifTrue:[ |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2480 |
s nextPutAll:additionalExitCode. |
8 | 2481 |
]. |
2482 |
withOriginalClass ifTrue:[ |
|
256 | 2483 |
s nextPutAll:'self changeClassTo:stubClass. '. |
8 | 2484 |
]. |
2485 |
s nextPutAll:'^ retVal'; cr. |
|
2486 |
||
1452 | 2487 |
ParserFlags |
2488 |
withSTCCompilation:#never |
|
2489 |
do:[ |
|
2490 |
Class withoutUpdatingChangesDo:[ |
|
2491 |
trapMethod := Compiler compile:s contents |
|
2492 |
forClass:newClass |
|
2493 |
inCategory:'breakpointed' |
|
2494 |
notifying:nil |
|
2495 |
install:false |
|
2496 |
skipIfSame:false |
|
2497 |
silent:true. |
|
2498 |
] |
|
2499 |
]. |
|
8 | 2500 |
|
646 | 2501 |
trapMethod == #Error ifTrue:[ |
2502 |
Transcript showCR:('cannot place trap on method: ' , aSelector). |
|
2503 |
^ self |
|
2504 |
]. |
|
2505 |
||
29 | 2506 |
implClass := orgClass whichClassIncludesSelector:aSelector. |
2507 |
implClass isNil ifTrue:[ |
|
256 | 2508 |
Transcript showCR:aSelector , ' is not understood by ' , orgClass name. |
29 | 2509 |
] ifFalse:[ |
955
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
2510 |
originalMethod := (implClass compiledMethodAt:aSelector). |
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
2511 |
originalMethod notNil ifTrue:[ |
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
2512 |
trapMethod setPackage:originalMethod package. |
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
2513 |
]. |
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
2514 |
|
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
2515 |
trapMethod changeLiteral:#originalMethod to:originalMethod. |
29 | 2516 |
]. |
8 | 2517 |
entryBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
2518 |
trapMethod changeLiteral:#literal1 to:entryBlock. |
8 | 2519 |
]. |
2520 |
exitBlock notNil ifTrue:[ |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
2521 |
trapMethod changeLiteral:#literal2 to:exitBlock. |
8 | 2522 |
]. |
2523 |
" |
|
2524 |
change the source of this new method |
|
2525 |
(to avoid confusion in the debugger ...) |
|
2526 |
" |
|
2527 |
trapMethod source:'this is a wrapper method - not the real one'. |
|
27 | 2528 |
trapMethod changeClassTo:WrappedMethod. |
8 | 2529 |
|
2530 |
" |
|
2531 |
install this new method |
|
2532 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2533 |
dict := newClass methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2534 |
dict := dict at:aSelector putOrAppend:trapMethod. |
660 | 2535 |
flushCaches ifTrue:[ |
2536 |
newClass methodDictionary:dict. |
|
2537 |
] ifFalse:[ |
|
2538 |
newClass setMethodDictionary:dict. |
|
2539 |
]. |
|
8 | 2540 |
|
2541 |
" |
|
2542 |
and finally, the big trick: |
|
2543 |
" |
|
660 | 2544 |
newClass ~~ orgClass ifTrue:[ |
2545 |
anObject changeClassTo:newClass |
|
2546 |
]. |
|
8 | 2547 |
|
2548 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2549 |
[exBegin] |
8 | 2550 |
|p| |
2551 |
||
2552 |
p := Point new copy. |
|
2553 |
MessageTracer |
|
256 | 2554 |
wrap:p |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2555 |
selector:#y: |
256 | 2556 |
onEntry:nil |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2557 |
onExit:[:context :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2558 |
Transcript show:'leave Point>>y:, returning:'. |
256 | 2559 |
Transcript showCR:retVal printString. |
2560 |
Transcript endEntry |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2561 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2562 |
withOriginalClass:true. |
256 | 2563 |
Transcript showCR:'sending x: ...'. |
8 | 2564 |
p x:1. |
256 | 2565 |
Transcript showCR:'sending y: ...'. |
8 | 2566 |
p y:2. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2567 |
MessageTracer untrap:p. |
256 | 2568 |
Transcript showCR:'sending x: ...'. |
8 | 2569 |
p x:2. |
256 | 2570 |
Transcript showCR:'sending y: ...'. |
8 | 2571 |
p y:1. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2572 |
[exEnd] |
8 | 2573 |
" |
2574 |
||
2575 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2576 |
[exBegin] |
8 | 2577 |
|p| |
2578 |
||
2579 |
p := Point new copy. |
|
2580 |
MessageTracer wrap:p |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2581 |
selector:#y: |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2582 |
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
|
2583 |
onExit:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2584 |
withOriginalClass:false. |
256 | 2585 |
Transcript showCR:'sending x: ...'. |
8 | 2586 |
p x:1. |
256 | 2587 |
Transcript showCR:'sending y: ...'. |
8 | 2588 |
p y:2. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2589 |
MessageTracer untrap:p. |
256 | 2590 |
Transcript showCR:'sending x: ...'. |
8 | 2591 |
p x:2. |
256 | 2592 |
Transcript showCR:'sending y: ...'. |
8 | 2593 |
p y:1. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2594 |
[exEnd] |
8 | 2595 |
" |
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
2596 |
|
646 | 2597 |
"Modified: / 25.6.1996 / 22:11:21 / stefan" |
2598 |
"Modified: / 6.2.1998 / 02:48:13 / cg" |
|
660 | 2599 |
"Created: / 21.4.1998 / 15:30:27 / cg" |
8 | 2600 |
! |
2601 |
||
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2602 |
wrap:anObject selector:aSelector onEntry:entryBlock onExit:exitBlock withOriginalClass:withOriginalClass flushCaches:flushCaches |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2603 |
"arrange for the two blocks entryBlock and exitBlock to be evaluated whenever |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2604 |
a message with aSelector is sent to anObject. EntryBlock will be called on |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2605 |
entry, and get the current context passed as argument. ExitBlock will be called, |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2606 |
when the method is left, and get the current context and the methods return value as argument. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2607 |
If withOriginalClass is true, the class of anObject will be set to its original class |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2608 |
before the wrapped method will be called. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2609 |
NOTICE: The current implementation does not allow integers or nil to be wrapped." |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2610 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2611 |
^ self |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2612 |
wrap:anObject selector:aSelector onEntry:entryBlock onExit:exitBlock |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2613 |
additionalEntryCode:nil additionalExitCode:nil additionalVariables:nil |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2614 |
withOriginalClass:withOriginalClass flushCaches:flushCaches |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2615 |
! |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2616 |
|
88 | 2617 |
wrap:anObject selectors:aCollection onEntry:entryBlock onExit:exitBlock |
2618 |
"install wrappers for anObject on all selectors from aCollection" |
|
8 | 2619 |
|
88 | 2620 |
aCollection do:[:aSelector | |
660 | 2621 |
self |
2622 |
wrap:anObject selector:aSelector |
|
2623 |
onEntry:entryBlock onExit:exitBlock |
|
2624 |
withOriginalClass:true |
|
2625 |
flushCaches:false |
|
2626 |
]. |
|
2627 |
ObjectMemory flushCaches |
|
2628 |
||
2629 |
"Modified: / 21.4.1998 / 15:40:28 / cg" |
|
8 | 2630 |
! |
2631 |
||
88 | 2632 |
wrapAll:anObject onEntry:entryBlock onExit:exitBlock |
2633 |
"install wrappers for anObject on all implemented selectors" |
|
27 | 2634 |
|
2635 |
|allSelectors| |
|
2636 |
||
2637 |
allSelectors := IdentitySet new. |
|
972 | 2638 |
anObject class withAllSuperclassesDo:[:aClass | |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2639 |
aClass methodDictionary keys addAllTo:allSelectors |
27 | 2640 |
]. |
88 | 2641 |
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
|
2642 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2643 |
"Modified: 5.6.1996 / 14:50:07 / stefan" |
88 | 2644 |
! ! |
2645 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2646 |
!MessageTracer class methodsFor:'queries'! |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2647 |
|
1369 | 2648 |
allWrappedMethods |
2649 |
|methods| |
|
2650 |
||
2651 |
methods := IdentitySet new. |
|
2652 |
||
1472
6bf86c3d084e
code cleanup: use new Smalltalk>>allMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
1452
diff
changeset
|
2653 |
Smalltalk allMethodsDo:[:mthd | |
6bf86c3d084e
code cleanup: use new Smalltalk>>allMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
1452
diff
changeset
|
2654 |
mthd isWrapped ifTrue:[ |
6bf86c3d084e
code cleanup: use new Smalltalk>>allMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
1452
diff
changeset
|
2655 |
methods add:mthd. |
6bf86c3d084e
code cleanup: use new Smalltalk>>allMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
1452
diff
changeset
|
2656 |
] |
1369 | 2657 |
]. |
2658 |
^ methods asOrderedCollection |
|
2659 |
! |
|
2660 |
||
2661 |
areAnyMethodsWrapped |
|
1472
6bf86c3d084e
code cleanup: use new Smalltalk>>allMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
1452
diff
changeset
|
2662 |
Smalltalk allMethodsDo:[:mthd | |
6bf86c3d084e
code cleanup: use new Smalltalk>>allMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
1452
diff
changeset
|
2663 |
mthd isWrapped ifTrue:[ ^ true ] |
1369 | 2664 |
]. |
2665 |
^ false |
|
2666 |
! |
|
2667 |
||
579 | 2668 |
isCounting:aMethod |
2669 |
"return true if aMethod is counted" |
|
2670 |
||
2671 |
MethodCounts isNil ifTrue:[^ false]. |
|
2672 |
(MethodCounts includesKey:aMethod) ifTrue:[^ true]. |
|
2673 |
aMethod isWrapped ifTrue:[ |
|
2674 |
^ MethodCounts includesKey:aMethod originalMethod |
|
2675 |
]. |
|
2676 |
^ false |
|
2677 |
||
2678 |
"Created: 15.12.1995 / 11:07:58 / cg" |
|
2679 |
"Modified: 15.12.1995 / 15:42:10 / cg" |
|
2680 |
! |
|
2681 |
||
2682 |
isTiming:aMethod |
|
2683 |
"return true if aMethod is timed" |
|
2684 |
||
2685 |
MethodTiming isNil ifTrue:[^ false]. |
|
2686 |
(MethodTiming includesKey:aMethod) ifTrue:[^ true]. |
|
2687 |
aMethod isWrapped ifTrue:[ |
|
2688 |
^ MethodTiming includesKey:aMethod originalMethod |
|
2689 |
]. |
|
2690 |
^ false |
|
2691 |
||
2692 |
"Modified: 15.12.1995 / 15:42:10 / cg" |
|
2693 |
"Created: 17.6.1996 / 17:04:29 / cg" |
|
2694 |
! |
|
2695 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2696 |
isTrapped:aMethod |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2697 |
"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
|
2698 |
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
|
2699 |
this returns false)" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2700 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2701 |
aMethod isWrapped ifFalse:[^ false]. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2702 |
^ aMethod basicLiterals includesIdentical:LeaveBreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2703 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2704 |
" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2705 |
MessageTracer trapMethod:(Collection compiledMethodAt:#select:). |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2706 |
Transcript showCR:(Collection compiledMethodAt:#select:) isWrapped. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2707 |
Transcript showCR:(MessageTracer isTrapped:(Collection compiledMethodAt:#select:)). |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2708 |
MessageTracer unwrapMethod:(Collection compiledMethodAt:#select:). |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2709 |
" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2710 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2711 |
"Modified: 22.10.1996 / 17:40:37 / cg" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2712 |
! ! |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2713 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2714 |
!MessageTracer class methodsFor:'trace helpers'! |
88 | 2715 |
|
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2716 |
dummyEmptyMethod |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2717 |
"helper - to get the time it takes to evaluate the wrappers for |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2718 |
a dummy method." |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2719 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2720 |
"Created: / 30.7.1998 / 16:58:08 / cg" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2721 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2722 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2723 |
getTimeForWrappers |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2724 |
"helper - get the overhead (in ms) spent in the wrapper code of |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2725 |
a timed method." |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2726 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2727 |
|m times| |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2728 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2729 |
TimeForWrappers := 0. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2730 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2731 |
"/ wrap the dummy method ... |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2732 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2733 |
m := self class compiledMethodAt:#dummyEmptyMethod. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2734 |
m := self timeMethod:m. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2735 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2736 |
"/ invoke it a few times ... |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2737 |
"/ (cannot take the smallest, since the work done in the wrapper |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2738 |
"/ depends on whether there is already some statistic data) |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2739 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2740 |
10 timesRepeat:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2741 |
self dummyEmptyMethod. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2742 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2743 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2744 |
"/ fetch min time & unwrap |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2745 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2746 |
times := self executionTimesOfMethod:m. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2747 |
self stopTimingMethod:m. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2748 |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
2749 |
^ (TimeForWrappers := times avgTime) |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2750 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2751 |
" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2752 |
self getTimeForWrappers |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2753 |
" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2754 |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
2755 |
"Modified: / 05-03-2007 / 15:44:24 / cg" |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2756 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2757 |
|
88 | 2758 |
printEntryFull:aContext |
664 | 2759 |
self printEntryFull:aContext level:0 on:Stderr |
88 | 2760 |
! |
27 | 2761 |
|
88 | 2762 |
printEntryFull:aContext level:lvl |
664 | 2763 |
self printEntryFull:aContext level:lvl on:Stderr |
2764 |
! |
|
2765 |
||
2766 |
printEntryFull:aContext level:lvl on:aStream |
|
2767 |
aStream |
|
2768 |
spaces:lvl; |
|
734 | 2769 |
nextPutAll:'enter '. |
2770 |
self printFull:aContext on:aStream withSender:true. |
|
88 | 2771 |
! |
27 | 2772 |
|
664 | 2773 |
printEntryFull:aContext on:aStream |
2774 |
self printEntryFull:aContext level:0 on:aStream |
|
2775 |
! |
|
2776 |
||
2777 |
printEntrySender:aContext on:aStream |
|
2778 |
|sender mClass mClassName| |
|
2779 |
||
2780 |
mClass := aContext methodClass. |
|
2781 |
mClass isNil ifTrue:[ |
|
2782 |
mClassName := '???' |
|
2783 |
] ifFalse:[ |
|
2784 |
mClassName := mClass name |
|
2785 |
]. |
|
734 | 2786 |
|
664 | 2787 |
aStream |
2788 |
nextPutAll:mClassName; |
|
2789 |
space; |
|
665 | 2790 |
bold; |
664 | 2791 |
nextPutAll:aContext selector; |
665 | 2792 |
normal; |
664 | 2793 |
nextPutAll:' from '. |
538
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
2794 |
|
555
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2795 |
sender := aContext sender. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2796 |
sender notNil ifTrue:[ |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2797 |
(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
|
2798 |
sender := sender sender. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2799 |
]. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2800 |
]. |
664 | 2801 |
sender printOn:aStream. |
666 | 2802 |
aStream cr; flush. |
555
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2803 |
|
695 | 2804 |
"Modified: / 30.7.1998 / 20:40:14 / cg" |
88 | 2805 |
! |
2806 |
||
2807 |
printExit:aContext with:retVal |
|
664 | 2808 |
self printExit:aContext with:retVal level:0 on:Stderr |
27 | 2809 |
! |
2810 |
||
88 | 2811 |
printExit:aContext with:retVal level:lvl |
664 | 2812 |
self printExit:aContext with:retVal level:lvl on:Stderr |
2813 |
! |
|
2814 |
||
2815 |
printExit:aContext with:retVal level:lvl on:aStream |
|
2816 |
|mClass mClassName| |
|
2817 |
||
2818 |
mClass := aContext methodClass. |
|
2819 |
mClass isNil ifTrue:[ |
|
2820 |
mClassName := '???' |
|
2821 |
] ifFalse:[ |
|
2822 |
mClassName := mClass name |
|
2823 |
]. |
|
2824 |
aStream |
|
2825 |
spaces:lvl; |
|
2826 |
nextPutAll:'leave '; |
|
2827 |
nextPutAll:mClassName; |
|
2828 |
space; |
|
665 | 2829 |
bold; |
664 | 2830 |
nextPutAll:aContext selector; |
665 | 2831 |
normal; |
666 | 2832 |
nextPutAll:' rec=['. |
664 | 2833 |
|
1486
d7ae9a86ea38
print same receiver on entry and exit
Stefan Vogel <sv@exept.de>
parents:
1472
diff
changeset
|
2834 |
self printObject:aContext receiver on:aStream. |
666 | 2835 |
aStream nextPutAll:'] return: ['. |
664 | 2836 |
retVal printOn:aStream. |
666 | 2837 |
aStream nextPutAll:']'; cr; flush. |
664 | 2838 |
! |
2839 |
||
2840 |
printExit:aContext with:retVal on:aStream |
|
2841 |
self printExit:aContext with:retVal level:0 on:aStream |
|
2842 |
! |
|
2843 |
||
734 | 2844 |
printFull:aContext on:aStream withSender:withSender |
1071 | 2845 |
self |
2846 |
printFull:aContext on:aStream |
|
2847 |
withSenderContext:(withSender ifTrue:[aContext sender] |
|
2848 |
ifFalse:[nil]) |
|
2849 |
! |
|
2850 |
||
2851 |
printFull:aContext on:aStream withSenderContext:aSenderContextOrNil |
|
2852 |
|mClass mClassName| |
|
734 | 2853 |
|
2854 |
mClass := aContext methodClass. |
|
2855 |
mClass isNil ifTrue:[ |
|
2856 |
mClassName := '???' |
|
2857 |
] ifFalse:[ |
|
2858 |
mClassName := mClass name |
|
2859 |
]. |
|
2860 |
||
2861 |
aStream |
|
2862 |
nextPutAll:mClassName; |
|
2863 |
space; |
|
2864 |
bold; |
|
2865 |
nextPutAll:aContext selector; |
|
2866 |
normal; |
|
2867 |
nextPutAll:' rec=['. |
|
2868 |
||
735 | 2869 |
self printObject:aContext receiver on:aStream. |
2870 |
||
734 | 2871 |
aStream nextPutAll:'] '. |
2872 |
(aContext args) keysAndValuesDo:[:idx :arg | |
|
2873 |
aStream nextPutAll:'arg'. idx printOn:aStream. aStream nextPutAll:'=['. |
|
735 | 2874 |
self printObject:arg on:aStream. |
734 | 2875 |
aStream nextPutAll:'] '. |
2876 |
]. |
|
2877 |
||
1071 | 2878 |
aSenderContextOrNil notNil ifTrue:[ |
2879 |
self printSender:aSenderContextOrNil on:aStream. |
|
734 | 2880 |
]. |
2881 |
aStream cr; flush. |
|
2882 |
! |
|
2883 |
||
735 | 2884 |
printObject:anObject on:aStream |
2885 |
|s| |
|
2886 |
||
2887 |
s := anObject printString. |
|
2085
21d40e42e3fa
Better traces of object printStrings
Stefan Vogel <sv@exept.de>
parents:
2004
diff
changeset
|
2888 |
s size > 40 ifTrue:[ |
21d40e42e3fa
Better traces of object printStrings
Stefan Vogel <sv@exept.de>
parents:
2004
diff
changeset
|
2889 |
s := s chopTo:40. |
735 | 2890 |
]. |
2891 |
aStream nextPutAll:s |
|
2892 |
! |
|
2893 |
||
1071 | 2894 |
printSender:aSenderContext on:aStream |
2895 |
|sender| |
|
2896 |
||
2897 |
sender := aSenderContext. |
|
2898 |
sender notNil ifTrue:[ |
|
2899 |
(sender selector startsWith:'perform:') ifTrue:[ |
|
2900 |
sender := sender sender. |
|
2901 |
]. |
|
2902 |
]. |
|
2903 |
aStream nextPutAll:'from:'. |
|
2904 |
aStream bold. |
|
2905 |
sender printOn:aStream. |
|
2906 |
aStream normal. |
|
2907 |
! |
|
2908 |
||
2909 |
printUpdateEntryFull:aContext level:lvl on:aStream |
|
2910 |
|con| |
|
2911 |
||
2912 |
con := aContext. |
|
2913 |
||
2914 |
[con notNil |
|
2915 |
and:[con selector ~~ #'changed:with:'] |
|
2916 |
] whileTrue:[ |
|
2917 |
con := con sender. |
|
2918 |
]. |
|
2919 |
"/ con is #'changed:with:' |
|
2920 |
con isNil ifTrue:[ |
|
2921 |
^ self printEntryFull:aContext level:lvl on:aStream. |
|
2922 |
]. |
|
2923 |
||
2924 |
(con sender notNil |
|
2925 |
and:[ con sender selector == #'changed:']) ifTrue:[ |
|
2926 |
con := con sender. |
|
2927 |
]. |
|
2928 |
(con sender notNil |
|
2929 |
and:[ con sender selector == #'changed']) ifTrue:[ |
|
2930 |
con := con sender. |
|
2931 |
]. |
|
2932 |
(con sender notNil) ifTrue:[ |
|
2933 |
con := con sender. |
|
2934 |
]. |
|
2935 |
||
2936 |
aStream spaces:lvl; nextPutAll:'enter '. |
|
2937 |
self |
|
2938 |
printFull:aContext |
|
2939 |
on:aStream |
|
2940 |
withSenderContext:con |
|
2941 |
! |
|
2942 |
||
697 | 2943 |
traceEntryFull:aContext on:aStream |
2944 |
aStream nextPutLine:'-----------------------------------------'. |
|
2945 |
aContext fullPrintAllOn:aStream |
|
2946 |
||
2947 |
"Created: / 30.7.1998 / 20:39:57 / cg" |
|
2948 |
"Modified: / 30.7.1998 / 20:42:23 / cg" |
|
2949 |
! |
|
2950 |
||
664 | 2951 |
traceFullBlockFor:aStream |
2952 |
"avoid generation of fullBlocks" |
|
2953 |
||
2954 |
aStream == Transcript ifTrue:[ |
|
2955 |
^ TraceFullBlock2 |
|
2956 |
]. |
|
2957 |
aStream == Stderr ifTrue:[ |
|
2958 |
^ TraceFullBlock |
|
2959 |
]. |
|
2960 |
^ [:con | con fullPrintAllOn:aStream] |
|
2961 |
||
2962 |
||
2963 |
||
2964 |
! |
|
2965 |
||
2966 |
traceSenderBlockFor:aStream |
|
2967 |
"avoid generation of fullBlocks" |
|
2968 |
||
2969 |
aStream == Transcript ifTrue:[ |
|
2970 |
^ TraceSenderBlock2 |
|
2971 |
]. |
|
2972 |
aStream == Stderr ifTrue:[ |
|
2973 |
^ TraceSenderBlock |
|
2974 |
]. |
|
2975 |
^ [:con | MessageTracer printEntrySender:con on:aStream] |
|
2976 |
||
2977 |
||
2978 |
||
88 | 2979 |
! ! |
13 | 2980 |
|
1082 | 2981 |
!MessageTracer methodsFor:'trace helpers'! |
88 | 2982 |
|
2983 |
trace:aBlock detail:fullDetail |
|
2984 |
"trace execution of aBlock." |
|
2985 |
||
2986 |
traceDetail := fullDetail. |
|
735 | 2987 |
tracedBlock := aBlock. |
2988 |
||
88 | 2989 |
ObjectMemory stepInterruptHandler:self. |
2990 |
^ [ |
|
735 | 2991 |
ObjectMemory flushInlineCaches. |
2992 |
StepInterruptPending := 1. |
|
2993 |
InterruptPending := 1. |
|
2994 |
aBlock value |
|
1139
56861678ff27
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
1082
diff
changeset
|
2995 |
] ensure:[ |
735 | 2996 |
tracedBlock := nil. |
2997 |
StepInterruptPending := nil. |
|
2998 |
ObjectMemory stepInterruptHandler:nil. |
|
11 | 2999 |
] |
3000 |
||
3001 |
" |
|
735 | 3002 |
PrintingMessageTracer new trace:[#(6 5 4 3 2 1) sort] detail:false |
3003 |
||
3004 |
PrintingMessageTracer new trace:[#(6 5 4 3 2 1) sort] detail:true |
|
3005 |
||
3006 |
PrintingMessageTracer new trace:[#(6 5 4 3 2 1) sort] detail:#indent |
|
3007 |
||
3008 |
PrintingMessageTracer new trace:[#(6 5 4 3 2 1) sort] detail:#fullIndent |
|
8 | 3009 |
" |
3010 |
! ! |
|
27 | 3011 |
|
1082 | 3012 |
!MessageTracer::InteractionCollector methodsFor:'trace helpers'! |
1008
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3013 |
|
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3014 |
stepInterrupt |
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3015 |
StepInterruptPending := nil. |
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3016 |
ObjectMemory flushInlineCaches. |
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3017 |
StepInterruptPending := 1. |
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3018 |
InterruptPending := 1. |
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3019 |
! ! |
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3020 |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3021 |
!MessageTracer::MethodTimingInfo methodsFor:'accessing'! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3022 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3023 |
avgTime |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3024 |
sumTimes notNil ifTrue:[ |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3025 |
^ sumTimes / count |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3026 |
]. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3027 |
^ nil |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3028 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3029 |
"Created: / 05-03-2007 / 15:38:43 / cg" |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3030 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3031 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3032 |
avgTimeRounded |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3033 |
|avg| |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3034 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3035 |
avg := self avgTime. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3036 |
avg > 100 ifTrue:[ ^ avg roundTo:1 ]. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3037 |
avg > 10 ifTrue:[ ^ avg roundTo:0.1 ]. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3038 |
avg > 1 ifTrue:[ ^ avg roundTo:0.01 ]. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3039 |
^ avg roundTo:0.001 |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3040 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3041 |
"Created: / 05-03-2007 / 15:47:02 / cg" |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3042 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3043 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3044 |
count |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3045 |
^ count |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3046 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3047 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3048 |
count:countArg minTime:minTimeArg maxTime:maxTimeArg sumTimes:sumTimesArg |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3049 |
count := countArg. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3050 |
minTime := minTimeArg. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3051 |
maxTime := maxTimeArg. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3052 |
sumTimes := sumTimesArg. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3053 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3054 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3055 |
maxTime |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3056 |
^ maxTime |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3057 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3058 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3059 |
maxTimeRounded |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3060 |
|max| |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3061 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3062 |
max := self maxTime. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3063 |
^ max roundTo:(max > 10 ifTrue:0.1 ifFalse:0.01) |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3064 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3065 |
"Created: / 05-03-2007 / 15:47:22 / cg" |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3066 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3067 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3068 |
minTime |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3069 |
^ minTime |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3070 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3071 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3072 |
minTimeRounded |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3073 |
|min| |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3074 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3075 |
min := self minTime. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3076 |
^ min roundTo:(min > 10 ifTrue:0.1 ifFalse:0.01) |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3077 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3078 |
"Created: / 05-03-2007 / 15:47:16 / cg" |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3079 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3080 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3081 |
sumTimes |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3082 |
^ sumTimes |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3083 |
! ! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3084 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3085 |
!MessageTracer::MethodTimingInfo methodsFor:'initialization'! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3086 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3087 |
rememberExecutionTime:t |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3088 |
(count isNil or:[count == 0]) ifTrue:[ |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3089 |
minTime := maxTime := sumTimes := t. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3090 |
count := 1. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3091 |
] ifFalse:[ |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3092 |
t < minTime ifTrue:[ |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3093 |
minTime := t. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3094 |
] ifFalse:[ |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3095 |
t > maxTime ifTrue:[ |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3096 |
maxTime := t. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3097 |
] |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3098 |
]. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3099 |
sumTimes := (sumTimes + t). |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3100 |
count := count + 1 |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3101 |
]. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3102 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3103 |
"Created: / 05-03-2007 / 15:32:43 / cg" |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3104 |
! ! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3105 |
|
1082 | 3106 |
!MessageTracer::PrintingMessageTracer methodsFor:'trace helpers'! |
734 | 3107 |
|
3108 |
stepInterrupt |
|
3109 |
"called for every send while tracing" |
|
3110 |
||
3111 |
|ignore sel con r| |
|
3112 |
||
3113 |
StepInterruptPending := nil. |
|
3114 |
con := thisContext sender. |
|
3115 |
ignore := false. |
|
3116 |
||
3117 |
con receiver == Processor ifTrue:[ |
|
3118 |
(sel := con selector) == #threadSwitch: ifTrue:[ |
|
3119 |
ignore := true. |
|
3120 |
]. |
|
3121 |
sel == #timerInterrupt ifTrue:[ |
|
3122 |
ignore := true. |
|
3123 |
] |
|
3124 |
]. |
|
3125 |
||
3126 |
con lineNumber == 1 ifFalse:[ |
|
3127 |
ignore := true |
|
3128 |
]. |
|
3129 |
||
3130 |
ignore ifFalse:[ |
|
3131 |
con markForInterruptOnUnwind. |
|
3132 |
||
3133 |
((r := con receiver) ~~ self |
|
3134 |
and:[r ~~ tracedBlock]) ifTrue:[ |
|
3135 |
traceDetail == #fullIndent ifTrue:[ |
|
3136 |
[con notNil |
|
3137 |
and:[(r := con receiver) ~~ self |
|
3138 |
and:[r ~~ tracedBlock]]] whileTrue:[ |
|
3139 |
' ' printOn:Stderr. |
|
3140 |
con := con sender. |
|
3141 |
]. |
|
3142 |
con := thisContext sender. |
|
3143 |
self class printFull:con on:Stderr withSender:false. |
|
3144 |
] ifFalse:[ |
|
3145 |
traceDetail == #indent ifTrue:[ |
|
3146 |
[con notNil |
|
3147 |
and:[(r := con receiver) ~~ self |
|
3148 |
and:[r ~~ tracedBlock]]] whileTrue:[ |
|
3149 |
' ' printOn:Stderr. |
|
3150 |
con := con sender. |
|
3151 |
]. |
|
3152 |
con := thisContext sender. |
|
3153 |
con printOn:Stderr. |
|
3154 |
Stderr cr. |
|
3155 |
] ifFalse:[ |
|
3156 |
traceDetail == true ifTrue:[ |
|
3157 |
self class printFull:con on:Stderr withSender:true. |
|
3158 |
] ifFalse:[ |
|
3159 |
con printOn:Stderr. |
|
3160 |
Stderr cr. |
|
3161 |
] |
|
3162 |
] |
|
3163 |
]. |
|
3164 |
]. |
|
3165 |
]. |
|
3166 |
||
3167 |
ObjectMemory flushInlineCaches. |
|
3168 |
StepInterruptPending := 1. |
|
3169 |
InterruptPending := 1. |
|
3170 |
||
3171 |
" |
|
3172 |
self new trace:[#(6 5 4 3 2 1) sort] detail:false |
|
3173 |
||
3174 |
self new trace:[#(6 5 4 3 2 1) sort] detail:true |
|
3175 |
||
3176 |
self new trace:[#(6 5 4 3 2 1) sort] detail:#indent |
|
3177 |
||
3178 |
self new trace:[#(6 5 4 3 2 1) sort] detail:#fullIndent |
|
3179 |
self new trace:[ View new ] detail:#fullIndent |
|
3180 |
" |
|
3181 |
! ! |
|
3182 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
3183 |
!MessageTracer class methodsFor:'documentation'! |
98 | 3184 |
|
3185 |
version |
|
2085
21d40e42e3fa
Better traces of object printStrings
Stefan Vogel <sv@exept.de>
parents:
2004
diff
changeset
|
3186 |
^ '$Header: /cvs/stx/stx/libbasic3/MessageTracer.st,v 1.108 2009-04-03 12:29:29 stefan Exp $' |
98 | 3187 |
! ! |
1320
f346fa1fdb3a
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
3188 |
|
27 | 3189 |
MessageTracer initialize! |