Add -[DebuggerBackEnd evalScript:] to send the command.
authorRobert Sesek <rsesek@bluestatic.org>
Sun, 1 May 2011 16:25:35 +0000 (12:25 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 1 May 2011 16:46:35 +0000 (12:46 -0400)
But the command format is atypical and has the transaction ID before the last
parameter, so also add -[NetworkConnection sendCustomCommandWithFormat:] to
support placing the transaction ID in an arbitrary place using a string
placeholder.

Source/DebuggerBackEnd.h
Source/DebuggerBackEnd.m
Source/EvalController.m
Source/NetworkConnection.h
Source/NetworkConnection.mm

index 8de4c2e5256f167d0250b58c58c77a5cc1d9b494..21b55803b5d29211d762059d82eaf6ede13ab443 100644 (file)
@@ -87,6 +87,9 @@
 - (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.
index a739b2197337782d7f455534cd6031aa9ed7e363..7de4ce0ed0a5fd190506926b72683902f63ec2a4 100644 (file)
@@ -17,6 +17,7 @@
 #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
 
index ced155975193fec3f8a33c148ced3e7a717aff8c..7e1cb52d72db052da5f62fe3368804369953b498 100644 (file)
@@ -16,6 +16,8 @@
 
 #import "EvalController.h"
 
+#import "DebuggerBackEnd.h"
+
 @implementation EvalController
 
 @synthesize dataField = dataField_;
@@ -54,7 +56,8 @@
 
 - (IBAction)evaluateScript:(id)sender
 {
-  NSLog(@"will evluate: %@", [self.dataField stringValue]);
+  NSString* code = [self.dataField stringValue];
+  [backEnd_ evalScript:code];
 }
 
 - (IBAction)closeWindow:(id)sender
index 99301e18abd4cb7cbb2f0ca6e69a00110dd5a991..928671484f8a8afe5c6bcae7e6ea4d2451e7ee81 100644 (file)
@@ -98,6 +98,11 @@ class NetworkCallbackController;
 // 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;
index 5fede2c923db20606ef642a02ef9eea52cdef71f..63370a88cea1785267687d7f6a3cb9c356ec408a 100644 (file)
@@ -205,6 +205,31 @@ void PerformQuitSignal(void* info)
   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.