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 1683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1694 // Called by the V8 thread. | 1694 // Called by the V8 thread. |
1695 // The new copy of the event string is destroyed in Run(). | 1695 // The new copy of the event string is destroyed in Run(). |
1696 void DebugMessageThread::SendMessage(Vector<uint16_t> message) { | 1696 void DebugMessageThread::SendMessage(Vector<uint16_t> message) { |
1697 Vector<uint16_t> message_copy = message.Clone(); | 1697 Vector<uint16_t> message_copy = message.Clone(); |
1698 Logger::DebugTag("Put message on event message_queue."); | 1698 Logger::DebugTag("Put message on event message_queue."); |
1699 message_queue_.Put(message_copy); | 1699 message_queue_.Put(message_copy); |
1700 message_received_->Signal(); | 1700 message_received_->Signal(); |
1701 } | 1701 } |
1702 | 1702 |
1703 | 1703 |
1704 void DebugMessageThread::SetEventJSONFromEvent(Handle<Object> event_data) { | 1704 bool DebugMessageThread::SetEventJSONFromEvent(Handle<Object> event_data) { |
1705 v8::HandleScope scope; | 1705 v8::HandleScope scope; |
1706 // Call toJSONProtocol on the debug event object. | 1706 // Call toJSONProtocol on the debug event object. |
1707 v8::Local<v8::Object> api_event_data = | 1707 v8::Local<v8::Object> api_event_data = |
1708 v8::Utils::ToLocal(Handle<JSObject>::cast(event_data)); | 1708 v8::Utils::ToLocal(Handle<JSObject>::cast(event_data)); |
1709 v8::Local<v8::String> fun_name = v8::String::New("toJSONProtocol"); | 1709 v8::Local<v8::String> fun_name = v8::String::New("toJSONProtocol"); |
1710 v8::Local<v8::Function> fun = | 1710 v8::Local<v8::Function> fun = |
1711 v8::Function::Cast(*api_event_data->Get(fun_name)); | 1711 v8::Function::Cast(*api_event_data->Get(fun_name)); |
1712 v8::TryCatch try_catch; | 1712 v8::TryCatch try_catch; |
1713 v8::Local<v8::Value> json_event = *fun->Call(api_event_data, 0, NULL); | 1713 v8::Local<v8::Value> json_event = *fun->Call(api_event_data, 0, NULL); |
1714 v8::Local<v8::String> json_event_string; | 1714 v8::Local<v8::String> json_event_string; |
1715 if (!try_catch.HasCaught()) { | 1715 if (!try_catch.HasCaught()) { |
1716 if (!json_event->IsUndefined()) { | 1716 if (!json_event->IsUndefined()) { |
1717 json_event_string = json_event->ToString(); | 1717 json_event_string = json_event->ToString(); |
1718 if (FLAG_trace_debug_json) { | 1718 if (FLAG_trace_debug_json) { |
1719 PrintLn(json_event_string); | 1719 PrintLn(json_event_string); |
1720 } | 1720 } |
1721 v8::String::Value val(json_event_string); | 1721 v8::String::Value val(json_event_string); |
1722 Vector<uint16_t> str(reinterpret_cast<uint16_t*>(*val), | 1722 Vector<uint16_t> str(reinterpret_cast<uint16_t*>(*val), |
1723 json_event_string->Length()); | 1723 json_event_string->Length()); |
1724 SendMessage(str); | 1724 SendMessage(str); |
1725 } else { | 1725 } else { |
1726 SendMessage(Vector<uint16_t>::empty()); | 1726 SendMessage(Vector<uint16_t>::empty()); |
1727 } | 1727 } |
1728 } else { | 1728 } else { |
1729 PrintLn(try_catch.Exception()); | 1729 PrintLn(try_catch.Exception()); |
1730 SendMessage(Vector<uint16_t>::empty()); | 1730 return false; |
1731 } | 1731 } |
| 1732 return true; |
1732 } | 1733 } |
1733 | 1734 |
1734 | 1735 |
1735 void DebugMessageThread::Run() { | 1736 void DebugMessageThread::Run() { |
1736 // Sends debug events to an installed debugger message callback. | 1737 // Sends debug events to an installed debugger message callback. |
1737 while (true) { | 1738 while (true) { |
1738 // Wait and Get are paired so that semaphore count equals queue length. | 1739 // Wait and Get are paired so that semaphore count equals queue length. |
1739 message_received_->Wait(); | 1740 message_received_->Wait(); |
1740 Logger::DebugTag("Get message from event message_queue."); | 1741 Logger::DebugTag("Get message from event message_queue."); |
1741 Vector<uint16_t> message = message_queue_.Get(); | 1742 Vector<uint16_t> message = message_queue_.Get(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1784 v8::Function::Cast(*api_exec_state->Get(fun_name)); | 1785 v8::Function::Cast(*api_exec_state->Get(fun_name)); |
1785 v8::TryCatch try_catch; | 1786 v8::TryCatch try_catch; |
1786 v8::Local<v8::Object> cmd_processor = | 1787 v8::Local<v8::Object> cmd_processor = |
1787 v8::Object::Cast(*fun->Call(api_exec_state, 0, NULL)); | 1788 v8::Object::Cast(*fun->Call(api_exec_state, 0, NULL)); |
1788 if (try_catch.HasCaught()) { | 1789 if (try_catch.HasCaught()) { |
1789 PrintLn(try_catch.Exception()); | 1790 PrintLn(try_catch.Exception()); |
1790 return; | 1791 return; |
1791 } | 1792 } |
1792 | 1793 |
1793 // Notify the debugger that a debug event has occurred. | 1794 // Notify the debugger that a debug event has occurred. |
1794 host_running_ = false; | 1795 bool success = SetEventJSONFromEvent(event_data); |
1795 SetEventJSONFromEvent(event_data); | 1796 if (!success) { |
| 1797 // If failed to notify debugger just continue running. |
| 1798 return; |
| 1799 } |
1796 | 1800 |
1797 // Wait for requests from the debugger. | 1801 // Wait for requests from the debugger. |
| 1802 host_running_ = false; |
1798 while (true) { | 1803 while (true) { |
1799 command_received_->Wait(); | 1804 command_received_->Wait(); |
1800 Logger::DebugTag("Got request from command queue, in interactive loop."); | 1805 Logger::DebugTag("Got request from command queue, in interactive loop."); |
1801 Vector<uint16_t> command = command_queue_.Get(); | 1806 Vector<uint16_t> command = command_queue_.Get(); |
1802 ASSERT(!host_running_); | 1807 ASSERT(!host_running_); |
1803 if (!Debugger::debugger_active()) { | 1808 if (!Debugger::debugger_active()) { |
1804 host_running_ = true; | 1809 host_running_ = true; |
1805 return; | 1810 return; |
1806 } | 1811 } |
1807 | 1812 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1961 } | 1966 } |
1962 | 1967 |
1963 | 1968 |
1964 void LockingMessageQueue::Clear() { | 1969 void LockingMessageQueue::Clear() { |
1965 ScopedLock sl(lock_); | 1970 ScopedLock sl(lock_); |
1966 queue_.Clear(); | 1971 queue_.Clear(); |
1967 } | 1972 } |
1968 | 1973 |
1969 | 1974 |
1970 } } // namespace v8::internal | 1975 } } // namespace v8::internal |
OLD | NEW |