- (void)addBreakpoint:(Breakpoint*)bp;
- (void)removeBreakpoint:(Breakpoint*)bp;
+// Evaluates a given string in the current execution context.
+- (void)evalScript:(NSString*)str;
+
// Gets a property by name from the debugger engine. Returns a transaction ID
// which used in the delegate callback. Properties must be retrieved at a
// certain stack depth.
#import "DebuggerBackEnd.h"
#import "AppDelegate.h"
+#import "modp_b64.h"
#import "NSXMLElementAdditions.h"
// GDBpConnection (Private) ////////////////////////////////////////////////////
[connection_ sendCommandWithFormat:@"breakpoint_remove -d %i", [bp debuggerId]];
}
+/**
+ * Sends a string to be evaluated by the engine.
+ */
+- (void)evalScript:(NSString*)str
+{
+ if (![connection_ connected])
+ return;
+
+ char* encodedString = malloc(modp_b64_encode_len([str length]));
+ modp_b64_encode(encodedString, [str UTF8String], [str length]);
+ [connection_ sendCustomCommandWithFormat:@"eval -i {txn} -- %s", encodedString];
+ free(encodedString);
+}
+
// Specific Response Handlers //////////////////////////////////////////////////
#pragma mark Response Handlers
#import "EvalController.h"
+#import "DebuggerBackEnd.h"
+
@implementation EvalController
@synthesize dataField = dataField_;
- (IBAction)evaluateScript:(id)sender
{
- NSLog(@"will evluate: %@", [self.dataField stringValue]);
+ NSString* code = [self.dataField stringValue];
+ [backEnd_ evalScript:code];
}
- (IBAction)closeWindow:(id)sender
// safe and schedules the request on the |runLoop_|.
- (NSNumber*)sendCommandWithFormat:(NSString*)format, ...;
+// Sends a command to the debugger. The command must have a substring |{txn}|
+// within it, which will be replaced with the transaction ID. Use this if
+// |-sendCommandWithFormat:|'s insertion of the transaction ID is incorrect.
+- (NSNumber*)sendCustomCommandWithFormat:(NSString*)format, ...;
+
- (NSString*)escapedURIPath:(NSString*)path;
- (NSInteger)transactionIDFromResponse:(NSXMLDocument*)response;
- (NSInteger)transactionIDFromCommand:(NSString*)command;
return callbackKey;
}
+/**
+ * Certain commands expect encoded data to be the the last, unnamed parameter
+ * of the command. In these cases, inserting the transaction ID at the end is
+ * incorrect, so clients use this method to have |{txn}| replaced with the
+ * transaction ID.
+ */
+- (NSNumber*)sendCustomCommandWithFormat:(NSString*)format, ...
+{
+ // Collect varargs and format command.
+ va_list args;
+ va_start(args, format);
+ NSString* command = [[[NSString alloc] initWithFormat:format arguments:args] autorelease];
+ va_end(args);
+
+ NSNumber* callbackKey = [NSNumber numberWithInt:transactionID++];
+ NSString* taggedCommand = [command stringByReplacingOccurrencesOfString:@"{txn}"
+ withString:[callbackKey stringValue]];
+ [self performSelector:@selector(send:)
+ onThread:thread_
+ withObject:taggedCommand
+ waitUntilDone:connected_];
+
+ return callbackKey;
+}
+
/**
* Given a file path, this returns a file:// URI and escapes any spaces for the
* debugger engine.