Do not ever close the socket until we are definitely closing the connection. We can...
[macgdbp.git] / Source / DebuggerProcessor.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 "DebuggerConnection.h"
21 #import "StackFrame.h"
22
23 @protocol DebuggerProcessorDelegate;
24
25 // The DebuggerProcessor is the communication layer between the application
26 // and the back-end debugger. Clients issue debugger commands via this class,
27 // which are sent in an asynchronous manner. Reads are also asynchronous and
28 // the primary client of this class should set itself as the delegate. The
29 // primary unit that this class deals with is the StackFrame; clients should
30 // maintain a stack structure and the Connection will inform the delegate when
31 // a new frame is created or the stack should be destroyed.
32 @interface DebuggerProcessor : NSObject <DebuggerConnectionDelegate>
33 {
34 // The connection to the debugger engine.
35 DebuggerConnection* connection_;
36
37 // Human-readable status of the connection.
38 NSString* status;
39 BOOL active_;
40
41 // The connection's delegate.
42 id <DebuggerProcessorDelegate> delegate;
43
44 // A dictionary that maps routingIDs to StackFrame objects.
45 NSMutableDictionary* stackFrames_;
46 // The stack depth for the current build of |stackFrames_|.
47 NSInteger stackDepth_;
48 // The earliest transaction ID for the current build of |stackFrames_|.
49 NSInteger stackFirstTransactionID_;
50
51 // Callback table. This maps transaction IDs to selectors. When the engine
52 // returns a response to the debugger, we will dispatch the response XML to
53 // the selector, based on transaction_id.
54 NSMutableDictionary* callTable_;
55
56 // This stores additional context information for the callback selector.
57 // This dictionary is keyed by the same transaction IDs in |callTable_|, but
58 // also stores some other object that can be accessed in the callback.
59 NSMutableDictionary* callbackContext_;
60 }
61
62 @property (readonly, copy) NSString* status;
63 @property (assign) id <DebuggerProcessorDelegate> delegate;
64
65 // initializer
66 - (id)initWithPort:(NSUInteger)aPort;
67
68 // getter
69 - (NSUInteger)port;
70 - (NSString*)remoteHost;
71 - (BOOL)isConnected;
72
73 // communication
74 - (void)reconnect;
75 - (void)run;
76 - (void)stepIn;
77 - (void)stepOut;
78 - (void)stepOver;
79 - (void)addBreakpoint:(Breakpoint*)bp;
80 - (void)removeBreakpoint:(Breakpoint*)bp;
81
82 // Gets a property by name from the debugger engine. Returns a transaction ID
83 // which used in the delegate callback.
84 - (NSInteger)getProperty:(NSString*)property;
85
86 // Takes a partially loaded stack frame and fetches the rest of the information.
87 - (void)loadStackFrame:(StackFrame*)frame;
88
89 @end
90
91 // Delegate ////////////////////////////////////////////////////////////////////
92
93 @protocol DebuggerProcessorDelegate <NSObject>
94
95 // Passes up errors from SocketWrapper and any other errors generated by the
96 // GDBpConnection.
97 - (void)errorEncountered:(NSString*)error;
98
99 // Called when the socket connects. Passed up from SocketWrapper.
100 - (void)debuggerConnected;
101
102 // Called when we disconnect.
103 - (void)debuggerDisconnected;
104
105 // Tells the debugger to destroy the current stack display.
106 - (void)clobberStack;
107
108 // Tells the debugger that a new stack frame is avaliable.
109 - (void)newStackFrame:(StackFrame*)frame;
110
111 // Tells the debugger that new source is available for the given frame.
112 // TODO: rename to |-frameUpdated:|.
113 - (void)sourceUpdated:(StackFrame*)frame;
114
115 // Callback from |-getProperty:|.
116 - (void)receivedProperties:(NSArray*)properties forTransaction:(NSInteger)transaction;
117
118 @end
119