Hi,

Here is a patch that add #restart to the debugger
(restart the simulation of the method) and add
method changes in GtkDebugger

Cheers,
Gwen

>From b54f6a531841b6eae43d956d6cb3cec6337312e7 Mon Sep 17 00:00:00 2001
From: Gwenael Casaccio <mrg...@gmail.com>
Date: Mon, 21 Oct 2013 11:23:16 +0200
Subject: [PATCH] Add >>#restart to the debugger and add support for
 GtkDebugger too

---
 packages/debug/ChangeLog                   |  5 +++
 packages/debug/DebugTools.st               | 35 ++++++++++++++++++
 packages/debug/debugtests.st               | 57 ++++++++++++++++++++++++++++++
 packages/visualgst/ChangeLog               |  4 +++
 packages/visualgst/Debugger/GtkDebugger.st | 13 +++++++
 5 files changed, 114 insertions(+)

diff --git a/packages/debug/ChangeLog b/packages/debug/ChangeLog
index 55bd1a1..c118c0c 100644
--- a/packages/debug/ChangeLog
+++ b/packages/debug/ChangeLog
@@ -1,4 +1,9 @@
 2013-10-21  Gwenael Casaccio  <gwenael.casac...@gmail.com>
+ 
+	* debugtests.st: Add test for >>#restart.
+	* DebugTools.st: Restart a execution of a context (useful it the method is updated).
+
+2013-10-21  Gwenael Casaccio  <gwenael.casac...@gmail.com>
 
 	* DebugTools.st: Add >>#eval: allowing evaluation of code with the current context temps and args names.
 	* maybe/Maybe.st: Maybe monad pattern.
diff --git a/packages/debug/DebugTools.st b/packages/debug/DebugTools.st
index 1801c5c..c79c744 100644
--- a/packages/debug/DebugTools.st
+++ b/packages/debug/DebugTools.st
@@ -132,6 +132,41 @@ pointer bytecodes to line numbers.'>
 	exception isNil ifFalse: [exception signal]
     ]
 
+    restart [
+        <category: 'stepping commands'>
+
+        self restart: self suspendedContext.
+    ]
+
+    restart: aContext [
+        <category: 'stepping commands'>
+
+        | context method newContext |
+
+        context := self suspendedContext.
+
+        [ context = aContext ] whileFalse: [ context := context parentContext ].
+
+        context isBlock ifTrue: [ context outerContext isNil ifTrue: [ ^ self ].
+                                  context := context outerContext ].
+
+        method := context receiver class >> context method selector.
+
+        newContext := MethodContext new: method stackDepth.
+
+        newContext parentContext: context parentContext.
+        newContext ip: 0.
+        newContext instVarAt: 4 put: -1 + method numArgs + method numTemps. " stack pointer "
+        newContext instVarAt: 5 put: context receiver.                      " receiver "
+        newContext instVarAt: 6 put: method.                                " method "
+        newContext instVarAt: 7 put: (context instVarAt: 7).                " flags "
+
+        1 to: method numArgs do: [ :i |
+            newContext at: i put: (context at: i) ].
+
+        process suspendedContext: newContext
+    ]
+
     stepBytecode [
 	"Run a single bytecode in the inferior process."
 
diff --git a/packages/debug/debugtests.st b/packages/debug/debugtests.st
index 4ba1ada..c32f602 100644
--- a/packages/debug/debugtests.st
+++ b/packages/debug/debugtests.st
@@ -336,6 +336,51 @@ TestCase subclass: DebuggerTest [
         self assert: (debugger eval: '^ z') = 4.
     ]
 
+    testRestart [
+        " Test that #restart "
+
+        <category: 'test'>
+
+        | debugger i j |
+
+        debugger := self debuggerOn: [ 
+                            i := self restart ].
+        debugger step.
+        self assert: debugger suspendedContext method == (self class >> #restart).
+
+        self class compile: 'restart [ | i | i := 234. ^ i * 2 ]'.
+
+        debugger restart.
+        self assert: debugger suspendedContext method == (self class >> #restart).
+        self assert: debugger suspendedContext receiver == self.
+        self assert: debugger suspendedContext ip == 0.
+        self assert: debugger suspendedContext sp == 0.
+
+        debugger next; next.
+
+        self assert: i = 468.
+
+        j := OrderedCollection new.
+        j add: 123.
+        debugger := self debuggerOn: [
+                            i := self restart_1: j ].
+        debugger step; step.
+        self assert: debugger suspendedContext method == (self class >> #restart_1:).
+
+        self class compile: 'restart_1: anObject [ ^ anObject first ]'.
+
+        j addFirst: 234.
+        debugger restart.
+        self assert: debugger suspendedContext method == (self class >> #restart_1:).
+        self assert: debugger suspendedContext receiver == self.
+        self assert: debugger suspendedContext ip == 0.
+        self assert: debugger suspendedContext sp == 0.
+
+        debugger next; next.
+
+        self assert: i = 234.
+    ]
+
     w [
 	<category: 'support'>
 	self x: [:foo | ^foo]
@@ -355,5 +400,17 @@ TestCase subclass: DebuggerTest [
 	<category: 'support'>
 	^anObject
     ]
+
+    restart [
+        <category: 'support'>
+
+        ^ 123 * 2
+    ]
+
+    restart_1: anObject [
+        <category: 'support'>
+
+        ^ anObject first * 2
+    ]
 ]
 
diff --git a/packages/visualgst/ChangeLog b/packages/visualgst/ChangeLog
index 3b43a5f..addf608 100644
--- a/packages/visualgst/ChangeLog
+++ b/packages/visualgst/ChangeLog
@@ -1,5 +1,9 @@
 2013-10-21  Gwenael Casaccio  <gwenael.casac...@gmail.com>
 
+	* Debugger/GtkDebugger.st: Code can be changed in the debugger.
+
+2013-10-21  Gwenael Casaccio  <gwenael.casac...@gmail.com>
+
 	* Debugger/GtkDebugger.st: Eval code in the debugger.
 
 2013-10-18  Gwenael Casaccio  <gwenael.casac...@gmail.com>
diff --git a/packages/visualgst/Debugger/GtkDebugger.st b/packages/visualgst/Debugger/GtkDebugger.st
index f0fb969..e629a29 100644
--- a/packages/visualgst/Debugger/GtkDebugger.st
+++ b/packages/visualgst/Debugger/GtkDebugger.st
@@ -498,5 +498,18 @@ GtkBrowsingTool subclass: GtkDebugger [
         self onFocusPerform: #showReplace
     ]
 
+    selectAnInstanceMethod: aMethod [
+        <category: 'debugging events'>
+
+        debugger restart: contextWidget selectedContext.
+	self updateContextWidget
+    ]
+
+    selectAClassMethod: aMethod [
+        <category: 'debugging events'>
+
+        debugger restart: contextWidget selectedContext.
+	self updateContextWidget
+    ]
 ]
 
-- 
1.8.3.2

_______________________________________________
help-smalltalk mailing list
help-smalltalk@gnu.org
https://lists.gnu.org/mailman/listinfo/help-smalltalk

Reply via email to