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