| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 1632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1643 active_listener = !listeners.get(i)->IsUndefined(); | 1643 active_listener = !listeners.get(i)->IsUndefined(); |
| 1644 } | 1644 } |
| 1645 set_debugger_active((Debugger::message_thread_ != NULL && | 1645 set_debugger_active((Debugger::message_thread_ != NULL && |
| 1646 Debugger::debug_message_handler_ != NULL) || | 1646 Debugger::debug_message_handler_ != NULL) || |
| 1647 active_listener); | 1647 active_listener); |
| 1648 if (!debugger_active() && message_thread_) | 1648 if (!debugger_active() && message_thread_) |
| 1649 message_thread_->OnDebuggerInactive(); | 1649 message_thread_->OnDebuggerInactive(); |
| 1650 } | 1650 } |
| 1651 | 1651 |
| 1652 | 1652 |
| 1653 Handle<Object> Debugger::Call(Handle<JSFunction> fun, |
| 1654 Handle<Object> data, |
| 1655 bool* pending_exception) { |
| 1656 // Enter the debugger. |
| 1657 EnterDebugger debugger; |
| 1658 if (debugger.FailedToEnter() || !debugger.HasJavaScriptFrames()) { |
| 1659 return Factory::undefined_value(); |
| 1660 } |
| 1661 |
| 1662 // Create the execution state. |
| 1663 bool caught_exception = false; |
| 1664 Handle<Object> exec_state = MakeExecutionState(&caught_exception); |
| 1665 if (caught_exception) { |
| 1666 return Factory::undefined_value(); |
| 1667 } |
| 1668 |
| 1669 static const int kArgc = 2; |
| 1670 Object** argv[kArgc] = { exec_state.location(), data.location() }; |
| 1671 Handle<Object> result = Execution::Call(fun, Factory::undefined_value(), |
| 1672 kArgc, argv, pending_exception); |
| 1673 return result; |
| 1674 } |
| 1675 |
| 1676 |
| 1653 DebugMessageThread::DebugMessageThread() | 1677 DebugMessageThread::DebugMessageThread() |
| 1654 : host_running_(true), | 1678 : host_running_(true), |
| 1655 command_queue_(kQueueInitialSize), | 1679 command_queue_(kQueueInitialSize), |
| 1656 message_queue_(kQueueInitialSize) { | 1680 message_queue_(kQueueInitialSize) { |
| 1657 command_received_ = OS::CreateSemaphore(0); | 1681 command_received_ = OS::CreateSemaphore(0); |
| 1658 message_received_ = OS::CreateSemaphore(0); | 1682 message_received_ = OS::CreateSemaphore(0); |
| 1659 } | 1683 } |
| 1660 | 1684 |
| 1661 // Does not free resources held by DebugMessageThread | 1685 // Does not free resources held by DebugMessageThread |
| 1662 // because this cannot be done thread-safely. | 1686 // because this cannot be done thread-safely. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1762 v8::Object::Cast(*fun->Call(api_exec_state, 0, NULL)); | 1786 v8::Object::Cast(*fun->Call(api_exec_state, 0, NULL)); |
| 1763 if (try_catch.HasCaught()) { | 1787 if (try_catch.HasCaught()) { |
| 1764 PrintLn(try_catch.Exception()); | 1788 PrintLn(try_catch.Exception()); |
| 1765 return; | 1789 return; |
| 1766 } | 1790 } |
| 1767 | 1791 |
| 1768 // Notify the debugger that a debug event has occurred. | 1792 // Notify the debugger that a debug event has occurred. |
| 1769 host_running_ = false; | 1793 host_running_ = false; |
| 1770 SetEventJSONFromEvent(event_data); | 1794 SetEventJSONFromEvent(event_data); |
| 1771 | 1795 |
| 1772 // Wait for commands from the debugger. | 1796 // Wait for requests from the debugger. |
| 1773 while (true) { | 1797 while (true) { |
| 1774 command_received_->Wait(); | 1798 command_received_->Wait(); |
| 1775 Logger::DebugTag("Get command from command queue, in interactive loop."); | 1799 Logger::DebugTag("Got request from command queue, in interactive loop."); |
| 1776 Vector<uint16_t> command = command_queue_.Get(); | 1800 Vector<uint16_t> command = command_queue_.Get(); |
| 1777 ASSERT(!host_running_); | 1801 ASSERT(!host_running_); |
| 1778 if (!Debugger::debugger_active()) { | 1802 if (!Debugger::debugger_active()) { |
| 1779 host_running_ = true; | 1803 host_running_ = true; |
| 1780 return; | 1804 return; |
| 1781 } | 1805 } |
| 1782 | 1806 |
| 1783 // Invoke the JavaScript to convert the debug command line to a JSON | 1807 // Invoke the JavaScript to process the debug request. |
| 1784 // request, invoke the JSON request and convert the JSON response to a text | |
| 1785 // representation. | |
| 1786 v8::Local<v8::String> fun_name; | 1808 v8::Local<v8::String> fun_name; |
| 1787 v8::Local<v8::Function> fun; | 1809 v8::Local<v8::Function> fun; |
| 1788 v8::Local<v8::Value> args[1]; | 1810 v8::Local<v8::Value> request; |
| 1789 v8::TryCatch try_catch; | 1811 v8::TryCatch try_catch; |
| 1790 fun_name = v8::String::New("processDebugCommand"); | 1812 fun_name = v8::String::New("processDebugRequest"); |
| 1791 fun = v8::Function::Cast(*cmd_processor->Get(fun_name)); | 1813 fun = v8::Function::Cast(*cmd_processor->Get(fun_name)); |
| 1792 args[0] = v8::String::New(reinterpret_cast<uint16_t*>(command.start()), | 1814 request = v8::String::New(reinterpret_cast<uint16_t*>(command.start()), |
| 1793 command.length()); | 1815 command.length()); |
| 1794 v8::Local<v8::Value> result_val = fun->Call(cmd_processor, 1, args); | 1816 static const int kArgc = 1; |
| 1817 v8::Handle<Value> argv[kArgc] = { request }; |
| 1818 v8::Local<v8::Value> response_val = fun->Call(cmd_processor, kArgc, argv); |
| 1795 | 1819 |
| 1796 // Get the result of the command. | 1820 // Get the response. |
| 1797 v8::Local<v8::String> result_string; | 1821 v8::Local<v8::String> response; |
| 1798 bool running = false; | 1822 bool running = false; |
| 1799 if (!try_catch.HasCaught()) { | 1823 if (!try_catch.HasCaught()) { |
| 1800 // Get the result as an object. | 1824 // Get response string. |
| 1801 v8::Local<v8::Object> result = v8::Object::Cast(*result_val); | 1825 if (!response_val->IsUndefined()) { |
| 1826 response = v8::String::Cast(*response_val); |
| 1827 } else { |
| 1828 response = v8::String::New(""); |
| 1829 } |
| 1802 | 1830 |
| 1803 // Log the JSON request/response. | 1831 // Log the JSON request/response. |
| 1804 if (FLAG_trace_debug_json) { | 1832 if (FLAG_trace_debug_json) { |
| 1805 PrintLn(result->Get(v8::String::New("request"))); | 1833 PrintLn(request); |
| 1806 PrintLn(result->Get(v8::String::New("response"))); | 1834 PrintLn(response); |
| 1807 } | 1835 } |
| 1808 | 1836 |
| 1809 // Get the running state. | 1837 // Get the running state. |
| 1810 running = result->Get(v8::String::New("running"))->ToBoolean()->Value(); | 1838 fun_name = v8::String::New("isRunning"); |
| 1811 | 1839 fun = v8::Function::Cast(*cmd_processor->Get(fun_name)); |
| 1812 // Get result text. | 1840 static const int kArgc = 1; |
| 1813 v8::Local<v8::Value> text_result = | 1841 v8::Handle<Value> argv[kArgc] = { response }; |
| 1814 result->Get(v8::String::New("response")); | 1842 v8::Local<v8::Value> running_val = fun->Call(cmd_processor, kArgc, argv); |
| 1815 if (!text_result->IsUndefined()) { | 1843 if (!try_catch.HasCaught()) { |
| 1816 result_string = text_result->ToString(); | 1844 running = running_val->ToBoolean()->Value(); |
| 1817 } else { | |
| 1818 result_string = v8::String::New(""); | |
| 1819 } | 1845 } |
| 1820 } else { | 1846 } else { |
| 1821 // In case of failure the result text is the exception text. | 1847 // In case of failure the result text is the exception text. |
| 1822 result_string = try_catch.Exception()->ToString(); | 1848 response = try_catch.Exception()->ToString(); |
| 1823 } | 1849 } |
| 1824 | 1850 |
| 1825 // Convert text result to C string. | 1851 // Convert text result to C string. |
| 1826 v8::String::Value val(result_string); | 1852 v8::String::Value val(response); |
| 1827 Vector<uint16_t> str(reinterpret_cast<uint16_t*>(*val), | 1853 Vector<uint16_t> str(reinterpret_cast<uint16_t*>(*val), |
| 1828 result_string->Length()); | 1854 response->Length()); |
| 1829 | 1855 |
| 1830 // Set host_running_ correctly for nested debugger evaluations. | 1856 // Set host_running_ correctly for nested debugger evaluations. |
| 1831 host_running_ = running; | 1857 host_running_ = running; |
| 1832 | 1858 |
| 1833 // Return the result. | 1859 // Return the result. |
| 1834 SendMessage(str); | 1860 SendMessage(str); |
| 1835 | 1861 |
| 1836 // Return from debug event processing is VM should be running. | 1862 // Return from debug event processing is VM should be running. |
| 1837 if (running) { | 1863 if (running) { |
| 1838 return; | 1864 return; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1934 } | 1960 } |
| 1935 | 1961 |
| 1936 | 1962 |
| 1937 void LockingMessageQueue::Clear() { | 1963 void LockingMessageQueue::Clear() { |
| 1938 ScopedLock sl(lock_); | 1964 ScopedLock sl(lock_); |
| 1939 queue_.Clear(); | 1965 queue_.Clear(); |
| 1940 } | 1966 } |
| 1941 | 1967 |
| 1942 | 1968 |
| 1943 } } // namespace v8::internal | 1969 } } // namespace v8::internal |
| OLD | NEW |