Implement "wait for connection" feature
authorpeter.rybin@gmail.com <peter.rybin@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Sun, 13 Dec 2009 21:15:02 +0000 (21:15 +0000)
committerpeter.rybin@gmail.com <peter.rybin@gmail.com@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Sun, 13 Dec 2009 21:15:02 +0000 (21:15 +0000)
Review URL: http://codereview.chromium.org/489005

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3457 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

include/v8-debug.h
src/api.cc
src/debug.cc
src/debug.h

index b27bacc..2220b04 100644 (file)
@@ -258,8 +258,11 @@ class EXPORT Debug {
   * supplied TCP/IP port for remote debugger connection.
   * \param name the name of the embedding application
   * \param port the TCP/IP port to listen on
+  * \param wait_for_connection whether V8 should pause on a first breakpoint
+  *   allowing remote debugger to connect before anything interesting happened
   */
-  static bool EnableAgent(const char* name, int port);
+  static bool EnableAgent(const char* name, int port,
+                          bool wait_for_connection = false);
 };
 
 
index d793b9f..ab5d0a5 100644 (file)
@@ -3741,8 +3741,8 @@ Local<Value> Debug::GetMirror(v8::Handle<v8::Value> obj) {
 }
 
 
-bool Debug::EnableAgent(const char* name, int port) {
-  return i::Debugger::StartAgent(name, port);
+bool Debug::EnableAgent(const char* name, int port, bool wait_for_connection) {
+  return i::Debugger::StartAgent(name, port, wait_for_connection);
 }
 #endif  // ENABLE_DEBUGGER_SUPPORT
 
index 2c4552e..fbe0939 100644 (file)
@@ -2483,7 +2483,24 @@ Handle<Object> Debugger::Call(Handle<JSFunction> fun,
 }
 
 
-bool Debugger::StartAgent(const char* name, int port) {
+static void StubMessageHandler2(const v8::Debug::Message& message) {
+  // Simply ignore message.
+}
+
+
+bool Debugger::StartAgent(const char* name, int port,
+                          bool wait_for_connection) {
+  if (wait_for_connection) {
+    // Suspend V8 if it is already running or set V8 to suspend whenever
+    // it starts.
+    // Provide stub message handler; V8 auto-continues each suspend
+    // when there is no message handler; we doesn't need it.
+    // Once become suspended, V8 will stay so indefinitely long, until remote
+    // debugger connects and issues "continue" command.
+    Debugger::message_handler_ = StubMessageHandler2;
+    v8::Debug::DebugBreak();
+  }
+
   if (Socket::Setup()) {
     agent_ = new DebuggerAgent(name, port);
     agent_->Start();
index 24f0db4..096916e 100644 (file)
@@ -636,7 +636,7 @@ class Debugger {
                              bool* pending_exception);
 
   // Start the debugger agent listening on the provided port.
-  static bool StartAgent(const char* name, int port);
+  static bool StartAgent(const char* name, int port, bool wait_for_connection);
 
   // Stop the debugger agent.
   static void StopAgent();