Switch some basic ints to NSUInteger in GDBpConnection.
[macgdbp.git] / Source / DebuggerConnection.h
1 /*
2 * MacGDBp
3 * Copyright (c) 2007 - 2010, Blue Static <http://www.bluestatic.org>
4 *
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17 #import <Cocoa/Cocoa.h>
18
19 #import "Breakpoint.h"
20 #import "StackFrame.h"
21
22 @protocol DebuggerConnectionDelegate;
23
24 // The DebuggerConnection is the communication layer between the application
25 // and the Xdebug engine. Clients can issue debugger commands using this class,
26 // which are sent in an asynchronous manner. Reads are also asynchronous and
27 // the primary client of this class should set itself as the delegate. The
28 // primary unit that this class deals with is the StackFrame; clients should
29 // maintain a stack structure and the Connection will inform the delegate when
30 // a new frame is created or the stack should be destroyed.
31 @interface DebuggerConnection : NSObject
32 {
33 // The port to connect on.
34 NSUInteger port;
35
36 // If the connection to the debugger engine is currently active.
37 BOOL connected;
38
39 // Human-readable status of the connection.
40 NSString* status;
41
42 // The connection's delegate.
43 id <DebuggerConnectionDelegate> delegate;
44
45 // The raw CFSocket on which the two streams are based. Strong.
46 CFSocketRef socket_;
47
48 // The read stream that is scheduled on the main run loop. Weak.
49 CFReadStreamRef readStream_;
50
51 // The write stream. Weak.
52 CFWriteStreamRef writeStream_;
53
54 // An ever-increasing integer that gives each transaction a unique ID for the
55 // debugging engine.
56 NSUInteger transactionID;
57
58 // The most recently received transaction ID.
59 NSUInteger lastReadTransaction_;
60
61 // The last transactionID written to the stream.
62 NSUInteger lastWrittenTransaction_;
63
64 // Callback table. This maps transaction IDs to selectors. When the engine
65 // returns a response to the debugger, we will dispatch the response XML to
66 // the selector, based on transaction_id.
67 NSMutableDictionary* callTable_;
68
69 // To prevent blocked writing, we enqueue all writes and then wait for the
70 // write stream to tell us it's ready. We store the pending commands in this
71 // array. We use this as a stack (FIFO), with index 0 being first.
72 NSMutableArray* queuedWrites_;
73
74 // We send queued writes in multiple places, sometimes off a run loop event.
75 // Because of this, we need to ensure that only one client is dequeing and
76 // sending at a time.
77 NSRecursiveLock* writeQueueLock_;
78
79 // Information about the current read loop. We append to |currentPacket_|
80 // until |currentPacketSize_| has reached |packetSize_|.
81 NSMutableString* currentPacket_;
82 int packetSize_;
83 int currentPacketIndex_;
84
85 // A dictionary that maps routingIDs to StackFrame objects.
86 NSMutableDictionary* stackFrames_;
87 // The stack depth for the current build of |stackFrames_|.
88 NSInteger stackDepth_;
89 // The earliest transaction ID for the current build of |stackFrames_|.
90 NSInteger stackFirstTransactionID_;
91
92 // This stores additional context information for the callback selector.
93 // This dictionary is keyed by the same transaction IDs in |callTable_|, but
94 // also stores some other object that can be accessed in the callback.
95 NSMutableDictionary* callbackContext_;
96 }
97
98 @property (readonly, copy) NSString* status;
99 @property (assign) id <DebuggerConnectionDelegate> delegate;
100
101 // initializer
102 - (id)initWithPort:(NSUInteger)aPort;
103
104 // getter
105 - (NSUInteger)port;
106 - (NSString*)remoteHost;
107 - (BOOL)isConnected;
108 - (NSArray*)getCurrentStack;
109
110 // communication
111 - (void)reconnect;
112 - (void)run;
113 - (void)stepIn;
114 - (void)stepOut;
115 - (void)stepOver;
116 - (void)addBreakpoint:(Breakpoint*)bp;
117 - (void)removeBreakpoint:(Breakpoint*)bp;
118
119 // helpers
120 - (NSArray*)getProperty:(NSString*)property;
121
122 @end
123
124 // Delegate ////////////////////////////////////////////////////////////////////
125
126 @protocol DebuggerConnectionDelegate <NSObject>
127
128 // Passes up errors from SocketWrapper and any other errors generated by the
129 // GDBpConnection.
130 - (void)errorEncountered:(NSString*)error;
131
132 // Called when the socket connects. Passed up from SocketWrapper.
133 - (void)debuggerConnected;
134
135 // Called when we disconnect.
136 - (void)debuggerDisconnected;
137
138 // Tells the debugger to destroy the current stack display.
139 - (void)clobberStack;
140
141 // Tells the debugger that a new stack frame is avaliable.
142 - (void)newStackFrame:(StackFrame*)frame;
143
144 // Tells the debugger that new source is available for the given frame.
145 - (void)sourceUpdated:(StackFrame*)frame;
146
147 @end
148