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