Enable asynchronous remote debugging with d8.
authoryangguo@chromium.org <yangguo@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 20 Jan 2012 11:59:00 +0000 (11:59 +0000)
committeryangguo@chromium.org <yangguo@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Fri, 20 Jan 2012 11:59:00 +0000 (11:59 +0000)
BUG=v8:1691
TEST=

Review URL: https://chromiumcodereview.appspot.com/9138015

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

src/d8-readline.cc
src/d8.cc
src/d8.h

index 679c536..ed7721c 100644 (file)
@@ -91,7 +91,11 @@ bool ReadLineEditor::Close() {
 
 
 Handle<String> ReadLineEditor::Prompt(const char* prompt) {
-  char* result = readline(prompt);
+  char* result = NULL;
+  {  // Release lock for blocking input.
+    Unlocker unlock(Isolate::GetCurrent());
+    result = readline(prompt);
+  }
   if (result != NULL) {
     AddHistory(result);
   } else {
index 9e40997..bfb9944 100644 (file)
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -241,7 +241,12 @@ Handle<String> Shell::ReadFromStdin() {
     // Continue reading if the line ends with an escape '\\' or the line has
     // not been fully read into the buffer yet (does not end with '\n').
     // If fgets gets an error, just give up.
-    if (fgets(buffer, kBufferSize, stdin) == NULL) return Handle<String>();
+    char* input = NULL;
+    {  // Release lock for blocking input.
+      Unlocker unlock(Isolate::GetCurrent());
+      input = fgets(buffer, kBufferSize, stdin);
+    }
+    if (input == NULL) return Handle<String>();
     length = static_cast<int>(strlen(buffer));
     if (length == 0) {
       return accumulator;
@@ -604,6 +609,12 @@ Handle<Value> Shell::DebugCommandToJSONRequest(Handle<String> command) {
   Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv);
   return val;
 }
+
+
+void Shell::DispatchDebugMessages() {
+  v8::Context::Scope scope(Shell::evaluation_context_);
+  v8::Debug::ProcessDebugMessages();
+}
 #endif  // ENABLE_DEBUGGER_SUPPORT
 #endif  // V8_SHARED
 
@@ -873,6 +884,7 @@ void Shell::Initialize() {
   // Start the debugger agent if requested.
   if (i::FLAG_debugger_agent) {
     v8::Debug::EnableAgent("d8 shell", i::FLAG_debugger_port, true);
+    v8::Debug::SetDebugMessageDispatchHandler(DispatchDebugMessages, true);
   }
 #endif  // ENABLE_DEBUGGER_SUPPORT
 #endif  // V8_SHARED
index e9b417b..60a8c1b 100644 (file)
--- a/src/d8.h
+++ b/src/d8.h
@@ -266,12 +266,13 @@ class Shell : public i::AllStatic {
                                size_t buckets);
   static void AddHistogramSample(void* histogram, int sample);
   static void MapCounters(const char* name);
-#endif  // V8_SHARED
 
 #ifdef ENABLE_DEBUGGER_SUPPORT
   static Handle<Object> DebugMessageDetails(Handle<String> message);
   static Handle<Value> DebugCommandToJSONRequest(Handle<String> command);
-#endif
+  static void DispatchDebugMessages();
+#endif  // ENABLE_DEBUGGER_SUPPORT
+#endif  // V8_SHARED
 
 #ifdef WIN32
 #undef Yield