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