Start using our new StackFrame and StackController classes as struts
authorRobert Sesek <rsesek@bluestatic.org>
Mon, 1 Dec 2008 01:19:28 +0000 (20:19 -0500)
committerRobert Sesek <rsesek@bluestatic.org>
Mon, 1 Dec 2008 01:25:35 +0000 (20:25 -0500)
* Source/DebuggerController.h: Add the stackController ivar
* Source/DebuggerController.m:
(init): Initialize the stackController
(dealloc): Release stackController
(stepIn:): Pop and push the stackController appropriately
(stepOut:): ditto
(stepOver:): ditto
* Source/GDBpConnection.h: -[stepIn] -[stepOut] and -[stepOver] now all return StackFrame objects
* Source/GDBpConnection.m:
(stepIn): Generate and return the frame
(stepOut): ditto
(stepOver): ditto
(createStackFrame): New private method
* Source/StackController.m+h:
(peek): New method
* Source/StackFrame.m+h:
(isShiftedFrame:): New method
(description): Implemented

Source/DebuggerController.h
Source/DebuggerController.m
Source/GDBpConnection.h
Source/GDBpConnection.m
Source/StackController.h
Source/StackController.m
Source/StackFrame.h
Source/StackFrame.m

index ee98d02a7a1fd446ff3ba303614ed93388e95e11..bebcda17264590e21f3e0b8e3a1cbf69e8ec24ec 100644 (file)
@@ -16,6 +16,7 @@
 
 #import <Cocoa/Cocoa.h>
 #import "BSSourceView.h"
+#import "StackController.h"
 
 @class GDBpConnection;
 
