Revision: 5771
Author: [email protected]
Date: Thu Nov 4 08:43:12 2010
Log: 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.
Review URL: http://codereview.chromium.org/4405003
http://code.google.com/p/v8/source/detail?r=5771
Modified:
/branches/bleeding_edge/src/debug.cc
/branches/bleeding_edge/test/cctest/test-debug.cc
=======================================
--- /branches/bleeding_edge/src/debug.cc Thu Oct 28 04:50:50 2010
+++ /branches/bleeding_edge/src/debug.cc Thu Nov 4 08:43:12 2010
@@ -1839,6 +1839,7 @@
void Debug::ClearMirrorCache() {
+ PostponeInterruptsScope postpone;
HandleScope scope;
ASSERT(Top::context() == *Debug::debug_context());
=======================================
--- /branches/bleeding_edge/test/cctest/test-debug.cc Mon Oct 18 05:58:56
2010
+++ /branches/bleeding_edge/test/cctest/test-debug.cc Thu Nov 4 08:43:12
2010
@@ -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++;
-
- // Set the break flag again to come back here as soon as possible.
- v8::Debug::DebugBreak();
+ 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();
+ } else if (terminate_after_max_break_point_hit) {
+ // Terminate execution after the last break if requested.
+ v8::V8::TerminateExecution();
+ }
}
}
@@ -6891,5 +6897,34 @@
v8::Debug::SetDebugEventListener(NULL);
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