Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: test/cctest/test-debug.cc

Issue 24220003: Remove default isolate usage from almost all tests (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 } 968 }
969 } 969 }
970 } 970 }
971 971
972 972
973 // Debug event handler which re-issues a debug break and calls the garbage 973 // Debug event handler which re-issues a debug break and calls the garbage
974 // collector to have the heap verified. 974 // collector to have the heap verified.
975 static void DebugEventBreak( 975 static void DebugEventBreak(
976 const v8::Debug::EventDetails& event_details) { 976 const v8::Debug::EventDetails& event_details) {
977 v8::DebugEvent event = event_details.GetEvent(); 977 v8::DebugEvent event = event_details.GetEvent();
978 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); 978 v8::internal::Debug* debug = CcTest::i_isolate()->debug();
979 // When hitting a debug event listener there must be a break set. 979 // When hitting a debug event listener there must be a break set.
980 CHECK_NE(debug->break_id(), 0); 980 CHECK_NE(debug->break_id(), 0);
981 981
982 if (event == v8::Break) { 982 if (event == v8::Break) {
983 // Count the number of breaks. 983 // Count the number of breaks.
984 break_point_hit_count++; 984 break_point_hit_count++;
985 985
986 // Run the garbage collector to enforce heap verification if option 986 // Run the garbage collector to enforce heap verification if option
987 // --verify-heap is set. 987 // --verify-heap is set.
988 HEAP->CollectGarbage(v8::internal::NEW_SPACE); 988 HEAP->CollectGarbage(v8::internal::NEW_SPACE);
989 989
990 // Set the break flag again to come back here as soon as possible. 990 // Set the break flag again to come back here as soon as possible.
991 v8::Debug::DebugBreak(); 991 v8::Debug::DebugBreak(CcTest::isolate());
992 } 992 }
993 } 993 }
994 994
995 995
996 // Debug event handler which re-issues a debug break until a limit has been 996 // Debug event handler which re-issues a debug break until a limit has been
997 // reached. 997 // reached.
998 int max_break_point_hit_count = 0; 998 int max_break_point_hit_count = 0;
999 bool terminate_after_max_break_point_hit = false; 999 bool terminate_after_max_break_point_hit = false;
1000 static void DebugEventBreakMax( 1000 static void DebugEventBreakMax(
1001 const v8::Debug::EventDetails& event_details) { 1001 const v8::Debug::EventDetails& event_details) {
1002 v8::DebugEvent event = event_details.GetEvent(); 1002 v8::DebugEvent event = event_details.GetEvent();
1003 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState(); 1003 v8::Handle<v8::Object> exec_state = event_details.GetExecutionState();
1004 v8::internal::Isolate* isolate = v8::internal::Isolate::Current(); 1004 v8::Isolate* v8_isolate = CcTest::isolate();
1005 v8::internal::Isolate* isolate = CcTest::i_isolate();
1005 v8::internal::Debug* debug = isolate->debug(); 1006 v8::internal::Debug* debug = isolate->debug();
1006 // When hitting a debug event listener there must be a break set. 1007 // When hitting a debug event listener there must be a break set.
1007 CHECK_NE(debug->break_id(), 0); 1008 CHECK_NE(debug->break_id(), 0);
1008 1009
1009 if (event == v8::Break) { 1010 if (event == v8::Break) {
1010 if (break_point_hit_count < max_break_point_hit_count) { 1011 if (break_point_hit_count < max_break_point_hit_count) {
1011 // Count the number of breaks. 1012 // Count the number of breaks.
1012 break_point_hit_count++; 1013 break_point_hit_count++;
1013 1014
1014 // Collect the JavsScript stack height if the function frame_count is 1015 // Collect the JavsScript stack height if the function frame_count is
1015 // compiled. 1016 // compiled.
1016 if (!frame_count.IsEmpty()) { 1017 if (!frame_count.IsEmpty()) {
1017 static const int kArgc = 1; 1018 static const int kArgc = 1;
1018 v8::Handle<v8::Value> argv[kArgc] = { exec_state }; 1019 v8::Handle<v8::Value> argv[kArgc] = { exec_state };
1019 // Using exec_state as receiver is just to have a receiver. 1020 // Using exec_state as receiver is just to have a receiver.
1020 v8::Handle<v8::Value> result = 1021 v8::Handle<v8::Value> result =
1021 frame_count->Call(exec_state, kArgc, argv); 1022 frame_count->Call(exec_state, kArgc, argv);
1022 last_js_stack_height = result->Int32Value(); 1023 last_js_stack_height = result->Int32Value();
1023 } 1024 }
1024 1025
1025 // Set the break flag again to come back here as soon as possible. 1026 // Set the break flag again to come back here as soon as possible.
1026 v8::Debug::DebugBreak(); 1027 v8::Debug::DebugBreak(v8_isolate);
1027 1028
1028 } else if (terminate_after_max_break_point_hit) { 1029 } else if (terminate_after_max_break_point_hit) {
1029 // Terminate execution after the last break if requested. 1030 // Terminate execution after the last break if requested.
1030 v8::V8::TerminateExecution(); 1031 v8::V8::TerminateExecution(v8_isolate);
1031 } 1032 }
1032 1033
1033 // Perform a full deoptimization when the specified number of 1034 // Perform a full deoptimization when the specified number of
1034 // breaks have been hit. 1035 // breaks have been hit.
1035 if (break_point_hit_count == break_point_hit_count_deoptimize) { 1036 if (break_point_hit_count == break_point_hit_count_deoptimize) {
1036 i::Deoptimizer::DeoptimizeAll(isolate); 1037 i::Deoptimizer::DeoptimizeAll(isolate);
1037 } 1038 }
1038 } 1039 }
1039 } 1040 }
1040 1041
(...skipping 1678 matching lines...) Expand 10 before | Expand all | Expand 10 after
2719 uint16_t buffer[kBufferSize]; 2720 uint16_t buffer[kBufferSize];
2720 2721
2721 const char* command_111 = "{\"seq\":111," 2722 const char* command_111 = "{\"seq\":111,"
2722 "\"type\":\"request\"," 2723 "\"type\":\"request\","
2723 "\"command\":\"evaluate\"," 2724 "\"command\":\"evaluate\","
2724 "\"arguments\":{" 2725 "\"arguments\":{"
2725 " \"global\":true," 2726 " \"global\":true,"
2726 " \"expression\":\"v1\",\"disable_break\":true" 2727 " \"expression\":\"v1\",\"disable_break\":true"
2727 "}}"; 2728 "}}";
2728 2729
2729 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_111, buffer)); 2730 v8::Isolate* isolate = CcTest::default_isolate();
2731 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_111, buffer));
2730 2732
2731 const char* command_112 = "{\"seq\":112," 2733 const char* command_112 = "{\"seq\":112,"
2732 "\"type\":\"request\"," 2734 "\"type\":\"request\","
2733 "\"command\":\"evaluate\"," 2735 "\"command\":\"evaluate\","
2734 "\"arguments\":{" 2736 "\"arguments\":{"
2735 " \"global\":true," 2737 " \"global\":true,"
2736 " \"expression\":\"getAnimal()\",\"disable_break\":true" 2738 " \"expression\":\"getAnimal()\",\"disable_break\":true"
2737 "}}"; 2739 "}}";
2738 2740
2739 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_112, buffer)); 2741 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_112, buffer));
2740 2742
2741 const char* command_113 = "{\"seq\":113," 2743 const char* command_113 = "{\"seq\":113,"
2742 "\"type\":\"request\"," 2744 "\"type\":\"request\","
2743 "\"command\":\"evaluate\"," 2745 "\"command\":\"evaluate\","
2744 "\"arguments\":{" 2746 "\"arguments\":{"
2745 " \"global\":true," 2747 " \"global\":true,"
2746 " \"expression\":\"239 + 566\",\"disable_break\":true" 2748 " \"expression\":\"239 + 566\",\"disable_break\":true"
2747 "}}"; 2749 "}}";
2748 2750
2749 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_113, buffer)); 2751 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_113, buffer));
2750 2752
2751 v8::Debug::ProcessDebugMessages(); 2753 v8::Debug::ProcessDebugMessages();
2752 2754
2753 CHECK_EQ(3, process_debug_messages_data.counter); 2755 CHECK_EQ(3, process_debug_messages_data.counter);
2754 2756
2755 CHECK_EQ(strcmp("Pinguin", process_debug_messages_data.results[0].buffer), 0); 2757 CHECK_EQ(strcmp("Pinguin", process_debug_messages_data.results[0].buffer), 0);
2756 CHECK_EQ(strcmp("Capybara", process_debug_messages_data.results[1].buffer), 2758 CHECK_EQ(strcmp("Capybara", process_debug_messages_data.results[1].buffer),
2757 0); 2759 0);
2758 CHECK_EQ(strcmp("805", process_debug_messages_data.results[2].buffer), 0); 2760 CHECK_EQ(strcmp("805", process_debug_messages_data.results[2].buffer), 0);
2759 2761
(...skipping 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after
4155 v8::Number::New(1), 4157 v8::Number::New(1),
4156 v8::Number::New(1) }; 4158 v8::Number::New(1) };
4157 4159
4158 // Call all functions to make sure that they are compiled. 4160 // Call all functions to make sure that they are compiled.
4159 f0->Call(env->Global(), 0, NULL); 4161 f0->Call(env->Global(), 0, NULL);
4160 f1->Call(env->Global(), 0, NULL); 4162 f1->Call(env->Global(), 0, NULL);
4161 f2->Call(env->Global(), 0, NULL); 4163 f2->Call(env->Global(), 0, NULL);
4162 f3->Call(env->Global(), 0, NULL); 4164 f3->Call(env->Global(), 0, NULL);
4163 4165
4164 // Set the debug break flag. 4166 // Set the debug break flag.
4165 v8::Debug::DebugBreak(); 4167 v8::Debug::DebugBreak(env->GetIsolate());
4166 4168
4167 // Call all functions with different argument count. 4169 // Call all functions with different argument count.
4168 break_point_hit_count = 0; 4170 break_point_hit_count = 0;
4169 for (unsigned int i = 0; i < ARRAY_SIZE(argv); i++) { 4171 for (unsigned int i = 0; i < ARRAY_SIZE(argv); i++) {
4170 f0->Call(env->Global(), i, argv); 4172 f0->Call(env->Global(), i, argv);
4171 f1->Call(env->Global(), i, argv); 4173 f1->Call(env->Global(), i, argv);
4172 f2->Call(env->Global(), i, argv); 4174 f2->Call(env->Global(), i, argv);
4173 f3->Call(env->Global(), i, argv); 4175 f3->Call(env->Global(), i, argv);
4174 } 4176 }
4175 4177
(...skipping 13 matching lines...) Expand all
4189 v8::HandleScope scope(env->GetIsolate()); 4191 v8::HandleScope scope(env->GetIsolate());
4190 4192
4191 // Register a debug event listener which sets the break flag and counts. 4193 // Register a debug event listener which sets the break flag and counts.
4192 v8::Debug::SetDebugEventListener2(DebugEventCounter); 4194 v8::Debug::SetDebugEventListener2(DebugEventCounter);
4193 4195
4194 // Create a function for testing stepping. 4196 // Create a function for testing stepping.
4195 const char* src = "function f() {g()};function g(){i=0; while(i<10){i++}}"; 4197 const char* src = "function f() {g()};function g(){i=0; while(i<10){i++}}";
4196 v8::Local<v8::Function> f = CompileFunction(&env, src, "f"); 4198 v8::Local<v8::Function> f = CompileFunction(&env, src, "f");
4197 4199
4198 // Set the debug break flag. 4200 // Set the debug break flag.
4199 v8::Debug::DebugBreak(); 4201 v8::Debug::DebugBreak(env->GetIsolate());
4200 4202
4201 // Call all functions with different argument count. 4203 // Call all functions with different argument count.
4202 break_point_hit_count = 0; 4204 break_point_hit_count = 0;
4203 f->Call(env->Global(), 0, NULL); 4205 f->Call(env->Global(), 0, NULL);
4204 CHECK_EQ(1, break_point_hit_count); 4206 CHECK_EQ(1, break_point_hit_count);
4205 4207
4206 { 4208 {
4207 v8::Debug::DebugBreak(); 4209 v8::Debug::DebugBreak(env->GetIsolate());
4208 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(env->GetIsolate()); 4210 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(env->GetIsolate());
4209 v8::internal::DisableBreak disable_break(isolate, true); 4211 v8::internal::DisableBreak disable_break(isolate, true);
4210 f->Call(env->Global(), 0, NULL); 4212 f->Call(env->Global(), 0, NULL);
4211 CHECK_EQ(1, break_point_hit_count); 4213 CHECK_EQ(1, break_point_hit_count);
4212 } 4214 }
4213 4215
4214 f->Call(env->Global(), 0, NULL); 4216 f->Call(env->Global(), 0, NULL);
4215 CHECK_EQ(2, break_point_hit_count); 4217 CHECK_EQ(2, break_point_hit_count);
4216 4218
4217 // Get rid of the debug event listener. 4219 // Get rid of the debug event listener.
4218 v8::Debug::SetDebugEventListener2(NULL); 4220 v8::Debug::SetDebugEventListener2(NULL);
4219 CheckDebuggerUnloaded(); 4221 CheckDebuggerUnloaded();
4220 } 4222 }
4221 4223
4222 static const char* kSimpleExtensionSource = 4224 static const char* kSimpleExtensionSource =
4223 "(function Foo() {" 4225 "(function Foo() {"
4224 " return 4;" 4226 " return 4;"
4225 "})() "; 4227 "})() ";
4226 4228
4227 // http://crbug.com/28933 4229 // http://crbug.com/28933
4228 // Test that debug break is disabled when bootstrapper is active. 4230 // Test that debug break is disabled when bootstrapper is active.
4229 TEST(NoBreakWhenBootstrapping) { 4231 TEST(NoBreakWhenBootstrapping) {
4230 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 4232 v8::Isolate* isolate = v8::Isolate::GetCurrent();
4231 v8::HandleScope scope(isolate); 4233 v8::HandleScope scope(isolate);
4232 4234
4233 // Register a debug event listener which sets the break flag and counts. 4235 // Register a debug event listener which sets the break flag and counts.
4234 v8::Debug::SetDebugEventListener2(DebugEventCounter); 4236 v8::Debug::SetDebugEventListener2(DebugEventCounter);
4235 4237
4236 // Set the debug break flag. 4238 // Set the debug break flag.
4237 v8::Debug::DebugBreak(); 4239 v8::Debug::DebugBreak(isolate);
4238 break_point_hit_count = 0; 4240 break_point_hit_count = 0;
4239 { 4241 {
4240 // Create a context with an extension to make sure that some JavaScript 4242 // Create a context with an extension to make sure that some JavaScript
4241 // code is executed during bootstrapping. 4243 // code is executed during bootstrapping.
4242 v8::RegisterExtension(new v8::Extension("simpletest", 4244 v8::RegisterExtension(new v8::Extension("simpletest",
4243 kSimpleExtensionSource)); 4245 kSimpleExtensionSource));
4244 const char* extension_names[] = { "simpletest" }; 4246 const char* extension_names[] = { "simpletest" };
4245 v8::ExtensionConfiguration extensions(1, extension_names); 4247 v8::ExtensionConfiguration extensions(1, extension_names);
4246 v8::HandleScope handle_scope(isolate); 4248 v8::HandleScope handle_scope(isolate);
4247 v8::Context::New(isolate, &extensions); 4249 v8::Context::New(isolate, &extensions);
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
4882 4884
4883 /* Interleaved sequence of actions by the two threads:*/ 4885 /* Interleaved sequence of actions by the two threads:*/
4884 // Main thread compiles and runs source_1 4886 // Main thread compiles and runs source_1
4885 message_queue_barriers.semaphore_1.Signal(); 4887 message_queue_barriers.semaphore_1.Signal();
4886 message_queue_barriers.barrier_1.Wait(); 4888 message_queue_barriers.barrier_1.Wait();
4887 // Post 6 commands, filling the command queue and making it expand. 4889 // Post 6 commands, filling the command queue and making it expand.
4888 // These calls return immediately, but the commands stay on the queue 4890 // These calls return immediately, but the commands stay on the queue
4889 // until the execution of source_2. 4891 // until the execution of source_2.
4890 // Note: AsciiToUtf16 executes before SendCommand, so command is copied 4892 // Note: AsciiToUtf16 executes before SendCommand, so command is copied
4891 // to buffer before buffer is sent to SendCommand. 4893 // to buffer before buffer is sent to SendCommand.
4892 v8::Debug::SendCommand(buffer_1, AsciiToUtf16(command_1, buffer_1)); 4894 v8::Isolate* isolate = CcTest::default_isolate();
4893 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_2, buffer_2)); 4895 v8::Debug::SendCommand(isolate, buffer_1, AsciiToUtf16(command_1, buffer_1));
4894 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2)); 4896 v8::Debug::SendCommand(isolate, buffer_2, AsciiToUtf16(command_2, buffer_2));
4895 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2)); 4897 v8::Debug::SendCommand(isolate, buffer_2, AsciiToUtf16(command_3, buffer_2));
4896 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2)); 4898 v8::Debug::SendCommand(isolate, buffer_2, AsciiToUtf16(command_3, buffer_2));
4899 v8::Debug::SendCommand(isolate, buffer_2, AsciiToUtf16(command_3, buffer_2));
4897 message_queue_barriers.barrier_2.Wait(); 4900 message_queue_barriers.barrier_2.Wait();
4898 // Main thread compiles and runs source_2. 4901 // Main thread compiles and runs source_2.
4899 // Queued commands are executed at the start of compilation of source_2( 4902 // Queued commands are executed at the start of compilation of source_2(
4900 // beforeCompile event). 4903 // beforeCompile event).
4901 // Free the message handler to process all the messages from the queue. 7 4904 // Free the message handler to process all the messages from the queue. 7
4902 // messages are expected: 2 afterCompile events and 5 responses. 4905 // messages are expected: 2 afterCompile events and 5 responses.
4903 // All the commands added so far will fail to execute as long as call stack 4906 // All the commands added so far will fail to execute as long as call stack
4904 // is empty on beforeCompile event. 4907 // is empty on beforeCompile event.
4905 for (int i = 0; i < 6 ; ++i) { 4908 for (int i = 0; i < 6 ; ++i) {
4906 message_queue_barriers.semaphore_1.Signal(); 4909 message_queue_barriers.semaphore_1.Signal();
4907 } 4910 }
4908 message_queue_barriers.barrier_3.Wait(); 4911 message_queue_barriers.barrier_3.Wait();
4909 // Main thread compiles and runs source_3. 4912 // Main thread compiles and runs source_3.
4910 // Don't stop in the afterCompile handler. 4913 // Don't stop in the afterCompile handler.
4911 message_queue_barriers.semaphore_1.Signal(); 4914 message_queue_barriers.semaphore_1.Signal();
4912 // source_3 includes a debugger statement, which causes a break event. 4915 // source_3 includes a debugger statement, which causes a break event.
4913 // Wait on break event from hitting "debugger" statement 4916 // Wait on break event from hitting "debugger" statement
4914 message_queue_barriers.semaphore_2.Wait(); 4917 message_queue_barriers.semaphore_2.Wait();
4915 // These should execute after the "debugger" statement in source_2 4918 // These should execute after the "debugger" statement in source_2
4916 v8::Debug::SendCommand(buffer_1, AsciiToUtf16(command_1, buffer_1)); 4919 v8::Debug::SendCommand(isolate, buffer_1, AsciiToUtf16(command_1, buffer_1));
4917 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_2, buffer_2)); 4920 v8::Debug::SendCommand(isolate, buffer_2, AsciiToUtf16(command_2, buffer_2));
4918 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_3, buffer_2)); 4921 v8::Debug::SendCommand(isolate, buffer_2, AsciiToUtf16(command_3, buffer_2));
4919 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_single_step, buffer_2)); 4922 v8::Debug::SendCommand(
4923 isolate, buffer_2, AsciiToUtf16(command_single_step, buffer_2));
4920 // Run after 2 break events, 4 responses. 4924 // Run after 2 break events, 4 responses.
4921 for (int i = 0; i < 6 ; ++i) { 4925 for (int i = 0; i < 6 ; ++i) {
4922 message_queue_barriers.semaphore_1.Signal(); 4926 message_queue_barriers.semaphore_1.Signal();
4923 } 4927 }
4924 // Wait on break event after a single step executes. 4928 // Wait on break event after a single step executes.
4925 message_queue_barriers.semaphore_2.Wait(); 4929 message_queue_barriers.semaphore_2.Wait();
4926 v8::Debug::SendCommand(buffer_1, AsciiToUtf16(command_2, buffer_1)); 4930 v8::Debug::SendCommand(isolate, buffer_1, AsciiToUtf16(command_2, buffer_1));
4927 v8::Debug::SendCommand(buffer_2, AsciiToUtf16(command_continue, buffer_2)); 4931 v8::Debug::SendCommand(
4932 isolate, buffer_2, AsciiToUtf16(command_continue, buffer_2));
4928 // Run after 2 responses. 4933 // Run after 2 responses.
4929 for (int i = 0; i < 2 ; ++i) { 4934 for (int i = 0; i < 2 ; ++i) {
4930 message_queue_barriers.semaphore_1.Signal(); 4935 message_queue_barriers.semaphore_1.Signal();
4931 } 4936 }
4932 // Main thread continues running source_3 to end, waits for this thread. 4937 // Main thread continues running source_3 to end, waits for this thread.
4933 } 4938 }
4934 4939
4935 4940
4936 // This thread runs the v8 engine. 4941 // This thread runs the v8 engine.
4937 TEST(MessageQueues) { 4942 TEST(MessageQueues) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
5023 if (message.GetClientData() != NULL) { 5028 if (message.GetClientData() != NULL) {
5024 handled_client_data_instances_count++; 5029 handled_client_data_instances_count++;
5025 } 5030 }
5026 } 5031 }
5027 5032
5028 5033
5029 // Tests that all client data passed to the debugger are sent to the handler. 5034 // Tests that all client data passed to the debugger are sent to the handler.
5030 TEST(SendClientDataToHandler) { 5035 TEST(SendClientDataToHandler) {
5031 // Create a V8 environment 5036 // Create a V8 environment
5032 DebugLocalContext env; 5037 DebugLocalContext env;
5033 v8::HandleScope scope(env->GetIsolate()); 5038 v8::Isolate* isolate = env->GetIsolate();
5039 v8::HandleScope scope(isolate);
5034 TestClientData::ResetCounters(); 5040 TestClientData::ResetCounters();
5035 handled_client_data_instances_count = 0; 5041 handled_client_data_instances_count = 0;
5036 v8::Debug::SetMessageHandler2(MessageHandlerCountingClientData); 5042 v8::Debug::SetMessageHandler2(MessageHandlerCountingClientData);
5037 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;"; 5043 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;";
5038 const int kBufferSize = 1000; 5044 const int kBufferSize = 1000;
5039 uint16_t buffer[kBufferSize]; 5045 uint16_t buffer[kBufferSize];
5040 const char* command_1 = 5046 const char* command_1 =
5041 "{\"seq\":117," 5047 "{\"seq\":117,"
5042 "\"type\":\"request\"," 5048 "\"type\":\"request\","
5043 "\"command\":\"evaluate\"," 5049 "\"command\":\"evaluate\","
5044 "\"arguments\":{\"expression\":\"1+2\"}}"; 5050 "\"arguments\":{\"expression\":\"1+2\"}}";
5045 const char* command_2 = 5051 const char* command_2 =
5046 "{\"seq\":118," 5052 "{\"seq\":118,"
5047 "\"type\":\"request\"," 5053 "\"type\":\"request\","
5048 "\"command\":\"evaluate\"," 5054 "\"command\":\"evaluate\","
5049 "\"arguments\":{\"expression\":\"1+a\"}}"; 5055 "\"arguments\":{\"expression\":\"1+a\"}}";
5050 const char* command_continue = 5056 const char* command_continue =
5051 "{\"seq\":106," 5057 "{\"seq\":106,"
5052 "\"type\":\"request\"," 5058 "\"type\":\"request\","
5053 "\"command\":\"continue\"}"; 5059 "\"command\":\"continue\"}";
5054 5060
5055 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer), 5061 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_1, buffer),
5056 new TestClientData()); 5062 new TestClientData());
5057 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer), NULL); 5063 v8::Debug::SendCommand(
5058 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer), 5064 isolate, buffer, AsciiToUtf16(command_2, buffer), NULL);
5065 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_2, buffer),
5059 new TestClientData()); 5066 new TestClientData());
5060 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer), 5067 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_2, buffer),
5061 new TestClientData()); 5068 new TestClientData());
5062 // All the messages will be processed on beforeCompile event. 5069 // All the messages will be processed on beforeCompile event.
5063 CompileRun(source_1); 5070 CompileRun(source_1);
5064 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer)); 5071 v8::Debug::SendCommand(
5072 isolate, buffer, AsciiToUtf16(command_continue, buffer));
5065 CHECK_EQ(3, TestClientData::constructor_call_counter); 5073 CHECK_EQ(3, TestClientData::constructor_call_counter);
5066 CHECK_EQ(TestClientData::constructor_call_counter, 5074 CHECK_EQ(TestClientData::constructor_call_counter,
5067 handled_client_data_instances_count); 5075 handled_client_data_instances_count);
5068 CHECK_EQ(TestClientData::constructor_call_counter, 5076 CHECK_EQ(TestClientData::constructor_call_counter,
5069 TestClientData::destructor_call_counter); 5077 TestClientData::destructor_call_counter);
5070 } 5078 }
5071 5079
5072 5080
5073 /* Test ThreadedDebugging */ 5081 /* Test ThreadedDebugging */
5074 /* This test interrupts a running infinite loop that is 5082 /* This test interrupts a running infinite loop that is
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
5155 uint16_t buffer[kBufSize]; 5163 uint16_t buffer[kBufSize];
5156 5164
5157 const char* command_1 = "{\"seq\":102," 5165 const char* command_1 = "{\"seq\":102,"
5158 "\"type\":\"request\"," 5166 "\"type\":\"request\","
5159 "\"command\":\"evaluate\"," 5167 "\"command\":\"evaluate\","
5160 "\"arguments\":{\"expression\":\"bar(false)\"}}"; 5168 "\"arguments\":{\"expression\":\"bar(false)\"}}";
5161 const char* command_2 = "{\"seq\":103," 5169 const char* command_2 = "{\"seq\":103,"
5162 "\"type\":\"request\"," 5170 "\"type\":\"request\","
5163 "\"command\":\"continue\"}"; 5171 "\"command\":\"continue\"}";
5164 5172
5173 v8::Isolate* isolate = CcTest::isolate();
5165 threaded_debugging_barriers.barrier_1.Wait(); 5174 threaded_debugging_barriers.barrier_1.Wait();
5166 v8::Debug::DebugBreak(); 5175 v8::Debug::DebugBreak(isolate);
5167 threaded_debugging_barriers.barrier_2.Wait(); 5176 threaded_debugging_barriers.barrier_2.Wait();
5168 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer)); 5177 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_1, buffer));
5169 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer)); 5178 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_2, buffer));
5170 } 5179 }
5171 5180
5172 5181
5173 TEST(ThreadedDebugging) { 5182 UNINITIALIZED_TEST(ThreadedDebugging) {
5174 DebuggerThread debugger_thread; 5183 DebuggerThread debugger_thread;
5175 V8Thread v8_thread; 5184 V8Thread v8_thread;
5176 5185
5177 // Create a V8 environment 5186 // Create a V8 environment
5178 v8_thread.Start(); 5187 v8_thread.Start();
5179 debugger_thread.Start(); 5188 debugger_thread.Start();
5180 5189
5181 v8_thread.Join(); 5190 v8_thread.Join();
5182 debugger_thread.Join(); 5191 debugger_thread.Join();
5183 } 5192 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
5316 command_7 = "{\"seq\":107," 5325 command_7 = "{\"seq\":107,"
5317 "\"type\":\"request\"," 5326 "\"type\":\"request\","
5318 "\"command\":\"evaluate\"," 5327 "\"command\":\"evaluate\","
5319 "\"arguments\":{\"expression\":\"dog()\",\"disable_break\":true}}"; 5328 "\"arguments\":{\"expression\":\"dog()\",\"disable_break\":true}}";
5320 } 5329 }
5321 const char* command_8 = "{\"seq\":108," 5330 const char* command_8 = "{\"seq\":108,"
5322 "\"type\":\"request\"," 5331 "\"type\":\"request\","
5323 "\"command\":\"continue\"}"; 5332 "\"command\":\"continue\"}";
5324 5333
5325 5334
5335 v8::Isolate* isolate = CcTest::isolate();
5326 // v8 thread initializes, runs source_1 5336 // v8 thread initializes, runs source_1
5327 breakpoints_barriers->barrier_1.Wait(); 5337 breakpoints_barriers->barrier_1.Wait();
5328 // 1:Set breakpoint in cat() (will get id 1). 5338 // 1:Set breakpoint in cat() (will get id 1).
5329 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer)); 5339 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_1, buffer));
5330 // 2:Set breakpoint in dog() (will get id 2). 5340 // 2:Set breakpoint in dog() (will get id 2).
5331 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer)); 5341 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_2, buffer));
5332 breakpoints_barriers->barrier_2.Wait(); 5342 breakpoints_barriers->barrier_2.Wait();
5333 // V8 thread starts compiling source_2. 5343 // V8 thread starts compiling source_2.
5334 // Automatic break happens, to run queued commands 5344 // Automatic break happens, to run queued commands
5335 // breakpoints_barriers->semaphore_1.Wait(); 5345 // breakpoints_barriers->semaphore_1.Wait();
5336 // Commands 1 through 3 run, thread continues. 5346 // Commands 1 through 3 run, thread continues.
5337 // v8 thread runs source_2 to breakpoint in cat(). 5347 // v8 thread runs source_2 to breakpoint in cat().
5338 // message callback receives break event. 5348 // message callback receives break event.
5339 breakpoints_barriers->semaphore_1.Wait(); 5349 breakpoints_barriers->semaphore_1.Wait();
5340 // Must have hit breakpoint #1. 5350 // Must have hit breakpoint #1.
5341 CHECK_EQ(1, break_event_breakpoint_id); 5351 CHECK_EQ(1, break_event_breakpoint_id);
5342 // 4:Evaluate dog() (which has a breakpoint). 5352 // 4:Evaluate dog() (which has a breakpoint).
5343 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_3, buffer)); 5353 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_3, buffer));
5344 // V8 thread hits breakpoint in dog(). 5354 // V8 thread hits breakpoint in dog().
5345 breakpoints_barriers->semaphore_1.Wait(); // wait for break event 5355 breakpoints_barriers->semaphore_1.Wait(); // wait for break event
5346 // Must have hit breakpoint #2. 5356 // Must have hit breakpoint #2.
5347 CHECK_EQ(2, break_event_breakpoint_id); 5357 CHECK_EQ(2, break_event_breakpoint_id);
5348 // 5:Evaluate (x + 1). 5358 // 5:Evaluate (x + 1).
5349 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_4, buffer)); 5359 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_4, buffer));
5350 // Evaluate (x + 1) finishes. 5360 // Evaluate (x + 1) finishes.
5351 breakpoints_barriers->semaphore_1.Wait(); 5361 breakpoints_barriers->semaphore_1.Wait();
5352 // Must have result 108. 5362 // Must have result 108.
5353 CHECK_EQ(108, evaluate_int_result); 5363 CHECK_EQ(108, evaluate_int_result);
5354 // 6:Continue evaluation of dog(). 5364 // 6:Continue evaluation of dog().
5355 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_5, buffer)); 5365 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_5, buffer));
5356 // Evaluate dog() finishes. 5366 // Evaluate dog() finishes.
5357 breakpoints_barriers->semaphore_1.Wait(); 5367 breakpoints_barriers->semaphore_1.Wait();
5358 // Must have result 107. 5368 // Must have result 107.
5359 CHECK_EQ(107, evaluate_int_result); 5369 CHECK_EQ(107, evaluate_int_result);
5360 // 7:Continue evaluation of source_2, finish cat(17), hit breakpoint 5370 // 7:Continue evaluation of source_2, finish cat(17), hit breakpoint
5361 // in cat(19). 5371 // in cat(19).
5362 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_6, buffer)); 5372 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_6, buffer));
5363 // Message callback gets break event. 5373 // Message callback gets break event.
5364 breakpoints_barriers->semaphore_1.Wait(); // wait for break event 5374 breakpoints_barriers->semaphore_1.Wait(); // wait for break event
5365 // Must have hit breakpoint #1. 5375 // Must have hit breakpoint #1.
5366 CHECK_EQ(1, break_event_breakpoint_id); 5376 CHECK_EQ(1, break_event_breakpoint_id);
5367 // 8: Evaluate dog() with breaks disabled. 5377 // 8: Evaluate dog() with breaks disabled.
5368 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_7, buffer)); 5378 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_7, buffer));
5369 // Evaluate dog() finishes. 5379 // Evaluate dog() finishes.
5370 breakpoints_barriers->semaphore_1.Wait(); 5380 breakpoints_barriers->semaphore_1.Wait();
5371 // Must have result 116. 5381 // Must have result 116.
5372 CHECK_EQ(116, evaluate_int_result); 5382 CHECK_EQ(116, evaluate_int_result);
5373 // 9: Continue evaluation of source2, reach end. 5383 // 9: Continue evaluation of source2, reach end.
5374 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_8, buffer)); 5384 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_8, buffer));
5375 } 5385 }
5376 5386
5377 5387
5378 void TestRecursiveBreakpointsGeneric(bool global_evaluate) { 5388 void TestRecursiveBreakpointsGeneric(bool global_evaluate) {
5379 i::FLAG_debugger_auto_break = true; 5389 i::FLAG_debugger_auto_break = true;
5380 5390
5381 BreakpointsDebuggerThread breakpoints_debugger_thread(global_evaluate); 5391 BreakpointsDebuggerThread breakpoints_debugger_thread(global_evaluate);
5382 BreakpointsV8Thread breakpoints_v8_thread; 5392 BreakpointsV8Thread breakpoints_v8_thread;
5383 5393
5384 // Create a V8 environment 5394 // Create a V8 environment
5385 Barriers stack_allocated_breakpoints_barriers; 5395 Barriers stack_allocated_breakpoints_barriers;
5386 breakpoints_barriers = &stack_allocated_breakpoints_barriers; 5396 breakpoints_barriers = &stack_allocated_breakpoints_barriers;
5387 5397
5388 breakpoints_v8_thread.Start(); 5398 breakpoints_v8_thread.Start();
5389 breakpoints_debugger_thread.Start(); 5399 breakpoints_debugger_thread.Start();
5390 5400
5391 breakpoints_v8_thread.Join(); 5401 breakpoints_v8_thread.Join();
5392 breakpoints_debugger_thread.Join(); 5402 breakpoints_debugger_thread.Join();
5393 } 5403 }
5394 5404
5395 5405
5396 TEST(RecursiveBreakpoints) { 5406 UNINITIALIZED_TEST(RecursiveBreakpoints) {
5397 TestRecursiveBreakpointsGeneric(false); 5407 TestRecursiveBreakpointsGeneric(false);
5398 } 5408 }
5399 5409
5400 5410
5401 TEST(RecursiveBreakpointsGlobal) { 5411 UNINITIALIZED_TEST(RecursiveBreakpointsGlobal) {
5402 TestRecursiveBreakpointsGeneric(true); 5412 TestRecursiveBreakpointsGeneric(true);
5403 } 5413 }
5404 5414
5405 5415
5406 static void DummyDebugEventListener( 5416 static void DummyDebugEventListener(
5407 const v8::Debug::EventDetails& event_details) { 5417 const v8::Debug::EventDetails& event_details) {
5408 } 5418 }
5409 5419
5410 5420
5411 TEST(SetDebugEventListenerOnUninitializedVM) { 5421 TEST(SetDebugEventListenerOnUninitializedVM) {
5412 v8::Debug::SetDebugEventListener2(DummyDebugEventListener); 5422 v8::Debug::SetDebugEventListener2(DummyDebugEventListener);
5413 } 5423 }
5414 5424
5415 5425
5416 static void DummyMessageHandler(const v8::Debug::Message& message) { 5426 static void DummyMessageHandler(const v8::Debug::Message& message) {
5417 } 5427 }
5418 5428
5419 5429
5420 TEST(SetMessageHandlerOnUninitializedVM) { 5430 TEST(SetMessageHandlerOnUninitializedVM) {
5421 v8::Debug::SetMessageHandler2(DummyMessageHandler); 5431 v8::Debug::SetMessageHandler2(DummyMessageHandler);
5422 } 5432 }
5423 5433
5424 5434
5425 TEST(DebugBreakOnUninitializedVM) {
5426 v8::Debug::DebugBreak();
5427 }
5428
5429
5430 TEST(SendCommandToUninitializedVM) {
5431 const char* dummy_command = "{}";
5432 uint16_t dummy_buffer[80];
5433 int dummy_length = AsciiToUtf16(dummy_command, dummy_buffer);
5434 v8::Debug::SendCommand(dummy_buffer, dummy_length);
5435 }
5436
5437
5438 // Source for a JavaScript function which returns the data parameter of a 5435 // Source for a JavaScript function which returns the data parameter of a
5439 // function called in the context of the debugger. If no data parameter is 5436 // function called in the context of the debugger. If no data parameter is
5440 // passed it throws an exception. 5437 // passed it throws an exception.
5441 static const char* debugger_call_with_data_source = 5438 static const char* debugger_call_with_data_source =
5442 "function debugger_call_with_data(exec_state, data) {" 5439 "function debugger_call_with_data(exec_state, data) {"
5443 " if (data) return data;" 5440 " if (data) return data;"
5444 " throw 'No data!'" 5441 " throw 'No data!'"
5445 "}"; 5442 "}";
5446 v8::Handle<v8::Function> debugger_call_with_data; 5443 v8::Handle<v8::Function> debugger_call_with_data;
5447 5444
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
5657 5654
5658 // Sends continue command to the debugger. 5655 // Sends continue command to the debugger.
5659 static void SendContinueCommand() { 5656 static void SendContinueCommand() {
5660 const int kBufferSize = 1000; 5657 const int kBufferSize = 1000;
5661 uint16_t buffer[kBufferSize]; 5658 uint16_t buffer[kBufferSize];
5662 const char* command_continue = 5659 const char* command_continue =
5663 "{\"seq\":0," 5660 "{\"seq\":0,"
5664 "\"type\":\"request\"," 5661 "\"type\":\"request\","
5665 "\"command\":\"continue\"}"; 5662 "\"command\":\"continue\"}";
5666 5663
5667 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer)); 5664 v8::Debug::SendCommand(
5665 CcTest::isolate(), buffer, AsciiToUtf16(command_continue, buffer));
5668 } 5666 }
5669 5667
5670 5668
5671 // Debugger message handler which counts the number of times it is called. 5669 // Debugger message handler which counts the number of times it is called.
5672 static int message_handler_hit_count = 0; 5670 static int message_handler_hit_count = 0;
5673 static void MessageHandlerHitCount(const v8::Debug::Message& message) { 5671 static void MessageHandlerHitCount(const v8::Debug::Message& message) {
5674 message_handler_hit_count++; 5672 message_handler_hit_count++;
5675 5673
5676 static char print_buffer[1000]; 5674 static char print_buffer[1000];
5677 v8::String::Value json(message.GetJSON()); 5675 v8::String::Value json(message.GetJSON());
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
5811 uint16_t buffer[kBufSize]; 5809 uint16_t buffer[kBufSize];
5812 5810
5813 const char* command_1 = "{\"seq\":101," 5811 const char* command_1 = "{\"seq\":101,"
5814 "\"type\":\"request\"," 5812 "\"type\":\"request\","
5815 "\"command\":\"setbreakpoint\"," 5813 "\"command\":\"setbreakpoint\","
5816 "\"arguments\":{\"type\":\"function\",\"target\":\"cat\",\"line\":3}}"; 5814 "\"arguments\":{\"type\":\"function\",\"target\":\"cat\",\"line\":3}}";
5817 const char* command_2 = "{\"seq\":102," 5815 const char* command_2 = "{\"seq\":102,"
5818 "\"type\":\"request\"," 5816 "\"type\":\"request\","
5819 "\"command\":\"continue\"}"; 5817 "\"command\":\"continue\"}";
5820 5818
5819 v8::Isolate* isolate = CcTest::isolate();
5821 // v8 thread initializes, runs source_1 5820 // v8 thread initializes, runs source_1
5822 host_dispatch_barriers->barrier_1.Wait(); 5821 host_dispatch_barriers->barrier_1.Wait();
5823 // 1: Set breakpoint in cat(). 5822 // 1: Set breakpoint in cat().
5824 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer)); 5823 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_1, buffer));
5825 5824
5826 host_dispatch_barriers->barrier_2.Wait(); 5825 host_dispatch_barriers->barrier_2.Wait();
5827 // v8 thread starts compiling source_2. 5826 // v8 thread starts compiling source_2.
5828 // Break happens, to run queued commands and host dispatches. 5827 // Break happens, to run queued commands and host dispatches.
5829 // Wait for host dispatch to be processed. 5828 // Wait for host dispatch to be processed.
5830 host_dispatch_barriers->semaphore_1.Wait(); 5829 host_dispatch_barriers->semaphore_1.Wait();
5831 // 2: Continue evaluation 5830 // 2: Continue evaluation
5832 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer)); 5831 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_2, buffer));
5833 } 5832 }
5834 5833
5835 5834
5836 TEST(DebuggerHostDispatch) { 5835 UNINITIALIZED_TEST(DebuggerHostDispatch) {
5837 HostDispatchDebuggerThread host_dispatch_debugger_thread; 5836 HostDispatchDebuggerThread host_dispatch_debugger_thread;
5838 HostDispatchV8Thread host_dispatch_v8_thread; 5837 HostDispatchV8Thread host_dispatch_v8_thread;
5839 i::FLAG_debugger_auto_break = true; 5838 i::FLAG_debugger_auto_break = true;
5840 5839
5841 // Create a V8 environment 5840 // Create a V8 environment
5842 Barriers stack_allocated_host_dispatch_barriers; 5841 Barriers stack_allocated_host_dispatch_barriers;
5843 host_dispatch_barriers = &stack_allocated_host_dispatch_barriers; 5842 host_dispatch_barriers = &stack_allocated_host_dispatch_barriers;
5844 5843
5845 host_dispatch_v8_thread.Start(); 5844 host_dispatch_v8_thread.Start();
5846 host_dispatch_debugger_thread.Start(); 5845 host_dispatch_debugger_thread.Start();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
5892 } 5891 }
5893 5892
5894 5893
5895 void DebugMessageDispatchDebuggerThread::Run() { 5894 void DebugMessageDispatchDebuggerThread::Run() {
5896 debug_message_dispatch_barriers->barrier_1.Wait(); 5895 debug_message_dispatch_barriers->barrier_1.Wait();
5897 SendContinueCommand(); 5896 SendContinueCommand();
5898 debug_message_dispatch_barriers->barrier_2.Wait(); 5897 debug_message_dispatch_barriers->barrier_2.Wait();
5899 } 5898 }
5900 5899
5901 5900
5902 TEST(DebuggerDebugMessageDispatch) { 5901 UNINITIALIZED_TEST(DebuggerDebugMessageDispatch) {
5903 DebugMessageDispatchDebuggerThread debug_message_dispatch_debugger_thread; 5902 DebugMessageDispatchDebuggerThread debug_message_dispatch_debugger_thread;
5904 DebugMessageDispatchV8Thread debug_message_dispatch_v8_thread; 5903 DebugMessageDispatchV8Thread debug_message_dispatch_v8_thread;
5905 5904
5906 i::FLAG_debugger_auto_break = true; 5905 i::FLAG_debugger_auto_break = true;
5907 5906
5908 // Create a V8 environment 5907 // Create a V8 environment
5909 Barriers stack_allocated_debug_message_dispatch_barriers; 5908 Barriers stack_allocated_debug_message_dispatch_barriers;
5910 debug_message_dispatch_barriers = 5909 debug_message_dispatch_barriers =
5911 &stack_allocated_debug_message_dispatch_barriers; 5910 &stack_allocated_debug_message_dispatch_barriers;
5912 5911
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
6291 } 6290 }
6292 6291
6293 6292
6294 // Debug message handler which issues a debug break when it hits a break event. 6293 // Debug message handler which issues a debug break when it hits a break event.
6295 static int message_handler_break_hit_count = 0; 6294 static int message_handler_break_hit_count = 0;
6296 static void DebugBreakMessageHandler(const v8::Debug::Message& message) { 6295 static void DebugBreakMessageHandler(const v8::Debug::Message& message) {
6297 // Schedule a debug break for break events. 6296 // Schedule a debug break for break events.
6298 if (message.IsEvent() && message.GetEvent() == v8::Break) { 6297 if (message.IsEvent() && message.GetEvent() == v8::Break) {
6299 message_handler_break_hit_count++; 6298 message_handler_break_hit_count++;
6300 if (message_handler_break_hit_count == 1) { 6299 if (message_handler_break_hit_count == 1) {
6301 v8::Debug::DebugBreak(); 6300 v8::Debug::DebugBreak(message.GetIsolate());
6302 } 6301 }
6303 } 6302 }
6304 6303
6305 // Issue a continue command if this event will not cause the VM to start 6304 // Issue a continue command if this event will not cause the VM to start
6306 // running. 6305 // running.
6307 if (!message.WillStartRunning()) { 6306 if (!message.WillStartRunning()) {
6308 SendContinueCommand(); 6307 SendContinueCommand();
6309 } 6308 }
6310 } 6309 }
6311 6310
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
6363 } 6362 }
6364 6363
6365 // Keep forcing breaks. 6364 // Keep forcing breaks.
6366 if (break_point_hit_count < 20) { 6365 if (break_point_hit_count < 20) {
6367 v8::Debug::DebugBreak(); 6366 v8::Debug::DebugBreak();
6368 } 6367 }
6369 } 6368 }
6370 } 6369 }
6371 6370
6372 6371
6373 TEST(RegExpDebugBreak) { 6372 UNINITIALIZED_TEST(RegExpDebugBreak) {
6374 // This test only applies to native regexps. 6373 // This test only applies to native regexps.
6375 DebugLocalContext env; 6374 DebugLocalContext env;
6376 v8::HandleScope scope(env->GetIsolate()); 6375 v8::HandleScope scope(env->GetIsolate());
6377 6376
6378 // Create a function for checking the function when hitting a break point. 6377 // Create a function for checking the function when hitting a break point.
6379 frame_function_name = CompileFunction(&env, 6378 frame_function_name = CompileFunction(&env,
6380 frame_function_name_source, 6379 frame_function_name_source,
6381 "frame_function_name"); 6380 "frame_function_name");
6382 6381
6383 // Test RegExp which matches white spaces and comments at the begining of a 6382 // Test RegExp which matches white spaces and comments at the begining of a
6384 // source line. 6383 // source line.
6385 const char* script = 6384 const char* script =
6386 "var sourceLineBeginningSkip = /^(?:[ \\v\\h]*(?:\\/\\*.*?\\*\\/)*)*/;\n" 6385 "var sourceLineBeginningSkip = /^(?:[ \\v\\h]*(?:\\/\\*.*?\\*\\/)*)*/;\n"
6387 "function f(s) { return s.match(sourceLineBeginningSkip)[0].length; }"; 6386 "function f(s) { return s.match(sourceLineBeginningSkip)[0].length; }";
6388 6387
6389 v8::Local<v8::Function> f = CompileFunction(script, "f"); 6388 v8::Local<v8::Function> f = CompileFunction(script, "f");
6390 const int argc = 1; 6389 const int argc = 1;
6391 v8::Handle<v8::Value> argv[argc] = { v8::String::New(" /* xxx */ a=0;") }; 6390 v8::Handle<v8::Value> argv[argc] = { v8::String::New(" /* xxx */ a=0;") };
6392 v8::Local<v8::Value> result = f->Call(env->Global(), argc, argv); 6391 v8::Local<v8::Value> result = f->Call(env->Global(), argc, argv);
6393 CHECK_EQ(12, result->Int32Value()); 6392 CHECK_EQ(12, result->Int32Value());
6394 6393
6395 v8::Debug::SetDebugEventListener2(DebugEventDebugBreak); 6394 v8::Debug::SetDebugEventListener2(DebugEventDebugBreak);
6396 v8::Debug::DebugBreak(); 6395 v8::Debug::DebugBreak(env->GetIsolate());
6397 result = f->Call(env->Global(), argc, argv); 6396 result = f->Call(env->Global(), argc, argv);
6398 6397
6399 // Check that there was only one break event. Matching RegExp should not 6398 // Check that there was only one break event. Matching RegExp should not
6400 // cause Break events. 6399 // cause Break events.
6401 CHECK_EQ(1, break_point_hit_count); 6400 CHECK_EQ(1, break_point_hit_count);
6402 CHECK_EQ("f", last_function_hit); 6401 CHECK_EQ("f", last_function_hit);
6403 } 6402 }
6404 #endif // V8_INTERPRETED_REGEXP 6403 #endif // V8_INTERPRETED_REGEXP
6405 6404
6406 6405
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
6464 const v8::Debug::Message& message) { 6463 const v8::Debug::Message& message) {
6465 CHECK(message.GetEventContext() == expected_context); 6464 CHECK(message.GetEventContext() == expected_context);
6466 CHECK(message.GetEventContext()->GetEmbedderData(0)->StrictEquals( 6465 CHECK(message.GetEventContext()->GetEmbedderData(0)->StrictEquals(
6467 expected_context_data)); 6466 expected_context_data));
6468 message_handler_hit_count++; 6467 message_handler_hit_count++;
6469 6468
6470 static char print_buffer[1000]; 6469 static char print_buffer[1000];
6471 v8::String::Value json(message.GetJSON()); 6470 v8::String::Value json(message.GetJSON());
6472 Utf16ToAscii(*json, json.length(), print_buffer); 6471 Utf16ToAscii(*json, json.length(), print_buffer);
6473 6472
6473 v8::Isolate* isolate = message.GetIsolate();
6474 if (IsBreakEventMessage(print_buffer)) { 6474 if (IsBreakEventMessage(print_buffer)) {
6475 break_count++; 6475 break_count++;
6476 if (!sent_eval) { 6476 if (!sent_eval) {
6477 sent_eval = true; 6477 sent_eval = true;
6478 6478
6479 const int kBufferSize = 1000; 6479 const int kBufferSize = 1000;
6480 uint16_t buffer[kBufferSize]; 6480 uint16_t buffer[kBufferSize];
6481 const char* eval_command = 6481 const char* eval_command =
6482 "{\"seq\":0," 6482 "{\"seq\":0,"
6483 "\"type\":\"request\"," 6483 "\"type\":\"request\","
6484 "\"command\":\"evaluate\"," 6484 "\"command\":\"evaluate\","
6485 "\"arguments\":{\"expression\":\"debugger;\"," 6485 "\"arguments\":{\"expression\":\"debugger;\","
6486 "\"global\":true,\"disable_break\":false}}"; 6486 "\"global\":true,\"disable_break\":false}}";
6487 6487
6488 // Send evaluate command. 6488 // Send evaluate command.
6489 v8::Debug::SendCommand(buffer, AsciiToUtf16(eval_command, buffer)); 6489 v8::Debug::SendCommand(
6490 isolate, buffer, AsciiToUtf16(eval_command, buffer));
6490 return; 6491 return;
6491 } else { 6492 } else {
6492 // It's a break event caused by the evaluation request above. 6493 // It's a break event caused by the evaluation request above.
6493 SendContinueCommand(); 6494 SendContinueCommand();
6494 continue_command_send_count++; 6495 continue_command_send_count++;
6495 } 6496 }
6496 } else if (IsEvaluateResponseMessage(print_buffer) && 6497 } else if (IsEvaluateResponseMessage(print_buffer) &&
6497 continue_command_send_count < 2) { 6498 continue_command_send_count < 2) {
6498 // Response to the evaluation request. We're still on the breakpoint so 6499 // Response to the evaluation request. We're still on the breakpoint so
6499 // send continue. 6500 // send continue.
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
6653 DebugLocalContext env; 6654 DebugLocalContext env;
6654 v8::HandleScope scope(env->GetIsolate()); 6655 v8::HandleScope scope(env->GetIsolate());
6655 after_compile_message_count = 0; 6656 after_compile_message_count = 0;
6656 const char* script = "var a=1"; 6657 const char* script = "var a=1";
6657 6658
6658 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler); 6659 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
6659 v8::Script::Compile(v8::String::New(script))->Run(); 6660 v8::Script::Compile(v8::String::New(script))->Run();
6660 v8::Debug::SetMessageHandler2(NULL); 6661 v8::Debug::SetMessageHandler2(NULL);
6661 6662
6662 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler); 6663 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
6663 v8::Debug::DebugBreak(); 6664 v8::Debug::DebugBreak(env->GetIsolate());
6664 v8::Script::Compile(v8::String::New(script))->Run(); 6665 v8::Script::Compile(v8::String::New(script))->Run();
6665 6666
6666 // Setting listener to NULL should cause debugger unload. 6667 // Setting listener to NULL should cause debugger unload.
6667 v8::Debug::SetMessageHandler2(NULL); 6668 v8::Debug::SetMessageHandler2(NULL);
6668 CheckDebuggerUnloaded(); 6669 CheckDebuggerUnloaded();
6669 6670
6670 // Compilation cache should be disabled when debugger is active. 6671 // Compilation cache should be disabled when debugger is active.
6671 CHECK_EQ(2, after_compile_message_count); 6672 CHECK_EQ(2, after_compile_message_count);
6672 } 6673 }
6673 6674
6674 6675
6675 // Tests that break event is sent when message handler is reset. 6676 // Tests that break event is sent when message handler is reset.
6676 TEST(BreakMessageWhenMessageHandlerIsReset) { 6677 TEST(BreakMessageWhenMessageHandlerIsReset) {
6677 DebugLocalContext env; 6678 DebugLocalContext env;
6678 v8::HandleScope scope(env->GetIsolate()); 6679 v8::HandleScope scope(env->GetIsolate());
6679 after_compile_message_count = 0; 6680 after_compile_message_count = 0;
6680 const char* script = "function f() {};"; 6681 const char* script = "function f() {};";
6681 6682
6682 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler); 6683 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
6683 v8::Script::Compile(v8::String::New(script))->Run(); 6684 v8::Script::Compile(v8::String::New(script))->Run();
6684 v8::Debug::SetMessageHandler2(NULL); 6685 v8::Debug::SetMessageHandler2(NULL);
6685 6686
6686 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler); 6687 v8::Debug::SetMessageHandler2(AfterCompileMessageHandler);
6687 v8::Debug::DebugBreak(); 6688 v8::Debug::DebugBreak(env->GetIsolate());
6688 v8::Local<v8::Function> f = 6689 v8::Local<v8::Function> f =
6689 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f"))); 6690 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("f")));
6690 f->Call(env->Global(), 0, NULL); 6691 f->Call(env->Global(), 0, NULL);
6691 6692
6692 // Setting message handler to NULL should cause debugger unload. 6693 // Setting message handler to NULL should cause debugger unload.
6693 v8::Debug::SetMessageHandler2(NULL); 6694 v8::Debug::SetMessageHandler2(NULL);
6694 CheckDebuggerUnloaded(); 6695 CheckDebuggerUnloaded();
6695 6696
6696 // Compilation cache should be disabled when debugger is active. 6697 // Compilation cache should be disabled when debugger is active.
6697 CHECK_EQ(1, after_compile_message_count); 6698 CHECK_EQ(1, after_compile_message_count);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
6797 isolate->stack_guard()->DebugBreak(); 6798 isolate->stack_guard()->DebugBreak();
6798 } else { 6799 } else {
6799 isolate->stack_guard()->Continue(i::DEBUGBREAK); 6800 isolate->stack_guard()->Continue(i::DEBUGBREAK);
6800 } 6801 }
6801 } 6802 }
6802 } 6803 }
6803 6804
6804 6805
6805 // Test that if DebugBreak is forced it is ignored when code from 6806 // Test that if DebugBreak is forced it is ignored when code from
6806 // debug-delay.js is executed. 6807 // debug-delay.js is executed.
6807 TEST(NoDebugBreakInAfterCompileMessageHandler) { 6808 UNINITIALIZED_TEST(NoDebugBreakInAfterCompileMessageHandler) {
6808 DebugLocalContext env; 6809 DebugLocalContext env;
6809 v8::HandleScope scope(env->GetIsolate()); 6810 v8::HandleScope scope(env->GetIsolate());
6810 6811
6811 // Register a debug event listener which sets the break flag and counts. 6812 // Register a debug event listener which sets the break flag and counts.
6812 v8::Debug::SetMessageHandler2(BreakMessageHandler); 6813 v8::Debug::SetMessageHandler2(BreakMessageHandler);
6813 6814
6814 // Set the debug break flag. 6815 // Set the debug break flag.
6815 v8::Debug::DebugBreak(); 6816 v8::Debug::DebugBreak();
6816 6817
6817 // Create a function for testing stepping. 6818 // Create a function for testing stepping.
6818 const char* src = "function f() { eval('var x = 10;'); } "; 6819 const char* src = "function f() { eval('var x = 10;'); } ";
6819 v8::Local<v8::Function> f = CompileFunction(&env, src, "f"); 6820 v8::Local<v8::Function> f = CompileFunction(&env, src, "f");
6820 6821
6821 // There should be only one break event. 6822 // There should be only one break event.
6822 CHECK_EQ(1, break_point_hit_count); 6823 CHECK_EQ(1, break_point_hit_count);
6823 6824
6824 // Set the debug break flag again. 6825 // Set the debug break flag again.
6825 v8::Debug::DebugBreak(); 6826 v8::Debug::DebugBreak(env->GetIsolate());
6826 f->Call(env->Global(), 0, NULL); 6827 f->Call(env->Global(), 0, NULL);
6827 // There should be one more break event when the script is evaluated in 'f'. 6828 // There should be one more break event when the script is evaluated in 'f'.
6828 CHECK_EQ(2, break_point_hit_count); 6829 CHECK_EQ(2, break_point_hit_count);
6829 6830
6830 // Get rid of the debug message handler. 6831 // Get rid of the debug message handler.
6831 v8::Debug::SetMessageHandler2(NULL); 6832 v8::Debug::SetMessageHandler2(NULL);
6832 CheckDebuggerUnloaded(); 6833 CheckDebuggerUnloaded();
6833 } 6834 }
6834 6835
6835 6836
6836 static int counting_message_handler_counter; 6837 static int counting_message_handler_counter;
6837 6838
6838 static void CountingMessageHandler(const v8::Debug::Message& message) { 6839 static void CountingMessageHandler(const v8::Debug::Message& message) {
6839 counting_message_handler_counter++; 6840 counting_message_handler_counter++;
6840 } 6841 }
6841 6842
6842 6843
6843 // Test that debug messages get processed when ProcessDebugMessages is called. 6844 // Test that debug messages get processed when ProcessDebugMessages is called.
6844 TEST(ProcessDebugMessages) { 6845 TEST(ProcessDebugMessages) {
6845 DebugLocalContext env; 6846 DebugLocalContext env;
6846 v8::HandleScope scope(env->GetIsolate()); 6847 v8::Isolate* isolate = env->GetIsolate();
6848 v8::HandleScope scope(isolate);
6847 6849
6848 counting_message_handler_counter = 0; 6850 counting_message_handler_counter = 0;
6849 6851
6850 v8::Debug::SetMessageHandler2(CountingMessageHandler); 6852 v8::Debug::SetMessageHandler2(CountingMessageHandler);
6851 6853
6852 const int kBufferSize = 1000; 6854 const int kBufferSize = 1000;
6853 uint16_t buffer[kBufferSize]; 6855 uint16_t buffer[kBufferSize];
6854 const char* scripts_command = 6856 const char* scripts_command =
6855 "{\"seq\":0," 6857 "{\"seq\":0,"
6856 "\"type\":\"request\"," 6858 "\"type\":\"request\","
6857 "\"command\":\"scripts\"}"; 6859 "\"command\":\"scripts\"}";
6858 6860
6859 // Send scripts command. 6861 // Send scripts command.
6860 v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer)); 6862 v8::Debug::SendCommand(
6863 isolate, buffer, AsciiToUtf16(scripts_command, buffer));
6861 6864
6862 CHECK_EQ(0, counting_message_handler_counter); 6865 CHECK_EQ(0, counting_message_handler_counter);
6863 v8::Debug::ProcessDebugMessages(); 6866 v8::Debug::ProcessDebugMessages();
6864 // At least one message should come 6867 // At least one message should come
6865 CHECK_GE(counting_message_handler_counter, 1); 6868 CHECK_GE(counting_message_handler_counter, 1);
6866 6869
6867 counting_message_handler_counter = 0; 6870 counting_message_handler_counter = 0;
6868 6871
6869 v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer)); 6872 v8::Debug::SendCommand(
6870 v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer)); 6873 isolate, buffer, AsciiToUtf16(scripts_command, buffer));
6874 v8::Debug::SendCommand(
6875 isolate, buffer, AsciiToUtf16(scripts_command, buffer));
6871 CHECK_EQ(0, counting_message_handler_counter); 6876 CHECK_EQ(0, counting_message_handler_counter);
6872 v8::Debug::ProcessDebugMessages(); 6877 v8::Debug::ProcessDebugMessages();
6873 // At least two messages should come 6878 // At least two messages should come
6874 CHECK_GE(counting_message_handler_counter, 2); 6879 CHECK_GE(counting_message_handler_counter, 2);
6875 6880
6876 // Get rid of the debug message handler. 6881 // Get rid of the debug message handler.
6877 v8::Debug::SetMessageHandler2(NULL); 6882 v8::Debug::SetMessageHandler2(NULL);
6878 CheckDebuggerUnloaded(); 6883 CheckDebuggerUnloaded();
6879 } 6884 }
6880 6885
(...skipping 11 matching lines...) Expand all
6892 frame_counter = GetTotalFramesInt(print_buffer); 6897 frame_counter = GetTotalFramesInt(print_buffer);
6893 } 6898 }
6894 }; 6899 };
6895 6900
6896 int BacktraceData::frame_counter; 6901 int BacktraceData::frame_counter;
6897 6902
6898 6903
6899 // Test that debug messages get processed when ProcessDebugMessages is called. 6904 // Test that debug messages get processed when ProcessDebugMessages is called.
6900 TEST(Backtrace) { 6905 TEST(Backtrace) {
6901 DebugLocalContext env; 6906 DebugLocalContext env;
6902 v8::HandleScope scope(env->GetIsolate()); 6907 v8::Isolate* isolate = env->GetIsolate();
6908 v8::HandleScope scope(isolate);
6903 6909
6904 v8::Debug::SetMessageHandler2(BacktraceData::MessageHandler); 6910 v8::Debug::SetMessageHandler2(BacktraceData::MessageHandler);
6905 6911
6906 const int kBufferSize = 1000; 6912 const int kBufferSize = 1000;
6907 uint16_t buffer[kBufferSize]; 6913 uint16_t buffer[kBufferSize];
6908 const char* scripts_command = 6914 const char* scripts_command =
6909 "{\"seq\":0," 6915 "{\"seq\":0,"
6910 "\"type\":\"request\"," 6916 "\"type\":\"request\","
6911 "\"command\":\"backtrace\"}"; 6917 "\"command\":\"backtrace\"}";
6912 6918
6913 // Check backtrace from ProcessDebugMessages. 6919 // Check backtrace from ProcessDebugMessages.
6914 BacktraceData::frame_counter = -10; 6920 BacktraceData::frame_counter = -10;
6915 v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer)); 6921 v8::Debug::SendCommand(
6922 isolate,
6923 buffer,
6924 AsciiToUtf16(scripts_command, buffer),
6925 NULL);
6916 v8::Debug::ProcessDebugMessages(); 6926 v8::Debug::ProcessDebugMessages();
6917 CHECK_EQ(BacktraceData::frame_counter, 0); 6927 CHECK_EQ(BacktraceData::frame_counter, 0);
6918 6928
6919 v8::Handle<v8::String> void0 = v8::String::New("void(0)"); 6929 v8::Handle<v8::String> void0 = v8::String::New("void(0)");
6920 v8::Handle<v8::Script> script = v8::Script::Compile(void0, void0); 6930 v8::Handle<v8::Script> script = v8::Script::Compile(void0, void0);
6921 6931
6922 // Check backtrace from "void(0)" script. 6932 // Check backtrace from "void(0)" script.
6923 BacktraceData::frame_counter = -10; 6933 BacktraceData::frame_counter = -10;
6924 v8::Debug::SendCommand(buffer, AsciiToUtf16(scripts_command, buffer)); 6934 v8::Debug::SendCommand(
6935 isolate,
6936 buffer,
6937 AsciiToUtf16(scripts_command, buffer),
6938 NULL);
6925 script->Run(); 6939 script->Run();
6926 CHECK_EQ(BacktraceData::frame_counter, 1); 6940 CHECK_EQ(BacktraceData::frame_counter, 1);
6927 6941
6928 // Get rid of the debug message handler. 6942 // Get rid of the debug message handler.
6929 v8::Debug::SetMessageHandler2(NULL); 6943 v8::Debug::SetMessageHandler2(NULL);
6930 CheckDebuggerUnloaded(); 6944 CheckDebuggerUnloaded();
6931 } 6945 }
6932 6946
6933 6947
6934 TEST(GetMirror) { 6948 TEST(GetMirror) {
(...skipping 23 matching lines...) Expand all
6958 &env, 6972 &env,
6959 "function baz(x) { }" 6973 "function baz(x) { }"
6960 "function bar(x) { baz(); }" 6974 "function bar(x) { baz(); }"
6961 "function foo(){ bar.apply(this, [1]); }", 6975 "function foo(){ bar.apply(this, [1]); }",
6962 "foo"); 6976 "foo");
6963 6977
6964 // Register a debug event listener which steps and counts. 6978 // Register a debug event listener which steps and counts.
6965 v8::Debug::SetDebugEventListener2(DebugEventBreakMax); 6979 v8::Debug::SetDebugEventListener2(DebugEventBreakMax);
6966 6980
6967 // Set the debug break flag before calling the code using function.apply. 6981 // Set the debug break flag before calling the code using function.apply.
6968 v8::Debug::DebugBreak(); 6982 v8::Debug::DebugBreak(env->GetIsolate());
6969 6983
6970 // Limit the number of debug breaks. This is a regression test for issue 493 6984 // Limit the number of debug breaks. This is a regression test for issue 493
6971 // where this test would enter an infinite loop. 6985 // where this test would enter an infinite loop.
6972 break_point_hit_count = 0; 6986 break_point_hit_count = 0;
6973 max_break_point_hit_count = 10000; // 10000 => infinite loop. 6987 max_break_point_hit_count = 10000; // 10000 => infinite loop.
6974 foo->Call(env->Global(), 0, NULL); 6988 foo->Call(env->Global(), 0, NULL);
6975 6989
6976 // When keeping the debug break several break will happen. 6990 // When keeping the debug break several break will happen.
6977 CHECK_GT(break_point_hit_count, 1); 6991 CHECK_GT(break_point_hit_count, 1);
6978 6992
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
7105 was_debug_event_called = true; 7119 was_debug_event_called = true;
7106 } else if (details.GetEvent() == v8::Break) { 7120 } else if (details.GetEvent() == v8::Break) {
7107 was_debug_break_called = true; 7121 was_debug_break_called = true;
7108 } 7122 }
7109 } 7123 }
7110 7124
7111 7125
7112 // Check that event details contain context where debug event occured. 7126 // Check that event details contain context where debug event occured.
7113 TEST(DebugEventBreakData) { 7127 TEST(DebugEventBreakData) {
7114 DebugLocalContext env; 7128 DebugLocalContext env;
7115 v8::HandleScope scope(env->GetIsolate()); 7129 v8::Isolate* isolate = env->GetIsolate();
7130 v8::HandleScope scope(isolate);
7116 v8::Debug::SetDebugEventListener2(DebugEventBreakDataChecker); 7131 v8::Debug::SetDebugEventListener2(DebugEventBreakDataChecker);
7117 7132
7118 TestClientData::constructor_call_counter = 0; 7133 TestClientData::constructor_call_counter = 0;
7119 TestClientData::destructor_call_counter = 0; 7134 TestClientData::destructor_call_counter = 0;
7120 7135
7121 expected_break_data = NULL; 7136 expected_break_data = NULL;
7122 was_debug_event_called = false; 7137 was_debug_event_called = false;
7123 was_debug_break_called = false; 7138 was_debug_break_called = false;
7124 v8::Debug::DebugBreakForCommand(); 7139 v8::Debug::DebugBreakForCommand(NULL, isolate);
7125 v8::Script::Compile(v8::String::New("(function(x){return x;})(1);"))->Run(); 7140 v8::Script::Compile(v8::String::New("(function(x){return x;})(1);"))->Run();
7126 CHECK(was_debug_event_called); 7141 CHECK(was_debug_event_called);
7127 CHECK(!was_debug_break_called); 7142 CHECK(!was_debug_break_called);
7128 7143
7129 TestClientData* data1 = new TestClientData(); 7144 TestClientData* data1 = new TestClientData();
7130 expected_break_data = data1; 7145 expected_break_data = data1;
7131 was_debug_event_called = false; 7146 was_debug_event_called = false;
7132 was_debug_break_called = false; 7147 was_debug_break_called = false;
7133 v8::Debug::DebugBreakForCommand(data1); 7148 v8::Debug::DebugBreakForCommand(data1, isolate);
7134 v8::Script::Compile(v8::String::New("(function(x){return x+1;})(1);"))->Run(); 7149 v8::Script::Compile(v8::String::New("(function(x){return x+1;})(1);"))->Run();
7135 CHECK(was_debug_event_called); 7150 CHECK(was_debug_event_called);
7136 CHECK(!was_debug_break_called); 7151 CHECK(!was_debug_break_called);
7137 7152
7138 expected_break_data = NULL; 7153 expected_break_data = NULL;
7139 was_debug_event_called = false; 7154 was_debug_event_called = false;
7140 was_debug_break_called = false; 7155 was_debug_break_called = false;
7141 v8::Debug::DebugBreak(); 7156 v8::Debug::DebugBreak(isolate);
7142 v8::Script::Compile(v8::String::New("(function(x){return x+2;})(1);"))->Run(); 7157 v8::Script::Compile(v8::String::New("(function(x){return x+2;})(1);"))->Run();
7143 CHECK(!was_debug_event_called); 7158 CHECK(!was_debug_event_called);
7144 CHECK(was_debug_break_called); 7159 CHECK(was_debug_break_called);
7145 7160
7146 TestClientData* data2 = new TestClientData(); 7161 TestClientData* data2 = new TestClientData();
7147 expected_break_data = data2; 7162 expected_break_data = data2;
7148 was_debug_event_called = false; 7163 was_debug_event_called = false;
7149 was_debug_break_called = false; 7164 was_debug_break_called = false;
7150 v8::Debug::DebugBreak(); 7165 v8::Debug::DebugBreak(isolate);
7151 v8::Debug::DebugBreakForCommand(data2); 7166 v8::Debug::DebugBreakForCommand(data2, isolate);
7152 v8::Script::Compile(v8::String::New("(function(x){return x+3;})(1);"))->Run(); 7167 v8::Script::Compile(v8::String::New("(function(x){return x+3;})(1);"))->Run();
7153 CHECK(was_debug_event_called); 7168 CHECK(was_debug_event_called);
7154 CHECK(was_debug_break_called); 7169 CHECK(was_debug_break_called);
7155 7170
7156 CHECK_EQ(2, TestClientData::constructor_call_counter); 7171 CHECK_EQ(2, TestClientData::constructor_call_counter);
7157 CHECK_EQ(TestClientData::constructor_call_counter, 7172 CHECK_EQ(TestClientData::constructor_call_counter,
7158 TestClientData::destructor_call_counter); 7173 TestClientData::destructor_call_counter);
7159 7174
7160 v8::Debug::SetDebugEventListener2(NULL); 7175 v8::Debug::SetDebugEventListener2(NULL);
7161 CheckDebuggerUnloaded(); 7176 CheckDebuggerUnloaded();
(...skipping 17 matching lines...) Expand all
7179 CHECK(result->IsString()); 7194 CHECK(result->IsString());
7180 v8::Handle<v8::String> function_name(result->ToString()); 7195 v8::Handle<v8::String> function_name(result->ToString());
7181 function_name->WriteUtf8(fn); 7196 function_name->WriteUtf8(fn);
7182 if (strcmp(fn, "bar") == 0) { 7197 if (strcmp(fn, "bar") == 0) {
7183 i::Deoptimizer::DeoptimizeAll(v8::internal::Isolate::Current()); 7198 i::Deoptimizer::DeoptimizeAll(v8::internal::Isolate::Current());
7184 debug_event_break_deoptimize_done = true; 7199 debug_event_break_deoptimize_done = true;
7185 } 7200 }
7186 } 7201 }
7187 } 7202 }
7188 7203
7189 v8::Debug::DebugBreak(); 7204 v8::Debug::DebugBreak(v8::Isolate::GetCurrent());
7190 } 7205 }
7191 } 7206 }
7192 7207
7193 7208
7194 // Test deoptimization when execution is broken using the debug break stack 7209 // Test deoptimization when execution is broken using the debug break stack
7195 // check interrupt. 7210 // check interrupt.
7196 TEST(DeoptimizeDuringDebugBreak) { 7211 TEST(DeoptimizeDuringDebugBreak) {
7197 DebugLocalContext env; 7212 DebugLocalContext env;
7198 v8::HandleScope scope(env->GetIsolate()); 7213 v8::HandleScope scope(env->GetIsolate());
7199 env.ExposeDebug(); 7214 env.ExposeDebug();
7200 7215
7201 // Create a function for checking the function when hitting a break point. 7216 // Create a function for checking the function when hitting a break point.
7202 frame_function_name = CompileFunction(&env, 7217 frame_function_name = CompileFunction(&env,
7203 frame_function_name_source, 7218 frame_function_name_source,
7204 "frame_function_name"); 7219 "frame_function_name");
7205 7220
7206 7221
7207 // Set a debug event listener which will keep interrupting execution until 7222 // Set a debug event listener which will keep interrupting execution until
7208 // debug break. When inside function bar it will deoptimize all functions. 7223 // debug break. When inside function bar it will deoptimize all functions.
7209 // This tests lazy deoptimization bailout for the stack check, as the first 7224 // This tests lazy deoptimization bailout for the stack check, as the first
7210 // time in function bar when using debug break and no break points will be at 7225 // time in function bar when using debug break and no break points will be at
7211 // the initial stack check. 7226 // the initial stack check.
7212 v8::Debug::SetDebugEventListener2(DebugEventBreakDeoptimize); 7227 v8::Debug::SetDebugEventListener2(DebugEventBreakDeoptimize);
7213 7228
7214 // Compile and run function bar which will optimize it for some flag settings. 7229 // Compile and run function bar which will optimize it for some flag settings.
7215 v8::Script::Compile(v8::String::New("function bar(){}; bar()"))->Run(); 7230 v8::Script::Compile(v8::String::New("function bar(){}; bar()"))->Run();
7216 7231
7217 // Set debug break and call bar again. 7232 // Set debug break and call bar again.
7218 v8::Debug::DebugBreak(); 7233 v8::Debug::DebugBreak(env->GetIsolate());
7219 v8::Script::Compile(v8::String::New("bar()"))->Run(); 7234 v8::Script::Compile(v8::String::New("bar()"))->Run();
7220 7235
7221 CHECK(debug_event_break_deoptimize_done); 7236 CHECK(debug_event_break_deoptimize_done);
7222 7237
7223 v8::Debug::SetDebugEventListener2(NULL); 7238 v8::Debug::SetDebugEventListener2(NULL);
7224 } 7239 }
7225 7240
7226 7241
7227 static void DebugEventBreakWithOptimizedStack( 7242 static void DebugEventBreakWithOptimizedStack(
7228 const v8::Debug::EventDetails& event_details) { 7243 const v8::Debug::EventDetails& event_details) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
7266 result = frame_local_value->Call(exec_state, argc, argv); 7281 result = frame_local_value->Call(exec_state, argc, argv);
7267 CHECK(result->IsUndefined() || (result->Int32Value() == 42)); 7282 CHECK(result->IsUndefined() || (result->Int32Value() == 42));
7268 } 7283 }
7269 } 7284 }
7270 } 7285 }
7271 } 7286 }
7272 7287
7273 7288
7274 static void ScheduleBreak(const v8::FunctionCallbackInfo<v8::Value>& args) { 7289 static void ScheduleBreak(const v8::FunctionCallbackInfo<v8::Value>& args) {
7275 v8::Debug::SetDebugEventListener2(DebugEventBreakWithOptimizedStack); 7290 v8::Debug::SetDebugEventListener2(DebugEventBreakWithOptimizedStack);
7276 v8::Debug::DebugBreak(); 7291 v8::Debug::DebugBreak(args.GetIsolate());
7277 } 7292 }
7278 7293
7279 7294
7280 TEST(DebugBreakStackInspection) { 7295 TEST(DebugBreakStackInspection) {
7281 DebugLocalContext env; 7296 DebugLocalContext env;
7282 v8::HandleScope scope(env->GetIsolate()); 7297 v8::HandleScope scope(env->GetIsolate());
7283 7298
7284 frame_function_name = 7299 frame_function_name =
7285 CompileFunction(&env, frame_function_name_source, "frame_function_name"); 7300 CompileFunction(&env, frame_function_name_source, "frame_function_name");
7286 frame_argument_name = 7301 frame_argument_name =
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
7331 7346
7332 EmbeddedVector<char, 1024> buffer; 7347 EmbeddedVector<char, 1024> buffer;
7333 OS::SNPrintF(buffer, 7348 OS::SNPrintF(buffer,
7334 "function f() {%s%s%s}", 7349 "function f() {%s%s%s}",
7335 loop_head, loop_bodies[i], loop_tail); 7350 loop_head, loop_bodies[i], loop_tail);
7336 7351
7337 // Function with infinite loop. 7352 // Function with infinite loop.
7338 CompileRun(buffer.start()); 7353 CompileRun(buffer.start());
7339 7354
7340 // Set the debug break to enter the debugger as soon as possible. 7355 // Set the debug break to enter the debugger as soon as possible.
7341 v8::Debug::DebugBreak(); 7356 v8::Debug::DebugBreak(CcTest::isolate());
7342 7357
7343 // Call function with infinite loop. 7358 // Call function with infinite loop.
7344 CompileRun("f();"); 7359 CompileRun("f();");
7345 CHECK_EQ(kBreaksPerTest, break_point_hit_count); 7360 CHECK_EQ(kBreaksPerTest, break_point_hit_count);
7346 7361
7347 CHECK(!v8::V8::IsExecutionTerminating()); 7362 CHECK(!v8::V8::IsExecutionTerminating());
7348 } 7363 }
7349 } 7364 }
7350 } 7365 }
7351 7366
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
7401 v8::DebugEvent event = event_details.GetEvent(); 7416 v8::DebugEvent event = event_details.GetEvent();
7402 if (event != v8::Break) return; 7417 if (event != v8::Break) return;
7403 7418
7404 int expected_frame_count = 4; 7419 int expected_frame_count = 4;
7405 int expected_line_number[] = {1, 4, 7, 12}; 7420 int expected_line_number[] = {1, 4, 7, 12};
7406 7421
7407 i::Handle<i::Object> compiled_script = v8::Utils::OpenHandle(*inline_script); 7422 i::Handle<i::Object> compiled_script = v8::Utils::OpenHandle(*inline_script);
7408 i::Handle<i::Script> source_script = i::Handle<i::Script>(i::Script::cast( 7423 i::Handle<i::Script> source_script = i::Handle<i::Script>(i::Script::cast(
7409 i::JSFunction::cast(*compiled_script)->shared()->script())); 7424 i::JSFunction::cast(*compiled_script)->shared()->script()));
7410 7425
7411 int break_id = v8::internal::Isolate::Current()->debug()->break_id(); 7426 int break_id = CcTest::i_isolate()->debug()->break_id();
7412 char script[128]; 7427 char script[128];
7413 i::Vector<char> script_vector(script, sizeof(script)); 7428 i::Vector<char> script_vector(script, sizeof(script));
7414 OS::SNPrintF(script_vector, "%%GetFrameCount(%d)", break_id); 7429 OS::SNPrintF(script_vector, "%%GetFrameCount(%d)", break_id);
7415 v8::Local<v8::Value> result = CompileRun(script); 7430 v8::Local<v8::Value> result = CompileRun(script);
7416 7431
7417 int frame_count = result->Int32Value(); 7432 int frame_count = result->Int32Value();
7418 CHECK_EQ(expected_frame_count, frame_count); 7433 CHECK_EQ(expected_frame_count, frame_count);
7419 7434
7420 for (int i = 0; i < frame_count; i++) { 7435 for (int i = 0; i < frame_count; i++) {
7421 // The 5. element in the returned array of GetFrameDetails contains the 7436 // The 5. element in the returned array of GetFrameDetails contains the
7422 // source position of that frame. 7437 // source position of that frame.
7423 OS::SNPrintF(script_vector, "%%GetFrameDetails(%d, %d)[5]", break_id, i); 7438 OS::SNPrintF(script_vector, "%%GetFrameDetails(%d, %d)[5]", break_id, i);
7424 v8::Local<v8::Value> result = CompileRun(script); 7439 v8::Local<v8::Value> result = CompileRun(script);
7425 CHECK_EQ(expected_line_number[i], 7440 CHECK_EQ(expected_line_number[i],
7426 i::GetScriptLineNumber(source_script, result->Int32Value())); 7441 i::GetScriptLineNumber(source_script, result->Int32Value()));
7427 } 7442 }
7428 v8::Debug::SetDebugEventListener2(NULL); 7443 v8::Debug::SetDebugEventListener2(NULL);
7429 v8::V8::TerminateExecution(); 7444 v8::V8::TerminateExecution(CcTest::isolate());
7430 } 7445 }
7431 7446
7432 7447
7433 TEST(DebugBreakInline) { 7448 TEST(DebugBreakInline) {
7434 i::FLAG_allow_natives_syntax = true; 7449 i::FLAG_allow_natives_syntax = true;
7435 DebugLocalContext env; 7450 DebugLocalContext env;
7436 v8::HandleScope scope(env->GetIsolate()); 7451 v8::HandleScope scope(env->GetIsolate());
7437 const char* source = 7452 const char* source =
7438 "function debug(b) { \n" 7453 "function debug(b) { \n"
7439 " if (b) debugger; \n" 7454 " if (b) debugger; \n"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
7519 CHECK_EQ(2, CountNativeContexts()); 7534 CHECK_EQ(2, CountNativeContexts());
7520 7535
7521 v8::Debug::SetDebugEventListener2(NULL); 7536 v8::Debug::SetDebugEventListener2(NULL);
7522 } 7537 }
7523 7538
7524 7539
7525 TEST(LiveEditEnabled) { 7540 TEST(LiveEditEnabled) {
7526 v8::internal::FLAG_allow_natives_syntax = true; 7541 v8::internal::FLAG_allow_natives_syntax = true;
7527 LocalContext env; 7542 LocalContext env;
7528 v8::HandleScope scope(env->GetIsolate()); 7543 v8::HandleScope scope(env->GetIsolate());
7529 v8::Debug::SetLiveEditEnabled(true); 7544 v8::Debug::SetLiveEditEnabled(true, env->GetIsolate());
7530 CompileRun("%LiveEditCompareStrings('', '')"); 7545 CompileRun("%LiveEditCompareStrings('', '')");
7531 } 7546 }
7532 7547
7533 7548
7534 TEST(LiveEditDisabled) { 7549 TEST(LiveEditDisabled) {
7535 v8::internal::FLAG_allow_natives_syntax = true; 7550 v8::internal::FLAG_allow_natives_syntax = true;
7536 LocalContext env; 7551 LocalContext env;
7537 v8::HandleScope scope(env->GetIsolate()); 7552 v8::HandleScope scope(env->GetIsolate());
7538 v8::Debug::SetLiveEditEnabled(false); 7553 v8::Debug::SetLiveEditEnabled(false), env->GetIsolate();
marja 2013/12/02 15:40:45 FYI, I'm fixing the C++ misuse of this old CL here
7539 CompileRun("%LiveEditCompareStrings('', '')"); 7554 CompileRun("%LiveEditCompareStrings('', '')");
7540 } 7555 }
7541 7556
7542 7557
7543 #endif // ENABLE_DEBUGGER_SUPPORT 7558 #endif // ENABLE_DEBUGGER_SUPPORT
OLDNEW
« src/api.cc ('K') | « test/cctest/test-cpu-profiler.cc ('k') | test/cctest/test-lockers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698