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