eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'MessageTracer':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: MessageTracer


Inheritance:

   Object
   |
   +--MessageTracer
      |
      +--MessageTracer::InteractionCollector
      |
      +--MessageTracer::PrintingMessageTracer

Package:
stx:libbasic3
Category:
System-Debugging-Support
Version:
rev: 1.148 date: 2018/05/07 10:58:30
user: cg
file: MessageTracer.st directory: libbasic3
module: stx stc-classLibrary: libbasic3
Author:
Claus Gittinger

Description:


This class provides a common home for the tracing
facilities (originally, they where in Object, but have been moved to
allow easier separation of development vs. runtime configurations).

tracing execution of a block:

    MessageTracer trace:[ ... ]

    MessageTracer traceFull:[ ... ]

    (for system developer only:)

    MessageTracer debugTrace:[ ... ]


trapping sends to a specific object:

    MessageTracer trap:anObject selector:aSelector
    ...
    MessageTracer untrap:anObject selector:aSelector
    or:
    MessageTracer untrap:anObject



trapping some messages sent to a specific object:

    MessageTracer trap:anObject selectors:aCollectionOfSelectors
    ...
    MessageTracer untrap:anObject



trapping any message sent to a specific object:

    MessageTracer trapAll:anObject
    ...
    MessageTracer untrap:anObject



trapping evaluation of a specific method:

    MessageTracer trapMethod:aMethod
    ...
    MessageTracer unwrapMethod:aMethod



trapping evaluation of a specific method with
receiver being an instance of some class:

    MessageTracer trapMethod:aMethod forInstancesOf:aClass
    ...
    MessageTracer unwrapMethod:aMethod



tracing sends to a specific object:

    MessageTracer trace:anObject selector:aSelector
    ...
    MessageTracer untrace:anObject selector:aSelector
    or:
    MessageTracer untrace:anObject



tracing sender only:

    MessageTracer traceSender:anObject selector:aSelector
    ...
    MessageTracer untrace:anObject selector:aSelector
    or:
    MessageTracer untrace:anObject



tracing evaluation of a specific method:

    MessageTracer traceMethod:aMethod
    ...
    MessageTracer unwrapmethod:aMethod

  see more in examples and in method comments.


Class protocol:

Signal constants
o  breakpointSignal

o  objectWrittenBreakpointSignal

class initialization
o  initialize
BreakpointSignal := HaltSignal newSignalMayProceed:true.
usage example(s):
     BreakpointSignal := nil.
     MessageTracer initialize

o  update: something with: parameter from: changedObject
sent when restarted after a snapIn

class tracing
o  untraceAllClasses
remove all traces of messages sent to any class

o  untraceClass: aClass
remove all traces of messages sent to instances of aClass

class wrapping
o  wrapClass: orgClass selector: aSelector onEntry: entryBlock onExit: exitBlock
arrange for the two blocks entryBlock and exitBlock to be evaluated whenever
aSelector is sent to instances of orgClass or subclasses.
EntryBlock will be called on entry, and get the current context passed as argument.
ExitBlock will be called, when the method is left, and get context and the method's return value as arguments.

usage example(s):
     MessageTracer
                wrapClass:Point
                 selector:#scaleBy:
                   onEntry:nil
                    onExit:[:con :retVal |
                               Transcript show:'leave Point>>scaleBy:; returning:'.
                               Transcript showCR:retVal printString.
                               Transcript endEntry
                           ].
     (1@2) scaleBy:5.
     MessageTracer untrapClass:Point selector:#scaleBy:.
     (1@2) scaleBy:5.
usage example(s):
     MessageTracer
                wrapClass:Integer
                 selector:#factorial
                   onEntry:[:con |
                               Transcript showCR:('entering ' , con receiver printString , '>>factorial').
                           ]
                    onExit:[:con :retVal |
                               Transcript show:'leave Integer>>factorial; returning:'.
                               Transcript showCR:retVal printString.
                               Transcript endEntry
                           ].
     Transcript showCR:'5 factorial traced'.
     5 factorial.
     MessageTracer untrapClass:Integer selector:#factorial.
     Transcript showCR:'5 factorial normal'.
     5 factorial.

cleanup
o  cleanup
if you forgot which classes/methods where wrapped and/or trapped,
this cleans up everything ...
usage example(s):
     MessageTracer cleanup

