Commit 75350f1e authored by yangguo's avatar yangguo Committed by Commit bot

Debugger: require debugger to be active when dealing with breaks.

This invariant will save us some head ache.
The changes to test-debug/DebugStub is due to the fact that it abuses
the ability to set break points in code that has no debug break slots.
This is now no longer possible.

R=ulan@chromium.org
BUG=v8:4132
LOG=N

Review URL: https://codereview.chromium.org/1181013007

Cr-Commit-Position: refs/heads/master@{#29038}
parent 2c44f4f9
...@@ -58,6 +58,23 @@ static v8::Handle<v8::Context> GetDebugEventContext(Isolate* isolate) { ...@@ -58,6 +58,23 @@ static v8::Handle<v8::Context> GetDebugEventContext(Isolate* isolate) {
} }
BreakLocation::BreakLocation(Handle<DebugInfo> debug_info, RelocInfo* rinfo,
RelocInfo* original_rinfo, int position,
int statement_position)
: debug_info_(debug_info),
pc_offset_(static_cast<int>(rinfo->pc() - debug_info->code()->entry())),
original_pc_offset_(static_cast<int>(
original_rinfo->pc() - debug_info->original_code()->entry())),
rmode_(rinfo->rmode()),
original_rmode_(original_rinfo->rmode()),
data_(rinfo->data()),
original_data_(original_rinfo->data()),
position_(position),
statement_position_(statement_position) {
DCHECK(debug_info_->GetIsolate()->debug()->is_active());
}
BreakLocation::Iterator::Iterator(Handle<DebugInfo> debug_info, BreakLocation::Iterator::Iterator(Handle<DebugInfo> debug_info,
BreakLocatorType type) BreakLocatorType type)
: debug_info_(debug_info), : debug_info_(debug_info),
...@@ -503,6 +520,8 @@ ScriptCache::ScriptCache(Isolate* isolate) : isolate_(isolate) { ...@@ -503,6 +520,8 @@ ScriptCache::ScriptCache(Isolate* isolate) : isolate_(isolate) {
Heap* heap = isolate_->heap(); Heap* heap = isolate_->heap();
HandleScope scope(isolate_); HandleScope scope(isolate_);
DCHECK(isolate_->debug()->is_active());
// Perform a GC to get rid of all unreferenced scripts. // Perform a GC to get rid of all unreferenced scripts.
heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "ScriptCache"); heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "ScriptCache");
...@@ -2941,16 +2960,17 @@ void Debug::SetMessageHandler(v8::Debug::MessageHandler handler) { ...@@ -2941,16 +2960,17 @@ void Debug::SetMessageHandler(v8::Debug::MessageHandler handler) {
void Debug::UpdateState() { void Debug::UpdateState() {
is_active_ = message_handler_ != NULL || !event_listener_.is_null(); bool is_active = message_handler_ != NULL || !event_listener_.is_null();
if (is_active_ || in_debug_scope()) { if (is_active || in_debug_scope()) {
// Note that the debug context could have already been loaded to // Note that the debug context could have already been loaded to
// bootstrap test cases. // bootstrap test cases.
isolate_->compilation_cache()->Disable(); isolate_->compilation_cache()->Disable();
is_active_ = Load(); is_active = Load();
} else if (is_loaded()) { } else if (is_loaded()) {
isolate_->compilation_cache()->Enable(); isolate_->compilation_cache()->Enable();
Unload(); Unload();
} }
is_active_ = is_active;
} }
......
...@@ -129,17 +129,8 @@ class BreakLocation { ...@@ -129,17 +129,8 @@ class BreakLocation {
private: private:
BreakLocation(Handle<DebugInfo> debug_info, RelocInfo* rinfo, BreakLocation(Handle<DebugInfo> debug_info, RelocInfo* rinfo,
RelocInfo* original_rinfo, int position, int statement_position) RelocInfo* original_rinfo, int position,
: debug_info_(debug_info), int statement_position);
pc_offset_(static_cast<int>(rinfo->pc() - debug_info->code()->entry())),
original_pc_offset_(static_cast<int>(
original_rinfo->pc() - debug_info->original_code()->entry())),
rmode_(rinfo->rmode()),
original_rmode_(original_rinfo->rmode()),
data_(rinfo->data()),
original_data_(original_rinfo->data()),
position_(position),
statement_position_(statement_position) {}
class Iterator { class Iterator {
public: public:
...@@ -526,7 +517,8 @@ class Debug { ...@@ -526,7 +517,8 @@ class Debug {
static void RecordEvalCaller(Handle<Script> script); static void RecordEvalCaller(Handle<Script> script);
bool CheckExecutionState(int id) { bool CheckExecutionState(int id) {
return !debug_context().is_null() && break_id() != 0 && break_id() == id; return is_active() && !debug_context().is_null() && break_id() != 0 &&
break_id() == id;
} }
// Flags and states. // Flags and states.
......
...@@ -2183,7 +2183,7 @@ static bool IsPositionAlignmentCodeCorrect(int alignment) { ...@@ -2183,7 +2183,7 @@ static bool IsPositionAlignmentCodeCorrect(int alignment) {
RUNTIME_FUNCTION(Runtime_GetBreakLocations) { RUNTIME_FUNCTION(Runtime_GetBreakLocations) {
HandleScope scope(isolate); HandleScope scope(isolate);
DCHECK(args.length() == 2); DCHECK(args.length() == 2);
RUNTIME_ASSERT(isolate->debug()->is_active());
CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0); CONVERT_ARG_HANDLE_CHECKED(JSFunction, fun, 0);
CONVERT_NUMBER_CHECKED(int32_t, statement_aligned_code, Int32, args[1]); CONVERT_NUMBER_CHECKED(int32_t, statement_aligned_code, Int32, args[1]);
...@@ -2211,6 +2211,7 @@ RUNTIME_FUNCTION(Runtime_GetBreakLocations) { ...@@ -2211,6 +2211,7 @@ RUNTIME_FUNCTION(Runtime_GetBreakLocations) {
RUNTIME_FUNCTION(Runtime_SetFunctionBreakPoint) { RUNTIME_FUNCTION(Runtime_SetFunctionBreakPoint) {
HandleScope scope(isolate); HandleScope scope(isolate);
DCHECK(args.length() == 3); DCHECK(args.length() == 3);
RUNTIME_ASSERT(isolate->debug()->is_active());
CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]); CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]);
RUNTIME_ASSERT(source_position >= function->shared()->start_position() && RUNTIME_ASSERT(source_position >= function->shared()->start_position() &&
...@@ -2235,6 +2236,7 @@ RUNTIME_FUNCTION(Runtime_SetFunctionBreakPoint) { ...@@ -2235,6 +2236,7 @@ RUNTIME_FUNCTION(Runtime_SetFunctionBreakPoint) {
RUNTIME_FUNCTION(Runtime_SetScriptBreakPoint) { RUNTIME_FUNCTION(Runtime_SetScriptBreakPoint) {
HandleScope scope(isolate); HandleScope scope(isolate);
DCHECK(args.length() == 4); DCHECK(args.length() == 4);
RUNTIME_ASSERT(isolate->debug()->is_active());
CONVERT_ARG_HANDLE_CHECKED(JSValue, wrapper, 0); CONVERT_ARG_HANDLE_CHECKED(JSValue, wrapper, 0);
CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]); CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]);
RUNTIME_ASSERT(source_position >= 0); RUNTIME_ASSERT(source_position >= 0);
...@@ -2266,6 +2268,7 @@ RUNTIME_FUNCTION(Runtime_SetScriptBreakPoint) { ...@@ -2266,6 +2268,7 @@ RUNTIME_FUNCTION(Runtime_SetScriptBreakPoint) {
RUNTIME_FUNCTION(Runtime_ClearBreakPoint) { RUNTIME_FUNCTION(Runtime_ClearBreakPoint) {
HandleScope scope(isolate); HandleScope scope(isolate);
DCHECK(args.length() == 1); DCHECK(args.length() == 1);
RUNTIME_ASSERT(isolate->debug()->is_active());
CONVERT_ARG_HANDLE_CHECKED(Object, break_point_object_arg, 0); CONVERT_ARG_HANDLE_CHECKED(Object, break_point_object_arg, 0);
// Clear break point. // Clear break point.
...@@ -2363,6 +2366,7 @@ RUNTIME_FUNCTION(Runtime_PrepareStep) { ...@@ -2363,6 +2366,7 @@ RUNTIME_FUNCTION(Runtime_PrepareStep) {
RUNTIME_FUNCTION(Runtime_ClearStepping) { RUNTIME_FUNCTION(Runtime_ClearStepping) {
HandleScope scope(isolate); HandleScope scope(isolate);
DCHECK(args.length() == 0); DCHECK(args.length() == 0);
RUNTIME_ASSERT(isolate->debug()->is_active());
isolate->debug()->ClearStepping(); isolate->debug()->ClearStepping();
return isolate->heap()->undefined_value(); return isolate->heap()->undefined_value();
} }
...@@ -2709,6 +2713,7 @@ RUNTIME_FUNCTION(Runtime_DebugEvaluateGlobal) { ...@@ -2709,6 +2713,7 @@ RUNTIME_FUNCTION(Runtime_DebugEvaluateGlobal) {
RUNTIME_FUNCTION(Runtime_DebugGetLoadedScripts) { RUNTIME_FUNCTION(Runtime_DebugGetLoadedScripts) {
HandleScope scope(isolate); HandleScope scope(isolate);
DCHECK(args.length() == 0); DCHECK(args.length() == 0);
RUNTIME_ASSERT(isolate->debug()->is_active());
Handle<FixedArray> instances; Handle<FixedArray> instances;
{ {
...@@ -2976,6 +2981,7 @@ RUNTIME_FUNCTION(Runtime_GetFunctionCodePositionFromSource) { ...@@ -2976,6 +2981,7 @@ RUNTIME_FUNCTION(Runtime_GetFunctionCodePositionFromSource) {
HandleScope scope(isolate); HandleScope scope(isolate);
CHECK(isolate->debug()->live_edit_enabled()); CHECK(isolate->debug()->live_edit_enabled());
DCHECK(args.length() == 2); DCHECK(args.length() == 2);
RUNTIME_ASSERT(isolate->debug()->is_active());
CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]); CONVERT_NUMBER_CHECKED(int32_t, source_position, Int32, args[1]);
...@@ -3117,6 +3123,8 @@ RUNTIME_FUNCTION(Runtime_DebugCallbackSupportsStepping) { ...@@ -3117,6 +3123,8 @@ RUNTIME_FUNCTION(Runtime_DebugCallbackSupportsStepping) {
// built-in function such as Array.forEach to enable stepping into the callback. // built-in function such as Array.forEach to enable stepping into the callback.
RUNTIME_FUNCTION(Runtime_DebugPrepareStepInIfStepping) { RUNTIME_FUNCTION(Runtime_DebugPrepareStepInIfStepping) {
DCHECK(args.length() == 1); DCHECK(args.length() == 1);
RUNTIME_ASSERT(isolate->debug()->is_active());
Debug* debug = isolate->debug(); Debug* debug = isolate->debug();
if (!debug->IsStepping()) return isolate->heap()->undefined_value(); if (!debug->IsStepping()) return isolate->heap()->undefined_value();
......
...@@ -575,6 +575,18 @@ static inline void SimulateIncrementalMarking(i::Heap* heap) { ...@@ -575,6 +575,18 @@ static inline void SimulateIncrementalMarking(i::Heap* heap) {
} }
static void DummyDebugEventListener(
const v8::Debug::EventDetails& event_details) {}
static inline void EnableDebugger() {
v8::Debug::SetDebugEventListener(&DummyDebugEventListener);
}
static inline void DisableDebugger() { v8::Debug::SetDebugEventListener(NULL); }
// Helper class for new allocations tracking and checking. // Helper class for new allocations tracking and checking.
// To use checking of JS allocations tracking in a test, // To use checking of JS allocations tracking in a test,
// just create an instance of this class. // just create an instance of this class.
......
...@@ -20960,6 +20960,7 @@ TEST(StreamingWithDebuggingDoesNotProduceParserCache) { ...@@ -20960,6 +20960,7 @@ TEST(StreamingWithDebuggingDoesNotProduceParserCache) {
CompileRun("function break_here() { }"); CompileRun("function break_here() { }");
i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast( i::Handle<i::JSFunction> func = i::Handle<i::JSFunction>::cast(
v8::Utils::OpenHandle(*env->Global()->Get(v8_str("break_here")))); v8::Utils::OpenHandle(*env->Global()->Get(v8_str("break_here"))));
EnableDebugger();
v8::internal::Debug* debug = CcTest::i_isolate()->debug(); v8::internal::Debug* debug = CcTest::i_isolate()->debug();
int position = 0; int position = 0;
debug->SetBreakPoint(func, i::Handle<i::Object>(v8::internal::Smi::FromInt(1), debug->SetBreakPoint(func, i::Handle<i::Object>(v8::internal::Smi::FromInt(1),
...@@ -20980,6 +20981,7 @@ TEST(StreamingWithDebuggingDoesNotProduceParserCache) { ...@@ -20980,6 +20981,7 @@ TEST(StreamingWithDebuggingDoesNotProduceParserCache) {
// Check that we got no cached data. // Check that we got no cached data.
CHECK(source.GetCachedData() == NULL); CHECK(source.GetCachedData() == NULL);
DisableDebugger();
} }
......
...@@ -445,6 +445,7 @@ void CheckDebugBreakFunction(DebugLocalContext* env, ...@@ -445,6 +445,7 @@ void CheckDebugBreakFunction(DebugLocalContext* env,
const char* source, const char* name, const char* source, const char* name,
int position, v8::internal::RelocInfo::Mode mode, int position, v8::internal::RelocInfo::Mode mode,
Code* debug_break) { Code* debug_break) {
EnableDebugger();
i::Debug* debug = CcTest::i_isolate()->debug(); i::Debug* debug = CcTest::i_isolate()->debug();
// Create function and set the break point. // Create function and set the break point.
...@@ -488,6 +489,8 @@ void CheckDebugBreakFunction(DebugLocalContext* env, ...@@ -488,6 +489,8 @@ void CheckDebugBreakFunction(DebugLocalContext* env,
i::RelocInfo rinfo = location.rinfo(); i::RelocInfo rinfo = location.rinfo();
CHECK(!rinfo.IsPatchedReturnSequence()); CHECK(!rinfo.IsPatchedReturnSequence());
} }
DisableDebugger();
} }
...@@ -986,12 +989,10 @@ TEST(DebugStub) { ...@@ -986,12 +989,10 @@ TEST(DebugStub) {
v8::internal::RelocInfo::CODE_TARGET, v8::internal::RelocInfo::CODE_TARGET,
CcTest::i_isolate()->builtins()->builtin( CcTest::i_isolate()->builtins()->builtin(
Builtins::kStoreIC_DebugBreak)); Builtins::kStoreIC_DebugBreak));
CheckDebugBreakFunction(&env, CheckDebugBreakFunction(
"function f3(){var a=x;}", "f3", &env, "function f3(){x();}", "f3", 0,
0, v8::internal::RelocInfo::CODE_TARGET,
v8::internal::RelocInfo::CODE_TARGET, CcTest::i_isolate()->builtins()->builtin(Builtins::kLoadIC_DebugBreak));
CcTest::i_isolate()->builtins()->builtin(
Builtins::kLoadIC_DebugBreak));
// TODO(1240753): Make the test architecture independent or split // TODO(1240753): Make the test architecture independent or split
// parts of the debugger into architecture dependent files. This // parts of the debugger into architecture dependent files. This
...@@ -1001,29 +1002,21 @@ TEST(DebugStub) { ...@@ -1001,29 +1002,21 @@ TEST(DebugStub) {
CheckDebugBreakFunction( CheckDebugBreakFunction(
&env, &env,
"function f4(){var index='propertyName'; var a={}; a[index] = 'x';}", "function f4(){var index='propertyName'; var a={}; a[index] = 'x';}",
"f4", "f4", 39, v8::internal::RelocInfo::CODE_TARGET,
0,
v8::internal::RelocInfo::CODE_TARGET,
CcTest::i_isolate()->builtins()->builtin( CcTest::i_isolate()->builtins()->builtin(
Builtins::kKeyedStoreIC_DebugBreak)); Builtins::kKeyedStoreIC_DebugBreak));
CheckDebugBreakFunction( CheckDebugBreakFunction(
&env, &env,
"function f5(){var index='propertyName'; var a={}; return a[index];}", "function f5(){var index='propertyName'; var a={}; return a[index];}",
"f5", "f5", 39, v8::internal::RelocInfo::CODE_TARGET,
0,
v8::internal::RelocInfo::CODE_TARGET,
CcTest::i_isolate()->builtins()->builtin( CcTest::i_isolate()->builtins()->builtin(
Builtins::kKeyedLoadIC_DebugBreak)); Builtins::kKeyedLoadIC_DebugBreak));
#endif #endif
CheckDebugBreakFunction( CheckDebugBreakFunction(&env, "function f6(){(0==null)()}", "f6", 0,
&env, v8::internal::RelocInfo::CODE_TARGET,
"function f6(a){return a==null;}", CcTest::i_isolate()->builtins()->builtin(
"f6", Builtins::kCompareNilIC_DebugBreak));
0,
v8::internal::RelocInfo::CODE_TARGET,
CcTest::i_isolate()->builtins()->builtin(
Builtins::kCompareNilIC_DebugBreak));
// Check the debug break code stubs for call ICs with different number of // Check the debug break code stubs for call ICs with different number of
// parameters. // parameters.
...@@ -1066,6 +1059,7 @@ TEST(DebugInfo) { ...@@ -1066,6 +1059,7 @@ TEST(DebugInfo) {
CHECK_EQ(0, v8::internal::GetDebuggedFunctions()->length()); CHECK_EQ(0, v8::internal::GetDebuggedFunctions()->length());
CHECK(!HasDebugInfo(foo)); CHECK(!HasDebugInfo(foo));
CHECK(!HasDebugInfo(bar)); CHECK(!HasDebugInfo(bar));
EnableDebugger();
// One function (foo) is debugged. // One function (foo) is debugged.
int bp1 = SetBreakPoint(foo, 0); int bp1 = SetBreakPoint(foo, 0);
CHECK_EQ(1, v8::internal::GetDebuggedFunctions()->length()); CHECK_EQ(1, v8::internal::GetDebuggedFunctions()->length());
...@@ -1083,6 +1077,7 @@ TEST(DebugInfo) { ...@@ -1083,6 +1077,7 @@ TEST(DebugInfo) {
CHECK(HasDebugInfo(bar)); CHECK(HasDebugInfo(bar));
// No functions are debugged. // No functions are debugged.
ClearBreakPoint(bp2); ClearBreakPoint(bp2);
DisableDebugger();
CHECK_EQ(0, v8::internal::GetDebuggedFunctions()->length()); CHECK_EQ(0, v8::internal::GetDebuggedFunctions()->length());
CHECK(!HasDebugInfo(foo)); CHECK(!HasDebugInfo(foo));
CHECK(!HasDebugInfo(bar)); CHECK(!HasDebugInfo(bar));
...@@ -2290,11 +2285,12 @@ TEST(RemoveBreakPointInBreak) { ...@@ -2290,11 +2285,12 @@ TEST(RemoveBreakPointInBreak) {
v8::Local<v8::Function> foo = v8::Local<v8::Function> foo =
CompileFunction(&env, "function foo(){a=1;}", "foo"); CompileFunction(&env, "function foo(){a=1;}", "foo");
debug_event_remove_break_point = SetBreakPoint(foo, 0);
// Register the debug event listener pasing the function // Register the debug event listener pasing the function
v8::Debug::SetDebugEventListener(DebugEventRemoveBreakPoint, foo); v8::Debug::SetDebugEventListener(DebugEventRemoveBreakPoint, foo);
debug_event_remove_break_point = SetBreakPoint(foo, 0);
break_point_hit_count = 0; break_point_hit_count = 0;
foo->Call(env->Global(), 0, NULL); foo->Call(env->Global(), 0, NULL);
CHECK_EQ(1, break_point_hit_count); CHECK_EQ(1, break_point_hit_count);
...@@ -2781,11 +2777,11 @@ TEST(DebugStepLinear) { ...@@ -2781,11 +2777,11 @@ TEST(DebugStepLinear) {
// Run foo to allow it to get optimized. // Run foo to allow it to get optimized.
CompileRun("a=0; b=0; c=0; foo();"); CompileRun("a=0; b=0; c=0; foo();");
SetBreakPoint(foo, 3);
// Register a debug event listener which steps and counts. // Register a debug event listener which steps and counts.
v8::Debug::SetDebugEventListener(DebugEventStep); v8::Debug::SetDebugEventListener(DebugEventStep);
SetBreakPoint(foo, 3);
step_action = StepIn; step_action = StepIn;
break_point_hit_count = 0; break_point_hit_count = 0;
foo->Call(env->Global(), 0, NULL); foo->Call(env->Global(), 0, NULL);
...@@ -5579,11 +5575,6 @@ TEST(RecursiveBreakpointsGlobal) { ...@@ -5579,11 +5575,6 @@ TEST(RecursiveBreakpointsGlobal) {
} }
static void DummyDebugEventListener(
const v8::Debug::EventDetails& event_details) {
}
TEST(SetDebugEventListenerOnUninitializedVM) { TEST(SetDebugEventListenerOnUninitializedVM) {
v8::Debug::SetDebugEventListener(DummyDebugEventListener); v8::Debug::SetDebugEventListener(DummyDebugEventListener);
} }
...@@ -5957,7 +5948,7 @@ TEST(DebugGetLoadedScripts) { ...@@ -5957,7 +5948,7 @@ TEST(DebugGetLoadedScripts) {
v8::String::NewExternal(env->GetIsolate(), &source_ext_str); v8::String::NewExternal(env->GetIsolate(), &source_ext_str);
v8::Handle<v8::Script> evil_script(v8::Script::Compile(source)); v8::Handle<v8::Script> evil_script(v8::Script::Compile(source));
// "use" evil_script to make the compiler happy. // "use" evil_script to make the compiler happy.
(void) evil_script; USE(evil_script);
Handle<i::ExternalTwoByteString> i_source( Handle<i::ExternalTwoByteString> i_source(
i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source))); i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source)));
// This situation can happen if source was an external string disposed // This situation can happen if source was an external string disposed
...@@ -5966,12 +5957,14 @@ TEST(DebugGetLoadedScripts) { ...@@ -5966,12 +5957,14 @@ TEST(DebugGetLoadedScripts) {
bool allow_natives_syntax = i::FLAG_allow_natives_syntax; bool allow_natives_syntax = i::FLAG_allow_natives_syntax;
i::FLAG_allow_natives_syntax = true; i::FLAG_allow_natives_syntax = true;
EnableDebugger();
CompileRun( CompileRun(
"var scripts = %DebugGetLoadedScripts();" "var scripts = %DebugGetLoadedScripts();"
"var count = scripts.length;" "var count = scripts.length;"
"for (var i = 0; i < count; ++i) {" "for (var i = 0; i < count; ++i) {"
" scripts[i].line_ends;" " scripts[i].line_ends;"
"}"); "}");
DisableDebugger();
// Must not crash while accessing line_ends. // Must not crash while accessing line_ends.
i::FLAG_allow_natives_syntax = allow_natives_syntax; i::FLAG_allow_natives_syntax = allow_natives_syntax;
...@@ -6539,6 +6532,8 @@ TEST(ProvisionalBreakpointOnLineOutOfRange) { ...@@ -6539,6 +6532,8 @@ TEST(ProvisionalBreakpointOnLineOutOfRange) {
const char* script = "function f() {};"; const char* script = "function f() {};";
const char* resource_name = "test_resource"; const char* resource_name = "test_resource";
v8::Debug::SetMessageHandler(AfterCompileMessageHandler);
// Set a couple of provisional breakpoint on lines out of the script lines // Set a couple of provisional breakpoint on lines out of the script lines
// range. // range.
int sbp1 = SetScriptBreakPointByNameFromJS(env->GetIsolate(), resource_name, int sbp1 = SetScriptBreakPointByNameFromJS(env->GetIsolate(), resource_name,
...@@ -6547,7 +6542,6 @@ TEST(ProvisionalBreakpointOnLineOutOfRange) { ...@@ -6547,7 +6542,6 @@ TEST(ProvisionalBreakpointOnLineOutOfRange) {
SetScriptBreakPointByNameFromJS(env->GetIsolate(), resource_name, 5, 5); SetScriptBreakPointByNameFromJS(env->GetIsolate(), resource_name, 5, 5);
after_compile_message_count = 0; after_compile_message_count = 0;
v8::Debug::SetMessageHandler(AfterCompileMessageHandler);
v8::ScriptOrigin origin( v8::ScriptOrigin origin(
v8::String::NewFromUtf8(env->GetIsolate(), resource_name), v8::String::NewFromUtf8(env->GetIsolate(), resource_name),
......
...@@ -1382,8 +1382,10 @@ TEST(TestCodeFlushingIncrementalAbort) { ...@@ -1382,8 +1382,10 @@ TEST(TestCodeFlushingIncrementalAbort) {
// disabled. // disabled.
int position = 0; int position = 0;
Handle<Object> breakpoint_object(Smi::FromInt(0), isolate); Handle<Object> breakpoint_object(Smi::FromInt(0), isolate);
EnableDebugger();
isolate->debug()->SetBreakPoint(function, breakpoint_object, &position); isolate->debug()->SetBreakPoint(function, breakpoint_object, &position);
isolate->debug()->ClearAllBreakPoints(); isolate->debug()->ClearAllBreakPoints();
DisableDebugger();
// Force optimization now that code flushing is disabled. // Force optimization now that code flushing is disabled.
{ v8::HandleScope scope(CcTest::isolate()); { v8::HandleScope scope(CcTest::isolate());
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
// Get the Debug object exposed from the debug context global object. // Get the Debug object exposed from the debug context global object.
Debug = debug.Debug Debug = debug.Debug
Debug.setListener(function(){});
var function_z_text = var function_z_text =
" function Z() {\n" " function Z() {\n"
...@@ -111,3 +112,4 @@ for (var i = 0; i < breaks_ids.length; i++) { ...@@ -111,3 +112,4 @@ for (var i = 0; i < breaks_ids.length; i++) {
} }
assertEquals(0, Debug.scriptBreakPoints().length); assertEquals(0, Debug.scriptBreakPoints().length);
Debug.setListener(null);
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
// corresponding byte-code PCs should coincide before change and after it. // corresponding byte-code PCs should coincide before change and after it.
Debug = debug.Debug Debug = debug.Debug
Debug.setListener(function() {});
eval( eval(
"function F1() { return 5; }\n" + "function F1() { return 5; }\n" +
...@@ -124,3 +125,5 @@ print(pcArray2); ...@@ -124,3 +125,5 @@ print(pcArray2);
if (pcArray1 && pcArray2) { if (pcArray1 && pcArray2) {
assertArrayEquals(pcArray1, pcArray2); assertArrayEquals(pcArray1, pcArray2);
} }
Debug.setListener(null);
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
// Get the Debug object exposed from the debug context global object. // Get the Debug object exposed from the debug context global object.
Debug = debug.Debug; Debug = debug.Debug;
Debug.setListener(listener);
SlimFunction = eval( SlimFunction = eval(
"(function() {\n " + "(function() {\n " +
...@@ -76,7 +77,6 @@ function listener(event, exec_state, event_data, data) { ...@@ -76,7 +77,6 @@ function listener(event, exec_state, event_data, data) {
} }
} }
Debug.setListener(listener);
var animal = SlimFunction(); var animal = SlimFunction();
...@@ -86,3 +86,5 @@ if (saved_exception) { ...@@ -86,3 +86,5 @@ if (saved_exception) {
} }
assertEquals("Capybara", animal); assertEquals("Capybara", animal);
Debug.setListener(null);
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
// Flags: --expose-debug-as debug // Flags: --expose-debug-as debug
// Get the Debug object exposed from the debug context global object. // Get the Debug object exposed from the debug context global object.
Debug = debug.Debug Debug = debug.Debug
Debug.setListener(function(){});
// Set and remove a script break point for a named script. // Set and remove a script break point for a named script.
var sbp = Debug.setScriptBreakPointByName("1", 2, 3); var sbp = Debug.setScriptBreakPointByName("1", 2, 3);
...@@ -110,3 +111,5 @@ Debug.clearBreakPoint(sbp3); ...@@ -110,3 +111,5 @@ Debug.clearBreakPoint(sbp3);
assertEquals(1, Debug.scriptBreakPoints().length); assertEquals(1, Debug.scriptBreakPoints().length);
Debug.clearBreakPoint(sbp2); Debug.clearBreakPoint(sbp2);
assertEquals(0, Debug.scriptBreakPoints().length); assertEquals(0, Debug.scriptBreakPoints().length);
Debug.setListener(null);
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
// Get the Debug object exposed from the debug context global object. // Get the Debug object exposed from the debug context global object.
Debug = debug.Debug; Debug = debug.Debug;
Debug.setListener(function(){});
Date(); Date();
RegExp(); RegExp();
...@@ -103,3 +104,5 @@ assertEquals(Debug.ScriptType.Normal, debug_script.type); ...@@ -103,3 +104,5 @@ assertEquals(Debug.ScriptType.Normal, debug_script.type);
// Check a nonexistent script. // Check a nonexistent script.
var dummy_script = Debug.findScript('dummy.js'); var dummy_script = Debug.findScript('dummy.js');
assertTrue(typeof dummy_script == 'undefined'); assertTrue(typeof dummy_script == 'undefined');
Debug.setListener(null);
...@@ -33,7 +33,7 @@ function DebuggerStatement() { ...@@ -33,7 +33,7 @@ function DebuggerStatement() {
debugger; /*pause*/ debugger; /*pause*/
} }
function TestCase(fun, frame_number) { function TestCase(fun, frame_number, line_number) {
var exception = false; var exception = false;
var codeSnippet = undefined; var codeSnippet = undefined;
var resultPositions = undefined; var resultPositions = undefined;
...@@ -64,8 +64,13 @@ function TestCase(fun, frame_number) { ...@@ -64,8 +64,13 @@ function TestCase(fun, frame_number) {
Debug.setListener(listener); Debug.setListener(listener);
var breakpointId;
if (line_number) breakpointId = Debug.setBreakPoint(fun, line_number);
fun(); fun();
if (line_number) Debug.clearBreakPoint(breakpointId);
Debug.setListener(null); Debug.setListener(null);
assertTrue(!exception, exception); assertTrue(!exception, exception);
...@@ -116,9 +121,7 @@ function TestCaseWithDebugger(fun) { ...@@ -116,9 +121,7 @@ function TestCaseWithDebugger(fun) {
} }
function TestCaseWithBreakpoint(fun, line_number, frame_number) { function TestCaseWithBreakpoint(fun, line_number, frame_number) {
var breakpointId = Debug.setBreakPoint(fun, line_number); TestCase(fun, frame_number, line_number);
TestCase(fun, frame_number);
Debug.clearBreakPoint(breakpointId);
} }
function TestCaseWithException(fun, frame_number) { function TestCaseWithException(fun, frame_number) {
......
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
// Flags: --allow-natives-syntax --cache=code // Flags: --allow-natives-syntax --cache=code
// Test that script ids are unique and we found the correct ones. // Test that script ids are unique and we found the correct ones.
var Debug = %GetDebugContext().Debug;
Debug.setListener(function(){});
var scripts = %DebugGetLoadedScripts(); var scripts = %DebugGetLoadedScripts();
scripts.sort(function(a, b) { return a.id - b.id; }); scripts.sort(function(a, b) { return a.id - b.id; });
var user_script_count = 0; var user_script_count = 0;
...@@ -15,3 +18,5 @@ scripts.reduce(function(prev, cur) { ...@@ -15,3 +18,5 @@ scripts.reduce(function(prev, cur) {
// Found mjsunit.js and this script. // Found mjsunit.js and this script.
assertEquals(2, user_script_count); assertEquals(2, user_script_count);
Debug.setListener(null);
...@@ -48,8 +48,6 @@ function f() { ...@@ -48,8 +48,6 @@ function f() {
// Get the Debug object exposed from the debug context global object. // Get the Debug object exposed from the debug context global object.
var Debug = debug.Debug var Debug = debug.Debug
// Set breakpoint on line 6.
var bp = Debug.setBreakPoint(f, 6);
function listener(event, exec_state, event_data, data) { function listener(event, exec_state, event_data, data) {
if (event == Debug.DebugEvent.Break) { if (event == Debug.DebugEvent.Break) {
...@@ -59,6 +57,10 @@ function listener(event, exec_state, event_data, data) { ...@@ -59,6 +57,10 @@ function listener(event, exec_state, event_data, data) {
// Add the debug event listener. // Add the debug event listener.
Debug.setListener(listener); Debug.setListener(listener);
//Set breakpoint on line 6.
var bp = Debug.setBreakPoint(f, 6);
result = -1; result = -1;
f(); f();
assertEquals(1, result); assertEquals(1, result);
...@@ -107,3 +109,5 @@ assertEquals(null, exception, exception); ...@@ -107,3 +109,5 @@ assertEquals(null, exception, exception);
exception = null; exception = null;
f2(); f2();
assertEquals(null, exception, exception); assertEquals(null, exception, exception);
Debug.setListener(null);
...@@ -25,13 +25,13 @@ function RunTest(formals_and_body, args, value1, value2) { ...@@ -25,13 +25,13 @@ function RunTest(formals_and_body, args, value1, value2) {
// Advance to the first yield. // Advance to the first yield.
assertIteratorResult(value1, false, obj.next()); assertIteratorResult(value1, false, obj.next());
// Add a breakpoint on line 3 (the second yield).
var bp = Debug.setBreakPoint(gen, 3);
// Enable the debugger, which should force recompilation of the generator // Enable the debugger, which should force recompilation of the generator
// function and relocation of the suspended generator activation. // function and relocation of the suspended generator activation.
Debug.setListener(listener); Debug.setListener(listener);
// Add a breakpoint on line 3 (the second yield).
var bp = Debug.setBreakPoint(gen, 3);
// Check that the generator resumes and suspends properly. // Check that the generator resumes and suspends properly.
assertIteratorResult(value2, false, obj.next()); assertIteratorResult(value2, false, obj.next());
......
...@@ -43,8 +43,6 @@ function f() { ...@@ -43,8 +43,6 @@ function f() {
// Get the Debug object exposed from the debug context global object. // Get the Debug object exposed from the debug context global object.
Debug = debug.Debug Debug = debug.Debug
// Set breakpoint on line 6.
var bp = Debug.setBreakPoint(f, 6);
function listener(event, exec_state, event_data, data) { function listener(event, exec_state, event_data, data) {
if (event == Debug.DebugEvent.Break) { if (event == Debug.DebugEvent.Break) {
...@@ -54,6 +52,10 @@ function listener(event, exec_state, event_data, data) { ...@@ -54,6 +52,10 @@ function listener(event, exec_state, event_data, data) {
// Add the debug event listener. // Add the debug event listener.
Debug.setListener(listener); Debug.setListener(listener);
//Set breakpoint on line 6.
var bp = Debug.setBreakPoint(f, 6);
result = -1; result = -1;
f(); f();
assertEquals(1, result); assertEquals(1, result);
......
...@@ -56,11 +56,12 @@ function f() { ...@@ -56,11 +56,12 @@ function f() {
}; };
Debug = debug.Debug; Debug = debug.Debug;
var bp = Debug.setBreakPoint(f, 0);
function listener(event, exec_state, event_data, data) { function listener(event, exec_state, event_data, data) {
result = exec_state.frame().evaluate("i").value(); result = exec_state.frame().evaluate("i").value();
}; };
Debug.setListener(listener); Debug.setListener(listener);
var bp = Debug.setBreakPoint(f, 0);
assertThrows(function() { f(); }, RangeError); assertThrows(function() { f(); }, RangeError);
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
function sentinel() {} function sentinel() {}
Debug = debug.Debug; Debug = debug.Debug;
Debug.setListener(function(){});
var script = Debug.findScript(sentinel); var script = Debug.findScript(sentinel);
var line = 14; var line = 14;
...@@ -34,3 +35,5 @@ var actual = Debug.setBreakPointByScriptIdAndPosition( ...@@ -34,3 +35,5 @@ var actual = Debug.setBreakPointByScriptIdAndPosition(
// the break point. // the break point.
assertTrue(line_start <= actual); assertTrue(line_start <= actual);
assertTrue(actual <= line_end); assertTrue(actual <= line_end);
Debug.setListener(null);
...@@ -4,4 +4,9 @@ ...@@ -4,4 +4,9 @@
// Flags: --gc-interval=33 --expose-gc --allow-natives-syntax // Flags: --gc-interval=33 --expose-gc --allow-natives-syntax
var Debug = %GetDebugContext().Debug;
Debug.setListener(function(){});
%DebugGetLoadedScripts(); %DebugGetLoadedScripts();
Debug.setListener(null);
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
// Flags: --expose-debug-as debug // Flags: --expose-debug-as debug
Debug = debug.Debug Debug = debug.Debug
Debug.setListener(function(){});
function f() {a=1;b=2}; function f() {a=1;b=2};
function g() { function g() {
...@@ -46,3 +47,5 @@ Debug.clearBreakPoint(bp); ...@@ -46,3 +47,5 @@ Debug.clearBreakPoint(bp);
%OptimizeFunctionOnNextCall(Debug.setBreakPoint); %OptimizeFunctionOnNextCall(Debug.setBreakPoint);
bp = Debug.setBreakPoint(f, 0, 0); bp = Debug.setBreakPoint(f, 0, 0);
Debug.clearBreakPoint(bp); Debug.clearBreakPoint(bp);
Debug.setListener(null);
...@@ -54,8 +54,10 @@ foo(); ...@@ -54,8 +54,10 @@ foo();
// and (shared) unoptimized code on foo, and sets both to lazy-compile builtin. // and (shared) unoptimized code on foo, and sets both to lazy-compile builtin.
// Clear the break point immediately after to deactivate the debugger. // Clear the break point immediately after to deactivate the debugger.
// Do all of this after compile graph has been created. // Do all of this after compile graph has been created.
Debug.setListener(function(){});
Debug.setBreakPoint(bar, 0, 0); Debug.setBreakPoint(bar, 0, 0);
Debug.clearAllBreakPoints(); Debug.clearAllBreakPoints();
Debug.setListener(null);
// At this point, concurrent recompilation is still blocked. // At this point, concurrent recompilation is still blocked.
assertUnoptimized(foo, "no sync"); assertUnoptimized(foo, "no sync");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment