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