MethodWithBreakpoints.st
author Claus Gittinger <cg@exept.de>
Thu, 10 Jul 2014 14:23:18 +0200
changeset 16738 bd9416219f7c
parent 16603 f416f263fe99
child 16790 3d7753eeb111
permissions -rw-r--r--
displayOn: cleanup

"
 COPYRIGHT (c) 2012 by Claus Gittinger
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
"{ Package: 'stx:libbasic' }"

Method variableSubclass:#MethodWithBreakpoints
	instanceVariableNames:'originalMethod'
	classVariableNames:'BreakpointedMethods'
	poolDictionaries:''
	category:'Kernel-Methods'
!

!MethodWithBreakpoints class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2012 by Claus Gittinger
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    support for line-Breakpoints

    instances of me are created when line-breakpoints are placed.
    The only function I serve is to provide the originalMethod information,
    and an easy way to check for having a breakpoint (is breakpointed).

    [author:]
        Claus Gittinger

    [see also:]
        Tools::BreakpointService
"
! !

!MethodWithBreakpoints class methodsFor:'instance creation'!

new
    |newMethod|

    newMethod := super new.
    BreakpointedMethods add:newMethod.
    ^ newMethod
!

new:numLiterals
    |newMethod|

    newMethod := super new:numLiterals.
    BreakpointedMethods add:newMethod.
    ^ newMethod
! !

!MethodWithBreakpoints class methodsFor:'class initialization'!

initialize
    BreakpointedMethods := WeakIdentitySet new.
! !

!MethodWithBreakpoints class methodsFor:'misc'!

removeAllBreakpoints
    "remove all statement breakpoints on any method in the whole system"

    MethodWithBreakpoints allBreakpointedMethods do:[:m | m restoreOriginalMethod]
! !

!MethodWithBreakpoints class methodsFor:'queries'!

allBreakpointedMethods
    BreakpointedMethods isNil ifTrue:[^ #() ].
    ^ BreakpointedMethods 
        select:[:m |
            "/ must double check - as this is a weak set, it gets cleaned up with a delay.
            m mclass notNil
        ]
        as:OrderedCollection
! !

!MethodWithBreakpoints methodsFor:'accessing'!

originalMethod
    ^ originalMethod
!

originalMethod:something
    originalMethod := something.
! !

!MethodWithBreakpoints methodsFor:'enumeration'!

breakpointsDo:aBlock
    self literalsDo:[:lit | 
        lit class == Breakpoint ifTrue:[
            aBlock value:lit 
        ]
    ].

    "Created: / 03-02-2014 / 10:34:45 / cg"
! !

!MethodWithBreakpoints methodsFor:'misc'!

disableAllBreakpoints
    "disable all of my breakpoints"

    self breakpointsDo:[:bp | bp disable].
!

restoreOriginalMethod
    "remove myself - i.e. replace by the original method 
     (i.e. the one without line breakpoints)"

    | cls selector original |

    (cls := self mclass) notNil ifTrue:[
        (selector := self selector) notNil ifTrue:[
            self breakPoint:#cg.
            "/ disable my breakpoints, in case it is currently active
            self disableAllBreakpoints.
            
            originalMethod notNil ifTrue:[ 
                original := originalMethod
            ] ifFalse:[
                original := self programmingLanguage compilerClass
                                        compile: self source 
                                        in: self mclass 
                                        notifying:nil 
                                        install:false 
                                        ifFail:[ self error:'Failed to recompile method' ].
                original setPackage: self package.
                original setCategory: self category  .
            ].
            cls basicAddSelector:selector withMethod:original.
            BreakpointedMethods remove:self ifAbsent:[].
        ]
    ]

    "Modified: / 29-08-2013 / 01:17:05 / cg"
    "Modified: / 10-05-2014 / 11:03:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!MethodWithBreakpoints methodsFor:'queries'!

isMethodWithBreakpoints
    ^ true

    "Created: / 01-08-2012 / 17:26:59 / cg"
! !

!MethodWithBreakpoints class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libbasic/MethodWithBreakpoints.st,v 1.7 2014-06-23 08:58:44 cg Exp $'
!

version_CVS
    ^ '$Header: /cvs/stx/stx/libbasic/MethodWithBreakpoints.st,v 1.7 2014-06-23 08:58:44 cg Exp $'
! !


MethodWithBreakpoints initialize!