OLD | NEW |
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 5770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5781 // handler. | 5781 // handler. |
5782 CompileRun("throw 1"); | 5782 CompileRun("throw 1"); |
5783 | 5783 |
5784 // The message handler should be called. | 5784 // The message handler should be called. |
5785 CHECK_EQ(1, message_handler_hit_count); | 5785 CHECK_EQ(1, message_handler_hit_count); |
5786 | 5786 |
5787 CheckDebuggerUnloaded(true); | 5787 CheckDebuggerUnloaded(true); |
5788 } | 5788 } |
5789 | 5789 |
5790 | 5790 |
5791 /* Test DebuggerHostDispatch */ | |
5792 /* In this test, the debugger waits for a command on a breakpoint | |
5793 * and is dispatching host commands while in the infinite loop. | |
5794 */ | |
5795 | |
5796 class HostDispatchV8Thread : public v8::internal::Thread { | |
5797 public: | |
5798 HostDispatchV8Thread() : Thread("HostDispatchV8Thread") { } | |
5799 void Run(); | |
5800 }; | |
5801 | |
5802 class HostDispatchDebuggerThread : public v8::internal::Thread { | |
5803 public: | |
5804 HostDispatchDebuggerThread() : Thread("HostDispatchDebuggerThread") { } | |
5805 void Run(); | |
5806 }; | |
5807 | |
5808 Barriers* host_dispatch_barriers; | |
5809 | |
5810 static void HostDispatchMessageHandler(const v8::Debug::Message& message) { | |
5811 static char print_buffer[1000]; | |
5812 v8::String::Value json(message.GetJSON()); | |
5813 Utf16ToAscii(*json, json.length(), print_buffer); | |
5814 } | |
5815 | |
5816 | |
5817 static void HostDispatchDispatchHandler() { | |
5818 host_dispatch_barriers->semaphore_1.Signal(); | |
5819 } | |
5820 | |
5821 | |
5822 void HostDispatchV8Thread::Run() { | |
5823 const char* source_1 = "var y_global = 3;\n" | |
5824 "function cat( new_value ) {\n" | |
5825 " var x = new_value;\n" | |
5826 " y_global = 4;\n" | |
5827 " x = 3 * x + 1;\n" | |
5828 " y_global = 5;\n" | |
5829 " return x;\n" | |
5830 "}\n" | |
5831 "\n"; | |
5832 const char* source_2 = "cat(17);\n"; | |
5833 | |
5834 v8::Isolate::Scope isolate_scope(CcTest::isolate()); | |
5835 DebugLocalContext env; | |
5836 v8::HandleScope scope(env->GetIsolate()); | |
5837 | |
5838 // Set up message and host dispatch handlers. | |
5839 v8::Debug::SetMessageHandler2(HostDispatchMessageHandler); | |
5840 v8::Debug::SetHostDispatchHandler(HostDispatchDispatchHandler, 10 /* ms */); | |
5841 | |
5842 CompileRun(source_1); | |
5843 host_dispatch_barriers->barrier_1.Wait(); | |
5844 host_dispatch_barriers->barrier_2.Wait(); | |
5845 CompileRun(source_2); | |
5846 } | |
5847 | |
5848 | |
5849 void HostDispatchDebuggerThread::Run() { | |
5850 const int kBufSize = 1000; | |
5851 uint16_t buffer[kBufSize]; | |
5852 | |
5853 const char* command_1 = "{\"seq\":101," | |
5854 "\"type\":\"request\"," | |
5855 "\"command\":\"setbreakpoint\"," | |
5856 "\"arguments\":{\"type\":\"function\",\"target\":\"cat\",\"line\":3}}"; | |
5857 const char* command_2 = "{\"seq\":102," | |
5858 "\"type\":\"request\"," | |
5859 "\"command\":\"continue\"}"; | |
5860 | |
5861 v8::Isolate* isolate = CcTest::isolate(); | |
5862 // v8 thread initializes, runs source_1 | |
5863 host_dispatch_barriers->barrier_1.Wait(); | |
5864 // 1: Set breakpoint in cat(). | |
5865 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_1, buffer)); | |
5866 | |
5867 host_dispatch_barriers->barrier_2.Wait(); | |
5868 // v8 thread starts compiling source_2. | |
5869 // Break happens, to run queued commands and host dispatches. | |
5870 // Wait for host dispatch to be processed. | |
5871 host_dispatch_barriers->semaphore_1.Wait(); | |
5872 // 2: Continue evaluation | |
5873 v8::Debug::SendCommand(isolate, buffer, AsciiToUtf16(command_2, buffer)); | |
5874 } | |
5875 | |
5876 | |
5877 TEST(DebuggerHostDispatch) { | |
5878 HostDispatchDebuggerThread host_dispatch_debugger_thread; | |
5879 HostDispatchV8Thread host_dispatch_v8_thread; | |
5880 | |
5881 // Create a V8 environment | |
5882 Barriers stack_allocated_host_dispatch_barriers; | |
5883 host_dispatch_barriers = &stack_allocated_host_dispatch_barriers; | |
5884 | |
5885 host_dispatch_v8_thread.Start(); | |
5886 host_dispatch_debugger_thread.Start(); | |
5887 | |
5888 host_dispatch_v8_thread.Join(); | |
5889 host_dispatch_debugger_thread.Join(); | |
5890 } | |
5891 | |
5892 | |
5893 /* Test DebugMessageDispatch */ | 5791 /* Test DebugMessageDispatch */ |
5894 /* In this test, the V8 thread waits for a message from the debug thread. | 5792 /* In this test, the V8 thread waits for a message from the debug thread. |
5895 * The DebugMessageDispatchHandler is executed from the debugger thread | 5793 * The DebugMessageDispatchHandler is executed from the debugger thread |
5896 * which signals the V8 thread to wake up. | 5794 * which signals the V8 thread to wake up. |
5897 */ | 5795 */ |
5898 | 5796 |
5899 class DebugMessageDispatchV8Thread : public v8::internal::Thread { | 5797 class DebugMessageDispatchV8Thread : public v8::internal::Thread { |
5900 public: | 5798 public: |
5901 DebugMessageDispatchV8Thread() : Thread("DebugMessageDispatchV8Thread") { } | 5799 DebugMessageDispatchV8Thread() : Thread("DebugMessageDispatchV8Thread") { } |
5902 void Run(); | 5800 void Run(); |
(...skipping 1780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7683 env->Global()->Set(v8_str("add_debug_break"), add_debug_break); | 7581 env->Global()->Set(v8_str("add_debug_break"), add_debug_break); |
7684 | 7582 |
7685 CompileRun("(function loop() {" | 7583 CompileRun("(function loop() {" |
7686 " for (var j = 0; j < 1000; j++) {" | 7584 " for (var j = 0; j < 1000; j++) {" |
7687 " for (var i = 0; i < 1000; i++) {" | 7585 " for (var i = 0; i < 1000; i++) {" |
7688 " if (i == 999) add_debug_break();" | 7586 " if (i == 999) add_debug_break();" |
7689 " }" | 7587 " }" |
7690 " }" | 7588 " }" |
7691 "})()"); | 7589 "})()"); |
7692 } | 7590 } |
OLD | NEW |