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

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

Issue 7003108: "Deiceolate" Thread classes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 6 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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 4710 matching lines...) Expand 10 before | Expand all | Expand 10 after
4721 /* Tests the message queues that hold debugger commands and 4721 /* Tests the message queues that hold debugger commands and
4722 * response messages to the debugger. Fills queues and makes 4722 * response messages to the debugger. Fills queues and makes
4723 * them grow. 4723 * them grow.
4724 */ 4724 */
4725 Barriers message_queue_barriers; 4725 Barriers message_queue_barriers;
4726 4726
4727 // This is the debugger thread, that executes no v8 calls except 4727 // This is the debugger thread, that executes no v8 calls except
4728 // placing JSON debugger commands in the queue. 4728 // placing JSON debugger commands in the queue.
4729 class MessageQueueDebuggerThread : public v8::internal::Thread { 4729 class MessageQueueDebuggerThread : public v8::internal::Thread {
4730 public: 4730 public:
4731 explicit MessageQueueDebuggerThread(v8::internal::Isolate* isolate) 4731 MessageQueueDebuggerThread()
4732 : Thread(isolate, "MessageQueueDebuggerThread") { } 4732 : Thread("MessageQueueDebuggerThread") { }
4733 void Run(); 4733 void Run();
4734 }; 4734 };
4735 4735
4736 static void MessageHandler(const uint16_t* message, int length, 4736 static void MessageHandler(const uint16_t* message, int length,
4737 v8::Debug::ClientData* client_data) { 4737 v8::Debug::ClientData* client_data) {
4738 static char print_buffer[1000]; 4738 static char print_buffer[1000];
4739 Utf16ToAscii(message, length, print_buffer); 4739 Utf16ToAscii(message, length, print_buffer);
4740 if (IsBreakEventMessage(print_buffer)) { 4740 if (IsBreakEventMessage(print_buffer)) {
4741 // Lets test script wait until break occurs to send commands. 4741 // Lets test script wait until break occurs to send commands.
4742 // Signals when a break is reported. 4742 // Signals when a break is reported.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
4825 // Run after 2 responses. 4825 // Run after 2 responses.
4826 for (int i = 0; i < 2 ; ++i) { 4826 for (int i = 0; i < 2 ; ++i) {
4827 message_queue_barriers.semaphore_1->Signal(); 4827 message_queue_barriers.semaphore_1->Signal();
4828 } 4828 }
4829 // Main thread continues running source_3 to end, waits for this thread. 4829 // Main thread continues running source_3 to end, waits for this thread.
4830 } 4830 }
4831 4831
4832 4832
4833 // This thread runs the v8 engine. 4833 // This thread runs the v8 engine.
4834 TEST(MessageQueues) { 4834 TEST(MessageQueues) {
4835 MessageQueueDebuggerThread message_queue_debugger_thread( 4835 MessageQueueDebuggerThread message_queue_debugger_thread;
4836 i::Isolate::Current());
4837 4836
4838 // Create a V8 environment 4837 // Create a V8 environment
4839 v8::HandleScope scope; 4838 v8::HandleScope scope;
4840 DebugLocalContext env; 4839 DebugLocalContext env;
4841 message_queue_barriers.Initialize(); 4840 message_queue_barriers.Initialize();
4842 v8::Debug::SetMessageHandler(MessageHandler); 4841 v8::Debug::SetMessageHandler(MessageHandler);
4843 message_queue_debugger_thread.Start(); 4842 message_queue_debugger_thread.Start();
4844 4843
4845 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;"; 4844 const char* source_1 = "a = 3; b = 4; c = new Object(); c.d = 5;";
4846 const char* source_2 = "e = 17;"; 4845 const char* source_2 = "e = 17;";
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
4973 /* This test interrupts a running infinite loop that is 4972 /* This test interrupts a running infinite loop that is
4974 * occupying the v8 thread by a break command from the 4973 * occupying the v8 thread by a break command from the
4975 * debugger thread. It then changes the value of a 4974 * debugger thread. It then changes the value of a
4976 * global object, to make the loop terminate. 4975 * global object, to make the loop terminate.
4977 */ 4976 */
4978 4977
4979 Barriers threaded_debugging_barriers; 4978 Barriers threaded_debugging_barriers;
4980 4979
4981 class V8Thread : public v8::internal::Thread { 4980 class V8Thread : public v8::internal::Thread {
4982 public: 4981 public:
4983 explicit V8Thread(v8::internal::Isolate* isolate) 4982 V8Thread() : Thread("V8Thread") { }
4984 : Thread(isolate, "V8Thread") { }
4985 void Run(); 4983 void Run();
4986 }; 4984 };
4987 4985
4988 class DebuggerThread : public v8::internal::Thread { 4986 class DebuggerThread : public v8::internal::Thread {
4989 public: 4987 public:
4990 explicit DebuggerThread(v8::internal::Isolate* isolate) 4988 DebuggerThread() : Thread("DebuggerThread") { }
4991 : Thread(isolate, "DebuggerThread") { }
4992 void Run(); 4989 void Run();
4993 }; 4990 };
4994 4991
4995 4992
4996 static v8::Handle<v8::Value> ThreadedAtBarrier1(const v8::Arguments& args) { 4993 static v8::Handle<v8::Value> ThreadedAtBarrier1(const v8::Arguments& args) {
4997 threaded_debugging_barriers.barrier_1.Wait(); 4994 threaded_debugging_barriers.barrier_1.Wait();
4998 return v8::Undefined(); 4995 return v8::Undefined();
4999 } 4996 }
5000 4997
5001 4998
(...skipping 23 matching lines...) Expand all
5025 " while ( flag == true ) {\n" 5022 " while ( flag == true ) {\n"
5026 " if ( x == 1 ) {\n" 5023 " if ( x == 1 ) {\n"
5027 " ThreadedAtBarrier1();\n" 5024 " ThreadedAtBarrier1();\n"
5028 " }\n" 5025 " }\n"
5029 " x = x + 1;\n" 5026 " x = x + 1;\n"
5030 " }\n" 5027 " }\n"
5031 "}\n" 5028 "}\n"
5032 "\n" 5029 "\n"
5033 "foo();\n"; 5030 "foo();\n";
5034 5031
5032 v8::V8::Initialize();
5035 v8::HandleScope scope; 5033 v8::HandleScope scope;
5036 DebugLocalContext env; 5034 DebugLocalContext env;
5037 v8::Debug::SetMessageHandler2(&ThreadedMessageHandler); 5035 v8::Debug::SetMessageHandler2(&ThreadedMessageHandler);
5038 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(); 5036 v8::Handle<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
5039 global_template->Set(v8::String::New("ThreadedAtBarrier1"), 5037 global_template->Set(v8::String::New("ThreadedAtBarrier1"),
5040 v8::FunctionTemplate::New(ThreadedAtBarrier1)); 5038 v8::FunctionTemplate::New(ThreadedAtBarrier1));
5041 v8::Handle<v8::Context> context = v8::Context::New(NULL, global_template); 5039 v8::Handle<v8::Context> context = v8::Context::New(NULL, global_template);
5042 v8::Context::Scope context_scope(context); 5040 v8::Context::Scope context_scope(context);
5043 5041
5044 CompileRun(source); 5042 CompileRun(source);
(...skipping 13 matching lines...) Expand all
5058 5056
5059 threaded_debugging_barriers.barrier_1.Wait(); 5057 threaded_debugging_barriers.barrier_1.Wait();
5060 v8::Debug::DebugBreak(); 5058 v8::Debug::DebugBreak();
5061 threaded_debugging_barriers.barrier_2.Wait(); 5059 threaded_debugging_barriers.barrier_2.Wait();
5062 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer)); 5060 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_1, buffer));
5063 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer)); 5061 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer));
5064 } 5062 }
5065 5063
5066 5064
5067 TEST(ThreadedDebugging) { 5065 TEST(ThreadedDebugging) {
5068 DebuggerThread debugger_thread(i::Isolate::Current()); 5066 DebuggerThread debugger_thread;
5069 V8Thread v8_thread(i::Isolate::Current()); 5067 V8Thread v8_thread;
5070 5068
5071 // Create a V8 environment 5069 // Create a V8 environment
5072 threaded_debugging_barriers.Initialize(); 5070 threaded_debugging_barriers.Initialize();
5073 5071
5074 v8_thread.Start(); 5072 v8_thread.Start();
5075 debugger_thread.Start(); 5073 debugger_thread.Start();
5076 5074
5077 v8_thread.Join(); 5075 v8_thread.Join();
5078 debugger_thread.Join(); 5076 debugger_thread.Join();
5079 } 5077 }
5080 5078
5081 /* Test RecursiveBreakpoints */ 5079 /* Test RecursiveBreakpoints */
5082 /* In this test, the debugger evaluates a function with a breakpoint, after 5080 /* In this test, the debugger evaluates a function with a breakpoint, after
5083 * hitting a breakpoint in another function. We do this with both values 5081 * hitting a breakpoint in another function. We do this with both values
5084 * of the flag enabling recursive breakpoints, and verify that the second 5082 * of the flag enabling recursive breakpoints, and verify that the second
5085 * breakpoint is hit when enabled, and missed when disabled. 5083 * breakpoint is hit when enabled, and missed when disabled.
5086 */ 5084 */
5087 5085
5088 class BreakpointsV8Thread : public v8::internal::Thread { 5086 class BreakpointsV8Thread : public v8::internal::Thread {
5089 public: 5087 public:
5090 explicit BreakpointsV8Thread(v8::internal::Isolate* isolate) 5088 BreakpointsV8Thread() : Thread("BreakpointsV8Thread") { }
5091 : Thread(isolate, "BreakpointsV8Thread") { }
5092 void Run(); 5089 void Run();
5093 }; 5090 };
5094 5091
5095 class BreakpointsDebuggerThread : public v8::internal::Thread { 5092 class BreakpointsDebuggerThread : public v8::internal::Thread {
5096 public: 5093 public:
5097 explicit BreakpointsDebuggerThread(v8::internal::Isolate* isolate, 5094 explicit BreakpointsDebuggerThread(bool global_evaluate)
5098 bool global_evaluate) 5095 : Thread("BreakpointsDebuggerThread"),
5099 : Thread(isolate, "BreakpointsDebuggerThread"),
5100 global_evaluate_(global_evaluate) {} 5096 global_evaluate_(global_evaluate) {}
5101 void Run(); 5097 void Run();
5102 5098
5103 private: 5099 private:
5104 bool global_evaluate_; 5100 bool global_evaluate_;
5105 }; 5101 };
5106 5102
5107 5103
5108 Barriers* breakpoints_barriers; 5104 Barriers* breakpoints_barriers;
5109 int break_event_breakpoint_id; 5105 int break_event_breakpoint_id;
(...skipping 29 matching lines...) Expand all
5139 " var x = 1;\n" 5135 " var x = 1;\n"
5140 " x = y_global;" 5136 " x = y_global;"
5141 " var z = 3;" 5137 " var z = 3;"
5142 " x += 100;\n" 5138 " x += 100;\n"
5143 " return x;\n" 5139 " return x;\n"
5144 "}\n" 5140 "}\n"
5145 "\n"; 5141 "\n";
5146 const char* source_2 = "cat(17);\n" 5142 const char* source_2 = "cat(17);\n"
5147 "cat(19);\n"; 5143 "cat(19);\n";
5148 5144
5145 v8::V8::Initialize();
5149 v8::HandleScope scope; 5146 v8::HandleScope scope;
5150 DebugLocalContext env; 5147 DebugLocalContext env;
5151 v8::Debug::SetMessageHandler2(&BreakpointsMessageHandler); 5148 v8::Debug::SetMessageHandler2(&BreakpointsMessageHandler);
5152 5149
5153 CompileRun(source_1); 5150 CompileRun(source_1);
5154 breakpoints_barriers->barrier_1.Wait(); 5151 breakpoints_barriers->barrier_1.Wait();
5155 breakpoints_barriers->barrier_2.Wait(); 5152 breakpoints_barriers->barrier_2.Wait();
5156 CompileRun(source_2); 5153 CompileRun(source_2);
5157 } 5154 }
5158 5155
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
5266 breakpoints_barriers->semaphore_1->Wait(); 5263 breakpoints_barriers->semaphore_1->Wait();
5267 // Must have result 116. 5264 // Must have result 116.
5268 CHECK_EQ(116, evaluate_int_result); 5265 CHECK_EQ(116, evaluate_int_result);
5269 // 9: Continue evaluation of source2, reach end. 5266 // 9: Continue evaluation of source2, reach end.
5270 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_8, buffer)); 5267 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_8, buffer));
5271 } 5268 }
5272 5269
5273 void TestRecursiveBreakpointsGeneric(bool global_evaluate) { 5270 void TestRecursiveBreakpointsGeneric(bool global_evaluate) {
5274 i::FLAG_debugger_auto_break = true; 5271 i::FLAG_debugger_auto_break = true;
5275 5272
5276 BreakpointsDebuggerThread breakpoints_debugger_thread(i::Isolate::Current(), 5273 BreakpointsDebuggerThread breakpoints_debugger_thread(global_evaluate);
5277 global_evaluate); 5274 BreakpointsV8Thread breakpoints_v8_thread;
5278 BreakpointsV8Thread breakpoints_v8_thread(i::Isolate::Current());
5279 5275
5280 // Create a V8 environment 5276 // Create a V8 environment
5281 Barriers stack_allocated_breakpoints_barriers; 5277 Barriers stack_allocated_breakpoints_barriers;
5282 stack_allocated_breakpoints_barriers.Initialize(); 5278 stack_allocated_breakpoints_barriers.Initialize();
5283 breakpoints_barriers = &stack_allocated_breakpoints_barriers; 5279 breakpoints_barriers = &stack_allocated_breakpoints_barriers;
5284 5280
5285 breakpoints_v8_thread.Start(); 5281 breakpoints_v8_thread.Start();
5286 breakpoints_debugger_thread.Start(); 5282 breakpoints_debugger_thread.Start();
5287 5283
5288 breakpoints_v8_thread.Join(); 5284 breakpoints_v8_thread.Join();
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
5650 } 5646 }
5651 5647
5652 5648
5653 /* Test DebuggerHostDispatch */ 5649 /* Test DebuggerHostDispatch */
5654 /* In this test, the debugger waits for a command on a breakpoint 5650 /* In this test, the debugger waits for a command on a breakpoint
5655 * and is dispatching host commands while in the infinite loop. 5651 * and is dispatching host commands while in the infinite loop.
5656 */ 5652 */
5657 5653
5658 class HostDispatchV8Thread : public v8::internal::Thread { 5654 class HostDispatchV8Thread : public v8::internal::Thread {
5659 public: 5655 public:
5660 explicit HostDispatchV8Thread(v8::internal::Isolate* isolate) 5656 HostDispatchV8Thread() : Thread("HostDispatchV8Thread") { }
5661 : Thread(isolate, "HostDispatchV8Thread") { }
5662 void Run(); 5657 void Run();
5663 }; 5658 };
5664 5659
5665 class HostDispatchDebuggerThread : public v8::internal::Thread { 5660 class HostDispatchDebuggerThread : public v8::internal::Thread {
5666 public: 5661 public:
5667 explicit HostDispatchDebuggerThread(v8::internal::Isolate* isolate) 5662 HostDispatchDebuggerThread() : Thread("HostDispatchDebuggerThread") { }
5668 : Thread(isolate, "HostDispatchDebuggerThread") { }
5669 void Run(); 5663 void Run();
5670 }; 5664 };
5671 5665
5672 Barriers* host_dispatch_barriers; 5666 Barriers* host_dispatch_barriers;
5673 5667
5674 static void HostDispatchMessageHandler(const v8::Debug::Message& message) { 5668 static void HostDispatchMessageHandler(const v8::Debug::Message& message) {
5675 static char print_buffer[1000]; 5669 static char print_buffer[1000];
5676 v8::String::Value json(message.GetJSON()); 5670 v8::String::Value json(message.GetJSON());
5677 Utf16ToAscii(*json, json.length(), print_buffer); 5671 Utf16ToAscii(*json, json.length(), print_buffer);
5678 } 5672 }
5679 5673
5680 5674
5681 static void HostDispatchDispatchHandler() { 5675 static void HostDispatchDispatchHandler() {
5682 host_dispatch_barriers->semaphore_1->Signal(); 5676 host_dispatch_barriers->semaphore_1->Signal();
5683 } 5677 }
5684 5678
5685 5679
5686 void HostDispatchV8Thread::Run() { 5680 void HostDispatchV8Thread::Run() {
5687 const char* source_1 = "var y_global = 3;\n" 5681 const char* source_1 = "var y_global = 3;\n"
5688 "function cat( new_value ) {\n" 5682 "function cat( new_value ) {\n"
5689 " var x = new_value;\n" 5683 " var x = new_value;\n"
5690 " y_global = 4;\n" 5684 " y_global = 4;\n"
5691 " x = 3 * x + 1;\n" 5685 " x = 3 * x + 1;\n"
5692 " y_global = 5;\n" 5686 " y_global = 5;\n"
5693 " return x;\n" 5687 " return x;\n"
5694 "}\n" 5688 "}\n"
5695 "\n"; 5689 "\n";
5696 const char* source_2 = "cat(17);\n"; 5690 const char* source_2 = "cat(17);\n";
5697 5691
5692 v8::V8::Initialize();
5698 v8::HandleScope scope; 5693 v8::HandleScope scope;
5699 DebugLocalContext env; 5694 DebugLocalContext env;
5700 5695
5701 // Setup message and host dispatch handlers. 5696 // Setup message and host dispatch handlers.
5702 v8::Debug::SetMessageHandler2(HostDispatchMessageHandler); 5697 v8::Debug::SetMessageHandler2(HostDispatchMessageHandler);
5703 v8::Debug::SetHostDispatchHandler(HostDispatchDispatchHandler, 10 /* ms */); 5698 v8::Debug::SetHostDispatchHandler(HostDispatchDispatchHandler, 10 /* ms */);
5704 5699
5705 CompileRun(source_1); 5700 CompileRun(source_1);
5706 host_dispatch_barriers->barrier_1.Wait(); 5701 host_dispatch_barriers->barrier_1.Wait();
5707 host_dispatch_barriers->barrier_2.Wait(); 5702 host_dispatch_barriers->barrier_2.Wait();
(...skipping 22 matching lines...) Expand all
5730 // v8 thread starts compiling source_2. 5725 // v8 thread starts compiling source_2.
5731 // Break happens, to run queued commands and host dispatches. 5726 // Break happens, to run queued commands and host dispatches.
5732 // Wait for host dispatch to be processed. 5727 // Wait for host dispatch to be processed.
5733 host_dispatch_barriers->semaphore_1->Wait(); 5728 host_dispatch_barriers->semaphore_1->Wait();
5734 // 2: Continue evaluation 5729 // 2: Continue evaluation
5735 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer)); 5730 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_2, buffer));
5736 } 5731 }
5737 5732
5738 5733
5739 TEST(DebuggerHostDispatch) { 5734 TEST(DebuggerHostDispatch) {
5740 HostDispatchDebuggerThread host_dispatch_debugger_thread( 5735 HostDispatchDebuggerThread host_dispatch_debugger_thread;
5741 i::Isolate::Current()); 5736 HostDispatchV8Thread host_dispatch_v8_thread;
5742 HostDispatchV8Thread host_dispatch_v8_thread(i::Isolate::Current());
5743 i::FLAG_debugger_auto_break = true; 5737 i::FLAG_debugger_auto_break = true;
5744 5738
5745 // Create a V8 environment 5739 // Create a V8 environment
5746 Barriers stack_allocated_host_dispatch_barriers; 5740 Barriers stack_allocated_host_dispatch_barriers;
5747 stack_allocated_host_dispatch_barriers.Initialize(); 5741 stack_allocated_host_dispatch_barriers.Initialize();
5748 host_dispatch_barriers = &stack_allocated_host_dispatch_barriers; 5742 host_dispatch_barriers = &stack_allocated_host_dispatch_barriers;
5749 5743
5750 host_dispatch_v8_thread.Start(); 5744 host_dispatch_v8_thread.Start();
5751 host_dispatch_debugger_thread.Start(); 5745 host_dispatch_debugger_thread.Start();
5752 5746
5753 host_dispatch_v8_thread.Join(); 5747 host_dispatch_v8_thread.Join();
5754 host_dispatch_debugger_thread.Join(); 5748 host_dispatch_debugger_thread.Join();
5755 } 5749 }
5756 5750
5757 5751
5758 /* Test DebugMessageDispatch */ 5752 /* Test DebugMessageDispatch */
5759 /* In this test, the V8 thread waits for a message from the debug thread. 5753 /* In this test, the V8 thread waits for a message from the debug thread.
5760 * The DebugMessageDispatchHandler is executed from the debugger thread 5754 * The DebugMessageDispatchHandler is executed from the debugger thread
5761 * which signals the V8 thread to wake up. 5755 * which signals the V8 thread to wake up.
5762 */ 5756 */
5763 5757
5764 class DebugMessageDispatchV8Thread : public v8::internal::Thread { 5758 class DebugMessageDispatchV8Thread : public v8::internal::Thread {
5765 public: 5759 public:
5766 explicit DebugMessageDispatchV8Thread(v8::internal::Isolate* isolate) 5760 DebugMessageDispatchV8Thread() : Thread("DebugMessageDispatchV8Thread") { }
5767 : Thread(isolate, "DebugMessageDispatchV8Thread") { }
5768 void Run(); 5761 void Run();
5769 }; 5762 };
5770 5763
5771 class DebugMessageDispatchDebuggerThread : public v8::internal::Thread { 5764 class DebugMessageDispatchDebuggerThread : public v8::internal::Thread {
5772 public: 5765 public:
5773 explicit DebugMessageDispatchDebuggerThread(v8::internal::Isolate* isolate) 5766 DebugMessageDispatchDebuggerThread()
5774 : Thread(isolate, "DebugMessageDispatchDebuggerThread") { } 5767 : Thread("DebugMessageDispatchDebuggerThread") { }
5775 void Run(); 5768 void Run();
5776 }; 5769 };
5777 5770
5778 Barriers* debug_message_dispatch_barriers; 5771 Barriers* debug_message_dispatch_barriers;
5779 5772
5780 5773
5781 static void DebugMessageHandler() { 5774 static void DebugMessageHandler() {
5782 debug_message_dispatch_barriers->semaphore_1->Signal(); 5775 debug_message_dispatch_barriers->semaphore_1->Signal();
5783 } 5776 }
5784 5777
5785 5778
5786 void DebugMessageDispatchV8Thread::Run() { 5779 void DebugMessageDispatchV8Thread::Run() {
5780 v8::V8::Initialize();
5787 v8::HandleScope scope; 5781 v8::HandleScope scope;
5788 DebugLocalContext env; 5782 DebugLocalContext env;
5789 5783
5790 // Setup debug message dispatch handler. 5784 // Setup debug message dispatch handler.
5791 v8::Debug::SetDebugMessageDispatchHandler(DebugMessageHandler); 5785 v8::Debug::SetDebugMessageDispatchHandler(DebugMessageHandler);
5792 5786
5793 CompileRun("var y = 1 + 2;\n"); 5787 CompileRun("var y = 1 + 2;\n");
5794 debug_message_dispatch_barriers->barrier_1.Wait(); 5788 debug_message_dispatch_barriers->barrier_1.Wait();
5795 debug_message_dispatch_barriers->semaphore_1->Wait(); 5789 debug_message_dispatch_barriers->semaphore_1->Wait();
5796 debug_message_dispatch_barriers->barrier_2.Wait(); 5790 debug_message_dispatch_barriers->barrier_2.Wait();
5797 } 5791 }
5798 5792
5799 5793
5800 void DebugMessageDispatchDebuggerThread::Run() { 5794 void DebugMessageDispatchDebuggerThread::Run() {
5801 debug_message_dispatch_barriers->barrier_1.Wait(); 5795 debug_message_dispatch_barriers->barrier_1.Wait();
5802 SendContinueCommand(); 5796 SendContinueCommand();
5803 debug_message_dispatch_barriers->barrier_2.Wait(); 5797 debug_message_dispatch_barriers->barrier_2.Wait();
5804 } 5798 }
5805 5799
5806 5800
5807 TEST(DebuggerDebugMessageDispatch) { 5801 TEST(DebuggerDebugMessageDispatch) {
5808 DebugMessageDispatchDebuggerThread debug_message_dispatch_debugger_thread( 5802 DebugMessageDispatchDebuggerThread debug_message_dispatch_debugger_thread;
5809 i::Isolate::Current()); 5803 DebugMessageDispatchV8Thread debug_message_dispatch_v8_thread;
5810 DebugMessageDispatchV8Thread debug_message_dispatch_v8_thread(
5811 i::Isolate::Current());
5812 5804
5813 i::FLAG_debugger_auto_break = true; 5805 i::FLAG_debugger_auto_break = true;
5814 5806
5815 // Create a V8 environment 5807 // Create a V8 environment
5816 Barriers stack_allocated_debug_message_dispatch_barriers; 5808 Barriers stack_allocated_debug_message_dispatch_barriers;
5817 stack_allocated_debug_message_dispatch_barriers.Initialize(); 5809 stack_allocated_debug_message_dispatch_barriers.Initialize();
5818 debug_message_dispatch_barriers = 5810 debug_message_dispatch_barriers =
5819 &stack_allocated_debug_message_dispatch_barriers; 5811 &stack_allocated_debug_message_dispatch_barriers;
5820 5812
5821 debug_message_dispatch_v8_thread.Start(); 5813 debug_message_dispatch_v8_thread.Start();
(...skipping 18 matching lines...) Expand all
5840 OS::SNPrintF(i::Vector<char>(port2_str, kPortBufferLen), "%d", kPort2); 5832 OS::SNPrintF(i::Vector<char>(port2_str, kPortBufferLen), "%d", kPort2);
5841 5833
5842 bool ok; 5834 bool ok;
5843 5835
5844 // Initialize the socket library. 5836 // Initialize the socket library.
5845 i::Socket::Setup(); 5837 i::Socket::Setup();
5846 5838
5847 // Test starting and stopping the agent without any client connection. 5839 // Test starting and stopping the agent without any client connection.
5848 debugger->StartAgent("test", kPort1); 5840 debugger->StartAgent("test", kPort1);
5849 debugger->StopAgent(); 5841 debugger->StopAgent();
5850
5851 // Test starting the agent, connecting a client and shutting down the agent 5842 // Test starting the agent, connecting a client and shutting down the agent
5852 // with the client connected. 5843 // with the client connected.
5853 ok = debugger->StartAgent("test", kPort2); 5844 ok = debugger->StartAgent("test", kPort2);
5854 CHECK(ok); 5845 CHECK(ok);
5855 debugger->WaitForAgent(); 5846 debugger->WaitForAgent();
5856 i::Socket* client = i::OS::CreateSocket(); 5847 i::Socket* client = i::OS::CreateSocket();
5857 ok = client->Connect("localhost", port2_str); 5848 ok = client->Connect("localhost", port2_str);
5858 CHECK(ok); 5849 CHECK(ok);
5850 // It is important to wait for a message from the agent. Otherwise,
5851 // we can close the server socket during "accept" syscall, making it failing
5852 // (at least on Linux), and the test will work incorrectly.
5853 char buf;
5854 ok = client->Receive(&buf, 1) == 1;
5855 CHECK(ok);
5859 debugger->StopAgent(); 5856 debugger->StopAgent();
5860 delete client; 5857 delete client;
5861 5858
5862 // Test starting and stopping the agent with the required port already 5859 // Test starting and stopping the agent with the required port already
5863 // occoupied. 5860 // occoupied.
5864 i::Socket* server = i::OS::CreateSocket(); 5861 i::Socket* server = i::OS::CreateSocket();
5865 server->Bind(kPort3); 5862 server->Bind(kPort3);
5866 5863
5867 debugger->StartAgent("test", kPort3); 5864 debugger->StartAgent("test", kPort3);
5868 debugger->StopAgent(); 5865 debugger->StopAgent();
5869 5866
5870 delete server; 5867 delete server;
5871 } 5868 }
5872 5869
5873 5870
5874 class DebuggerAgentProtocolServerThread : public i::Thread { 5871 class DebuggerAgentProtocolServerThread : public i::Thread {
5875 public: 5872 public:
5876 explicit DebuggerAgentProtocolServerThread(i::Isolate* isolate, int port) 5873 explicit DebuggerAgentProtocolServerThread(int port)
5877 : Thread(isolate, "DebuggerAgentProtocolServerThread"), 5874 : Thread("DebuggerAgentProtocolServerThread"),
5878 port_(port), 5875 port_(port),
5879 server_(NULL), 5876 server_(NULL),
5880 client_(NULL), 5877 client_(NULL),
5881 listening_(OS::CreateSemaphore(0)) { 5878 listening_(OS::CreateSemaphore(0)) {
5882 } 5879 }
5883 ~DebuggerAgentProtocolServerThread() { 5880 ~DebuggerAgentProtocolServerThread() {
5884 // Close both sockets. 5881 // Close both sockets.
5885 delete client_; 5882 delete client_;
5886 delete server_; 5883 delete server_;
5887 delete listening_; 5884 delete listening_;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
5932 // Make a string with the port number. 5929 // Make a string with the port number.
5933 const int kPortBufferLen = 6; 5930 const int kPortBufferLen = 6;
5934 char port_str[kPortBufferLen]; 5931 char port_str[kPortBufferLen];
5935 OS::SNPrintF(i::Vector<char>(port_str, kPortBufferLen), "%d", kPort); 5932 OS::SNPrintF(i::Vector<char>(port_str, kPortBufferLen), "%d", kPort);
5936 5933
5937 // Initialize the socket library. 5934 // Initialize the socket library.
5938 i::Socket::Setup(); 5935 i::Socket::Setup();
5939 5936
5940 // Create a socket server to receive a debugger agent message. 5937 // Create a socket server to receive a debugger agent message.
5941 DebuggerAgentProtocolServerThread* server = 5938 DebuggerAgentProtocolServerThread* server =
5942 new DebuggerAgentProtocolServerThread(i::Isolate::Current(), kPort); 5939 new DebuggerAgentProtocolServerThread(kPort);
5943 server->Start(); 5940 server->Start();
5944 server->WaitForListening(); 5941 server->WaitForListening();
5945 5942
5946 // Connect. 5943 // Connect.
5947 i::Socket* client = i::OS::CreateSocket(); 5944 i::Socket* client = i::OS::CreateSocket();
5948 CHECK(client != NULL); 5945 CHECK(client != NULL);
5949 bool ok = client->Connect(kLocalhost, port_str); 5946 bool ok = client->Connect(kLocalhost, port_str);
5950 CHECK(ok); 5947 CHECK(ok);
5951 5948
5952 // Send headers which overflow the receive buffer. 5949 // Send headers which overflow the receive buffer.
(...skipping 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after
7260 TestDebugBreakInLoop("for (;;) {", loop_bodies, "}"); 7257 TestDebugBreakInLoop("for (;;) {", loop_bodies, "}");
7261 TestDebugBreakInLoop("for (;a == 1;) {", loop_bodies, "}"); 7258 TestDebugBreakInLoop("for (;a == 1;) {", loop_bodies, "}");
7262 7259
7263 // Get rid of the debug event listener. 7260 // Get rid of the debug event listener.
7264 v8::Debug::SetDebugEventListener(NULL); 7261 v8::Debug::SetDebugEventListener(NULL);
7265 CheckDebuggerUnloaded(); 7262 CheckDebuggerUnloaded();
7266 } 7263 }
7267 7264
7268 7265
7269 #endif // ENABLE_DEBUGGER_SUPPORT 7266 #endif // ENABLE_DEBUGGER_SUPPORT
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698