MethodWithBreakpoints.st
author Jan Vrany <jan.vrany@labware.com>
Wed, 22 Mar 2023 13:57:18 +0000
branchjv
changeset 25445 1623217d2268
parent 20579 9add81aadb7a
permissions -rw-r--r--
Cherry-picked OrderedCollection.st from 0b286fd51da7: * d4c86d7c0bfc: #TUNING by stefan, Stefan Vogel <sv@exept.de> * 692b6497a669: #DOCUMENTATION by stefan, Stefan Vogel <sv@exept.de> * d47bb2912953: #DOCUMENTATION by stefan, Stefan Vogel <sv@exept.de> * abb4316c6bff: #FEATURE by cg, Claus Gittinger <cg@exept.de> * 3a8fce0e8d11: #TUNING by stefan, Stefan Vogel <sv@exept.de> * 03d29bf8c5bb: #REFACTORING by stefan, Stefan Vogel <sv@exept.de> * cccc6c4abcfc: #REFACTORING by stefan, Stefan Vogel <sv@exept.de> * 35d957c7a840: #FEATURE by cg, Claus Gittinger <cg@exept.de> * 6b11890f5f2c: #OTHER by cg, Claus Gittinger <cg@exept.de> * abb6108fb06b: #FEATURE by cg, Claus Gittinger <cg@exept.de> * 2c4768bb2e89: #FEATURE by cg, Claus Gittinger <cg@exept.de> * 4029e964d0f1: #FEATURE by cg, Claus Gittinger <cg@exept.de> * ddcab3a9c2df: #OTHER by cg, Claus Gittinger <cg@exept.de> * 2213eb56e0c7: #REFACTORING by exept, Claus Gittinger <cg@exept.de> * 09ca874a6160: #REFACTORING by exept, Claus Gittinger <cg@exept.de> * 30b332af1f33: #BUGFIX by stefan, Stefan Vogel <sv@exept.de> * 779764ba117b: #REFACTORING by cg, Claus Gittinger <cg@exept.de> * b3d232a613c9: #BUGFIX by stefan, Stefan Vogel <sv@exept.de> * c417f7edaec1: #BUGFIX by stefan, Stefan Vogel <sv@exept.de> * 904b6538f379: #FEATURE by exept, Claus Gittinger <cg@exept.de> * c5887f03e01f: #REFACTORING by stefan, Stefan Vogel <sv@exept.de> * 8912d03aff48: #BUGFIX by exept, Claus Gittinger <cg@exept.de> * de5cd1dab4c3: #DOCUMENTATION by exept, Claus Gittinger <cg@exept.de> * 9bbd26603378: #OTHER by exept, Claus Gittinger <cg@exept.de> * c2c9dc110f42: #FEATURE by stefan, Stefan Vogel <sv@exept.de> * 81d123c6703d: #DOCUMENTATION by stefan, Stefan Vogel <sv@exept.de> * 8aadbb21458a: #BUGFIX by stefan, Stefan Vogel <sv@exept.de> * f210dbb8b2f6: #TUNING by stefan, Stefan Vogel <sv@exept.de> * c2c774fc53c0: #FEATURE by exept, Claus Gittinger <cg@exept.de> * b6f462670875: #DOCUMENTATION by exept, Claus Gittinger <cg@exept.de> * 27ae4021d5d6: #FEATURE by stefan, Stefan Vogel <sv@exept.de> * 10d9e9d85594: #TUNING by exept, Claus Gittinger <cg@exept.de> * 2653d855dcc7: #DOCUMENTATION by exept, Claus Gittinger <cg@exept.de> * 6ea1698a1a34: #FEATURE by stefan, Stefan Vogel <sv@exept.de> * 28762315e664: #OTHER by exept, Claus Gittinger <cg@exept.de> * 7142ea786f3e: #TUNING by stefan, Stefan Vogel <sv@exept.de> * 7875acb42b53: #BUGFIX by stefan, Stefan Vogel <sv@exept.de> * 163a0eebc97e: #BUGFIX by Maren, matilk

"
 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' }"

"{ NameSpace: Smalltalk }"

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
    |invalidBreakpoints|

    BreakpointedMethods isNil ifTrue:[^ #() ].
    invalidBreakpoints := BreakpointedMethods select:[:m | m mclass isNil].
    invalidBreakpoints do:[:each | BreakpointedMethods remove:each ifAbsent:nil].
    ^ BreakpointedMethods asOrderedCollection
! !

!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].
!

disableBreakpointInLine:lineNr
    "disable one of my breakpoints"

    self breakpointsDo:[:bp | 
        bp line == lineNr ifTrue:[
            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'!

hasEnabledBreakpoints
    "true if any of my breakpoints is actually enabled"

    self breakpointsDo:[:any | 
        any isEnabled ifTrue:[
            any isTracepoint ifFalse:[ ^ true].
        ].    
    ].
    ^ false.
!

hasEnabledTracepoints
    "true if any of my tracepoints is actually enabled"

    self breakpointsDo:[:any | 
        any isEnabled ifTrue:[
            any isTracepoint ifTrue:[
                ^ true
            ].
        ].
    ].
    ^ false.
!

isMethodWithBreakpoints
    ^ true

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

!MethodWithBreakpoints class methodsFor:'documentation'!

version
    ^ '$Header$'
!

version_CVS
    ^ '$Header$'
! !


MethodWithBreakpoints initialize!