3 * Copyright (c) 2007 - 2011, Blue Static <http://www.bluestatic.org>
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.
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.
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
17 #import <Cocoa/Cocoa.h>
19 #import "Breakpoint.h"
20 #import "ProtocolClient.h"
21 #import "StackFrame.h"
23 @protocol DebuggerBackEndDelegate
;
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
>
35 // The connection to the debugger engine.
37 ProtocolClient
* client_
;
39 // Human-readable status of the connection.
43 // Whether the debugger should detach immediately after being contacted by the
44 // backend. YES means all debugger connections will be dropped.
47 // The connection's delegate.
48 id
<DebuggerBackEndDelegate
> delegate
;
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_
;
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_
;
62 // This stores additional context information for the callback selector.
63 // This dictionary is keyed by the same transaction IDs in |callTable_|, but
64 // also stores some other object that can be accessed in the callback.
65 NSMutableDictionary
* callbackContext_
;
68 @
property (readonly
, copy
) NSString
* status
;
69 @
property (nonatomic
, assign
) BOOL attached
;
70 @
property (assign
) id
<DebuggerBackEndDelegate
> delegate
;
73 - (id
)initWithPort
:(NSUInteger
)aPort
;
87 // Breakpoint management.
88 - (void)addBreakpoint
:(Breakpoint
*)bp
;
89 - (void)removeBreakpoint
:(Breakpoint
*)bp
;
91 // Evaluates a given string in the current execution context.
92 - (void)evalScript
:(NSString
*)str
;
94 // Gets a property by name from the debugger engine. Returns a transaction ID
95 // which used in the delegate callback. Properties must be retrieved at a
96 // certain stack depth.
97 - (NSInteger
)getChildrenOfProperty
:(VariableNode
*)property atDepth
:(NSInteger
)depth
;
99 // Takes a partially loaded stack frame and fetches the rest of the information.
100 - (void)loadStackFrame
:(StackFrame
*)frame
;
104 // Delegate ////////////////////////////////////////////////////////////////////
106 @protocol DebuggerBackEndDelegate
<NSObject
>
108 // Passes up errors from SocketWrapper and any other errors generated by the
110 - (void)errorEncountered
:(NSString
*)error
;
112 // Called when the socket connects. Passed up from SocketWrapper.
113 - (void)debuggerConnected
;
115 // Called when we disconnect.
116 - (void)debuggerDisconnected
;
118 // Tells the debugger to destroy the current stack display.
119 - (void)clobberStack
;
121 // Tells the debugger that a new stack frame is avaliable.
122 - (void)newStackFrame
:(StackFrame
*)frame
;
124 // Tells the debugger that new source is available for the given frame.
125 // TODO: rename to |-frameUpdated:|.
126 - (void)sourceUpdated
:(StackFrame
*)frame
;
128 // Callback from |-getProperty:|.
129 - (void)receivedProperties
:(NSArray
*)properties forTransaction
:(NSInteger
)transaction
;
131 // Callback for the result of |-evalScript:|.
132 - (void)scriptWasEvaluatedWithResult
:(NSString
*)result
;