Receive contexts and then request their variables; finish rewriting |-createStackFrame:|.
authorRobert Sesek <rsesek@bluestatic.org>
Sun, 21 Feb 2010 02:25:52 +0000 (21:25 -0500)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 21 Feb 2010 02:25:52 +0000 (21:25 -0500)
Source/DebuggerController.m
Source/GDBpConnection.m
Source/StackFrame.h

index f0784ebc34d6dd9f9a38137f9325ac4e04877764..8bfa2c41484d4f647d84dc4d4c98c7f08bd38705 100644 (file)
@@ -80,7 +80,7 @@
  */
 - (void)windowWillClose:(NSNotification*)notif
 {
-       [[connection socket] close];
+       [connection close];
 }
 
 /**
 }
 
 /**
- * Delegate functioni for GDBpConnection for when the debugger connects.
+ * Delegate function for GDBpConnection for when the debugger connects.
  */
 - (void)debuggerConnected
 {
 - (IBAction)run:(id)sender
 {
        [connection run];
-       if ([connection isConnected])
-               [self reloadStack];
 }
 
 /**
                selectedVariable = [[variablesTreeController selectedObjects] objectAtIndex:0];
        
        [connection stepIn];
-       if ([connection isConnected])
-               [self reloadStack];
 }
 
 /**
                selectedVariable = [[variablesTreeController selectedObjects] objectAtIndex:0];
        
        [connection stepOut];
-       if ([connection isConnected])
-               [self reloadStack];
 }
 
 /**
                selectedVariable = [[variablesTreeController selectedObjects] objectAtIndex:0];
        
        [connection stepOver];
-       if ([connection isConnected])
-               [self reloadStack];
 }
 
 /**
index 8a8f889c8dddb738ca40c9b54d2567de1efe2a4d..a065bc4c8fec3224bb534cb75c65204f7bb97d7e 100644 (file)
 - (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.
index 6c8acecae95ad74d1a63b8338f2275c057de8725..ac31ad0165111228d5b69c5d3370d116256bc97a 100644 (file)
@@ -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