execution trace
o  debugTrace: aBlock
trace execution of aBlock. This is for system debugging only;
The trace output is a low level trace generated in the VM.
usage example(s):
     MessageTracer debugTrace:[#(6 5 4 3 2 1) sort]

o  trace: aBlock
evaluate aBlock sending trace information to stdout.
Return the value of the block.
usage example(s):
     MessageTracer trace:[#(6 5 4 3 2 1) sort]

o  trace: aBlock on: aStream
evaluate aBlock sending trace information to stdout.
Return the value of the block.
usage example(s):
     MessageTracer trace:[#(6 5 4 3 2 1) sort] on:Transcript

o  traceFull: aBlock
evaluate aBlock sending trace information to stdout.
Return the value of the block.
The trace information is more detailed.
usage example(s):
     MessageTracer traceFull:[#(6 5 4 3 2 1) sort]

o  traceFull: aBlock on: aStream
evaluate aBlock sending trace information to stdout.
Return the value of the block.
The trace information is more detailed.
usage example(s):
     MessageTracer traceFull:[#(6 5 4 3 2 1) sort]

o  traceFullIndented: aBlock
evaluate aBlock sending trace information to stdout.
Return the value of the block.
The trace information is more detailed.
usage example(s):
     MessageTracer traceFullIndented:[ #(6 5 4 3 2 1) sort ]

o  traceFullIndented: aBlock on: aStream
evaluate aBlock sending trace information to stdout.
Return the value of the block.
The trace information is more detailed.
usage example(s):
     MessageTracer traceFullIndented:[ #(6 5 4 3 2 1) sort ]

o  traceIndented: aBlock
evaluate aBlock sending trace information to stdout.
Return the value of the block.
usage example(s):
     MessageTracer traceIndented:[ #(6 5 4 3 2 1) sort ]

o  traceIndented: aBlock on: aStream
evaluate aBlock sending trace information to stdout.
Return the value of the block.
usage example(s):
     MessageTracer traceIndented:[ #(6 5 4 3 2 1) sort ] on:Transcript

method breakpointing
o  trapClass: aClass selector: aSelector
arrange for the debugger to be entered when a message with aSelector is
sent to instances of aClass (or subclass instances). Use untrapClass to remove this trap.
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.);
if there is a need to trap those, use the low-level wrap-methods, and put a check into the
entry/leave blocks.
usage example(s):
     MessageTracer trapClass:Collection selector:#select:.
     Dictionary new select:[:e | ].       'not caught - Dictionary has its own select'.
     (Array new:10) select:[:e | ].       'not caught - SeqColl has its own select'.
     Set new select:[:e | ].              'caught - Set inherits this from Collection'.
     MessageTracer untrapClass:Collection

o  trapMethod: aMethod
arrange for the debugger to be entered when aMethod is about to be executed.
The trap is enabled for any process - see #trapMethod:inProcess: for a more
selective breakPoint.
Use unwrapMethod or untrapClass to remove this trap.
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.);
if there is a need to trap those, use the low-level wrap-methods, and put a check into the
entry/leave blocks.
usage example(s):
     MessageTracer trapMethod:(Collection compiledMethodAt:#select:).
     Dictionary new select:[:e | ].       'not caught - Dictionary has its own select'.
     (Array new:10) select:[:e | ].       'not caught - SeqColl has its own select'.
     Set new select:[:e | ].              'caught - Set inherits this from Collection'.
     MessageTracer unwrapMethod:(Collection compiledMethodAt:#select:).

o  trapMethod: aMethod after: countInvocations
arrange for the debugger to be entered when aMethod has been invoked countInvocations times.
The trap is enabled for any process.
Use unwrapMethod or untrapClass to remove this trap.
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.);
if there is a need to trap those, use the low-level wrap-methods, and put a check into the
entry/leave blocks.

o  trapMethod: aMethod forInstancesOf: aClass
arrange for the debugger to be entered when aMethod is about to be executed
for an instance of aClass.
Use unwrapMethod or untrapClass to remove this trap.
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.);
if there is a need to trap those, use the low-level wrap-methods, and put a check into the
entry/leave blocks.
usage example(s):
     MessageTracer trapMethod:(View compiledMethodAt:#redraw) forInstancesOf:myView.

o  trapMethod: aMethod if: conditionBlock
arrange for the debugger to be entered when aMethod has been invoked and conditionBlock
evaluates to true.
conditionBlock gets context and method as (optional) arguments.
The trap is enabled for any process.
Use unwrapMethod or untrapClass to remove this trap.
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.);
if there is a need to trap those, use the low-level wrap-methods, and put a check into the
entry/leave blocks.

o  trapMethod: aMethod inProcess: aProcess
arrange for the debugger to be entered when aMethod is about to be executed,
but only, if executed aProcess or one of aProcess's offspring.
This allows for breakpoints to be set on system-critical code.
The trap will only fire for selected processes (making browsers etc. still usable).
Use unwrapMethod or untrapClass to remove this trap.
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.);
if there is a need to trap those, use the low-level wrap-methods, and put a check into the
entry/leave blocks.

o  trapMethod: aMethod onReturnIf: conditionBlock
arrange for the debugger to be entered when aMethod returns
and conditionBlock evaluates to true.
conditionBlock gets retVal, context and method as (optional) arguments.
The trap is enabled for any process.
Use unwrapMethod or untrapClass to remove this trap.
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.);
if there is a need to trap those, use the low-level wrap-methods, and put a check into the
entry/leave blocks.

o  untrapAllClasses
remove any traps on any class
usage example(s):
     MessageTracer untrapAllClasses

o  untrapClass: aClass
remove any traps on aClass
usage example(s):
     MessageTracer untrapClass:Point

o  untrapClass: aClass selector: aSelector
remove trap of aSelector sent to aClass
usage example(s):
     MessageTracer trapClass:Point selector:#copy.
     (1@2) copy.
     (1@2) deepCopy.
     MessageTracer trapClass:Point selector:#deepCopy.
     (1@2) copy.
     (1@2) deepCopy.
     MessageTracer untrapClass:Point selector:#copy.
     (1@2) copy.
     (1@2) deepCopy.
     MessageTracer untrapClass:Point selector:#deepCopy.
     (1@2) copy.
     (1@2) deepCopy.

o  untrapMethod: aMethod
remove break on aMethod

method breakpointing - new
o  breakMethod: method atLine: line
Installs new breakpoint in given method at given line.
Returns the installed breakpoint or nil if none could be
installed

method counting
o  countMethod: aMethod
arrange for a aMethod's execution to be counted.
Use unwrapMethod to remove this.
usage example(s):
     MessageTracer countMethod:(Integer compiledMethodAt:#factorial).
     5 factorial.
     MessageTracer executionCountOf:(Integer compiledMethodAt:#factorial) printNL.
     MessageTracer stopCountingMethod:(Integer compiledMethodAt:#factorial)

o  countMethodByReceiverClass: aMethod
arrange for a aMethod's execution to be counted and maintain
a per-receiver class profile.
Use unwrapMethod to remove this.

o  executionCountOfMethod: aMethod
return the current count

o  executionCountsByReceiverClassOfMethod: aMethod
return a collection mapping receiver class to call counts

o  resetCountOfMethod: aMethod
return the current count

o  stopCountingMethod: aMethod
remove counting of aMethod

method memory usage
o  countMemoryUsageOfMethod: aMethod
arrange for aMethod's memory usage to be counted.
Use unwrapMethod to remove this.
usage example(s):
     MessageTracer countMemoryUsageOfMethod:(Integer compiledMethodAt:#factorialR).
     3 factorialR.
     Transcript showCR:(MessageTracer memoryUsageOfMethod:(Integer compiledMethodAt:#factorialR)).
     MessageTracer stopCountingMemoryUsageOfMethod:(Integer compiledMethodAt:#factorialR)

o  isCountingMemoryUsage: aMethod
return true if aMethod is counting memoryUsage

o  memoryUsageOfMethod: aMethod
return the current count

o  resetMemoryUsageOfMethod: aMethod
reset the current usage

o  stopCountingMemoryUsageOfMethod: aMethod
remove counting memory of aMethod

method mocking
o  mock: selector in: class do: block

o  mockMethod: method do: block
Temporarily change the behaviour of the given method to perform the given block instead
of the method's code. The value of the block is returned as the method's return value.
The behaviour is changed only for current thread, i.e., thread the calling this methood
and its child threads.

The block gets the receiver as the first argument, followed by method parameters
and then - optionally - the original method object.

Do not forget to 'unmock' by means of #unmockMethod: or #unmockAllMethods

CAVEAT: The 'current thread and its child threads' detection is done by walking
threads along their #creatorId. However, when the parent thread dies,
the link if broken and thus 'and its child threads' may not work 100%.
For the calling thread itself, mocking should work reliably.

usage example(s):
     MessageTracer
                mockMethod:(Color class compiledMethodAt:#magenta)
                do: [ :color |
                    Color red
                ].
     Color magenta.
     [ [ Color magenta inspect ] fork. Delay waitForSeconds: 1. ] fork.
     (Color class compiledMethodAt:#magenta) isMocked.
     MessageTracer unwrapMethod:(Color class compiledMethodAt:#magenta).
     Color magenta.    

o  unmock: selector in: class

o  unmockAllMethods
Remove mocking wrapper from all methods, unconditionally.
May (should) be called in tearDdown of each testcase that
uses method mocking

o  unmockMethod: method
Remove mocking wrapper from a method, if it has been mocked by
#mockMethod:do:

method profiling
o  spyMethod: aMethod
arrange for given method to collect profiling data
using message tally profiler.
Use unwrapMethod to remove this.

o  spyMethod: aMethod interval: anInteger
arrange for given method to collect profiling data
using message tally profiler.
Use unwrapMethod to remove this.

method timing
o  executionTimesOfMethod: aMethod
return the current gathered execution time statistics

o  resetExecutionTimesOfMethod: aMethod
reset the gathered execution times statistics for aMethod;
the method remains wrapped.

o  stopTimingMethod: aMethod
remove timing of aMethod

o  timeMethod: aMethod
arrange for a aMethod's execution time to be measured.
Use unwrapMethod: or stopTimingMethod: to remove this.
usage example(s):
     MessageTracer timeMethod:(Integer compiledMethodAt:#factorial).
     5 factorial.
     5 factorial.
     5 factorial.
     (MessageTracer executionTimesOfMethod:(Integer compiledMethodAt:#factorial)) printCR.
     MessageTracer stopTimingMethod:(Integer compiledMethodAt:#factorial)

method tracing
o  traceClass: aClass selector: aSelector
arrange for a trace message to be output on Stderr, when a message with aSelector is
sent to instances of aClass (or subclass instances). Use untraceClass to remove this.
usage example(s):
     MessageTracer traceClass:Integer selector:#factorial.
     5 factorial.
     MessageTracer untraceClass:Integer
usage example(s):
     MessageTracer traceClass:SequenceableCollection selector:#quickSortFrom:to:.
     #(6 1 9 66 2 17) copy sort.
     MessageTracer untraceClass:SequenceableCollection
usage example(s):
     MessageTracer traceClass:Array selector:#at:.
     MessageTracer traceClass:Array selector:#at:put:.
     #(6 1 9 66 2 17) copy sort.
     MessageTracer untraceClass:Array

o  traceClass: aClass selector: aSelector on: aStream
arrange for a trace message to be output on aStream, when a message with aSelector is
sent to instances of aClass (or subclass instances). Use untraceClass to remove this.
usage example(s):
     MessageTracer traceClass:Integer selector:#factorial on:Transcript.
     5 factorial.
     MessageTracer untraceClass:Integer
usage example(s):
     MessageTracer traceClass:Integer selector:#factorialR on:Transcript.
     5 factorialR.
     MessageTracer untraceClass:Integer

o  traceMethod: aMethod
arrange for a trace message to be output on Stderr,
when aMethod is executed. Traces both entry and exit.
Use unwrapMethod to remove this.
usage example(s):
     MessageTracer traceMethod:(Integer compiledMethodAt:#factorial).
     5 factorial.
     MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial)
usage example(s):
     MessageTracer traceMethod:(Integer compiledMethodAt:#factorialR).
     5 factorialR.
     MessageTracer untraceMethod:(Integer compiledMethodAt:#factorialR)
usage example(s):
     MessageTracer traceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:).
     #(6 1 9 66 2 17) copy sort.
     MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:).
usage example(s):
     MessageTracer traceMethod:(Object compiledMethodAt:#at:).
     MessageTracer traceMethod:(Object compiledMethodAt:#at:put:).
     #(6 1 9 66 2 17) copy sort.
     MessageTracer untraceMethod:(Object compiledMethodAt:#at:).
     MessageTracer untraceMethod:(Object compiledMethodAt:#at:put:).

o  traceMethod: aMethod on: aStream
arrange for a trace message to be output on aStream,
when aMethod is executed. Traces both entry and exit.
Use unwrapMethod to remove this.
usage example(s):
     MessageTracer traceMethod:(Integer compiledMethodAt:#factorial) on:Transcript.
     5 factorial.
     MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial)
usage example(s):
     MessageTracer traceMethod:(Integer compiledMethodAt:#factorialR) on:Transcript.
     5 factorialR.
     MessageTracer untraceMethod:(Integer compiledMethodAt:#factorialR)
usage example(s):
     MessageTracer traceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:) on:Transcript.
     #(6 1 9 66 2 17) copy sort.
     MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:).

o  traceMethodAll: aMethod
arrange for a full trace message to be output on Stderr, when aMethod is executed.
Only the sender is traced on entry.
Use untraceMethod to remove this trace.
This is for system debugging only;
The trace output is a low level trace generated in the VM.

o  traceMethodEntry: aMethod
arrange for a trace message to be output on stdErr,
when aMethod is executed. Only entry is traced.
Use unwrapMethod to remove this.
usage example(s):
     MessageTracer traceMethodEntry:(Integer compiledMethodAt:#factorial).
     5 factorial.
     MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial)
usage example(s):
     MessageTracer traceMethodEntry:(Integer compiledMethodAt:#factorialR).
     5 factorialR.
     MessageTracer untraceMethod:(Integer compiledMethodAt:#factorialR)
usage example(s):
     MessageTracer traceMethodEntry:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:).
     #(6 1 9 66 2 17) copy sort.
     MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:).

o  traceMethodEntry: aMethod on: aStream
arrange for a trace message to be output on aStream,
when aMethod is executed. Only entry is traced.
Use unwrapMethod to remove this.
usage example(s):
     MessageTracer traceMethodEntry:(Integer compiledMethodAt:#factorial) on:Transcript.
     5 factorial.
     MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial)
usage example(s):
     MessageTracer traceMethodEntry:(Integer compiledMethodAt:#factorialR) on:Transcript.
     5 factorialR.
     MessageTracer untraceMethod:(Integer compiledMethodAt:#factorialR)
usage example(s):
     MessageTracer traceMethodEntry:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:) on:Transcript.
     #(6 1 9 66 2 17) copy sort.
     MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:).

o  traceMethodFull: aMethod
arrange for a full trace message to be output on Stderr, when amethod is executed.
Only the sender is traced on entry.
Use untraceMethod to remove this trace.

o  traceMethodFull: aMethod on: aStream
arrange for a full trace message to be output on Stderr, when aMethod is executed.
Only the sender is traced on entry.
Use untraceMethod to remove this trace.

o  traceMethodSender: aMethod
arrange for a trace message to be output on Stderr,
when amethod is executed.
Only the sender is traced on entry.
Use untraceMethod to remove this trace.

o  traceMethodSender: aMethod on: aStream
arrange for a trace message to be output on Stderr, when amethod is executed.
Only the sender is traced on entry.
Use untraceMethod to remove this trace.

o  traceUpdateMethod: aMethod on: aStream
arrange for a trace message to be output on aStream,
when aMethod is executed.
Traces both entry and exit.
Use unwrapMethod to remove this.
This one is specialized for change-update calling i.e. it traces from the update
back to the origial change message.

o  tracelogMethod: aMethod
arrange for a trace log entry to be appended to a standard log using
Logger, when aMethod is executed. Traces both entry and exit.
Use unwrapMethod to remove this.

o  untraceMethod: aMethod
remove tracing of aMethod

method wrapping
o  unwrapAllMethods
just in case you don't know what methods have break/trace-points
on them; this removes them all
usage example(s):
     MessageTracer unwrapAllMethods

o  unwrapMethod: aMethod
remove any wrapper on aMethod

o  wrapMethod: aMethod onEntry: entryBlock onExit: exitBlock

o  wrapMethod: aMethod onEntry: entryBlock onExit: exitBlock onUnwind: unwindBlock
arrange for the two blocks entryBlock and exitBlock to be evaluated whenever
aMethod is evaluated.
EntryBlock will be called on entry, and gets the current context passed as argument.
ExitBlock will be called, when the method is left, and gets the context and
the method's return value as arguments.
UnwindBlock will be called when the contxt of aMethod is unwound.
If there is an unwindBlock, the entry and exitBlocks will be called within the unwind block,
because allocating the unwindBlock uses memory and some users want to count allocated memory.

usage example(s):
     MessageTracer
                wrapMethod:(Point compiledMethodAt:#scaleBy:)
                   onEntry:nil
                    onExit:[:con :retVal |
                               Transcript show:'leave Point>>scaleBy:; returning:'.
                               Transcript showCR:retVal printString.
                               Transcript endEntry
                           ].
     (1@2) scaleBy:5.
     MessageTracer unwrapMethod:(Point compiledMethodAt:#scaleBy:).
     (1@2) scaleBy:5.
usage example(s):
     MessageTracer
                wrapMethod:(Integer compiledMethodAt:#factorial)
                   onEntry:[:con |
                               Transcript showCR:('entering ' , con receiver printString , '>>factorial').
                           ]
                    onExit:[:con :retVal |
                               Transcript show:'leave Integer>>factorial; returning:'.
                               Transcript showCR:retVal printString.
                               Transcript endEntry
                           ].
     Transcript showCR:'5 factorial traced'.
     5 factorial.
     MessageTracer unwrapMethod:(Integer compiledMethodAt:#factorial).
     Transcript showCR:'5 factorial normal'.
     5 factorial.

o  wrapMethod: aMethod onEntryCode: entryCode onExitCode: exitCode

o  wrapMethod: aMethod onEntryCode: entryCode onExitCode: exitCode onUnwindCode: unwindCode
arrange for the entryCode and exitCode to be evaluated whenever
aMethod is evaluated.
EntryCode will be executed on entry, exitCode when the method is left.
UnwindCode will be executed when the context of aMethod is unwound.

Because the code is sliced in, it may return.
Useful to wrap existing methods with before and after code.

usage example(s):
     MessageTracer
                wrapMethod:(Point compiledMethodAt:#scaleBy:)
                onEntryCode:'Transcript showCR:''hello'' '
                onExitCode:'Transcript showCR:''good bye'' '.

     (1@2) scaleBy:5.
     MessageTracer unwrapMethod:(Point compiledMethodAt:#scaleBy:).
     (1@2) scaleBy:5.

object breakpointing
o  objectHasWraps: anObject
return true, if anObject has any wraps

o  realClassOf: anObject
return anObjects real class

o  trap: anObject selector: aSelector
arrange for the debugger to be entered when a message with aSelector is
sent to anObject. Use untrap to remove this trap.
The current implementation does not allow integers or nil to be trapped.

o  trap: anObject selectors: aCollection

o  trapAll: anObject
trap on all messages which are understood by anObject

o  trapAll: anObject from: aClass
trap on all messages defined in aClass sent to anObject

o  untrap: anObject
remove any traps on anObject

o  untrap: anObject selector: aSelector
remove trap on aSelector from anObject

o  wrappedSelectorsOf: anObject
return the set of wrapped selectors (if any)

object modification traps
o  trapModificationsIn: anObject
trap modifications in anObject

o  trapModificationsIn: anObject filter: aFilterBlock
trap modifications in anObject
usage example(s):
trap if arrays 5th slot is modified:

     |a|

     a := Array new:10.
     MessageTracer trapModificationsIn:a filter:[:old :new | (old at:5) ~~ (new at:5)].

     a size.
     a at:1.
     a at:2 put:nil.
     a at:2 put:2.
     a at:2.
     a at:3.
     a at:2 put:2.
     a at:2 put:3.
     a at:5 put:3.
     a at:5 put:3.
     MessageTracer untrace:a.
     a at:3 put:5.

o  trapModificationsIn: anObject selector: aSelector filter: aFilterBlock
install a trap for modifications in anObject by aSelector-messages.
the filterBlock will be invoked (after a modification) with the old and
new values as arguments and should return true,
if the debugger is really wanted.

o  trapModificationsIn: anObject selectors: aCollectionOfSelectors filter: aFilterBlock
install a trap for modifications in anObject by aSelector-messages.
the filterBlock will be invoked (after a modification) with the old and
new values as arguments and should return true,
if the debugger is really wanted.

o  trapModificationsOf: anInstVarOrOffset in: anObject
trap modifications in anObject

object tracing
o  trace: anObject selector: aSelector
arrange for a trace message to be output on Stderr, when a message with
aSelector is sent to anObject. Both entry and exit are traced.
Use untrap to remove this trace.
The current implementation does not allow integers or nil to be traced.

o  trace: anObject selector: aSelector on: aStream
arrange for a trace message to be output on Stderr, when a message with
aSelector is sent to anObject. Both entry and exit are traced.
Use untrap to remove this trace.
The current implementation does not allow integers or nil to be traced.

o  trace: anObject selectors: aCollectionOfSelectors
arrange for a trace message to be output on Stderr, when any message
from aCollectionOfSelectors is sent to anObject.
Both entry and exit are traced.
Use untrap:/untrace: to remove this trace.
The current implementation does not allow integers or nil to be traced.

o  trace: anObject selectors: aCollectionOfSelectors on: aStream
arrange for a trace message to be output on Stderr, when any message
from aCollectionOfSelectors is sent to anObject.
Both entry and exit are traced.
Use untrap:/untrace: to remove this trace.
The current implementation does not allow integers or nil to be traced.

o  traceAll: anObject
trace all messages which are understood by anObject
usage example(s):
     MessageTracer traceAll:Display
     MessageTracer untrace:Display

o  traceAll: anObject from: aClass
trace all messages defined in aClass sent to anObject
usage example(s):
     MessageTracer traceAll:Display from:XWorkstation
     MessageTracer untrace:Display

o  traceAll: anObject from: aClass on: aStream
trace all messages defined in aClass sent to anObject
usage example(s):
     MessageTracer traceAll:Display from:XWorkstation on:Transcript
     MessageTracer untrace:Display

o  traceAll: anObject on: aStream
trace all messages which are understood by anObject
usage example(s):
     MessageTracer traceAll:Display on:Transcript
     MessageTracer untrace:Display

o  traceEntry: anObject selectors: aCollectionOfSelectors on: aStream
arrange for a trace message to be output on Stderr, when any message
from aCollectionOfSelectors is sent to anObject.
Only entry is traced.
Use untrap:/untrace: to remove this trace.
The current implementation does not allow integers or nil to be traced.

o  traceSender: anObject selector: aSelector
arrange for a trace message to be output on Stderr, when a message with
aSelector is sent to anObject. Only the sender is traced on entry.
Use untrap to remove this trace.
The current implementation does not allow integers or nil to be traced.

o  traceSender: anObject selector: aSelector on: aStream
arrange for a trace message to be output on Stderr, when a message with
aSelector is sent to anObject. Only the sender is traced on entry.
Use untrap to remove this trace.
The current implementation does not allow integers or nil to be traced.

o  untrace: anObject
remove any traces on anObject

o  untrace: anObject selector: aSelector
remove traces of aSelector sent to anObject

object wrapping
o  wrap: anObject selector: aSelector onEntry: entryBlock onExit: exitBlock
arrange for the two blocks entryBlock and exitBlock to be evaluated whenever
a message with aSelector is sent to anObject. EntryBlock will be called on
entry, and get the current context passed as argument. ExitBlock will be called,
when the method is left, and get the context and the method's return value as arguments.
The current implementation does not allow integers or nil to be wrapped.

o  wrap: anObject selector: aSelector onEntry: entryBlock onExit: exitBlock additionalEntryCode: additionalEntryCode additionalExitCode: additionalExitCode additionalVariables: additionalVariables withOriginalClass: withOriginalClass flushCaches: flushCaches
arrange for the two blocks entryBlock and exitBlock to be evaluated whenever
a message with aSelector is sent to anObject. EntryBlock will be called on
entry, and get the current context passed as argument. ExitBlock will be called,
when the method is left, and get the current context and the method's return value as argument.
If withOriginalClass is true, the class of anObject will be set to its original class
before the wrapped method will be called.
NOTICE: The current implementation does not allow integers or nil to be wrapped.
usage example(s):
                                                                        [exBegin]
     |p|

     p := Point new copy.
     MessageTracer
                wrap:p
            selector:#y:
             onEntry:nil
              onExit:[:context :retVal |
                         Transcript show:'leave Point>>y:, returning:'.
                         Transcript showCR:retVal printString.
                         Transcript endEntry
                     ]
               withOriginalClass:true.
     Transcript showCR:'sending x: ...'.
     p x:1.
     Transcript showCR:'sending y: ...'.
     p y:2.
     MessageTracer untrap:p.
     Transcript showCR:'sending x: ...'.
     p x:2.
     Transcript showCR:'sending y: ...'.
     p y:1.
                                                                        [exEnd]
usage example(s):
                                                                        [exBegin]
     |p|

     p := Point new copy.
     MessageTracer wrap:p
               selector:#y:
                onEntry:[:context | self halt:'y: you are trapped']
                 onExit:nil
                  withOriginalClass:false.
     Transcript showCR:'sending x: ...'.
     p x:1.
     Transcript showCR:'sending y: ...'.
     p y:2.
     MessageTracer untrap:p.
     Transcript showCR:'sending x: ...'.
     p x:2.
     Transcript showCR:'sending y: ...'.
     p y:1.
                                                                        [exEnd]

o  wrap: anObject selector: aSelector onEntry: entryBlock onExit: exitBlock withOriginalClass: withOriginalClass flushCaches: flushCaches
arrange for the two blocks entryBlock and exitBlock to be evaluated whenever
a message with aSelector is sent to anObject. EntryBlock will be called on
entry, and get the current context passed as argument. ExitBlock will be called,
when the method is left, and get the current context and the method's return value as argument.
If withOriginalClass is true, the class of anObject will be set to its original class
before the wrapped method will be called.
NOTICE: The current implementation does not allow integers or nil to be wrapped.

o  wrap: anObject selectors: aCollection onEntry: entryBlock onExit: exitBlock
install wrappers for anObject on all selectors from aCollection

o  wrapAll: anObject onEntry: entryBlock onExit: exitBlock
install wrappers for anObject on all implemented selectors

queries
o  allWrappedMethods
^ Smalltalk allMethodsForWhich:[:mthd | mthd isWrapped]

o  areAnyMethodsWrapped
Smalltalk allMethodsDo:[:mthd |

o  isCounting: aMethod
return true if aMethod is counted

o  isCountingByReceiverClass: aMethod
return true if aMethod is counted with per receiver class statistics

o  isMocking: aMethod
Return true if aMethod is mocking

o  isTiming: aMethod
return true if aMethod is timed

o  isTrapped: aMethod
return true, if a breakpoint is set on aMethod.
This only returns true for standard breakpoints (i.e. for user-wraps,
this returns false)
usage example(s):
     MessageTracer trapMethod:(Collection compiledMethodAt:#select:).
     Transcript showCR:(Collection compiledMethodAt:#select:) isWrapped.
     Transcript showCR:(MessageTracer isTrapped:(Collection compiledMethodAt:#select:)).
     MessageTracer unwrapMethod:(Collection compiledMethodAt:#select:).

trace helpers
o  dummyEmptyMethod
helper - to get the time it takes to evaluate the wrappers for
a dummy method.

o  getTimeForWrappers
helper - get the overhead (in ms) spent in the wrapper code of
a timed method.
usage example(s):
     self getTimeForWrappers

o  printEntryFull: aContext

o  printEntryFull: aContext level: lvl

o  printEntryFull: aContext level: lvl on: aStream

o  printEntryFull: aContext on: aStream

o  printEntrySender: aContext on: aStream

o  printExit: aContext with: retVal

o  printExit: aContext with: retVal level: lvl

o  printExit: aContext with: retVal level: lvl on: aStream

o  printExit: aContext with: retVal on: aStream

o  printFull: aContext on: aStream withSender: withSender

o  printFull: aContext on: aStream withSenderContext: aSenderContextOrNil

o  printObject: anObject on: aStream

o  printSender: aSenderContext on: aStream

o  printUpdateEntryFull: aContext level: lvl on: aStream
con is #'changed:with:'

o  traceEntryFull: aContext on: aStream

o  traceFullBlockFor: aStream
avoid generation of fullBlocks

o  traceSenderBlockFor: aStream
avoid generation of fullBlocks


Instance protocol:

trace helpers
o  trace: aBlock detail: fullDetail
trace execution of aBlock.
usage example(s):
     PrintingMessageTracer new trace:[#(6 5 4 3 2 1) sort] detail:false

     PrintingMessageTracer new trace:[#(6 5 4 3 2 1) sort] detail:true

     PrintingMessageTracer new trace:[#(6 5 4 3 2 1) sort] detail:#indent

     PrintingMessageTracer new trace:[#(6 5 4 3 2 1) sort] detail:#fullIndent


Private classes:

    InteractionCollector
    MethodSpyInfo
    MethodTimingInfo
    PrintingMessageTracer

Examples:


For the common cases, you will find a menu entry in the SystemBrowser. Howeever, more special cases (especially with condition checks) can be set up by evaluating the lower level entries. trapping specific methods: (by class/selector):
   MessageTracer trapClass:Collection selector:#select:.
   Dictionary new select:[:e | ].       'not caught - Dictionary has its own select'.
   (Array new:10) select:[:e | ].       'not caught - SeqColl has its own select'.
   Set new select:[:e | ].              'caught - Set inherits this from Collection'.
   MessageTracer untrapClass:Collection
(by method):
   MessageTracer trapMethod:(Collection compiledMethodAt:#select:).
   Dictionary new select:[:e | ].       'not caught - Dictionary has its own select'.
   (Array new:10) select:[:e | ].       'not caught - SeqColl has its own select'.
   Set new select:[:e | ].              'caught - Set inherits this from Collection'.
   MessageTracer unwrapMethod:(Collection compiledMethodAt:#select:).
(by method & instance class):
   MessageTracer trapMethod:(SequenceableCollection compiledMethodAt:#select:)
                 forInstancesOf:SortedCollection.
   Dictionary new select:[:e | ].       'not caught - Dictionary has its own select'.
   (Array new:10) select:[:e | ].       'not caught - not a SortedCollection'.
   OrderedCollection new select:[:e | ]. 'not caught - not a SortedCollection'.
   SortedCollection new select:[:e | ].  'caught - Set inherits this from Collection'.
   MessageTracer unwrapMethod:(SequenceableCollection compiledMethodAt:#select:).
tracing specific methods: (by class/selector):
   MessageTracer traceClass:SequenceableCollection selector:#quickSortFrom:to:.
   #(6 1 9 66 2 17) copy sort.
   MessageTracer untraceClass:SequenceableCollection
(by method):
   MessageTracer traceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:).
   #(6 1 9 66 2 17) copy sort.
   MessageTracer unwrapMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:).
object trapping:
   |o|

   o := OrderedCollection new.
   MessageTracer trapAll:o.
   o collect:[:el | el].
trapping modifications to an objects instVars:
   |o|

   o := Point new.
   MessageTracer trapModificationsIn:o.
   o x:1.
   o y:2.
   o x:1.
   o y:2.
   MessageTracer untrap:o
trapping modifications of a particular instVar:
   |o|

   o := Point new.
   MessageTracer trapModificationsIn:o filter:[:old :new | old x ~~ new x].
   o x:1.
   o y:2.
   o x:1.
   o y:2.
   MessageTracer untrap:o
tracing during block execution:
   MessageTracer trace:[ 10 factorialR ]


ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Wed, 19 Sep 2018 03:54:14 GMT