Refactor -[DebuggerController fetchChildProperties:].
[macgdbp.git] / Source / DebuggerBackEnd.h
1 /*
2 * MacGDBp
3 * Copyright (c) 2007 - 2011, 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 "ProtocolClient.h"
21 #import "StackFrame.h"
22
23 @protocol DebuggerBackEndDelegate;
24 @class VariableNode;
25
26 // The DebuggerBackEnd is the communication layer between the application
27 // and the back-end debugger. Clients issue debugger commands via this class,
28 // which are sent in an asynchronous manner. Reads are also asynchronous and
29 // the primary client of this class should set itself as the delegate. The
30 // primary unit that this class deals with is the StackFrame; clients should
31 // maintain a stack structure and the BackEnd will inform the delegate when
32 // a new frame is created or the stack should be destroyed.
33 @interface DebuggerBackEnd : NSObject <ProtocolClientDelegate>
34 {
35 // The connection to the debugger engine.
36 NSUInteger port_;
37 ProtocolClient* client_;
38
39 // Human-readable status of the connection.
40 NSString* status;
41 BOOL active_;
42
43 // Whether the debugger should detach immediately after being contacted by the
44 // backend. YES means all debugger connections will be dropped.
45 BOOL attached_;
46
47 // The connection's delegate.
48 id <DebuggerBackEndDelegate> delegate;
49
50 // A dictionary that maps routingIDs to StackFrame objects.
51 NSMutableDictionary* stackFrames_;
52 // The stack depth for the current build of |stackFrames_|.
53 NSInteger stackDepth_;
54 // The earliest transaction ID for the current build of |stackFrames_|.
55 NSInteger stackFirstTransactionID_;
56
57 // Callback table. This maps transaction IDs to selectors. When the engine
58 // returns a response to the debugger, we will dispatch the response XML to
59 // the selector, based on transaction_id.
60 NSMutableDictionary* callTable_;
61 }
62
63 @property (readonly, copy) NSString* status;
64 @property (nonatomic, assign) BOOL attached;
65 @property (assign) id <DebuggerBackEndDelegate> delegate;
66
67 // initializer
68 - (id)initWithPort:(NSUInteger)aPort;
69
70 // getter
71 - (NSUInteger)port;
72 - (BOOL)isConnected;
73
74 // communication
75 - (void)run;
76 - (void)stepIn;
77 - (void)stepOut;
78 - (void)stepOver;
79 - (void)stop;
80 - (void)detach;
81
82 // Breakpoint management.
83 - (void)addBreakpoint:(Breakpoint*)bp;
84 - (void)removeBreakpoint:(Breakpoint*)bp;
85
86 // Evaluates a given string in the current execution context.
87 - (void)evalScript:(NSString*)str;
88
89 // Gets a property by name from the debugger engine. Properties must be
90 // retrieved at a certain stack depth.
91 - (void)getChildrenOfProperty:(VariableNode*)property
92 atDepth:(NSInteger)depth
93 callback:(void (^)(NSArray*))callback;
94
95 // Takes a partially loaded stack frame and fetches the rest of the information.
96 - (void)loadStackFrame:(StackFrame*)frame;
97
98 @end
99
100 // Delegate ////////////////////////////////////////////////////////////////////
101
102 @protocol DebuggerBackEndDelegate <NSObject>
103
104 // Passes up errors from SocketWrapper and any other errors generated by the
105 // GDBpConnection.
106 - (void)errorEncountered:(NSString*)error;
107
108 // Called when the socket connects. Passed up from SocketWrapper.
109 - (void)debuggerConnected;
110
111 // Called when we disconnect.
112 - (void)debuggerDisconnected;
113
114 // Tells the debugger to destroy the current stack display.
115 - (void)clobberStack;
116
117 // Tells the debugger that a new stack frame is avaliable.
118 - (void)newStackFrame:(StackFrame*)frame;
119
120 // Tells the debugger that new source is available for the given frame.
121 // TODO: rename to |-frameUpdated:|.
122 - (void)sourceUpdated:(StackFrame*)frame;
123
124 // Callback for the result of |-evalScript:|.
125 - (void)scriptWasEvaluatedWithResult:(NSString*)result;
126
127 @end
128