@@ -23,6 +24,8 @@
 {
        GDBpConnection *connection;
        
+       StackController *stackController;
+       
        IBOutlet NSArrayController *stackController2;
        NSArray *stack;
        
index e0669bba488913708a6dafcd7c3c18f7945deed8..f1e1569a34bb1b70b88adb941d8d95c6623aa395 100644 (file)
@@ -36,6 +36,8 @@
 {
        if (self = [super initWithWindowNibName:@"Debugger"])
        {
+               stackController = [[StackController alloc] init];
+               
                NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
                connection = [[GDBpConnection alloc] initWithWindowController:self
                                                                                                                                         port:[defaults integerForKey:@"Port"]
@@ -54,6 +56,7 @@
 {
        [connection release];
        [expandedRegisters release];
+       [stackController release];
        [super dealloc];
 }
 
  */
 - (IBAction)stepIn:(id)sender
 {
-       [connection stepIn];
+       StackFrame *frame = [connection stepIn];
+       if ([frame isShiftedFrame:[stackController peek]])
+               [stackController pop];
+       [stackController push:frame];
+       NSLog(@"stack = %@", stackController.stack);
 }
 
 /**
  */
 - (IBAction)stepOut:(id)sender
 {
-       [connection stepOut];
+       StackFrame *frame = [connection stepOut];
+       [stackController pop];
+       [stackController push:frame];
+       NSLog(@"stack = %@", stackController.stack);
 }
 
 /**
  */
 - (IBAction)stepOver:(id)sender
 {
-       [connection stepOver];
+       StackFrame *frame = [connection stepOver];
+       
+       [stackController pop];
+       [stackController push:frame];
+       
+       NSLog(@"stack = %@", stackController.stack);
 }
 
 /**
index eb7f747b5c40b8c0c6ebb62ebb0d87c7051279de..36e4c011bce337fb2e0135e95fbc0439221ec55a 100644 (file)
@@ -18,6 +18,7 @@
 #import "DebuggerController.h"
 #import "SocketWrapper.h"
 #import "Breakpoint.h"
+#import "StackFrame.h"
 
 @interface GDBpConnection : NSObject
 {
@@ -45,9 +46,9 @@
 // communication
 - (void)reconnect;
 - (void)run;
-- (void)stepIn;
-- (void)stepOut;
-- (void)stepOver;
+- (StackFrame *)stepIn;
+- (StackFrame *)stepOut;
+- (StackFrame *)stepOver;
 - (void)addBreakpoint:(Breakpoint *)bp;
 - (void)removeBreakpoint:(Breakpoint *)bp;
 - (void)refreshStatus;
index 10fa28af0d5e7be1fb5d0984ce05c107da342d0f..2219bb11325ace9ad5eb155ebb9803e6f9163228 100644 (file)
@@ -20,6 +20,7 @@
 @interface GDBpConnection (Private)
 - (NSString *)createCommand:(NSString *)cmd;
 - (NSXMLDocument *)processData:(NSString *)data;
+- (StackFrame *)createStackFrame;
 @end
 
 @implementation GDBpConnection
 /**
  * Tells the debugger to step into the current command.
  */
-- (void)stepIn
+- (StackFrame *)stepIn
 {
        [socket send:[self createCommand:@"step_into"]];
        [socket receive];
+       
+       StackFrame *frame = [self createStackFrame];
        [self refreshStatus];
+       
+       return frame;
 }
 
 /**
  * Tells the debugger to step out of the current context
  */
-- (void)stepOut
+- (StackFrame *)stepOut
 {
        [socket send:[self createCommand:@"step_out"]];
        [socket receive];
+       
+       StackFrame *frame = [self createStackFrame];
        [self refreshStatus];
+       
+       return frame;
 }
 
 /**
  * Tells the debugger to step over the current function
  */
-- (void)stepOver
+- (StackFrame *)stepOver
 {
        [socket send:[self createCommand:@"step_over"]];
        [socket receive];
+       
+       StackFrame *frame = [self createStackFrame];
        [self refreshStatus];
+       
+       return frame;
 }
 
 /**
        return [doc autorelease];
 }
 
+/**
+ * Creates a StackFrame based on the current position in the debugger
+ */
+- (StackFrame *)createStackFrame
+{
+       [socket send:[self createCommand:@"stack_get -d 0"]];
+       NSXMLDocument *doc = [self processData:[socket receive]];
+       
+       NSXMLElement *xmlframe = [[[doc rootElement] children] objectAtIndex:0];
+       StackFrame *frame = [[StackFrame alloc]
+               initWithIndex:[[[xmlframe attributeForName:@"level"] stringValue] intValue]
+               withFilename:[[xmlframe attributeForName:@"filename"] stringValue]
+               withSource:nil
+               atLine:[[[xmlframe attributeForName:@"lineno"] stringValue] intValue]
+               inFunction:[[xmlframe attributeForName:@"where"] stringValue]
+               withContexts:nil
+       ];
+       
+       return [frame autorelease];
+}
+
 @end
index fe58dda6ee08dc332f2b0df17f5b3c0ebf1b4367..c77883faed0f43155eed6b73744e900c2d214f8d 100644 (file)
@@ -27,6 +27,7 @@
 
 @property(readonly) NSMutableArray *stack;
 
+- (StackFrame *)peek;
 - (StackFrame *)pop;
 - (void)push:(StackFrame *)frame;
 
index 2caea7da30cb2f49dd25c2a9742fbcd388082c53..0109c41faf6c8958a30d55eacf93f87b66d6381e 100644 (file)
        [super dealloc];
 }
 
+/**
+ * Returns a reference to the top of the stack
+ */
+- (StackFrame *)peek
+{
+       return [stack lastObject];
+}
+
 /**
  * Pops the current frame off the stack and returns the frame
  */
index d327e6c4ebc6f97ae6a307111a7f4f959af760f7..1d080d94a3bc69180be8cbf6f4a59dd3bd4871f3 100644 (file)
@@ -64,4 +64,6 @@
                 inFunction:(NSString *)function
           withContexts:(NSDictionary *)contexts;
 
+- (BOOL)isShiftedFrame:(StackFrame *)frame;
+
 @end
index f5cd05a00800fbd99510923f4a4fbf8ebda00a15..140387ca5695c067f2baf55a346092ccdf429ba8 100644 (file)
        return self;
 }
 
+/**
+ * Determines whether or not the given frame was shifted, rather than jumped. Essentially,
+ * this checks if it's in the same file/function.
+ */
+- (BOOL)isShiftedFrame:(StackFrame *)frame
+{
+       return ([filename isEqualToString:frame.filename]);
+}
+
+/**
+ * Returns a human-readable representation
+ */
+- (NSString *)description
+{
+       return [NSString stringWithFormat:@"#%d %@ [%@:%d]", index, function, filename, lineNumber];
+}
+
 @end