From 57e7d89d0afad678d98c8e9c6609128719209735 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 16 May 2009 15:02:15 -0400 Subject: [PATCH] Factored out the stack reloading code * Source/DebuggerController.m: (reloadStack): New private method to fetch and insert new stack (run): Use reloadStack * Source/GDBpConnection.m+h: (getCurrentStack): New method to get the stack and create all the stack frames (run): Return only the current stack frame instead of a whole stack --- Source/DebuggerController.m | 29 ++++++++++++++++++++--------- Source/GDBpConnection.h | 1 + Source/GDBpConnection.m | 34 +++++++++++++++++++++------------- 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/Source/DebuggerController.m b/Source/DebuggerController.m index ae4d434..93b41ee 100644 --- a/Source/DebuggerController.m +++ b/Source/DebuggerController.m @@ -24,6 +24,7 @@ - (void)updateSourceViewer; - (void)updateStackViewer; - (void)expandVariables; +- (void)reloadStack; @end @implementation DebuggerController @@ -148,15 +149,9 @@ */ - (IBAction)run:(id)sender { - NSArray *frames = [connection run]; - - if ([connection isConnected] && frames != nil) - { - [stackController.stack removeAllObjects]; - [stackController.stack addObjectsFromArray:frames]; - [self updateStackViewer]; - [self updateSourceViewer]; - } + [connection run]; + if ([connection isConnected]) + [self reloadStack]; } /** @@ -305,6 +300,22 @@ } } +/** + * This updates the entire stack. Xdebug is queried to get the stack, non-shifted + * frames are reused and new ones are fetched. + */ +- (void)reloadStack +{ + NSArray* stack = [connection getCurrentStack]; + if (stack == nil) + return; + + [stackController.stack removeAllObjects]; + [stackController.stack addObjectsFromArray:stack]; + [self updateStackViewer]; + [self updateSourceViewer]; +} + #pragma mark BSSourceView Delegate /** diff --git a/Source/GDBpConnection.h b/Source/GDBpConnection.h index f334900..51cf295 100644 --- a/Source/GDBpConnection.h +++ b/Source/GDBpConnection.h @@ -46,6 +46,7 @@ extern NSString *kErrorOccurredNotif; - (NSString *)session; - (NSString *)remoteHost; - (BOOL)isConnected; +- (NSArray*)getCurrentStack; // communication - (void)reconnect; diff --git a/Source/GDBpConnection.m b/Source/GDBpConnection.m index 3a8425a..e0a1869 100644 --- a/Source/GDBpConnection.m +++ b/Source/GDBpConnection.m @@ -150,34 +150,42 @@ NSString *kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification"; } /** - * Tells the debugger to continue running the script. Returns an NSArray of the new stack + * Creates an entirely new stack and returns it as an array of StackFrame objects. */ -- (NSArray *)run +- (NSArray*)getCurrentStack { - [socket send:[self createCommand:@"run"]]; - [socket receive]; - - [self updateStatus]; - - if (!connected) - return nil; - // get the total stack depth [socket send:[self createCommand:@"stack_depth"]]; - NSXMLDocument *doc = [self processData:[socket receive]]; + NSXMLDocument* doc = [self processData:[socket receive]]; int depth = [[[[doc rootElement] attributeForName:@"depth"] stringValue] intValue]; // get all stack frames - NSMutableArray *stack = [NSMutableArray arrayWithCapacity:depth]; + NSMutableArray* stack = [NSMutableArray arrayWithCapacity:depth]; for (int i = 0; i < depth; i++) { - StackFrame *frame = [self createStackFrame:i]; + StackFrame* frame = [self createStackFrame:i]; [stack insertObject:frame atIndex:i]; } return stack; } +/** + * Tells the debugger to continue running the script. Returns the current stack frame. + */ +- (StackFrame*)run +{ + [socket send:[self createCommand:@"run"]]; + [socket receive]; + + [self updateStatus]; + + if (!connected) + return nil; + + return [self createCurrentStackFrame]; +} + /** * Tells the debugger to step into the current command. */ -- 2.22.5