From c5ab99fdee9c4ecf7eef9820cf5fabb0374261de Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 20 Feb 2010 21:25:52 -0500 Subject: [PATCH] Receive contexts and then request their variables; finish rewriting |-createStackFrame:|. --- Source/DebuggerController.m | 12 +---- Source/GDBpConnection.m | 91 ++++++++++++++++++++++++++----------- Source/StackFrame.h | 2 +- 3 files changed, 67 insertions(+), 38 deletions(-) diff --git a/Source/DebuggerController.m b/Source/DebuggerController.m index f0784eb..8bfa2c4 100644 --- a/Source/DebuggerController.m +++ b/Source/DebuggerController.m @@ -80,7 +80,7 @@ */ - (void)windowWillClose:(NSNotification*)notif { - [[connection socket] close]; + [connection close]; } /** @@ -141,7 +141,7 @@ } /** - * Delegate functioni for GDBpConnection for when the debugger connects. + * Delegate function for GDBpConnection for when the debugger connects. */ - (void)debuggerConnected { @@ -176,8 +176,6 @@ - (IBAction)run:(id)sender { [connection run]; - if ([connection isConnected]) - [self reloadStack]; } /** @@ -198,8 +196,6 @@ selectedVariable = [[variablesTreeController selectedObjects] objectAtIndex:0]; [connection stepIn]; - if ([connection isConnected]) - [self reloadStack]; } /** @@ -211,8 +207,6 @@ selectedVariable = [[variablesTreeController selectedObjects] objectAtIndex:0]; [connection stepOut]; - if ([connection isConnected]) - [self reloadStack]; } /** @@ -224,8 +218,6 @@ selectedVariable = [[variablesTreeController selectedObjects] objectAtIndex:0]; [connection stepOver]; - if ([connection isConnected]) - [self reloadStack]; } /** diff --git a/Source/GDBpConnection.m b/Source/GDBpConnection.m index 8a8f889..a065bc4 100644 --- a/Source/GDBpConnection.m +++ b/Source/GDBpConnection.m @@ -50,12 +50,12 @@ - (void)getStackFrame:(NSXMLDocument*)response; - (void)setSource:(NSXMLDocument*)response; - (void)contextsReceived:(NSXMLDocument*)response; +- (void)variablesReceived:(NSXMLDocument*)response; - (NSNumber*)sendCommandWithCallback:(SEL)callback format:(NSString*)format, ...; - (void)sendQueuedWrites; -- (StackFrame*)createStackFrame:(int)depth; - (NSString*)escapedURIPath:(NSString*)path; @end @@ -627,8 +627,12 @@ void SocketAcceptCallback(CFSocketRef socket, return; } - SEL callback = NSSelectorFromString([callTable_ objectForKey:[NSNumber numberWithInt:lastReadTransaction_]]); - [self performSelector:callback withObject:response]; + NSString* callbackStr = [callTable_ objectForKey:[NSNumber numberWithInt:lastReadTransaction_]]; + if (callbackStr) + { + SEL callback = NSSelectorFromString(callbackStr); + [self performSelector:callback withObject:response]; + } [self sendQueuedWrites]; } @@ -737,6 +741,10 @@ void SocketAcceptCallback(CFSocketRef socket, [callbackContext_ setObject:routingNumber forKey:transaction]; } +/** + * Callback for setting the source of a file while rebuilding a specific stack + * frame. + */ - (void)setSource:(NSXMLDocument*)response { NSNumber* transaction = [NSNumber numberWithInt:[[[[response rootElement] attributeForName:@"transaction_id"] stringValue] intValue]]; @@ -753,9 +761,61 @@ void SocketAcceptCallback(CFSocketRef socket, NSLog(@"frame.source = %@", frame.source); } +/** + * Enumerates all the contexts of a given stack frame. We then in turn get the + * contents of each one of these contexts. + */ - (void)contextsReceived:(NSXMLDocument*)response { - NSLog(@"got contexts = %@", response); + // Get the stack frame's routing ID and use it again. + NSNumber* receivedTransaction = + [NSNumber numberWithInt:[[[[response rootElement] attributeForName:@"transaction_id"] stringValue] intValue]]; + NSNumber* routingID = [callbackContext_ objectForKey:receivedTransaction]; + if (!routingID) + return; + + // Get the stack frame by the |routingID|. + StackFrame* frame = [stackFrames_ objectForKey:routingID]; + + NSXMLElement* contextNames = [response rootElement]; + for (NSXMLElement* context in [contextNames children]) + { + NSInteger cid = [[[context attributeForName:@"id"] stringValue] intValue]; + + // Fetch each context's variables. + NSNumber* transaction = [self sendCommandWithCallback:@selector(variablesReceived:) + format:@"context_get -d %d -c %d", frame.index, cid]; + [callbackContext_ setObject:routingID forKey:transaction]; + } +} + +/** + * Receives the variables from the context and attaches them to the stack frame. + */ +- (void)variablesReceived:(NSXMLDocument*)response +{ + // Get the stack frame's routing ID and use it again. + NSNumber* receivedTransaction = + [NSNumber numberWithInt:[[[[response rootElement] attributeForName:@"transaction_id"] stringValue] intValue]]; + NSNumber* routingID = [callbackContext_ objectForKey:receivedTransaction]; + if (!routingID) + return; + + // Get the stack frame by the |routingID|. + StackFrame* frame = [stackFrames_ objectForKey:routingID]; + + NSMutableArray* variables = [NSMutableArray array]; + + // Merge the frame's existing variables. + if (frame.variables) + [variables addObjectsFromArray:frame.variables]; + + // Add these new variables. + NSArray* addVariables = [[response rootElement] children]; + if (addVariables) + [variables addObjectsFromArray:addVariables]; + + frame.variables = variables; } #pragma mark Private @@ -807,29 +867,6 @@ void SocketAcceptCallback(CFSocketRef socket, [writeQueueLock_ unlock]; } -/** - * Generates a stack frame for the given depth - */ -- (StackFrame*)createStackFrame:(int)stackDepth -{ - // get the names of all the contexts - NSXMLElement* contextNames = [[self processData:[socket receive]] rootElement]; - NSMutableArray* variables = [NSMutableArray array]; - for (NSXMLElement* context in [contextNames children]) - { - NSString* name = [[context attributeForName:@"name"] stringValue]; - int cid = [[[context attributeForName:@"id"] stringValue] intValue]; - - // fetch the contexts - [socket send:[self createCommand:[NSString stringWithFormat:@"context_get -d %d -c %d", stackDepth, cid]]]; - NSArray* addVars = [[[self processData:[socket receive]] rootElement] children]; - if (addVars != nil && name != nil) - [variables addObjectsFromArray:addVars]; - } - - return nil; -} - /** * Given a file path, this returns a file:// URI and escapes any spaces for the * debugger engine. diff --git a/Source/StackFrame.h b/Source/StackFrame.h index 6c8acec..ac31ad0 100644 --- a/Source/StackFrame.h +++ b/Source/StackFrame.h @@ -60,7 +60,7 @@ @property (copy) NSString* source; @property (readwrite) int lineNumber; @property (readwrite, copy) NSString* function; -@property (copy) NSArray* variables; +@property (retain) NSArray* variables; - (id)initWithIndex:(int)anIndex withFilename:(NSString*)aFilename -- 2.22.5