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