From 3fee2c8d1fdbfaaaea5eb5ed2bdffedc3d65a1d7 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 10 Feb 2009 12:40:47 -0500 Subject: [PATCH] Convert the run command to use the StackFrame system * Source/GDBpConnection.m+h: (run): Now returns a StackFrame object (processData:): Return nil if the given data is nil (createStackFrame): If we get an empty NSXMLDocument for the stack, return nil (updateStatus): If the status is nil, the debugger is stopped * Source/DebuggerController.m: (run): Use the stack frame * Source/SocketWrapper.m: (receive): If the call to recv() returns -1 (error), return nil string --- Source/DebuggerController.m | 9 ++++++++- Source/GDBpConnection.h | 2 +- Source/GDBpConnection.m | 16 ++++++++++++++-- Source/SocketWrapper.m | 3 +++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Source/DebuggerController.m b/Source/DebuggerController.m index 2b46df8..3af8421 100644 --- a/Source/DebuggerController.m +++ b/Source/DebuggerController.m @@ -143,7 +143,14 @@ */ - (IBAction)run:(id)sender { - [connection run]; + StackFrame *frame = [connection run]; + [stackController pop]; + + if ([connection isConnected] && frame != nil) + { + [stackController push:frame]; + [self updateStackViewer]; + } } /** diff --git a/Source/GDBpConnection.h b/Source/GDBpConnection.h index 7b93083..8684e9e 100644 --- a/Source/GDBpConnection.h +++ b/Source/GDBpConnection.h @@ -49,7 +49,7 @@ extern NSString *kErrorOccurredNotif; // communication - (void)reconnect; -- (void)run; +- (StackFrame *)run; - (StackFrame *)stepIn; - (StackFrame *)stepOut; - (StackFrame *)stepOver; diff --git a/Source/GDBpConnection.m b/Source/GDBpConnection.m index 2f9662e..c3805c6 100644 --- a/Source/GDBpConnection.m +++ b/Source/GDBpConnection.m @@ -151,11 +151,17 @@ NSString *kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification"; /** * Tells the debugger to continue running the script */ -- (void)run +- (StackFrame *)run { [socket send:[self createCommand:@"run"]]; [socket receive]; + [self updateStatus]; + + if (!connected) + return nil; + + return [self createStackFrame]; } /** @@ -272,6 +278,9 @@ NSString *kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification"; */ - (NSXMLDocument *)processData:(NSString *)data { + if (data == nil) + return nil; + NSError *parseError = nil; NSXMLDocument *doc = [[NSXMLDocument alloc] initWithXMLString:data options:0 error:&parseError]; if (parseError) @@ -301,6 +310,9 @@ NSString *kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification"; // get the stack frame [socket send:[self createCommand:@"stack_get -d 0"]]; NSXMLDocument *doc = [self processData:[socket receive]]; + if (doc == nil) + return nil; + NSXMLElement *xmlframe = [[[doc rootElement] children] objectAtIndex:0]; // get the names of all the contexts @@ -346,7 +358,7 @@ NSString *kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification"; NSXMLDocument *doc = [self processData:[socket receive]]; self.status = [[[[doc rootElement] attributeForName:@"status"] stringValue] capitalizedString]; - if ([status isEqualToString:@"Stopped"] || [status isEqualToString:@"Stopping"]) + if (status == nil || [status isEqualToString:@"Stopped"] || [status isEqualToString:@"Stopping"]) { connected = NO; [socket close]; diff --git a/Source/SocketWrapper.m b/Source/SocketWrapper.m index 3f2321d..b37f99d 100644 --- a/Source/SocketWrapper.m +++ b/Source/SocketWrapper.m @@ -175,6 +175,9 @@ // take the received data and put it into an NSData NSMutableString *str = [NSMutableString string]; + if (recvd == -1) + return nil; + // strip the length from the packet, and clear the null byte then add it to the NSData char packetLength[8]; memset(packetLength, '\0', sizeof(packetLength)); -- 2.43.5