From 6520845660763bd979fe06aaea535655284478e6 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 22 Jul 2009 00:34:20 -0400 Subject: [PATCH] * Add a preference to automatically reconnect. Fixes bug #165. * Create a GDBpConnectionDelegate formal protocol. * No longer use notifications to pass errors from GDBpConnection to DebuggerController. * Add delegate methods for |-debuggerConnected| and |-debuggerDisconnected|. * Move GDBpConnection's |-socketDidAccept| implementation into a helper so it can be run on the main thread. --- CHANGES | 5 +++ English.lproj/Preferences.xib | 84 ++++++++++++++++++++++++++++++++--- Source/AppDelegate.m | 13 +++--- Source/DebuggerController.h | 3 +- Source/DebuggerController.m | 31 ++++++++----- Source/GDBpConnection.h | 24 ++++++++-- Source/GDBpConnection.m | 55 ++++++++++++----------- 7 files changed, 162 insertions(+), 53 deletions(-) diff --git a/CHANGES b/CHANGES index 9f4a9c7..2c2b4db 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,11 @@ MacGDBp CHANGE LOG ================================================================================ +1.4 +##################### +- New: #165 Added a preference to automatically reconnect after debugging + + 1.3 ##################### - New: #155 Add a variable inspector to display the full, untruncated value diff --git a/English.lproj/Preferences.xib b/English.lproj/Preferences.xib index e2176f7..0b28fa1 100644 --- a/English.lproj/Preferences.xib +++ b/English.lproj/Preferences.xib @@ -200,6 +200,10 @@ Preferences + + YES + AutoReconnect + YES @@ -329,7 +333,7 @@ 268 - {{164, 125}, {216, 18}} + {{164, 147}, {216, 18}} YES @@ -340,11 +344,11 @@ 1211912703 130 - + NSImage NSSwitch - + NSSwitch @@ -356,7 +360,7 @@ 268 - {{15, 127}, {146, 17}} + {{15, 149}, {146, 17}} YES @@ -369,8 +373,30 @@ + + + 268 + {{164, 125}, {216, 18}} + + YES + + 67239424 + 0 + Automatic reconnect + + + 1211912703 + 130 + + + + + 200 + 25 + + - {421, 164} + {421, 186} NSView @@ -822,6 +848,22 @@ 95 + + + value: values.AutoReconnect + + + + + + value: values.AutoReconnect + value + values.AutoReconnect + 2 + + + 98 + @@ -904,6 +946,7 @@ YES + @@ -1132,6 +1175,20 @@ + + 96 + + + YES + + + + + + 97 + + + @@ -1190,6 +1247,9 @@ 92.IBPluginDependency 93.IBPluginDependency 94.IBPluginDependency + 96.IBAttributePlaceholdersKey + 96.IBPluginDependency + 97.IBPluginDependency YES @@ -1209,7 +1269,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{483, 354}, {421, 164}} + {{483, 332}, {421, 186}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1252,6 +1312,16 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Automatically start listening for connections immediately after disconnecting. If disabled, you must use the reconnect toolbar button or menu command before debugging again. + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin @@ -1274,7 +1344,7 @@ - 95 + 98 diff --git a/Source/AppDelegate.m b/Source/AppDelegate.m index 7082161..b861bb2 100644 --- a/Source/AppDelegate.m +++ b/Source/AppDelegate.m @@ -40,12 +40,13 @@ NSAutoreleasePool* pool = [NSAutoreleasePool new]; NSDictionary* dict = [[NSDictionary alloc] initWithObjectsAndKeys: - [NSNumber numberWithInt:9000], @"Port", - @"macgdbp", @"IDEKey", - [NSNumber numberWithBool:YES], @"BreakpointsWindowVisible", - [NSNumber numberWithBool:YES], @"InspectorWindowVisible", - [NSMutableArray array], @"PathReplacements", - [NSNumber numberWithBool:YES], @"BreakOnFirstLine", + [NSNumber numberWithInt:9000], @"Port", + @"macgdbp", @"IDEKey", + [NSNumber numberWithBool:YES], @"BreakpointsWindowVisible", + [NSNumber numberWithBool:YES], @"InspectorWindowVisible", + [NSMutableArray array], @"PathReplacements", + [NSNumber numberWithBool:YES], @"BreakOnFirstLine", + [NSNumber numberWithBool:NO], @"AutoReconnect", nil ]; diff --git a/Source/DebuggerController.h b/Source/DebuggerController.h index 7000392..22eed81 100644 --- a/Source/DebuggerController.h +++ b/Source/DebuggerController.h @@ -19,8 +19,9 @@ #import "StackController.h" @class GDBpConnection; +@protocol GDBpConnectionDelegate; -@interface DebuggerController : NSWindowController +@interface DebuggerController : NSWindowController { GDBpConnection* connection; diff --git a/Source/DebuggerController.m b/Source/DebuggerController.m index 80aed82..638173b 100644 --- a/Source/DebuggerController.m +++ b/Source/DebuggerController.m @@ -14,8 +14,8 @@ * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#import "DebuggerController.h" #import "GDBpConnection.h" +#import "DebuggerController.h" #import "NSXMLElementAdditions.h" #import "AppDelegate.h" #import "BreakpointManager.h" @@ -43,17 +43,11 @@ NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; connection = [[GDBpConnection alloc] initWithPort:[defaults integerForKey:@"Port"] session:[defaults stringForKey:@"IDEKey"]]; + connection.delegate = self; expandedVariables = [[NSMutableSet alloc] init]; [[self window] makeKeyAndOrderFront:nil]; [[self window] setDelegate:self]; - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(handleConnectionError:) - name:kErrorOccurredNotif - object:connection - ]; - if ([[NSUserDefaults standardUserDefaults] boolForKey:@"InspectorWindowVisible"]) [inspector orderFront:self]; } @@ -142,9 +136,17 @@ /** * Handles a GDBpConnection error */ -- (void)handleConnectionError:(NSNotification*)notif +- (void)errorEncountered:(NSString*)error { - [self setError:[[notif userInfo] valueForKey:@"NSString"]]; + [self setError:error]; +} + +/** + * Delegate functioni for GDBpConnection for when the debugger connects. + */ +- (void)debuggerConnected +{ + [self startDebugger]; } /** @@ -156,6 +158,15 @@ [self stepIn:self]; } +/** + * Called once the debugger disconnects. + */ +- (void)debuggerDisconnected +{ + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"AutoReconnect"]) + [self reconnect:self]; +} + /** * Forwards the message to run script execution to the connection */ diff --git a/Source/GDBpConnection.h b/Source/GDBpConnection.h index 0a80c01..7c06b1f 100644 --- a/Source/GDBpConnection.h +++ b/Source/GDBpConnection.h @@ -19,7 +19,7 @@ #import "Breakpoint.h" #import "StackFrame.h" -extern NSString* kErrorOccurredNotif; +@protocol GDBpConnectionDelegate; @interface GDBpConnection : NSObject { @@ -33,10 +33,13 @@ extern NSString* kErrorOccurredNotif; NSString* status; SocketWrapper* socket; + + id delegate; } -@property(readonly, copy) NSString* status; -@property(readonly) SocketWrapper* socket; +@property (readonly, copy) NSString* status; +@property (readonly) SocketWrapper* socket; +@property (assign) id delegate; // initializer - (id)initWithPort:(int)aPort session:(NSString*)aSession; @@ -61,3 +64,18 @@ extern NSString* kErrorOccurredNotif; - (NSArray*)getProperty:(NSString*)property; @end + +@protocol GDBpConnectionDelegate + +// Passes up errors from SocketWrapper and any other errors generated by the +// GDBpConnection. +- (void)errorEncountered:(NSString*)error; + +// Called when the socket connects. Passed up from SocketWrapper. +- (void)debuggerConnected; + +// Called when we disconnect. +- (void)debuggerDisconnected; + +@end + diff --git a/Source/GDBpConnection.m b/Source/GDBpConnection.m index 0386d88..96a1700 100644 --- a/Source/GDBpConnection.m +++ b/Source/GDBpConnection.m @@ -17,8 +17,6 @@ #import "GDBpConnection.h" #import "AppDelegate.h" -NSString* kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification"; - @interface GDBpConnection() @property(readwrite, copy) NSString* status; @@ -28,11 +26,13 @@ NSString* kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification"; - (StackFrame*)createCurrentStackFrame; - (void)updateStatus; - (NSString*)escapedURIPath:(NSString*)path; +- (void)doSocketAccept:_nil; @end @implementation GDBpConnection - -@synthesize socket, status; +@synthesize socket; +@synthesize status; +@synthesize delegate; /** * Creates a new DebuggerConnection and initializes the socket from the given connection @@ -111,18 +111,7 @@ NSString* kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification"; */ - (void)socketDidAccept { - connected = YES; - [socket receive]; - [self updateStatus]; - - // register any breakpoints that exist offline - for (Breakpoint* bp in [[BreakpointManager sharedManager] breakpoints]) - { - [self addBreakpoint:bp]; - } - - // Load the debugger to make it look active. - [[[NSApp delegate] debugger] performSelectorOnMainThread:@selector(startDebugger) withObject:nil waitUntilDone:YES]; + [self performSelectorOnMainThread:@selector(doSocketAccept:) withObject:nil waitUntilDone:YES]; } /** @@ -130,14 +119,7 @@ NSString* kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification"; */ - (void)errorEncountered:(NSString*)error { - [[NSNotificationCenter defaultCenter] - postNotificationName:kErrorOccurredNotif - object:self - userInfo:[NSDictionary - dictionaryWithObject:error - forKey:@"NSString" - ] - ]; + [delegate errorEncountered:error]; } /** @@ -192,7 +174,6 @@ NSString* kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification"; [socket receive]; [self updateStatus]; - } /** @@ -317,7 +298,7 @@ NSString* kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification"; if ([error count] > 0) { NSLog(@"Xdebug error: %@", error); - [self errorEncountered:[[[[error objectAtIndex:0] children] objectAtIndex:0] stringValue]]; + [delegate errorEncountered:[[[[error objectAtIndex:0] children] objectAtIndex:0] stringValue]]; return nil; } @@ -397,6 +378,9 @@ NSString* kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification"; { connected = NO; [socket close]; + + [delegate debuggerDisconnected]; + self.status = @"Stopped"; } } @@ -423,4 +407,23 @@ NSString* kErrorOccurredNotif = @"GDBpConnection_ErrorOccured_Notification"; return urlString; } +/** + * Helper method for |-socketDidAccept| to be called on the main thread. + */ +- (void)doSocketAccept:_nil +{ + connected = YES; + [socket receive]; + [self updateStatus]; + + // register any breakpoints that exist offline + for (Breakpoint* bp in [[BreakpointManager sharedManager] breakpoints]) + { + [self addBreakpoint:bp]; + } + + // Load the debugger to make it look active. + [delegate debuggerConnected]; +} + @end -- 2.22.5