author | Claus Gittinger <cg@exept.de> |
Tue, 22 Oct 1996 19:57:06 +0200 | |
changeset 503 | 67f6584e0f9f |
parent 501 | c3ccbea7930c |
child 506 | 02c057d1ce1a |
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 |
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
16 |
LeaveBreakBlock LeaveTraceBlock MethodCounts MethodMemoryUsage |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
17 |
MethodTiming TraceFullBlock' |
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
18 |
poolDictionaries:'' |
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
19 |
category:'System-Debugging-Support' |
8 | 20 |
! |
21 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
22 |
!MessageTracer class methodsFor:'documentation'! |
8 | 23 |
|
9 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
11 | 27 |
All Rights Reserved |
9 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
8 | 38 |
documentation |
39 |
" |
|
11 | 40 |
This class provides a common home for the tracing |
41 |
facilities (originally, they where in Object, but have been moved to |
|
8 | 42 |
allow easier separation of development vs. runtime configurations. |
43 |
||
11 | 44 |
tracing execution of a block: |
45 |
||
236 | 46 |
MessageTracer trace:[ ... ] |
11 | 47 |
|
236 | 48 |
MessageTracer traceFull:[ ... ] |
11 | 49 |
|
236 | 50 |
(for system developper only:) |
11 | 51 |
|
236 | 52 |
MessageTracer debugTrace:[ ... ] |
11 | 53 |
|
54 |
||
8 | 55 |
trapping sends to a specific object: |
56 |
||
236 | 57 |
MessageTracer trap:anObject selector:aSelector |
58 |
... |
|
59 |
MessageTracer untrap:anObject selector:aSelector |
|
60 |
or: |
|
61 |
MessageTracer untrap:anObject |
|
11 | 62 |
|
8 | 63 |
|
64 |
||
27 | 65 |
trapping some messages sent to a specific object: |
66 |
||
236 | 67 |
MessageTracer trap:anObject selectors:aCollectionOfSelectors |
68 |
... |
|
69 |
MessageTracer untrap:anObject |
|
27 | 70 |
|
71 |
||
72 |
||
73 |
trapping any message sent to a specific object: |
|
74 |
||
236 | 75 |
MessageTracer trapAll:anObject |
76 |
... |
|
77 |
MessageTracer untrap:anObject |
|
27 | 78 |
|
79 |
||
80 |
||
8 | 81 |
trapping evaluation of a specific method: |
82 |
||
236 | 83 |
MessageTracer trapMethod:aMethod |
84 |
... |
|
85 |
MessageTracer unwrapMethod:aMethod |
|
8 | 86 |
|
87 |
||
88 |
||
12 | 89 |
trapping evaluation of a specific method with |
90 |
receiver being an instance of some class: |
|
91 |
||
236 | 92 |
MessageTracer trapMethod:aMethod forInstancesOf:aClass |
93 |
... |
|
94 |
MessageTracer unwrapMethod:aMethod |
|
12 | 95 |
|
96 |
||
97 |
||
8 | 98 |
tracing sends to a specific object: |
99 |
||
236 | 100 |
MessageTracer trace:anObject selector:aSelector |
101 |
... |
|
102 |
MessageTracer untrace:anObject selector:aSelector |
|
103 |
or: |
|
104 |
MessageTracer untrace:anObject |
|
11 | 105 |
|
8 | 106 |
|
107 |
||
108 |
tracing sender only: |
|
109 |
||
236 | 110 |
MessageTracer traceSender:anObject selector:aSelector |
111 |
... |
|
112 |
MessageTracer untrace:anObject selector:aSelector |
|
113 |
or: |
|
114 |
MessageTracer untrace:anObject |
|
11 | 115 |
|
8 | 116 |
|
117 |
||
118 |
tracing evaluation of a specific method: |
|
119 |
||
236 | 120 |
MessageTracer traceMethod:aMethod |
121 |
... |
|
122 |
MessageTracer unwrapmethod:aMethod |
|
18 | 123 |
|
124 |
see more in examples and in method comments. |
|
236 | 125 |
|
126 |
[author:] |
|
127 |
Claus Gittinger |
|
8 | 128 |
" |
12 | 129 |
! |
130 |
||
131 |
examples |
|
132 |
" |
|
133 |
For the common cases, you will find a menu entry in the SystemBrowser. |
|
134 |
Howeever, more special cases (especially with condition checks) can be |
|
135 |
set up by evaluating the lower level entries. |
|
136 |
||
137 |
||
138 |
trapping specific methods: |
|
139 |
(by class/selector): |
|
244 | 140 |
[exBegin] |
12 | 141 |
MessageTracer trapClass:Collection selector:#select:. |
142 |
Dictionary new select:[:e | ]. 'not cought - Dictionary has its own select'. |
|
143 |
(Array new:10) select:[:e | ]. 'not cought - SeqColl has its own select'. |
|
144 |
Set new select:[:e | ]. 'cought - Set inherits this from Collection'. |
|
145 |
MessageTracer untrapClass:Collection |
|
244 | 146 |
[exEnd] |
12 | 147 |
|
148 |
(by method): |
|
244 | 149 |
[exBegin] |
12 | 150 |
MessageTracer trapMethod:(Collection compiledMethodAt:#select:). |
151 |
Dictionary new select:[:e | ]. 'not cought - Dictionary has its own select'. |
|
152 |
(Array new:10) select:[:e | ]. 'not cought - SeqColl has its own select'. |
|
153 |
Set new select:[:e | ]. 'cought - Set inherits this from Collection'. |
|
154 |
MessageTracer unwrapMethod:(Collection compiledMethodAt:#select:). |
|
244 | 155 |
[exEnd] |
12 | 156 |
|
27 | 157 |
(by method & instance class): |
244 | 158 |
[exBegin] |
27 | 159 |
MessageTracer trapMethod:(SequenceableCollection compiledMethodAt:#select:) |
244 | 160 |
forInstancesOf:SortedCollection. |
27 | 161 |
Dictionary new select:[:e | ]. 'not cought - Dictionary has its own select'. |
162 |
(Array new:10) select:[:e | ]. 'not cought - not a SortedCollection'. |
|
163 |
OrderedCollection new select:[:e | ]. 'not cought - not a SortedCollection'. |
|
164 |
SortedCollection new select:[:e | ]. 'cought - Set inherits this from Collection'. |
|
165 |
MessageTracer unwrapMethod:(SequenceableCollection compiledMethodAt:#select:). |
|
244 | 166 |
[exEnd] |
27 | 167 |
|
12 | 168 |
tracing specific methods: |
169 |
(by class/selector): |
|
244 | 170 |
[exBegin] |
12 | 171 |
MessageTracer traceClass:SequenceableCollection selector:#quickSortFrom:to:. |
172 |
#(6 1 9 66 2 17) copy sort. |
|
173 |
MessageTracer untraceClass:SequenceableCollection |
|
244 | 174 |
[exEnd] |
12 | 175 |
|
176 |
(by method): |
|
244 | 177 |
[exBegin] |
12 | 178 |
MessageTracer traceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
179 |
#(6 1 9 66 2 17) copy sort. |
|
180 |
MessageTracer unwrapMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
244 | 181 |
[exEnd] |
27 | 182 |
|
183 |
object trapping: |
|
244 | 184 |
[exBegin] |
27 | 185 |
|o| |
186 |
||
187 |
o := OrderedCollection new. |
|
188 |
MessageTracer trapAll:o. |
|
189 |
o collect:[:el | el]. |
|
244 | 190 |
[exEnd] |
12 | 191 |
" |
8 | 192 |
! ! |
193 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
194 |
!MessageTracer class methodsFor:'initialization'! |
11 | 195 |
|
196 |
initialize |
|
197 |
BreakpointSignal isNil ifTrue:[ |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
198 |
BreakpointSignal := HaltSignal newSignalMayProceed:true. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
199 |
BreakpointSignal nameClass:self message:#breakpointSignal. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
200 |
BreakpointSignal notifierString:'breakpoint encountered'. |
27 | 201 |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
202 |
BreakBlock := [:con | BreakpointSignal raiseIn:con]. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
203 |
TraceSenderBlock := [:con | MessageTracer printEntrySender:con]. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
204 |
TraceFullBlock := [:con | con fullPrintAll]. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
205 |
LeaveBreakBlock := [:con :retVal | ]. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
206 |
LeaveTraceBlock := [:con :retVal | ]. |
11 | 207 |
] |
156 | 208 |
|
209 |
" |
|
210 |
BreakpointSignal := nil. |
|
211 |
MessageTracer initialize |
|
212 |
" |
|
213 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
214 |
"Modified: 22.10.1996 / 17:39:14 / cg" |
11 | 215 |
! ! |
216 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
217 |
!MessageTracer class methodsFor:'Signal constants'! |
88 | 218 |
|
219 |
breakpointSignal |
|
220 |
^ BreakpointSignal |
|
221 |
! ! |
|
222 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
223 |
!MessageTracer class methodsFor:'class tracing'! |
88 | 224 |
|
225 |
traceClass:aClass selector:aSelector |
|
226 |
"arrange for a trace message to be output on Stderr, when a message with aSelector is |
|
227 |
sent to instances of aClass (or subclass instances). Use untraceClass to remove this." |
|
228 |
||
229 |
self traceMethod:(aClass compiledMethodAt:aSelector) |
|
230 |
||
231 |
" |
|
232 |
MessageTracer traceClass:Integer selector:#factorial. |
|
233 |
5 factorial. |
|
234 |
MessageTracer untraceClass:Integer |
|
235 |
" |
|
236 |
" |
|
237 |
MessageTracer traceClass:SequenceableCollection selector:#quickSortFrom:to:. |
|
238 |
#(6 1 9 66 2 17) copy sort. |
|
239 |
MessageTracer untraceClass:SequenceableCollection |
|
240 |
" |
|
241 |
" |
|
242 |
MessageTracer traceClass:Array selector:#at:. |
|
243 |
MessageTracer traceClass:Array selector:#at:put:. |
|
244 |
#(6 1 9 66 2 17) copy sort. |
|
245 |
MessageTracer untraceClass:Array |
|
246 |
" |
|
247 |
! |
|
248 |
||
249 |
untraceAllClasses |
|
250 |
"remove all traces of messages sent to any class" |
|
251 |
||
252 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
253 |
trace facilities ..." |
|
254 |
||
255 |
^ self untrapAllClasses |
|
256 |
! |
|
257 |
||
258 |
untraceClass:aClass |
|
259 |
"remove all traces of messages sent to instances of aClass" |
|
260 |
||
261 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
262 |
trace facilities ..." |
|
263 |
||
264 |
^ self untrapClass:aClass |
|
265 |
! ! |
|
266 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
267 |
!MessageTracer class methodsFor:'class wrapping'! |
88 | 268 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
269 |
wrapClass:orgClass selector:aSelector onEntry:entryBlock onExit:exitBlock |
88 | 270 |
"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
|
271 |
aSelector is sent to instances of orgClass or subclasses. |
88 | 272 |
EntryBlock will be called on entry, and get the current context passed as argument. |
273 |
ExitBlock will be called, when the method is left, and get context and the methods return value as arguments. |
|
274 |
" |
|
275 |
||
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
276 |
|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
|
277 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
278 |
WrappedMethod autoload. "/ just to make sure ... |
88 | 279 |
|
280 |
" |
|
281 |
create a new method, which calls the original one, |
|
282 |
but only if not already being trapped. |
|
283 |
" |
|
284 |
spec := Parser methodSpecificationForSelector:aSelector. |
|
285 |
||
286 |
s := WriteStream on:String new. |
|
287 |
s nextPutAll:spec. |
|
288 |
s cr. |
|
289 |
s nextPutAll:'|retVal stubClass|'; cr. |
|
290 |
entryBlock notNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
291 |
s nextPutAll:'#literal1 yourself value:thisContext.'; cr. |
88 | 292 |
]. |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
293 |
s nextPutAll:('retVal := #originalMethod. '). "/ just to get a literal to be replaced by theoriginal method |
88 | 294 |
s nextPutAll:('retVal := super ' , spec , '.'); cr. |
295 |
exitBlock notNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
296 |
s nextPutAll:'#literal2 yourself value:thisContext value:retVal.'; cr. |
88 | 297 |
]. |
298 |
s nextPutAll:'^ retVal'; cr. |
|
299 |
||
300 |
save := Compiler stcCompilation. |
|
301 |
Compiler stcCompilation:#never. |
|
302 |
[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
303 |
Class withoutUpdatingChangesDo:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
304 |
trapMethod := Compiler compile:s contents |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
305 |
forClass:orgClass |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
306 |
inCategory:'trapping' |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
307 |
notifying:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
308 |
install:false |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
309 |
skipIfSame:false |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
310 |
silent:true. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
311 |
] |
88 | 312 |
] valueNowOrOnUnwindDo:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
313 |
Compiler stcCompilation:save |
88 | 314 |
]. |
315 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
316 |
implClass := orgClass whichClassIncludesSelector:aSelector. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
317 |
implClass isNil ifTrue:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
318 |
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
|
319 |
] ifFalse:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
320 |
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
|
321 |
]. |
88 | 322 |
entryBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
323 |
trapMethod changeLiteral:#literal1 to:entryBlock. |
88 | 324 |
]. |
325 |
exitBlock notNil ifTrue:[ |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
326 |
trapMethod changeLiteral:#literal2 to:exitBlock. |
88 | 327 |
]. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
328 |
|
88 | 329 |
" |
330 |
change the source of this new method |
|
331 |
(to avoid confusion in the debugger ...) |
|
332 |
" |
|
333 |
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
|
334 |
trapMethod changeClassTo:WrappedMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
335 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
336 |
dict := orgClass methodDictionary. |
88 | 337 |
|
338 |
" |
|
339 |
if not already trapping, create a new class |
|
340 |
" |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
341 |
orgClass category == #'* trapping *' ifTrue:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
342 |
dict at:aSelector put:trapMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
343 |
orgClass methodDictionary:dict. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
344 |
newClass := orgClass superclass. |
88 | 345 |
] ifFalse:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
346 |
myMetaclass := orgClass class. |
88 | 347 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
348 |
newClass := myMetaclass copy new. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
349 |
newClass setSuperclass:orgClass superclass. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
350 |
newClass instSize:orgClass instSize. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
351 |
newClass flags:orgClass flags. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
352 |
newClass setClassVariableString:orgClass classVariableString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
353 |
newClass setInstanceVariableString:orgClass instanceVariableString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
354 |
newClass setName:orgClass name. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
355 |
newClass category:orgClass category. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
356 |
newClass methodDictionary:dict. |
88 | 357 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
358 |
orgClass setSuperclass:newClass. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
359 |
orgClass setClassVariableString:''. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
360 |
orgClass setInstanceVariableString:''. |
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
361 |
orgClass category:#'* trapping *'. |
88 | 362 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
363 |
dict := MethodDictionary new:1. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
364 |
dict at:aSelector put:trapMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
365 |
orgClass methodDictionary:dict. |
88 | 366 |
]. |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
367 |
trapMethod changeLiteral:(newClass superclass) to:newClass. |
88 | 368 |
|
369 |
ObjectMemory flushCaches. |
|
370 |
||
371 |
" |
|
372 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
373 |
wrapClass:Point |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
374 |
selector:#scaleBy: |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
375 |
onEntry:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
376 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
377 |
Transcript show:'leave Point>>scaleBy:; returning:'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
378 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
379 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
380 |
]. |
88 | 381 |
(1@2) scaleBy:5. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
382 |
MessageTracer untrapClass:Point selector:#scaleBy:. |
88 | 383 |
(1@2) scaleBy:5. |
384 |
" |
|
385 |
" |
|
386 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
387 |
wrapClass:Integer |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
388 |
selector:#factorial |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
389 |
onEntry:[:con | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
390 |
Transcript showCR:('entering ' , con receiver printString , '>>factorial'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
391 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
392 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
393 |
Transcript show:'leave Integer>>factorial; returning:'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
394 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
395 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
396 |
]. |
258 | 397 |
Transcript showCR:'5 factorial traced'. |
88 | 398 |
5 factorial. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
399 |
MessageTracer untrapClass:Integer selector:#factorial. |
258 | 400 |
Transcript showCR:'5 factorial normal'. |
88 | 401 |
5 factorial. |
402 |
" |
|
403 |
" |
|
404 |
|lvl| |
|
405 |
||
406 |
lvl := 0. |
|
407 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
408 |
wrapClass:Integer |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
409 |
selector:#factorial |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
410 |
onEntry:[:con | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
411 |
Transcript spaces:lvl. lvl := lvl + 2. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
412 |
Transcript showCR:('entering ' , con receiver printString , '>>factorial'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
413 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
414 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
415 |
lvl := lvl - 2. Transcript spaces:lvl. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
416 |
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
|
417 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
418 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
419 |
]. |
258 | 420 |
Transcript showCR:'5 factorial traced'. |
88 | 421 |
5 factorial. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
422 |
MessageTracer untrapClass:Integer selector:#factorial. |
258 | 423 |
Transcript showCR:'5 factorial normal'. |
88 | 424 |
5 factorial. |
425 |
" |
|
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
426 |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
427 |
"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
|
428 |
"Modified: 10.9.1996 / 20:07:01 / cg" |
88 | 429 |
! ! |
430 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
431 |
!MessageTracer class methodsFor:'cleanup'! |
27 | 432 |
|
433 |
cleanup |
|
434 |
"if you forgot which classes/methods where wrapped and/or trapped, |
|
435 |
this cleans up everything ..." |
|
436 |
||
437 |
self untrapAllClasses. |
|
438 |
self unwrapAllMethods |
|
439 |
||
440 |
" |
|
441 |
MessageTracer cleanup |
|
442 |
" |
|
443 |
! ! |
|
444 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
445 |
!MessageTracer class methodsFor:'execution trace '! |
88 | 446 |
|
447 |
debugTrace:aBlock |
|
448 |
"trace execution of aBlock. This is for system debugging only" |
|
11 | 449 |
|
196
330cc5c849de
debugOn/Off is now called sendTraceOn/Off
Claus Gittinger <cg@exept.de>
parents:
172
diff
changeset
|
450 |
Smalltalk sendTraceOn. |
88 | 451 |
^ aBlock valueNowOrOnUnwindDo:[ |
196
330cc5c849de
debugOn/Off is now called sendTraceOn/Off
Claus Gittinger <cg@exept.de>
parents:
172
diff
changeset
|
452 |
Smalltalk sendTraceOff. |
88 | 453 |
] |
11 | 454 |
|
88 | 455 |
" |
456 |
MessageTracer debugTrace:[#(6 5 4 3 2 1) sort] |
|
457 |
" |
|
196
330cc5c849de
debugOn/Off is now called sendTraceOn/Off
Claus Gittinger <cg@exept.de>
parents:
172
diff
changeset
|
458 |
|
330cc5c849de
debugOn/Off is now called sendTraceOn/Off
Claus Gittinger <cg@exept.de>
parents:
172
diff
changeset
|
459 |
"Modified: 18.3.1996 / 19:49:36 / cg" |
88 | 460 |
! |
11 | 461 |
|
462 |
trace:aBlock |
|
463 |
"evaluate aBlock sending trace information to stdout. |
|
27 | 464 |
Return the value of the block." |
11 | 465 |
|
17 | 466 |
^ self new trace:aBlock detail:false. |
11 | 467 |
|
468 |
" |
|
469 |
MessageTracer trace:[#(6 5 4 3 2 1) sort] |
|
470 |
" |
|
471 |
! |
|
472 |
||
473 |
traceFull:aBlock |
|
474 |
"evaluate aBlock sending trace information to stdout. |
|
475 |
Return the value of the block. |
|
27 | 476 |
The trace information is more detailed." |
11 | 477 |
|
17 | 478 |
^ self new trace:aBlock detail:true. |
11 | 479 |
|
480 |
" |
|
481 |
MessageTracer traceFull:[#(6 5 4 3 2 1) sort] |
|
482 |
" |
|
88 | 483 |
! ! |
484 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
485 |
!MessageTracer class methodsFor:'method breakpointing'! |
88 | 486 |
|
487 |
trapClass:aClass selector:aSelector |
|
488 |
"arrange for the debugger to be entered when a message with aSelector is |
|
489 |
sent to instances of aClass (or subclass instances). Use untrapClass to remove this trap. |
|
490 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
491 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
492 |
entry/leave blocks." |
|
493 |
||
494 |
self trapMethod:(aClass compiledMethodAt:aSelector) |
|
495 |
||
496 |
" |
|
497 |
MessageTracer trapClass:Collection selector:#select:. |
|
498 |
Dictionary new select:[:e | ]. 'not cought - Dictionary has its own select'. |
|
499 |
(Array new:10) select:[:e | ]. 'not cought - SeqColl has its own select'. |
|
500 |
Set new select:[:e | ]. 'cought - Set inherits this from Collection'. |
|
501 |
MessageTracer untrapClass:Collection |
|
502 |
" |
|
11 | 503 |
! |
504 |
||
88 | 505 |
trapMethod:aMethod |
506 |
"arrange for the debugger to be entered when aMethod is about to be executed. |
|
495 | 507 |
The trap is enabled for any process - see #trapMethodInCurrentProcess: for a more |
508 |
selective breakPoint. |
|
88 | 509 |
Use unwrapMethod or untrapClass to remove this trap. |
510 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
511 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
512 |
entry/leave blocks." |
|
513 |
||
514 |
^ self wrapMethod:aMethod |
|
495 | 515 |
onEntry:BreakBlock |
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
516 |
onExit:LeaveBreakBlock. |
88 | 517 |
|
518 |
" |
|
519 |
MessageTracer trapMethod:(Collection compiledMethodAt:#select:). |
|
520 |
Dictionary new select:[:e | ]. 'not cought - Dictionary has its own select'. |
|
521 |
(Array new:10) select:[:e | ]. 'not cought - SeqColl has its own select'. |
|
522 |
Set new select:[:e | ]. 'cought - Set inherits this from Collection'. |
|
523 |
MessageTracer unwrapMethod:(Collection compiledMethodAt:#select:). |
|
524 |
" |
|
495 | 525 |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
526 |
"Modified: 22.10.1996 / 17:39:58 / cg" |
88 | 527 |
! |
11 | 528 |
|
88 | 529 |
trapMethod:aMethod forInstancesOf:aClass |
530 |
"arrange for the debugger to be entered when aMethod is about to be executed |
|
531 |
for an instance of aClass. |
|
532 |
Use unwrapMethod or untrapClass to remove this trap. |
|
533 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
534 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
535 |
entry/leave blocks." |
|
536 |
||
537 |
^ self wrapMethod:aMethod |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
538 |
onEntry:[:context | |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
539 |
(context receiver isMemberOf:aClass) ifTrue:[ |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
540 |
BreakpointSignal raiseIn:context |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
541 |
] |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
542 |
] |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
543 |
onExit:LeaveBreakBlock. |
88 | 544 |
|
545 |
" |
|
546 |
MessageTracer trapMethod:(View compiledMethodAt:#redraw) forInstancesOf:myView. |
|
547 |
" |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
548 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
549 |
"Modified: 22.10.1996 / 17:40:03 / cg" |
88 | 550 |
! |
551 |
||
496 | 552 |
trapMethod:aMethod inProcess:aProcess |
495 | 553 |
"arrange for the debugger to be entered when aMethod is about to be executed, |
554 |
but only, if executed in the current process. |
|
555 |
This allows for breakpoints to be set on system-critical code. |
|
556 |
The trap is enabled for any process. |
|
557 |
Use unwrapMethod or untrapClass to remove this trap. |
|
558 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
559 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
560 |
entry/leave blocks." |
|
561 |
||
562 |
^ self wrapMethod:aMethod |
|
496 | 563 |
onEntry:[:con | (Processor activeProcess == aProcess) |
495 | 564 |
ifTrue:[ |
565 |
BreakpointSignal raiseIn:con |
|
566 |
] |
|
567 |
] |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
568 |
onExit:LeaveBreakBlock. |
495 | 569 |
|
496 | 570 |
"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
|
571 |
"Modified: 22.10.1996 / 17:40:06 / cg" |
495 | 572 |
! |
573 |
||
88 | 574 |
untrapAllClasses |
575 |
"remove any traps on any class" |
|
576 |
||
577 |
Smalltalk allBehaviorsDo:[:aClass | |
|
578 |
self untrapClass:aClass |
|
11 | 579 |
] |
580 |
||
581 |
" |
|
88 | 582 |
MessageTracer untrapAllClasses |
583 |
" |
|
584 |
! |
|
585 |
||
586 |
untrapClass:aClass |
|
587 |
"remove any traps on aClass" |
|
588 |
||
589 |
"this is done by just patching the class back to the original" |
|
590 |
||
591 |
|orgClass| |
|
592 |
||
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
593 |
aClass category == #'* trapping *' ifFalse:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
594 |
^ self |
88 | 595 |
]. |
596 |
orgClass := aClass superclass. |
|
597 |
||
598 |
aClass setSuperclass:orgClass superclass. |
|
599 |
aClass setClassVariableString:orgClass classVariableString. |
|
600 |
aClass setInstanceVariableString:orgClass instanceVariableString. |
|
601 |
aClass category:orgClass category. |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
602 |
aClass methodDictionary:orgClass methodDictionary. |
88 | 603 |
|
604 |
ObjectMemory flushCaches. |
|
605 |
||
606 |
" |
|
607 |
MessageTracer untrapClass:Point |
|
11 | 608 |
" |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
609 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
610 |
"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
|
611 |
"Modified: 10.9.1996 / 20:06:23 / cg" |
88 | 612 |
! |
613 |
||
614 |
untrapClass:aClass selector:aSelector |
|
615 |
"remove trap of aSelector sent to aClass" |
|
616 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
617 |
|dict| |
88 | 618 |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
619 |
aClass category == #'* trapping *' ifFalse:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
620 |
^ self |
88 | 621 |
]. |
622 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
623 |
dict := aClass methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
624 |
dict at:aSelector ifAbsent:[^ self]. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
625 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
626 |
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
|
627 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
628 |
dict size == 1 ifTrue:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
629 |
"the last trapped method" |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
630 |
^ self untrapClass:aClass |
88 | 631 |
]. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
632 |
dict removeKey:aSelector. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
633 |
aClass methodDictionary:dict. |
88 | 634 |
|
635 |
" |
|
636 |
MessageTracer trapClass:Point selector:#copy. |
|
637 |
(1@2) copy. |
|
638 |
(1@2) deepCopy. |
|
639 |
MessageTracer trapClass:Point selector:#deepCopy. |
|
640 |
(1@2) copy. |
|
641 |
(1@2) deepCopy. |
|
642 |
MessageTracer untrapClass:Point selector:#copy. |
|
643 |
(1@2) copy. |
|
644 |
(1@2) deepCopy. |
|
645 |
MessageTracer untrapClass:Point selector:#deepCopy. |
|
646 |
(1@2) copy. |
|
647 |
(1@2) deepCopy. |
|
648 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
649 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
650 |
"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
|
651 |
"Modified: 10.9.1996 / 20:06:29 / cg" |
88 | 652 |
! |
653 |
||
654 |
untrapMethod:aMethod |
|
655 |
"remove break on aMethod" |
|
656 |
||
657 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
658 |
trace facilities ..." |
|
659 |
||
660 |
^ self unwrapMethod:aMethod |
|
11 | 661 |
! ! |
662 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
663 |
!MessageTracer class methodsFor:'method counting'! |
155 | 664 |
|
665 |
countMethod:aMethod |
|
666 |
"arrange for a aMethods execution to be counted. |
|
667 |
Use unwrapMethod to remove this." |
|
668 |
||
669 |
MethodCounts isNil ifTrue:[ |
|
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
670 |
MethodCounts := IdentityDictionary new. |
155 | 671 |
]. |
672 |
MethodCounts at:aMethod put:0. |
|
673 |
||
674 |
^ self wrapMethod:aMethod |
|
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
675 |
onEntry:[:con | |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
676 |
|cnt| |
155 | 677 |
|
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
678 |
cnt := MethodCounts at:aMethod ifAbsent:0. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
679 |
MethodCounts at:aMethod put:(cnt + 1). |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
680 |
] |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
681 |
onExit:[:con :retVal | |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
682 |
] |
155 | 683 |
|
684 |
" |
|
685 |
MessageTracer countMethod:(Integer compiledMethodAt:#factorial). |
|
686 |
5 factorial. |
|
687 |
MessageTracer executionCountOf:(Integer compiledMethodAt:#factorial) printNL. |
|
688 |
MessageTracer stopCountingMethod:(Integer compiledMethodAt:#factorial) |
|
689 |
" |
|
690 |
||
691 |
"Created: 15.12.1995 / 10:57:49 / cg" |
|
692 |
"Modified: 15.12.1995 / 15:46:41 / cg" |
|
693 |
! |
|
694 |
||
695 |
executionCountOfMethod:aMethod |
|
696 |
"return the current count" |
|
697 |
||
698 |
|count| |
|
699 |
||
700 |
MethodCounts isNil ifTrue:[^ 0]. |
|
701 |
aMethod isWrapped ifTrue:[ |
|
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
702 |
count := MethodCounts at:aMethod originalMethod ifAbsent:nil. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
703 |
count notNil ifTrue:[^ count]. |
155 | 704 |
]. |
705 |
^ MethodCounts at:aMethod ifAbsent:0 |
|
706 |
||
707 |
"Created: 15.12.1995 / 11:01:56 / cg" |
|
708 |
"Modified: 15.12.1995 / 15:45:15 / cg" |
|
709 |
! |
|
710 |
||
711 |
isCounting:aMethod |
|
712 |
"return true if aMethod is counted" |
|
713 |
||
714 |
MethodCounts isNil ifTrue:[^ false]. |
|
715 |
(MethodCounts includesKey:aMethod) ifTrue:[^ true]. |
|
716 |
aMethod isWrapped ifTrue:[ |
|
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
717 |
^ MethodCounts includesKey:aMethod originalMethod |
155 | 718 |
]. |
719 |
^ false |
|
720 |
||
721 |
"Created: 15.12.1995 / 11:07:58 / cg" |
|
722 |
"Modified: 15.12.1995 / 15:42:10 / cg" |
|
723 |
! |
|
724 |
||
725 |
stopCountingMethod:aMethod |
|
726 |
"remove counting of aMethod" |
|
727 |
||
728 |
^ self unwrapMethod:aMethod |
|
729 |
||
730 |
"Modified: 15.12.1995 / 15:43:53 / cg" |
|
731 |
! ! |
|
732 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
733 |
!MessageTracer class methodsFor:'method memory usage'! |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
734 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
735 |
countMemoryUsageOfMethod:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
736 |
"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
|
737 |
Use unwrapMethod to remove this." |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
738 |
|
501 | 739 |
|oldPriority oldScavengeCount oldNewUsed| |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
740 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
741 |
MethodCounts isNil ifTrue:[ |
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
742 |
MethodCounts := IdentityDictionary new. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
743 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
744 |
MethodMemoryUsage isNil ifTrue:[ |
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
745 |
MethodMemoryUsage := IdentityDictionary new. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
746 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
747 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
748 |
MethodCounts at:aMethod put:0. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
749 |
MethodMemoryUsage at:aMethod put:0. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
750 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
751 |
^ self wrapMethod:aMethod |
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
752 |
onEntry:[:con | |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
753 |
oldPriority := Processor activeProcess changePriority:(Processor userInterruptPriority). |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
754 |
oldNewUsed := ObjectMemory newSpaceUsed. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
755 |
oldScavengeCount := ObjectMemory scavengeCount. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
756 |
] |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
757 |
onExit:[:con :retVal | |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
758 |
|cnt memUse scavenges| |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
759 |
|
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
760 |
memUse := ObjectMemory newSpaceUsed - oldNewUsed. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
761 |
scavenges := ObjectMemory scavengeCount - oldScavengeCount. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
762 |
scavenges ~= 0 ifTrue:[ |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
763 |
memUse := memUse + (ObjectMemory newSpaceSize * scavenges) |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
764 |
]. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
765 |
|
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
766 |
MethodCounts notNil ifTrue:[ |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
767 |
cnt := MethodCounts at:aMethod ifAbsent:0. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
768 |
MethodCounts at:aMethod put:(cnt + 1). |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
769 |
]. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
770 |
MethodMemoryUsage notNil ifTrue:[ |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
771 |
cnt := MethodMemoryUsage at:aMethod ifAbsent:0. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
772 |
MethodMemoryUsage at:aMethod put:(cnt + memUse). |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
773 |
]. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
774 |
Processor activeProcess priority:oldPriority |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
775 |
] |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
776 |
onUnwind:[ |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
777 |
oldPriority notNil ifTrue:[ |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
778 |
Processor activeProcess priority:oldPriority |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
779 |
] |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
780 |
] |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
781 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
782 |
" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
783 |
MessageTracer countMemoryUsageOfMethod:(Integer compiledMethodAt:#factorial). |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
784 |
3 factorial. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
785 |
(MessageTracer memoryUsageOfMethod:(Integer compiledMethodAt:#factorial)) printNL. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
786 |
MessageTracer stopCountingMemoryUsageOfMethod:(Integer compiledMethodAt:#factorial) |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
787 |
" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
788 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
789 |
"Created: 18.12.1995 / 15:41:27 / stefan" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
790 |
"Modified: 18.12.1995 / 21:46:48 / stefan" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
791 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
792 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
793 |
isCountingMemoryUsage:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
794 |
"return true if aMethod is counting memoryUsage" |
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 |
MethodMemoryUsage isNil ifTrue:[^ false]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
797 |
(MethodMemoryUsage includesKey:aMethod) ifTrue:[^ true]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
798 |
aMethod isWrapped ifTrue:[ |
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
799 |
^ MethodMemoryUsage includesKey:aMethod originalMethod |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
800 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
801 |
^ false |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
802 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
803 |
"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
|
804 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
805 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
806 |
memoryUsageOfMethod:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
807 |
"return the current count" |
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 |
|count memUse| |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
810 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
811 |
(MethodCounts isNil or:[MethodMemoryUsage isNil]) ifTrue:[^ 0]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
812 |
aMethod isWrapped ifTrue:[ |
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
813 |
count := MethodCounts at:aMethod originalMethod ifAbsent:nil. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
814 |
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
|
815 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
816 |
memUse isNil ifTrue:[ |
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
817 |
count := MethodCounts at:aMethod ifAbsent:0. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
818 |
memUse := MethodMemoryUsage at:aMethod ifAbsent:0. |
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 |
count = 0 ifTrue:[^ 0]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
821 |
^ memUse//count |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
822 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
823 |
"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
|
824 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
825 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
826 |
stopCountingMemoryUsageOfMethod:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
827 |
"remove counting memory of aMethod" |
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 |
^ self unwrapMethod:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
830 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
831 |
"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
|
832 |
! ! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
833 |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
834 |
!MessageTracer class methodsFor:'method timing'! |
327 | 835 |
|
836 |
executionTimesOfMethod:aMethod |
|
837 |
"return the current times" |
|
838 |
||
839 |
|count info min max avg ret| |
|
840 |
||
841 |
count := min := max := avg := 0. |
|
842 |
MethodTiming notNil ifTrue:[ |
|
843 |
aMethod isWrapped ifTrue:[ |
|
844 |
info := MethodTiming at:aMethod originalMethod ifAbsent:nil. |
|
845 |
info notNil ifTrue:[ |
|
846 |
count := info at:1. |
|
847 |
min := info at:2. |
|
848 |
max := info at:3. |
|
849 |
avg := ((info at:4) / count) roundTo:0.01 |
|
850 |
]. |
|
851 |
]. |
|
852 |
]. |
|
853 |
||
854 |
ret := IdentityDictionary new. |
|
855 |
ret at:#count put:count. |
|
856 |
ret at:#minTime put:min. |
|
857 |
ret at:#maxTime put:max. |
|
858 |
ret at:#avgTime put:avg. |
|
859 |
^ ret |
|
860 |
||
861 |
"Created: 17.6.1996 / 17:07:30 / cg" |
|
862 |
"Modified: 17.6.1996 / 17:08:24 / cg" |
|
863 |
! |
|
864 |
||
865 |
isTiming:aMethod |
|
866 |
"return true if aMethod is timed" |
|
867 |
||
868 |
MethodTiming isNil ifTrue:[^ false]. |
|
869 |
(MethodTiming includesKey:aMethod) ifTrue:[^ true]. |
|
870 |
aMethod isWrapped ifTrue:[ |
|
871 |
^ MethodTiming includesKey:aMethod originalMethod |
|
872 |
]. |
|
873 |
^ false |
|
874 |
||
875 |
"Modified: 15.12.1995 / 15:42:10 / cg" |
|
876 |
"Created: 17.6.1996 / 17:04:29 / cg" |
|
877 |
! |
|
878 |
||
879 |
stopTimingMethod:aMethod |
|
880 |
"remove timing of aMethod" |
|
881 |
||
882 |
^ self unwrapMethod:aMethod |
|
883 |
||
884 |
"Modified: 15.12.1995 / 15:43:53 / cg" |
|
885 |
"Created: 17.6.1996 / 17:04:03 / cg" |
|
886 |
! |
|
887 |
||
888 |
timeMethod:aMethod |
|
889 |
"arrange for a aMethods execution time to be measured. |
|
890 |
Use unwrapMethod to remove this." |
|
891 |
||
501 | 892 |
|t0| |
327 | 893 |
|
894 |
MethodTiming isNil ifTrue:[ |
|
895 |
MethodTiming := IdentityDictionary new. |
|
896 |
]. |
|
897 |
MethodTiming removeKey:aMethod ifAbsent:nil. |
|
898 |
||
899 |
^ self wrapMethod:aMethod |
|
900 |
onEntry:[:con | |
|
901 |
t0 := OperatingSystem getMillisecondTime. |
|
902 |
] |
|
903 |
onExit:[:con :retVal | |
|
904 |
|info t cnt min max sumTimes| |
|
905 |
||
906 |
t := OperatingSystem getMillisecondTime - t0. |
|
907 |
info := MethodTiming at:aMethod ifAbsent:nil. |
|
908 |
info isNil ifTrue:[ |
|
909 |
MethodTiming at:aMethod put:(Array with:1 |
|
910 |
with:t |
|
911 |
with:t |
|
912 |
with:t) |
|
913 |
] ifFalse:[ |
|
914 |
cnt := info at:1. |
|
915 |
min := info at:2. |
|
916 |
max := info at:3. |
|
917 |
sumTimes := info at:4. |
|
918 |
t < min ifTrue:[ |
|
919 |
info at:2 put:t |
|
920 |
] ifFalse:[ |
|
921 |
t > max ifTrue:[ |
|
922 |
info at:3 put:t |
|
923 |
] |
|
924 |
]. |
|
925 |
info at:4 put:(sumTimes + t). |
|
926 |
info at:1 put:cnt + 1 |
|
927 |
]. |
|
928 |
] |
|
929 |
||
930 |
" |
|
931 |
MessageTracer timeMethod:(Integer compiledMethodAt:#factorial). |
|
932 |
5 factorial. |
|
933 |
5 factorial. |
|
934 |
5 factorial. |
|
935 |
(MessageTracer executionTimesOfMethod:(Integer compiledMethodAt:#factorial)) printCR. |
|
936 |
MessageTracer stopTimingMethod:(Integer compiledMethodAt:#factorial) |
|
937 |
" |
|
938 |
||
939 |
"Created: 17.6.1996 / 17:03:50 / cg" |
|
940 |
"Modified: 17.6.1996 / 17:10:43 / cg" |
|
941 |
! ! |
|
942 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
943 |
!MessageTracer class methodsFor:'method tracing'! |
11 | 944 |
|
88 | 945 |
traceMethod:aMethod |
946 |
"arrange for a trace message to be output on Stderr, when aMethod is executed. |
|
947 |
Use unwrapMethod to remove this." |
|
948 |
||
949 |
|lvl inside| |
|
11 | 950 |
|
88 | 951 |
^ self wrapMethod:aMethod |
952 |
onEntry:[:con | |
|
953 |
inside isNil ifTrue:[ |
|
954 |
inside := true. |
|
955 |
CallingLevel isNil ifTrue:[ |
|
956 |
CallingLevel := 0. |
|
957 |
]. |
|
958 |
lvl notNil ifTrue:[ |
|
959 |
lvl := lvl + 1 |
|
960 |
] ifFalse:[ |
|
961 |
CallingLevel := lvl := CallingLevel + 1. |
|
962 |
]. |
|
963 |
MessageTracer printEntryFull:con level:lvl. |
|
964 |
inside := nil |
|
965 |
] |
|
966 |
] |
|
967 |
onExit:[:con :retVal | |
|
968 |
inside isNil ifTrue:[ |
|
969 |
inside := true. |
|
970 |
MessageTracer printExit:con with:retVal level:lvl. |
|
971 |
CallingLevel := lvl := lvl - 1. |
|
972 |
inside := nil |
|
973 |
] |
|
974 |
] |
|
11 | 975 |
|
976 |
" |
|
88 | 977 |
MessageTracer traceMethod:(Integer compiledMethodAt:#factorial). |
978 |
5 factorial. |
|
979 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial) |
|
980 |
" |
|
981 |
" |
|
982 |
MessageTracer traceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
983 |
#(6 1 9 66 2 17) copy sort. |
|
984 |
MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
985 |
" |
|
986 |
" |
|
987 |
dont do this: |
|
988 |
" |
|
989 |
" |
|
990 |
MessageTracer traceMethod:(Object compiledMethodAt:#at:). |
|
991 |
MessageTracer traceMethod:(Object compiledMethodAt:#at:put:). |
|
992 |
#(6 1 9 66 2 17) copy sort. |
|
993 |
MessageTracer untraceMethod:(Object compiledMethodAt:#at:). |
|
994 |
MessageTracer untraceMethod:(Object compiledMethodAt:#at:put:). |
|
11 | 995 |
" |
996 |
! |
|
997 |
||
162
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
998 |
traceMethodAll:aMethod |
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
999 |
"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
|
1000 |
Only the sender is traced on entry. |
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1001 |
Use untraceMethod to remove this trace." |
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1002 |
|
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1003 |
^ self wrapMethod:aMethod |
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
1004 |
onEntry:[:con | ObjectMemory flushCaches. Smalltalk sendTraceOn.] |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
1005 |
onExit:[:con :val | Smalltalk sendTraceOff.]. |
162
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1006 |
|
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1007 |
"Created: 17.12.1995 / 17:08:28 / cg" |
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1008 |
"Modified: 17.12.1995 / 17:12:50 / cg" |
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1009 |
! |
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1010 |
|
156 | 1011 |
traceMethodFull:aMethod |
1012 |
"arrange for a full trace message to be output on Stderr, when amethod is executed. |
|
1013 |
Only the sender is traced on entry. |
|
1014 |
Use untraceMethod to remove this trace." |
|
1015 |
||
1016 |
^ self wrapMethod:aMethod |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1017 |
onEntry:TraceFullBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1018 |
onExit:LeaveTraceBlock. |
156 | 1019 |
|
1020 |
"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
|
1021 |
"Modified: 22.10.1996 / 17:39:28 / cg" |
156 | 1022 |
! |
1023 |
||
88 | 1024 |
traceMethodSender:aMethod |
1025 |
"arrange for a trace message to be output on Stderr, when amethod is executed. |
|
1026 |
Only the sender is traced on entry. |
|
1027 |
Use untraceMethod to remove this trace." |
|
35 | 1028 |
|
88 | 1029 |
^ self wrapMethod:aMethod |
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1030 |
onEntry:TraceSenderBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1031 |
onExit:LeaveTraceBlock. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1032 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1033 |
"Modified: 22.10.1996 / 17:39:33 / cg" |
88 | 1034 |
! |
1035 |
||
1036 |
untraceMethod:aMethod |
|
1037 |
"remove tracing of aMethod" |
|
1038 |
||
1039 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
1040 |
trace facilities ..." |
|
1041 |
||
1042 |
^ self unwrapMethod:aMethod |
|
11 | 1043 |
! ! |
1044 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1045 |
!MessageTracer class methodsFor:'method wrapping'! |
11 | 1046 |
|
88 | 1047 |
unwrapAllMethods |
1048 |
"just in case you dont know what methods have break/trace-points |
|
1049 |
on them; this removes them all" |
|
1050 |
||
1051 |
WrappedMethod allInstancesDo:[:aMethod | |
|
1052 |
self unwrapMethod:aMethod |
|
1053 |
] |
|
11 | 1054 |
! |
1055 |
||
88 | 1056 |
unwrapMethod:aMethod |
1057 |
"remove any wrapper on aMethod" |
|
1058 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1059 |
|selector class originalMethod dict mthd| |
88 | 1060 |
|
155 | 1061 |
MethodCounts notNil ifTrue:[ |
265 | 1062 |
aMethod isWrapped ifTrue:[ |
1063 |
MethodCounts removeKey:aMethod originalMethod ifAbsent:nil. |
|
1064 |
]. |
|
1065 |
MethodCounts removeKey:aMethod ifAbsent:nil. |
|
1066 |
MethodCounts isEmpty ifTrue:[MethodCounts := nil]. |
|
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
1067 |
]. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
1068 |
MethodMemoryUsage notNil ifTrue:[ |
265 | 1069 |
aMethod isWrapped ifTrue:[ |
1070 |
MethodMemoryUsage removeKey:aMethod originalMethod ifAbsent:nil. |
|
1071 |
]. |
|
1072 |
MethodMemoryUsage removeKey:aMethod ifAbsent:nil. |
|
1073 |
MethodMemoryUsage isEmpty ifTrue:[MethodMemoryUsage := nil]. |
|
155 | 1074 |
]. |
327 | 1075 |
MethodTiming notNil ifTrue:[ |
1076 |
aMethod isWrapped ifTrue:[ |
|
1077 |
MethodTiming removeKey:aMethod originalMethod ifAbsent:nil. |
|
1078 |
]. |
|
1079 |
MethodTiming removeKey:aMethod ifAbsent:nil. |
|
1080 |
MethodTiming isEmpty ifTrue:[MethodTiming := nil]. |
|
1081 |
]. |
|
155 | 1082 |
|
88 | 1083 |
CallingLevel := 0. |
1084 |
||
1085 |
(aMethod isNil or:[aMethod isWrapped not]) ifTrue:[ |
|
265 | 1086 |
^ aMethod |
88 | 1087 |
]. |
1088 |
||
1089 |
" |
|
1090 |
get class/selector |
|
1091 |
" |
|
1092 |
class := aMethod containingClass. |
|
1093 |
class isNil ifTrue:[ |
|
265 | 1094 |
'MSGTRACER: no containing class for method found' infoPrintCR. |
1095 |
^ aMethod |
|
88 | 1096 |
]. |
1097 |
selector := class selectorAtMethod:aMethod. |
|
1098 |
||
1099 |
originalMethod := aMethod originalMethod. |
|
1100 |
originalMethod isNil ifTrue:[ |
|
265 | 1101 |
self error:'oops, could not find original method'. |
1102 |
^ aMethod |
|
88 | 1103 |
]. |
1104 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1105 |
dict := class methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1106 |
mthd := dict at:selector ifAbsent:[0]. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1107 |
mthd ~~ 0 ifTrue:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1108 |
dict at:selector put:originalMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1109 |
class methodDictionary:dict. |
88 | 1110 |
] ifFalse:[ |
265 | 1111 |
self halt:'oops, unexpected error'. |
1112 |
^ aMethod |
|
88 | 1113 |
]. |
1114 |
||
1115 |
ObjectMemory flushCaches. |
|
1116 |
^ originalMethod |
|
265 | 1117 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1118 |
"Modified: 5.6.1996 / 14:08:08 / stefan" |
327 | 1119 |
"Modified: 17.6.1996 / 17:20:43 / cg" |
13 | 1120 |
! |
1121 |
||
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1122 |
wrapMethod:aMethod onEntry:entryBlock onExit:exitBlock |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1123 |
^ 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
|
1124 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1125 |
"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
|
1126 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1127 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1128 |
wrapMethod:aMethod onEntry:entryBlock onExit:exitBlock onUnwind:unwindBlock |
88 | 1129 |
"arrange for the two blocks entryBlock and exitBlock to be evaluated whenever |
1130 |
aMethod is evaluated. |
|
1131 |
EntryBlock will be called on entry, and gets the current context passed as argument. |
|
1132 |
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
|
1133 |
the methods return value as arguments. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1134 |
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
|
1135 |
If there is an unwindBlock, the entry and exitBlocks will be called within the unwind block, |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1136 |
beacause allocating the unwindBlock uses memory and some users want to count allocated memory. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1137 |
" |
88 | 1138 |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1139 |
|selector class trapMethod s spec src dict sel save| |
88 | 1140 |
|
1141 |
CallingLevel := 0. |
|
1142 |
||
1143 |
" |
|
1144 |
create a new method, which calls the original one, |
|
1145 |
but only if not already being trapped. |
|
1146 |
" |
|
1147 |
(aMethod isNil or:[aMethod isWrapped]) ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1148 |
^ aMethod |
88 | 1149 |
]. |
1150 |
aMethod isLazyMethod ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1151 |
aMethod makeRealMethod |
88 | 1152 |
]. |
1153 |
||
1154 |
" |
|
1155 |
get class/selector |
|
1156 |
" |
|
1157 |
class := aMethod containingClass. |
|
1158 |
class isNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1159 |
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
|
1160 |
^ aMethod |
88 | 1161 |
]. |
1162 |
selector := class selectorAtMethod:aMethod. |
|
1163 |
||
1164 |
||
1165 |
WrappedMethod autoload. "/ for small systems |
|
1166 |
||
1167 |
" |
|
1168 |
get a new method-spec |
|
1169 |
" |
|
1170 |
spec := Parser methodSpecificationForSelector:selector. |
|
1171 |
||
1172 |
" |
|
1173 |
create a method, executing the trap-blocks and the original method via a direct call |
|
1174 |
" |
|
1175 |
s := WriteStream on:String new. |
|
1176 |
s nextPutAll:spec. |
|
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1177 |
s nextPutAll:' |retVal context| '. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1178 |
s nextPutAll:' context := thisContext.'. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1179 |
unwindBlock notNil ifTrue:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1180 |
s nextPutAll:'['. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1181 |
]. |
88 | 1182 |
entryBlock notNil ifTrue:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1183 |
s nextPutAll:'#entryBlock yourself value:context. '. |
88 | 1184 |
]. |
1185 |
s nextPutAll:'retVal := #originalMethod yourself'; |
|
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1186 |
nextPutAll: ' valueWithReceiver:(context receiver)'; |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1187 |
nextPutAll: ' arguments:(context args)'; |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1188 |
nextPutAll: ' selector:(context selector)'; |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1189 |
nextPutAll: ' search:(context searchClass)'; |
88 | 1190 |
nextPutAll: ' sender:nil. '. |
1191 |
||
1192 |
exitBlock notNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1193 |
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
|
1194 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1195 |
unwindBlock notNil ifTrue:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1196 |
s nextPutAll:'] valueOnUnwindDo:#unwindBlock yourself.'. |
88 | 1197 |
]. |
1198 |
s nextPutAll:'^ retVal'; cr. |
|
1199 |
||
1200 |
src := s contents. |
|
1201 |
save := Compiler stcCompilation. |
|
1202 |
Compiler stcCompilation:#never. |
|
1203 |
[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1204 |
Class withoutUpdatingChangesDo:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1205 |
trapMethod := Compiler compile:src |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1206 |
forClass:UndefinedObject |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1207 |
inCategory:aMethod category |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1208 |
notifying:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1209 |
install:false |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1210 |
skipIfSame:false |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1211 |
silent:true. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1212 |
] |
88 | 1213 |
] valueNowOrOnUnwindDo:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1214 |
Compiler stcCompilation:save |
88 | 1215 |
]. |
1216 |
||
1217 |
trapMethod changeClassTo:WrappedMethod. |
|
1218 |
||
1219 |
" |
|
1220 |
raising our eyebrows here ... |
|
1221 |
" |
|
1222 |
entryBlock notNil ifTrue:[ |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1223 |
trapMethod changeLiteral:#entryBlock to:entryBlock. |
88 | 1224 |
]. |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1225 |
trapMethod changeLiteral:#originalMethod to:aMethod. |
88 | 1226 |
exitBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1227 |
trapMethod changeLiteral:#exitBlock to:exitBlock. |
88 | 1228 |
]. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1229 |
unwindBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1230 |
trapMethod changeLiteral:#unwindBlock to:unwindBlock. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1231 |
]. |
88 | 1232 |
" |
1233 |
change the source of this new method |
|
1234 |
(to avoid confusion in the debugger ...) |
|
1235 |
" |
|
1236 |
trapMethod source:'this is a wrapper method - not the real one'. |
|
1237 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1238 |
dict := class methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1239 |
sel := dict at:selector ifAbsent:[0]. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1240 |
sel == 0 ifTrue:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1241 |
self halt:'oops, unexpected error'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1242 |
^ aMethod |
88 | 1243 |
]. |
1244 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1245 |
dict at:selector put:trapMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1246 |
class methodDictionary:dict. |
88 | 1247 |
ObjectMemory flushCaches. |
1248 |
^ trapMethod |
|
1249 |
||
1250 |
" |
|
1251 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1252 |
wrapMethod:(Point compiledMethodAt:#scaleBy:) |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1253 |
onEntry:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1254 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1255 |
Transcript show:'leave Point>>scaleBy:; returning:'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1256 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1257 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1258 |
]. |
88 | 1259 |
(1@2) scaleBy:5. |
1260 |
MessageTracer unwrapMethod:(Point compiledMethodAt:#scaleBy:). |
|
1261 |
(1@2) scaleBy:5. |
|
1262 |
" |
|
1263 |
" |
|
1264 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1265 |
wrapMethod:(Integer compiledMethodAt:#factorial) |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1266 |
onEntry:[:con | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1267 |
Transcript showCR:('entering ' , con receiver printString , '>>factorial'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1268 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1269 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1270 |
Transcript show:'leave Integer>>factorial; returning:'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1271 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1272 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1273 |
]. |
258 | 1274 |
Transcript showCR:'5 factorial traced'. |
88 | 1275 |
5 factorial. |
1276 |
MessageTracer unwrapMethod:(Integer compiledMethodAt:#factorial). |
|
258 | 1277 |
Transcript showCR:'5 factorial normal'. |
88 | 1278 |
5 factorial. |
1279 |
" |
|
1280 |
" |
|
1281 |
|lvl| |
|
1282 |
||
1283 |
lvl := 0. |
|
1284 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1285 |
wrapMethod:(Integer compiledMethodAt:#factorial) |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1286 |
onEntry:[:con | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1287 |
Transcript spaces:lvl. lvl := lvl + 2. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1288 |
Transcript showCR:('entering ' , con receiver printString , '>>factorial'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1289 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1290 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1291 |
lvl := lvl - 2. Transcript spaces:lvl. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1292 |
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
|
1293 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1294 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1295 |
]. |
258 | 1296 |
Transcript showCR:'5 factorial traced'. |
88 | 1297 |
5 factorial. |
1298 |
MessageTracer unwrapMethod:(Integer compiledMethodAt:#factorial). |
|
258 | 1299 |
Transcript showCR:'5 factorial normal'. |
88 | 1300 |
5 factorial. |
1301 |
" |
|
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
1302 |
|
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
1303 |
"Modified: 13.12.1995 / 16:06:22 / cg" |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1304 |
"Modified: 25.6.1996 / 22:04:51 / stefan" |
88 | 1305 |
! ! |
1306 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1307 |
!MessageTracer class methodsFor:'object breakpointing'! |
88 | 1308 |
|
1309 |
trap:anObject selector:aSelector |
|
1310 |
"arrange for the debugger to be entered when a message with aSelector is |
|
1311 |
sent to anObject. Use untrap to remove this trap. |
|
1312 |
The current implementation does not allow integers or nil to be trapped." |
|
1313 |
||
1314 |
self wrap:anObject |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1315 |
selector:aSelector |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1316 |
onEntry:BreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1317 |
onExit:LeaveBreakBlock. |
88 | 1318 |
|
1319 |
" |
|
1320 |
|p| |
|
1321 |
||
1322 |
p := Point new. |
|
1323 |
MessageTracer trap:p selector:#x:. |
|
1324 |
p x:5 |
|
1325 |
" |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1326 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1327 |
"Modified: 22.10.1996 / 17:39:41 / cg" |
11 | 1328 |
! |
1329 |
||
88 | 1330 |
trap:anObject selectors:aCollection |
1331 |
self wrap:anObject |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1332 |
selectors:aCollection |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1333 |
onEntry:BreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1334 |
onExit:LeaveBreakBlock. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1335 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1336 |
"Modified: 22.10.1996 / 17:39:50 / cg" |
88 | 1337 |
! |
1338 |
||
1339 |
trapAll:anObject |
|
1340 |
"trap on all messages which are understood by anObject" |
|
1341 |
||
1342 |
self wrapAll:anObject |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1343 |
onEntry:BreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1344 |
onExit:LeaveBreakBlock. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1345 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1346 |
"Modified: 22.10.1996 / 17:39:54 / cg" |
88 | 1347 |
! |
1348 |
||
1349 |
trapAll:anObject from:aClass |
|
1350 |
"trap on all messages defined in aClass sent to anObject" |
|
1351 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1352 |
self trap:anObject selectors:aClass selectors |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1353 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1354 |
"Modified: 5.6.1996 / 13:46:06 / stefan" |
88 | 1355 |
! |
1356 |
||
1357 |
untrap:anObject |
|
1358 |
"remove any traps on anObject" |
|
1359 |
||
1360 |
"this is done by just patching the objects class back to the original" |
|
1361 |
||
1362 |
|orgClass| |
|
1363 |
||
1364 |
orgClass := anObject class. |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1365 |
orgClass category == #'* trapping *' ifFalse:[ |
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1366 |
^ self |
88 | 1367 |
]. |
1368 |
||
1369 |
anObject changeClassTo:orgClass superclass |
|
1370 |
||
1371 |
" |
|
1372 |
|p| |
|
1373 |
||
1374 |
p := Point new copy. |
|
1375 |
MessageTracer trace:p selector:#x:. |
|
1376 |
MessageTracer trace:p selector:#y:. |
|
1377 |
p y:1. |
|
1378 |
p x:2. |
|
1379 |
MessageTracer untrap:p |
|
1380 |
p y:2. |
|
1381 |
p x:1. |
|
1382 |
" |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1383 |
|
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1384 |
"Modified: 10.9.1996 / 20:06:07 / cg" |
13 | 1385 |
! |
1386 |
||
88 | 1387 |
untrap:anObject selector:aSelector |
1388 |
"remove trap on aSelector from anObject" |
|
1389 |
||
501 | 1390 |
|orgClass dict| |
88 | 1391 |
|
1392 |
orgClass := anObject class. |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1393 |
orgClass category == #'* trapping *' ifFalse:[^ self]. |
88 | 1394 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1395 |
dict := orgClass methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1396 |
dict at:aSelector ifAbsent:[^ self]. |
88 | 1397 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1398 |
dict size == 1 ifTrue:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1399 |
"the last trap got removed" |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1400 |
anObject changeClassTo:orgClass superclass. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1401 |
^ self |
88 | 1402 |
]. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1403 |
dict removeKey:aSelector. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1404 |
orgClass methodDictionary:dict. |
88 | 1405 |
ObjectMemory flushCaches. "avoid calling the old trap method" |
1406 |
||
1407 |
" |
|
1408 |
|p| |
|
1409 |
||
1410 |
p := Point new copy. |
|
1411 |
MessageTracer trace:p selector:#x:. |
|
1412 |
MessageTracer trace:p selector:#y:. |
|
1413 |
'trace both ...' errorPrintNL. |
|
1414 |
p x:2. |
|
1415 |
p y:1. |
|
1416 |
'trace only y ...' errorPrintNL. |
|
1417 |
MessageTracer untrap:p selector:#x:. |
|
1418 |
p x:2. |
|
1419 |
p y:1. |
|
1420 |
'trace none ...' errorPrintNL. |
|
1421 |
MessageTracer untrap:p selector:#y:. |
|
1422 |
p x:2. |
|
1423 |
p y:1. |
|
1424 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1425 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1426 |
"Modified: 5.6.1996 / 13:56:08 / stefan" |
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1427 |
"Modified: 10.9.1996 / 20:06:14 / cg" |
11 | 1428 |
! ! |
1429 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1430 |
!MessageTracer class methodsFor:'object tracing'! |
88 | 1431 |
|
1432 |
trace:anObject selector:aSelector |
|
1433 |
"arrange for a trace message to be output on Stderr, when a message with |
|
1434 |
aSelector is sent to anObject. Both entry and exit are traced. |
|
1435 |
Use untrap to remove this trace. |
|
1436 |
The current implementation does not allow integers or nil to be traced." |
|
1437 |
||
1438 |
|methodName| |
|
1439 |
||
1440 |
methodName := anObject class name , '>>' , aSelector. |
|
1441 |
self wrap:anObject |
|
1442 |
selector:aSelector |
|
1443 |
onEntry:[:con | |
|
1444 |
'enter ' errorPrint. methodName errorPrint. |
|
1445 |
' receiver=' errorPrint. con receiver printString errorPrint. |
|
1446 |
' args=' errorPrint. (con args) printString errorPrint. |
|
1447 |
' from:' errorPrint. con sender errorPrintNL. |
|
1448 |
] |
|
1449 |
onExit:[:con :retVal | |
|
1450 |
'leave ' errorPrint. methodName errorPrint. |
|
1451 |
' receiver=' errorPrint. con receiver printString errorPrint. |
|
1452 |
' returning:' errorPrint. retVal printString errorPrintNL. |
|
1453 |
]. |
|
1454 |
||
1455 |
" |
|
1456 |
|p| |
|
8 | 1457 |
|
88 | 1458 |
p := Point new. |
1459 |
MessageTracer trace:p selector:#x:. |
|
1460 |
p x:5. |
|
1461 |
p y:1. |
|
1462 |
p x:10. |
|
1463 |
MessageTracer untrap:p. |
|
1464 |
p x:7 |
|
1465 |
" |
|
1466 |
" |
|
1467 |
|a| |
|
1468 |
||
1469 |
a := #(6 1 9 66 2 17) copy. |
|
1470 |
MessageTracer trace:a selector:#at:put:. |
|
1471 |
MessageTracer trace:a selector:#at:. |
|
1472 |
a sort. |
|
1473 |
" |
|
1474 |
! |
|
1475 |
||
1476 |
trace:anObject selectors:aCollection |
|
1477 |
aCollection do:[:aSelector | |
|
1478 |
self trace:anObject selector:aSelector |
|
1479 |
] |
|
1480 |
||
1481 |
" |
|
1482 |
trace all methods in Display, which are implemented |
|
1483 |
in the DisplayWorkstation class. |
|
1484 |
" |
|
1485 |
||
1486 |
" |
|
1487 |
MessageTracer trace:Display selectors:(XWorkstation selectorArray) |
|
1488 |
MessageTracer untrace:Display |
|
1489 |
" |
|
1490 |
! |
|
1491 |
||
1492 |
traceAll:anObject |
|
1493 |
"trace all messages which are understood by anObject" |
|
27 | 1494 |
|
1495 |
|allSelectors| |
|
1496 |
||
1497 |
allSelectors := IdentitySet new. |
|
1498 |
anObject class withAllSuperclasses do:[:aClass | |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1499 |
aClass methodDictionary keys addAllTo:allSelectors |
27 | 1500 |
]. |
88 | 1501 |
self trace:anObject selectors:allSelectors |
1502 |
||
1503 |
" |
|
1504 |
trace all (implemented) messages sent to Display |
|
1505 |
(other messages lead to an error, anyway) |
|
1506 |
" |
|
1507 |
||
1508 |
" |
|
1509 |
MessageTracer traceAll:Display |
|
1510 |
MessageTracer untrace:Display |
|
1511 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1512 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1513 |
"Modified: 5.6.1996 / 13:43:51 / stefan" |
88 | 1514 |
! |
1515 |
||
1516 |
traceAll:anObject from:aClass |
|
1517 |
"trace all messages defined in aClass sent to anObject" |
|
1518 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1519 |
self trace:anObject selectors:aClass selectors |
88 | 1520 |
|
1521 |
" |
|
1522 |
trace all methods in Display, which are implemented |
|
1523 |
in the DisplayWorkstation class. |
|
1524 |
" |
|
1525 |
||
1526 |
" |
|
1527 |
MessageTracer traceAll:Display from:XWorkstation |
|
1528 |
MessageTracer untrace:Display |
|
1529 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1530 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1531 |
"Modified: 5.6.1996 / 13:45:37 / stefan" |
27 | 1532 |
! |
1533 |
||
88 | 1534 |
traceSender:anObject selector:aSelector |
1535 |
"arrange for a trace message to be output on Stderr, when a message with |
|
1536 |
aSelector is sent to anObject. Only the sender is traced on entry. |
|
1537 |
Use untrap to remove this trace. |
|
1538 |
The current implementation does not allow integers or nil to be traced." |
|
1539 |
||
1540 |
|methodName| |
|
1541 |
||
1542 |
methodName := anObject class name , '>>' , aSelector. |
|
1543 |
self wrap:anObject |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1544 |
selector:aSelector |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1545 |
onEntry:[:con | |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1546 |
methodName errorPrint. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1547 |
' from ' errorPrint. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1548 |
con sender errorPrintNL. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1549 |
] |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1550 |
onExit:LeaveTraceBlock. |
88 | 1551 |
|
1552 |
" |
|
1553 |
|p| |
|
27 | 1554 |
|
88 | 1555 |
p := Point new. |
1556 |
MessageTracer traceSender:p selector:#x:. |
|
1557 |
p x:5. |
|
1558 |
p y:1. |
|
1559 |
p x:10. |
|
1560 |
MessageTracer untrap:p. |
|
1561 |
p x:7 |
|
1562 |
" |
|
1563 |
" |
|
1564 |
|a| |
|
1565 |
||
1566 |
a := #(6 1 9 66 2 17) copy. |
|
1567 |
MessageTracer traceSender:a selector:#at:put:. |
|
1568 |
MessageTracer traceSender:a selector:#at:. |
|
1569 |
a sort. |
|
1570 |
" |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1571 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1572 |
"Modified: 22.10.1996 / 17:39:36 / cg" |
11 | 1573 |
! |
1574 |
||
88 | 1575 |
untrace:anObject |
1576 |
"remove any traces on anObject" |
|
1577 |
||
1578 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
1579 |
trace facilities ..." |
|
1580 |
||
1581 |
^ self untrap:anObject |
|
1582 |
! |
|
1583 |
||
1584 |
untrace:anObject selector:aSelector |
|
1585 |
"remove traces of aSelector sent to anObject" |
|
1586 |
||
1587 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
1588 |
trace facilities ..." |
|
1589 |
||
1590 |
^ self untrap:anObject selector:aSelector |
|
1591 |
! ! |
|
1592 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1593 |
!MessageTracer class methodsFor:'object wrapping'! |
88 | 1594 |
|
8 | 1595 |
wrap:anObject selector:aSelector onEntry:entryBlock onExit:exitBlock |
1596 |
"arrange for the two blocks entryBlock and exitBlock to be evaluated whenever |
|
1597 |
a message with aSelector is sent to anObject. EntryBlock will be called on |
|
1598 |
entry, and get the current context passed as argument. ExitBlock will be called, |
|
1599 |
when the method is left, and get the context and the methods return value as arguments. |
|
1600 |
The current implementation does not allow integers or nil to be wrapped." |
|
1601 |
||
1602 |
"I have not yet enough experience, if the wrapped original method should |
|
1603 |
run as an instance of the original, or of the catching class; |
|
1604 |
The latter has the advantage of catching recursive and other sends, while |
|
1605 |
it might lead into trouble when the message is sent from a debugger or a long |
|
1606 |
return is done out of the original method ... |
|
1607 |
Time will show, you can experiment by setting the withOriginalClass: flag to false |
|
1608 |
" |
|
1609 |
^ self wrap:anObject selector:aSelector onEntry:entryBlock onExit:exitBlock withOriginalClass:true |
|
1610 |
! |
|
1611 |
||
1612 |
wrap:anObject selector:aSelector onEntry:entryBlock onExit:exitBlock withOriginalClass:withOriginalClass |
|
1613 |
"arrange for the two blocks entryBlock and exitBlock to be evaluated whenever |
|
1614 |
a message with aSelector is sent to anObject. EntryBlock will be called on |
|
1615 |
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
|
1616 |
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
|
1617 |
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
|
1618 |
before the wrapped method will be called. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1619 |
NOTICE: The current implementation does not allow integers or nil to be wrapped." |
8 | 1620 |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1621 |
|newClass orgClass myMetaclass trapMethod s spec implClass save dict| |
8 | 1622 |
|
1623 |
" |
|
27 | 1624 |
some are not allowed (otherwise we get into trouble ...) |
1625 |
" |
|
1626 |
(#(class changeClassTo:) includes:aSelector) ifTrue:[ |
|
256 | 1627 |
Transcript showCR:'sorry, cannot place trap on: ' , aSelector. |
1628 |
^ self |
|
27 | 1629 |
]. |
1630 |
||
1631 |
WrappedMethod autoload. "/ just to make sure ... |
|
1632 |
||
1633 |
" |
|
8 | 1634 |
create a new (anonymous) subclass of the receivers class |
1635 |
but only if not already being trapped. |
|
1636 |
" |
|
1637 |
orgClass := anObject class. |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1638 |
orgClass category == #'* trapping *' ifTrue:[ |
256 | 1639 |
newClass := orgClass |
8 | 1640 |
] ifFalse:[ |
256 | 1641 |
myMetaclass := orgClass class. |
8 | 1642 |
|
256 | 1643 |
newClass := myMetaclass copy new. |
1644 |
newClass setSuperclass:orgClass. |
|
1645 |
newClass instSize:orgClass instSize. |
|
1646 |
newClass flags:orgClass flags. |
|
1647 |
newClass setClassVariableString:''. |
|
1648 |
newClass setInstanceVariableString:''. |
|
1649 |
newClass setName:orgClass name. |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1650 |
newClass category:#'* trapping *'. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1651 |
newClass methodDictionary:MethodDictionary new. |
8 | 1652 |
]. |
1653 |
||
1654 |
" |
|
1655 |
create a method, executing the trap-blocks and the original method via a super-send |
|
1656 |
" |
|
1657 |
spec := Parser methodSpecificationForSelector:aSelector. |
|
1658 |
s := WriteStream on:String new. |
|
1659 |
s nextPutAll:spec. |
|
27 | 1660 |
s nextPutAll:' |retVal stubClass| '. |
8 | 1661 |
withOriginalClass ifTrue:[ |
256 | 1662 |
s nextPutAll:'stubClass := self class. '. |
1663 |
s nextPutAll:'self changeClassTo:(stubClass superclass). '. |
|
8 | 1664 |
]. |
1665 |
entryBlock notNil ifTrue:[ |
|
256 | 1666 |
s nextPutAll:'#literal1 yourself value:thisContext. '. |
8 | 1667 |
]. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1668 |
s nextPutAll:('retVal := #originalMethod. '). "/ just to get a place for the originalMethod |
27 | 1669 |
s nextPutAll:('retVal := super ' , spec , '. '). |
8 | 1670 |
exitBlock notNil ifTrue:[ |
256 | 1671 |
s nextPutAll:'#literal2 yourself value:thisContext value:retVal. '. |
8 | 1672 |
]. |
1673 |
withOriginalClass ifTrue:[ |
|
256 | 1674 |
s nextPutAll:'self changeClassTo:stubClass. '. |
8 | 1675 |
]. |
1676 |
s nextPutAll:'^ retVal'; cr. |
|
1677 |
||
37 | 1678 |
save := Compiler stcCompilation. |
1679 |
Compiler stcCompilation:#never. |
|
1680 |
[ |
|
256 | 1681 |
Class withoutUpdatingChangesDo:[ |
1682 |
trapMethod := Compiler compile:s contents |
|
1683 |
forClass:newClass |
|
1684 |
inCategory:'breakpointed' |
|
1685 |
notifying:nil |
|
1686 |
install:false |
|
1687 |
skipIfSame:false |
|
1688 |
silent:true. |
|
1689 |
] |
|
37 | 1690 |
] valueNowOrOnUnwindDo:[ |
256 | 1691 |
Compiler stcCompilation:save |
37 | 1692 |
]. |
8 | 1693 |
|
29 | 1694 |
implClass := orgClass whichClassIncludesSelector:aSelector. |
1695 |
implClass isNil ifTrue:[ |
|
256 | 1696 |
Transcript showCR:aSelector , ' is not understood by ' , orgClass name. |
29 | 1697 |
] ifFalse:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1698 |
trapMethod changeLiteral:#originalMethod to:(implClass compiledMethodAt:aSelector). |
29 | 1699 |
]. |
8 | 1700 |
entryBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1701 |
trapMethod changeLiteral:#literal1 to:entryBlock. |
8 | 1702 |
]. |
1703 |
exitBlock notNil ifTrue:[ |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1704 |
trapMethod changeLiteral:#literal2 to:exitBlock. |
8 | 1705 |
]. |
1706 |
" |
|
1707 |
change the source of this new method |
|
1708 |
(to avoid confusion in the debugger ...) |
|
1709 |
" |
|
1710 |
trapMethod source:'this is a wrapper method - not the real one'. |
|
27 | 1711 |
trapMethod changeClassTo:WrappedMethod. |
8 | 1712 |
|
1713 |
" |
|
1714 |
install this new method |
|
1715 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1716 |
dict := newClass methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1717 |
dict := dict at:aSelector putOrAppend:trapMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1718 |
newClass methodDictionary:dict. |
8 | 1719 |
|
1720 |
" |
|
1721 |
and finally, the big trick: |
|
1722 |
" |
|
1723 |
anObject changeClassTo:newClass |
|
1724 |
||
1725 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1726 |
[exBegin] |
8 | 1727 |
|p| |
1728 |
||
1729 |
p := Point new copy. |
|
1730 |
MessageTracer |
|
256 | 1731 |
wrap:p |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1732 |
selector:#y: |
256 | 1733 |
onEntry:nil |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1734 |
onExit:[:context :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1735 |
Transcript show:'leave Point>>y:, returning:'. |
256 | 1736 |
Transcript showCR:retVal printString. |
1737 |
Transcript endEntry |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1738 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1739 |
withOriginalClass:true. |
256 | 1740 |
Transcript showCR:'sending x: ...'. |
8 | 1741 |
p x:1. |
256 | 1742 |
Transcript showCR:'sending y: ...'. |
8 | 1743 |
p y:2. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1744 |
MessageTracer untrap:p. |
256 | 1745 |
Transcript showCR:'sending x: ...'. |
8 | 1746 |
p x:2. |
256 | 1747 |
Transcript showCR:'sending y: ...'. |
8 | 1748 |
p y:1. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1749 |
[exEnd] |
8 | 1750 |
" |
1751 |
||
1752 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1753 |
[exBegin] |
8 | 1754 |
|p| |
1755 |
||
1756 |
p := Point new copy. |
|
1757 |
MessageTracer wrap:p |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1758 |
selector:#y: |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1759 |
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
|
1760 |
onExit:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1761 |
withOriginalClass:false. |
256 | 1762 |
Transcript showCR:'sending x: ...'. |
8 | 1763 |
p x:1. |
256 | 1764 |
Transcript showCR:'sending y: ...'. |
8 | 1765 |
p y:2. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1766 |
MessageTracer untrap:p. |
256 | 1767 |
Transcript showCR:'sending x: ...'. |
8 | 1768 |
p x:2. |
256 | 1769 |
Transcript showCR:'sending y: ...'. |
8 | 1770 |
p y:1. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1771 |
[exEnd] |
8 | 1772 |
" |
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
1773 |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1774 |
"Modified: 25.6.1996 / 22:11:21 / stefan" |
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1775 |
"Modified: 10.9.1996 / 20:06:54 / cg" |
8 | 1776 |
! |
1777 |
||
88 | 1778 |
wrap:anObject selectors:aCollection onEntry:entryBlock onExit:exitBlock |
1779 |
"install wrappers for anObject on all selectors from aCollection" |
|
8 | 1780 |
|
88 | 1781 |
aCollection do:[:aSelector | |
1782 |
self wrap:anObject selector:aSelector onEntry:entryBlock onExit:exitBlock |
|
1783 |
] |
|
8 | 1784 |
! |
1785 |
||
88 | 1786 |
wrapAll:anObject onEntry:entryBlock onExit:exitBlock |
1787 |
"install wrappers for anObject on all implemented selectors" |
|
27 | 1788 |
|
1789 |
|allSelectors| |
|
1790 |
||
1791 |
allSelectors := IdentitySet new. |
|
1792 |
anObject class withAllSuperclasses do:[:aClass | |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1793 |
aClass methodDictionary keys addAllTo:allSelectors |
27 | 1794 |
]. |
88 | 1795 |
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
|
1796 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1797 |
"Modified: 5.6.1996 / 14:50:07 / stefan" |
88 | 1798 |
! ! |
1799 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1800 |
!MessageTracer class methodsFor:'queries'! |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1801 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1802 |
isTrapped:aMethod |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1803 |
"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
|
1804 |
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
|
1805 |
this returns false)" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1806 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1807 |
aMethod isWrapped ifFalse:[^ false]. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1808 |
^ aMethod basicLiterals includesIdentical:LeaveBreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1809 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1810 |
" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1811 |
MessageTracer trapMethod:(Collection compiledMethodAt:#select:). |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1812 |
Transcript showCR:(Collection compiledMethodAt:#select:) isWrapped. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1813 |
Transcript showCR:(MessageTracer isTrapped:(Collection compiledMethodAt:#select:)). |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1814 |
MessageTracer unwrapMethod:(Collection compiledMethodAt:#select:). |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1815 |
" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1816 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1817 |
"Modified: 22.10.1996 / 17:40:37 / cg" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1818 |
! ! |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1819 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1820 |
!MessageTracer class methodsFor:'trace helpers'! |
88 | 1821 |
|
1822 |
printEntryFull:aContext |
|
1823 |
self printEntryFull:aContext level:0 |
|
1824 |
! |
|
27 | 1825 |
|
88 | 1826 |
printEntryFull:aContext level:lvl |
1827 |
(String new:lvl) errorPrint. |
|
1828 |
'enter ' errorPrint. |
|
1829 |
aContext methodClass name errorPrint. |
|
1830 |
' ' errorPrint. |
|
1831 |
aContext selector errorPrint. |
|
1832 |
' rcvr=' errorPrint. |
|
1833 |
aContext receiver "printString" errorPrint. |
|
1834 |
' args=' errorPrint. |
|
1835 |
(aContext args) "printString" errorPrint. |
|
1836 |
' from:' errorPrint. aContext sender errorPrintNL. |
|
1837 |
! |
|
27 | 1838 |
|
88 | 1839 |
printEntrySender:aContext |
1840 |
aContext methodClass name errorPrint. |
|
1841 |
' ' errorPrint. aContext selector errorPrint. |
|
1842 |
' from ' errorPrint. |
|
1843 |
aContext sender errorPrintNL. |
|
1844 |
! |
|
1845 |
||
1846 |
printExit:aContext with:retVal |
|
1847 |
self printExit:aContext with:retVal level:0 |
|
27 | 1848 |
! |
1849 |
||
88 | 1850 |
printExit:aContext with:retVal level:lvl |
1851 |
(String new:lvl) errorPrint. |
|
1852 |
'leave ' errorPrint. |
|
1853 |
aContext methodClass name errorPrint. |
|
1854 |
' ' errorPrint. |
|
1855 |
aContext selector errorPrint. |
|
1856 |
' rcvr=' errorPrint. |
|
1857 |
aContext receiver "printString" errorPrint. |
|
1858 |
' return:' errorPrint. retVal "printString" errorPrintNL. |
|
1859 |
! ! |
|
13 | 1860 |
|
88 | 1861 |
!MessageTracer methodsFor:'trace helpers '! |
1862 |
||
1863 |
stepInterrupt |
|
1864 |
"called for every send while tracing" |
|
13 | 1865 |
|
88 | 1866 |
|con| |
13 | 1867 |
|
88 | 1868 |
StepInterruptPending := nil. |
1869 |
con := thisContext sender. |
|
1870 |
con lineNumber == 1 ifTrue:[ |
|
265 | 1871 |
traceDetail == true ifTrue:[ |
1872 |
self class printEntryFull:con. |
|
1873 |
] ifFalse:[ |
|
1874 |
con printCR. |
|
1875 |
] |
|
88 | 1876 |
]. |
1877 |
ObjectMemory flushInlineCaches. |
|
1878 |
StepInterruptPending := 1. |
|
1879 |
InterruptPending := 1. |
|
1880 |
^ self |
|
265 | 1881 |
|
1882 |
"Modified: 20.5.1996 / 10:28:20 / cg" |
|
13 | 1883 |
! |
1884 |
||
88 | 1885 |
trace:aBlock detail:fullDetail |
1886 |
"trace execution of aBlock." |
|
1887 |
||
1888 |
traceDetail := fullDetail. |
|
1889 |
ObjectMemory stepInterruptHandler:self. |
|
1890 |
^ [ |
|
1891 |
ObjectMemory flushInlineCaches. |
|
1892 |
StepInterruptPending := 1. |
|
1893 |
InterruptPending := 1. |
|
1894 |
aBlock value |
|
1895 |
] valueNowOrOnUnwindDo:[ |
|
1896 |
StepInterruptPending := nil. |
|
1897 |
ObjectMemory stepInterruptHandler:nil. |
|
11 | 1898 |
] |
1899 |
||
1900 |
" |
|
88 | 1901 |
MessageTracer trace:[#(6 5 4 3 2 1) sort] detail:false |
1902 |
MessageTracer trace:[#(6 5 4 3 2 1) sort] detail:true |
|
8 | 1903 |
" |
1904 |
! ! |
|
27 | 1905 |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1906 |
!MessageTracer class methodsFor:'documentation'! |
98 | 1907 |
|
1908 |
version |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1909 |
^ '$Header: /cvs/stx/stx/libbasic3/MessageTracer.st,v 1.47 1996-10-22 17:57:06 cg Exp $' |
98 | 1910 |
! ! |
27 | 1911 |
MessageTracer initialize! |