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