From 4f8127acd66f9183e013237cdd650da1db7d7463 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 27 Mar 2010 15:44:53 -0400 Subject: [PATCH] Rename GDBpConnection to DebuggerConnection. Also organize all the ivars and methods. --- MacGDBp.xcodeproj/project.pbxproj | 12 +- Source/BreakpointManager.h | 6 +- ...{GDBpConnection.h => DebuggerConnection.h} | 73 +++++++------ ...{GDBpConnection.m => DebuggerConnection.m} | 103 ++++++++++-------- Source/DebuggerController.h | 8 +- Source/DebuggerController.m | 2 +- 6 files changed, 112 insertions(+), 92 deletions(-) rename Source/{GDBpConnection.h => DebuggerConnection.h} (76%) rename Source/{GDBpConnection.m => DebuggerConnection.m} (97%) diff --git a/MacGDBp.xcodeproj/project.pbxproj b/MacGDBp.xcodeproj/project.pbxproj index f82963b..efac4c2 100644 --- a/MacGDBp.xcodeproj/project.pbxproj +++ b/MacGDBp.xcodeproj/project.pbxproj @@ -11,7 +11,7 @@ 1E027F0B0D36F23F00885DEE /* StepOver.png in Resources */ = {isa = PBXBuildFile; fileRef = 1E027F090D36F23F00885DEE /* StepOver.png */; }; 1E027F390D36F60800885DEE /* Reconnect.png in Resources */ = {isa = PBXBuildFile; fileRef = 1E027F380D36F60800885DEE /* Reconnect.png */; }; 1E02C3D50C60EC2C006F1752 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E02C3D40C60EC2C006F1752 /* AppDelegate.m */; }; - 1E02C5710C610158006F1752 /* GDBpConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E02C5700C610158006F1752 /* GDBpConnection.m */; }; + 1E02C5710C610158006F1752 /* DebuggerConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E02C5700C610158006F1752 /* DebuggerConnection.m */; }; 1E02C5F60C610724006F1752 /* DebuggerController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1E02C5F50C610724006F1752 /* DebuggerController.m */; }; 1E0AFBB90FC2518700C67031 /* HUDIcon.png in Resources */ = {isa = PBXBuildFile; fileRef = 1E0AFBB80FC2518700C67031 /* HUDIcon.png */; }; 1E1E53030DF9B89800D334F9 /* Breakpoints.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1E1E53010DF9B89800D334F9 /* Breakpoints.xib */; }; @@ -65,8 +65,8 @@ 1E027F380D36F60800885DEE /* Reconnect.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Reconnect.png; path = Icons/Reconnect.png; sourceTree = ""; }; 1E02C3D30C60EC2C006F1752 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = Source/AppDelegate.h; sourceTree = ""; }; 1E02C3D40C60EC2C006F1752 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = Source/AppDelegate.m; sourceTree = ""; }; - 1E02C56F0C610158006F1752 /* GDBpConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GDBpConnection.h; path = Source/GDBpConnection.h; sourceTree = ""; }; - 1E02C5700C610158006F1752 /* GDBpConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GDBpConnection.m; path = Source/GDBpConnection.m; sourceTree = ""; }; + 1E02C56F0C610158006F1752 /* DebuggerConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DebuggerConnection.h; path = Source/DebuggerConnection.h; sourceTree = ""; }; + 1E02C5700C610158006F1752 /* DebuggerConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DebuggerConnection.m; path = Source/DebuggerConnection.m; sourceTree = ""; }; 1E02C5F40C610724006F1752 /* DebuggerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DebuggerController.h; path = Source/DebuggerController.h; sourceTree = ""; }; 1E02C5F50C610724006F1752 /* DebuggerController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DebuggerController.m; path = Source/DebuggerController.m; sourceTree = ""; }; 1E0AFBB80FC2518700C67031 /* HUDIcon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = HUDIcon.png; path = Icons/HUDIcon.png; sourceTree = ""; }; @@ -197,8 +197,8 @@ 1E1E52C10DF9B1FB00D334F9 /* Connection */ = { isa = PBXGroup; children = ( - 1E02C56F0C610158006F1752 /* GDBpConnection.h */, - 1E02C5700C610158006F1752 /* GDBpConnection.m */, + 1E02C56F0C610158006F1752 /* DebuggerConnection.h */, + 1E02C5700C610158006F1752 /* DebuggerConnection.m */, 1E35FFB00C65A74C0030F527 /* NSXMLElementAdditions.h */, 1E35FC750C6579CA0030F527 /* NSXMLElementAdditions.m */, ); @@ -388,7 +388,7 @@ files = ( 8D11072D0486CEB800E47090 /* main.m in Sources */, 1E02C3D50C60EC2C006F1752 /* AppDelegate.m in Sources */, - 1E02C5710C610158006F1752 /* GDBpConnection.m in Sources */, + 1E02C5710C610158006F1752 /* DebuggerConnection.m in Sources */, 1E02C5F60C610724006F1752 /* DebuggerController.m in Sources */, 1E35FC760C6579CA0030F527 /* NSXMLElementAdditions.m in Sources */, 1E35FEA10C6599040030F527 /* base64.c in Sources */, diff --git a/Source/BreakpointManager.h b/Source/BreakpointManager.h index 6aa8921..48cd184 100644 --- a/Source/BreakpointManager.h +++ b/Source/BreakpointManager.h @@ -16,17 +16,17 @@ #import #import "Breakpoint.h" -#import "GDBpConnection.h" +#import "DebuggerConnection.h" @interface BreakpointManager : NSObject { NSMutableArray* breakpoints; NSMutableArray* savedBreakpoints; - GDBpConnection* connection; + DebuggerConnection* connection; } -@property(readwrite, assign) GDBpConnection* connection; +@property(readwrite, assign) DebuggerConnection* connection; @property(readonly) NSMutableArray* breakpoints; + (BreakpointManager*)sharedManager; diff --git a/Source/GDBpConnection.h b/Source/DebuggerConnection.h similarity index 76% rename from Source/GDBpConnection.h rename to Source/DebuggerConnection.h index d3b4eda..3d56b8a 100644 --- a/Source/GDBpConnection.h +++ b/Source/DebuggerConnection.h @@ -19,54 +19,68 @@ #import "Breakpoint.h" #import "StackFrame.h" -@protocol GDBpConnectionDelegate; - -@interface GDBpConnection : NSObject +@protocol DebuggerConnectionDelegate; + +// The DebuggerConnection is the communication layer between the application +// and the Xdebug engine. Clients can issue debugger commands using this class, +// which are sent in an asynchronous manner. Reads are also asynchronous and +// the primary client of this class should set itself as the delegate. The +// primary unit that this class deals with is the StackFrame; clients should +// maintain a stack structure and the Connection will inform the delegate when +// a new frame is created or the stack should be destroyed. +@interface DebuggerConnection : NSObject { + // The port to connect on. NSUInteger port; - BOOL connected; - /** - * An ever-increasing integer that gives each transaction a unique ID for - * the debugging engine. Managed by |-createCommand:|. - */ - NSUInteger transactionID; + // If the connection to the debugger engine is currently active. + BOOL connected; - /** - * Human-readable status of the connection - */ + // Human-readable status of the connection. NSString* status; + // The connection's delegate. + id delegate; + // The raw CFSocket on which the two streams are based. Strong. CFSocketRef socket_; // The read stream that is scheduled on the main run loop. Weak. CFReadStreamRef readStream_; + // The write stream. Weak. + CFWriteStreamRef writeStream_; + + // An ever-increasing integer that gives each transaction a unique ID for the + // debugging engine. + NSUInteger transactionID; + // The most recently received transaction ID. NSUInteger lastReadTransaction_; - // Information about the current read loop. We append to |currentPacket_| - // until |currentPacketSize_| has reached |packetSize_|. - NSMutableString* currentPacket_; - int packetSize_; - int currentPacketIndex_; + // The last transactionID written to the stream. + NSUInteger lastWrittenTransaction_; + + // Callback table. This maps transaction IDs to selectors. When the engine + // returns a response to the debugger, we will dispatch the response XML to + // the selector, based on transaction_id. + NSMutableDictionary* callTable_; // To prevent blocked writing, we enqueue all writes and then wait for the // write stream to tell us it's ready. We store the pending commands in this // array. We use this as a stack (FIFO), with index 0 being first. NSMutableArray* queuedWrites_; - // We send queued writes in multiple places, sometimes of a run loop event. + // We send queued writes in multiple places, sometimes off a run loop event. // Because of this, we need to ensure that only one client is dequeing and // sending at a time. NSRecursiveLock* writeQueueLock_; - // The write stream. Weak. - CFWriteStreamRef writeStream_; - - // The last transactionID written to the stream. - NSUInteger lastWrittenTransaction_; + // Information about the current read loop. We append to |currentPacket_| + // until |currentPacketSize_| has reached |packetSize_|. + NSMutableString* currentPacket_; + int packetSize_; + int currentPacketIndex_; // A dictionary that maps routingIDs to StackFrame objects. NSMutableDictionary* stackFrames_; @@ -75,21 +89,14 @@ // The earliest transaction ID for the current build of |stackFrames_|. NSInteger stackFirstTransactionID_; - // Callback table. This maps transaction IDs to selectors. When the engine - // returns a response to the debugger, we will dispatch the response XML to - // the selector, based on transaction_id. - NSMutableDictionary* callTable_; - // This stores additional context information for the callback selector. // This dictionary is keyed by the same transaction IDs in |callTable_|, but // also stores some other object that can be accessed in the callback. NSMutableDictionary* callbackContext_; - - id delegate; } @property (readonly, copy) NSString* status; -@property (assign) id delegate; +@property (assign) id delegate; // initializer - (id)initWithPort:(NSUInteger)aPort; @@ -114,7 +121,9 @@ @end -@protocol GDBpConnectionDelegate +// Delegate //////////////////////////////////////////////////////////////////// + +@protocol DebuggerConnectionDelegate // Passes up errors from SocketWrapper and any other errors generated by the // GDBpConnection. diff --git a/Source/GDBpConnection.m b/Source/DebuggerConnection.m similarity index 97% rename from Source/GDBpConnection.m rename to Source/DebuggerConnection.m index 8924f8d..ee790b1 100644 --- a/Source/GDBpConnection.m +++ b/Source/DebuggerConnection.m @@ -17,13 +17,13 @@ #import #import -#import "GDBpConnection.h" +#import "DebuggerConnection.h" #import "AppDelegate.h" // GDBpConnection (Private) //////////////////////////////////////////////////// -@interface GDBpConnection () +@interface DebuggerConnection () @property (readwrite, copy) NSString* status; @property (assign) CFSocketRef socket; @property (assign) CFReadStreamRef readStream; @@ -64,7 +64,7 @@ void ReadStreamCallback(CFReadStreamRef stream, CFStreamEventType eventType, void* connectionRaw) { - GDBpConnection* connection = (GDBpConnection*)connectionRaw; + DebuggerConnection* connection = (DebuggerConnection*)connectionRaw; switch (eventType) { case kCFStreamEventHasBytesAvailable: @@ -93,7 +93,7 @@ void ReadStreamCallback(CFReadStreamRef stream, CFStreamEventType eventType, voi void WriteStreamCallback(CFWriteStreamRef stream, CFStreamEventType eventType, void* connectionRaw) { - GDBpConnection* connection = (GDBpConnection*)connectionRaw; + DebuggerConnection* connection = (DebuggerConnection*)connectionRaw; switch (eventType) { case kCFStreamEventCanAcceptBytes: @@ -128,7 +128,7 @@ void SocketAcceptCallback(CFSocketRef socket, assert(callbackType == kCFSocketAcceptCallBack); NSLog(@"SocketAcceptCallback()"); - GDBpConnection* connection = (GDBpConnection*)connectionRaw; + DebuggerConnection* connection = (DebuggerConnection*)connectionRaw; CFReadStreamRef readStream; CFWriteStreamRef writeStream; @@ -194,7 +194,7 @@ void SocketAcceptCallback(CFSocketRef socket, // GDBpConnection ////////////////////////////////////////////////////////////// -@implementation GDBpConnection +@implementation DebuggerConnection @synthesize socket = socket_; @synthesize readStream = readStream_; @synthesize lastReadTransaction = lastReadTransaction_; @@ -234,6 +234,10 @@ void SocketAcceptCallback(CFSocketRef socket, [super dealloc]; } + +// Getters ///////////////////////////////////////////////////////////////////// +#pragma mark Getters + /** * Gets the port number */ @@ -263,29 +267,8 @@ void SocketAcceptCallback(CFSocketRef socket, return connected; } -/** - * Called by SocketWrapper after the connection is successful. This immediately calls - * -[SocketWrapper receive] to clear the way for communication, though the information - * could be useful server information that we don't use right now. - */ -- (void)socketDidAccept -{ - connected = YES; - transactionID = 1; - stackFrames_ = [[NSMutableDictionary alloc] init]; - self.queuedWrites = [NSMutableArray array]; - writeQueueLock_ = [NSRecursiveLock new]; - callTable_ = [NSMutableDictionary new]; - callbackContext_ = [NSMutableDictionary new]; -} - -/** - * Receives errors from the SocketWrapper and updates the display - */ -- (void)errorEncountered:(NSString*)error -{ - [delegate errorEncountered:error]; -} +// Commands //////////////////////////////////////////////////////////////////// +#pragma mark Commands /** * Reestablishes communication with the remote debugger so that a new connection doesn't have to be @@ -365,6 +348,7 @@ void SocketAcceptCallback(CFSocketRef socket, return children; } +// Breakpoint Management /////////////////////////////////////////////////////// #pragma mark Breakpoints /** @@ -381,20 +365,6 @@ void SocketAcceptCallback(CFSocketRef socket, [callbackContext_ setObject:bp forKey:transaction]; } -/** - * Callback for setting a breakpoint. - */ -- (void)breakpointReceived:(NSXMLDocument*)response -{ - NSNumber* transaction = [NSNumber numberWithInt:[self transactionIDFromResponse:response]]; - Breakpoint* bp = [callbackContext_ objectForKey:transaction]; - if (!bp) - return; - - [callbackContext_ removeObjectForKey:callbackContext_]; - [bp setDebuggerId:[[[[response rootElement] attributeForName:@"id"] stringValue] intValue]]; -} - /** * Removes a breakpoint */ @@ -408,7 +378,33 @@ void SocketAcceptCallback(CFSocketRef socket, [self sendCommandWithCallback:nil format:@"breakpoint_remove -d %i", [bp debuggerId]]; } -#pragma mark Socket and Stream Callbacks + +// Socket and Stream Callbacks ///////////////////////////////////////////////// +#pragma mark Callbacks + +/** + * Called by SocketWrapper after the connection is successful. This immediately calls + * -[SocketWrapper receive] to clear the way for communication, though the information + * could be useful server information that we don't use right now. + */ +- (void)socketDidAccept +{ + connected = YES; + transactionID = 1; + stackFrames_ = [[NSMutableDictionary alloc] init]; + self.queuedWrites = [NSMutableArray array]; + writeQueueLock_ = [NSRecursiveLock new]; + callTable_ = [NSMutableDictionary new]; + callbackContext_ = [NSMutableDictionary new]; +} + +/** + * Receives errors from the SocketWrapper and updates the display + */ +- (void)errorEncountered:(NSString*)error +{ + [delegate errorEncountered:error]; +} /** * Creates, connects to, and schedules a CFSocket. @@ -608,8 +604,6 @@ void SocketAcceptCallback(CFSocketRef socket, } } -#pragma mark Response Handlers - - (void)handleResponse:(NSXMLDocument*)response { // Check and see if there's an error. @@ -651,6 +645,9 @@ void SocketAcceptCallback(CFSocketRef socket, [self sendQueuedWrites]; } +// Specific Response Handlers ////////////////////////////////////////////////// +#pragma mark Response Handlers + /** * Initial packet received. We've started a brand-new connection to the engine. */ @@ -848,6 +845,20 @@ void SocketAcceptCallback(CFSocketRef socket, frame.variables = variables; } +/** + * Callback for setting a breakpoint. + */ +- (void)breakpointReceived:(NSXMLDocument*)response +{ + NSNumber* transaction = [NSNumber numberWithInt:[self transactionIDFromResponse:response]]; + Breakpoint* bp = [callbackContext_ objectForKey:transaction]; + if (!bp) + return; + + [callbackContext_ removeObjectForKey:callbackContext_]; + [bp setDebuggerId:[[[[response rootElement] attributeForName:@"id"] stringValue] intValue]]; +} + #pragma mark Private /** diff --git a/Source/DebuggerController.h b/Source/DebuggerController.h index 20fdd05..6fc3b12 100644 --- a/Source/DebuggerController.h +++ b/Source/DebuggerController.h @@ -16,12 +16,12 @@ #import #import "BSSourceView.h" -#import "GDBpConnection.h" +#import "DebuggerConnection.h" #import "StackController.h" -@interface DebuggerController : NSWindowController +@interface DebuggerController : NSWindowController { - GDBpConnection* connection; + DebuggerConnection* connection; // This is true when the |connection| has told us to clobber. We will do // so upon receipt of the first new stack frame. @@ -43,7 +43,7 @@ IBOutlet BSSourceView* sourceViewer; } -@property(readonly) GDBpConnection* connection; +@property(readonly) DebuggerConnection* connection; @property(readonly) BSSourceView* sourceViewer; @property(readonly) NSWindow* inspector; diff --git a/Source/DebuggerController.m b/Source/DebuggerController.m index 00621df..62708cb 100644 --- a/Source/DebuggerController.m +++ b/Source/DebuggerController.m @@ -41,7 +41,7 @@ stackController = [[StackController alloc] init]; NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; - connection = [[GDBpConnection alloc] initWithPort:[defaults integerForKey:@"Port"]]; + connection = [[DebuggerConnection alloc] initWithPort:[defaults integerForKey:@"Port"]]; connection.delegate = self; expandedVariables = [[NSMutableSet alloc] init]; [[self window] makeKeyAndOrderFront:nil]; -- 2.22.5