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