class: MethodWithBreakpoints
authorClaus Gittinger <cg@exept.de>
Mon, 23 Jun 2014 10:58:44 +0200
changeset 16603 f416f263fe99
parent 16602 e828b35ec6df
child 16604 ebf5e5a3a581
class: MethodWithBreakpoints class definition added:6 methods changed: #restoreOriginalMethod category of:
MethodWithBreakpoints.st
--- a/MethodWithBreakpoints.st	Mon Jun 23 09:13:58 2014 +0200
+++ b/MethodWithBreakpoints.st	Mon Jun 23 10:58:44 2014 +0200
@@ -13,7 +13,7 @@
 
 Method variableSubclass:#MethodWithBreakpoints
 	instanceVariableNames:'originalMethod'
-	classVariableNames:''
+	classVariableNames:'BreakpointedMethods'
 	poolDictionaries:''
 	category:'Kernel-Methods'
 !
@@ -50,6 +50,50 @@
 "
 ! !
 
+!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
@@ -74,6 +118,12 @@
 
 !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)"
@@ -83,6 +133,9 @@
     (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:[
@@ -95,7 +148,8 @@
                 original setPackage: self package.
                 original setCategory: self category  .
             ].
-            cls basicAddSelector:selector withMethod:original.    
+            cls basicAddSelector:selector withMethod:original.
+            BreakpointedMethods remove:self ifAbsent:[].
         ]
     ]
 
@@ -114,10 +168,12 @@
 !MethodWithBreakpoints class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/MethodWithBreakpoints.st,v 1.6 2014-05-10 10:04:16 vrany Exp $'
+    ^ '$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.6 2014-05-10 10:04:16 vrany Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/MethodWithBreakpoints.st,v 1.7 2014-06-23 08:58:44 cg Exp $'
 ! !
 
+
+MethodWithBreakpoints initialize!