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