From 0c578979b77b3fa87e6527587041416029888cce Mon Sep 17 00:00:00 2001
From: Robert Sesek <rsesek@bluestatic.org>
Date: Sat, 4 Apr 2009 16:25:57 -0400
Subject: [PATCH] Fix the run command by having it obliterate the current stack
 and set a new one

* Source/GDBpConnection.h+m:
(run): Now returns an NSArray of the new stack frames
(createStackFrame): Sets the StackFrame's index to be the depth
* Source/DebuggerController.m:
(run:): Set the new stack and refresh the source viewer
---
 CHANGES                     |  1 +
 Source/DebuggerController.m |  9 +++++----
 Source/GDBpConnection.h     |  2 +-
 Source/GDBpConnection.m     | 21 +++++++++++++++++----
 4 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/CHANGES b/CHANGES
index 300ff90..065e88e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -10,6 +10,7 @@ MacGDBp                                                               CHANGE LOG
 retained
 - Fix: #160  The code pane could be unpopulated after the debugging the same
 script a subsequent time
+- Fix: After using the run command, the stack will now be properly updated
 
 
 1.2.1
diff --git a/Source/DebuggerController.m b/Source/DebuggerController.m
index e79837e..ae4d434 100644
--- a/Source/DebuggerController.m
+++ b/Source/DebuggerController.m
@@ -148,13 +148,14 @@
  */
 - (IBAction)run:(id)sender
 {
-	StackFrame *frame = [connection run];
-	[stackController pop];
+	NSArray *frames = [connection run];
 	
-	if ([connection isConnected] && frame != nil)
+	if ([connection isConnected] && frames != nil)
 	{
-		[stackController push:frame];
+		[stackController.stack removeAllObjects];
+		[stackController.stack addObjectsFromArray:frames];
 		[self updateStackViewer];
+		[self updateSourceViewer];
 	}
 }
 
diff --git a/Source/GDBpConnection.h b/Source/GDBpConnection.h
index 8684e9e..f334900 100644
--- a/Source/GDBpConnection.h
+++ b/Source/GDBpConnection.h
@@ -49,7 +49,7 @@ extern NSString *kErrorOccurredNotif;
 
 // communication
 - (void)reconnect;
-- (StackFrame *)run;
+- (NSArray *)run;
 - (StackFrame *)stepIn;
 - (StackFrame *)stepOut;
 - (StackFrame *)stepOver;
diff --git a/Source/GDBpConnection.m b/Source/GDBpConnection.m
index 4729504..3a8425a 100644
--- a/Source/GDBpConnection.m
+++ b/Source/GDBpConnection.m
@@ -150,9 +150,9 @@ NSString *kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification";
 }
 
 /**
- * Tells the debugger to continue running the script
+ * Tells the debugger to continue running the script. Returns an NSArray of the new stack
  */
-- (StackFrame *)run
+- (NSArray *)run
 {
 	[socket send:[self createCommand:@"run"]];
 	[socket receive];
@@ -162,7 +162,20 @@ NSString *kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification";
 	if (!connected)
 		return nil;
 	
-	return [self createCurrentStackFrame];
+	// get the total stack depth
+	[socket send:[self createCommand:@"stack_depth"]];
+	NSXMLDocument *doc = [self processData:[socket receive]];
+	int depth = [[[[doc rootElement] attributeForName:@"depth"] stringValue] intValue];
+	
+	// get all stack frames
+	NSMutableArray *stack = [NSMutableArray arrayWithCapacity:depth];
+	for (int i = 0; i < depth; i++)
+	{
+		StackFrame *frame = [self createStackFrame:i];
+		[stack insertObject:frame atIndex:i];
+	}
+	
+	return stack;
 }
 
 /**
@@ -353,7 +366,7 @@ NSString *kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification";
 	
 	// create stack frame
 	StackFrame *frame = [[StackFrame alloc]
-		initWithIndex:0
+		initWithIndex:stackDepth
 		withFilename:filename
 		withSource:source
 		atLine:[[[xmlframe attributeForName:@"lineno"] stringValue] intValue]
-- 
2.43.5