Reviewers: Mads Ager,

Description:
Add a test for debug break while running in an infinite loop

Fixed a bug where execution termination could get lost while leaving the
debugger.

Please review this at http://codereview.chromium.org/4405003/show

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

Affected files:
  M     src/debug.cc
  M     test/cctest/test-debug.cc


Index: src/debug.cc
===================================================================
--- src/debug.cc        (revision 5753)
+++ src/debug.cc        (working copy)
@@ -1839,6 +1839,7 @@


 void Debug::ClearMirrorCache() {
+  PostponeInterruptsScope postpone;
   HandleScope scope;
   ASSERT(Top::context() == *Debug::debug_context());

Index: test/cctest/test-debug.cc
===================================================================
--- test/cctest/test-debug.cc   (revision 5753)
+++ test/cctest/test-debug.cc   (working copy)
@@ -902,6 +902,7 @@
 // Debug event handler which re-issues a debug break until a limit has been
 // reached.
 int max_break_point_hit_count = 0;
+bool terminate_after_max_break_point_hit = false;
 static void DebugEventBreakMax(v8::DebugEvent event,
                                v8::Handle<v8::Object> exec_state,
                                v8::Handle<v8::Object> event_data,
@@ -909,12 +910,17 @@
   // When hitting a debug event listener there must be a break set.
   CHECK_NE(v8::internal::Debug::break_id(), 0);

- if (event == v8::Break && break_point_hit_count < max_break_point_hit_count) {
-    // Count the number of breaks.
-    break_point_hit_count++;
+  if (event == v8::Break) {
+    if (break_point_hit_count < max_break_point_hit_count) {
+      // Count the number of breaks.
+      break_point_hit_count++;

-    // Set the break flag again to come back here as soon as possible.
-    v8::Debug::DebugBreak();
+      // Set the break flag again to come back here as soon as possible.
+      v8::Debug::DebugBreak();
+    } else if (terminate_after_max_break_point_hit) {
+      // Terminate execution after the last break if requested.
+      v8::V8::TerminateExecution();
+    }
   }
 }

@@ -6892,4 +6898,33 @@
   CheckDebuggerUnloaded();
 }

+
+// Test that setting the terminate execution flag during debug break processing.
+TEST(DebugBreakLoop) {
+  v8::HandleScope scope;
+  DebugLocalContext env;
+
+  // Receive 100 breaks and terminate.
+  max_break_point_hit_count = 100;
+  terminate_after_max_break_point_hit = true;
+
+  // Register a debug event listener which sets the break flag and counts.
+  v8::Debug::SetDebugEventListener(DebugEventBreakMax);
+
+  // Function with infinite loop.
+  CompileRun("function f() { while (true) { } }");
+
+  // Set the debug break to enter the debugger as soon as possible.
+  v8::Debug::DebugBreak();
+
+  // Call function with infinite loop.
+  CompileRun("f();");
+  CHECK_EQ(100, break_point_hit_count);
+
+  // Get rid of the debug event listener.
+  v8::Debug::SetDebugEventListener(NULL);
+  CheckDebuggerUnloaded();
+}
+
+
 #endif  // ENABLE_DEBUGGER_SUPPORT


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

Reply via email to