Reviewers: Jakob,

Message:
When having a first instance of d8 started as debugger agent (--debugger-agent)
and a second instance as remote debugger (--remote-debugger), the second
instance crashes whenever unknown commands are issued. The reason is that when trying to output the exception to string using the js runtime, the context is
missing.

Description:
Fix remote debugger crash.


Please review this at http://codereview.chromium.org/9200006/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/d8-debug.h
  M src/d8-debug.cc
  M src/d8.cc


Index: src/d8-debug.cc
diff --git a/src/d8-debug.cc b/src/d8-debug.cc
index 1cbc0b39a018db7495aa8763d10853bffe5e9695..56f11a732137792a2aef8dc3706631c5f318cc8b 100644
--- a/src/d8-debug.cc
+++ b/src/d8-debug.cc
@@ -159,8 +159,8 @@ void HandleDebugEvent(DebugEvent event,
 }


-void RunRemoteDebugger(int port) {
-  RemoteDebugger debugger(port);
+void RunRemoteDebugger(int port, Handle<Context> context) {
+  RemoteDebugger debugger(port, context);
   debugger.Run();
 }

@@ -274,6 +274,7 @@ RemoteDebuggerEvent* RemoteDebugger::GetEvent() {

 void RemoteDebugger::HandleMessageReceived(char* message) {
   Locker lock;
+  Context::Scope cscope(context_);
   HandleScope scope;

   // Print the event details.
@@ -303,6 +304,7 @@ void RemoteDebugger::HandleMessageReceived(char* message) {

 void RemoteDebugger::HandleKeyboardCommand(char* command) {
   Locker lock;
+  Context::Scope cscope(context_);
   HandleScope scope;

   // Convert the debugger command to a JSON debugger request.
Index: src/d8-debug.h
diff --git a/src/d8-debug.h b/src/d8-debug.h
index aeff3c121c1b71244352d05fdc271327dbcb4283..694fa739fe01a989351b9470cd4d2e600092d40f 100644
--- a/src/d8-debug.h
+++ b/src/d8-debug.h
@@ -43,7 +43,7 @@ void HandleDebugEvent(DebugEvent event,

// Start the remove debugger connecting to a V8 debugger agent on the specified
 // port.
-void RunRemoteDebugger(int port);
+void RunRemoteDebugger(int port, Handle<Context> context);

 // Forward declerations.
 class RemoteDebuggerEvent;
@@ -53,11 +53,13 @@ class ReceiverThread;
 // Remote debugging class.
 class RemoteDebugger {
  public:
-  explicit RemoteDebugger(int port)
+  explicit RemoteDebugger(int port, Handle<Context> context)
       : port_(port),
         event_access_(i::OS::CreateMutex()),
         event_available_(i::OS::CreateSemaphore(0)),
-        head_(NULL), tail_(NULL) {}
+        head_(NULL),
+        tail_(NULL),
+        context_(context) {}
   void Run();

   // Handle events from the subordinate threads.
@@ -89,6 +91,7 @@ class RemoteDebugger {
   i::Semaphore* event_available_;
   RemoteDebuggerEvent* head_;
   RemoteDebuggerEvent* tail_;
+  Handle<Context> context_;

   friend class ReceiverThread;
 };
Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index b612c482a96573659a00b382050d54a4c34dd536..ffb077d3fdf0979fa6de4358373220be5ef7c08b 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -1456,7 +1456,7 @@ int Shell::Main(int argc, char* argv[]) {
   // Run remote debugger if requested, but never on --test
   if (i::FLAG_remote_debugger && !options.test_shell) {
     InstallUtilityScript();
-    RunRemoteDebugger(i::FLAG_debugger_port);
+    RunRemoteDebugger(i::FLAG_debugger_port, utility_context_);
     return 0;
   }
 #endif  // !V8_SHARED && ENABLE_DEBUGGER_SUPPORT


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to