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 1333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1344 0, NULL, &caught_exception); | 1344 0, NULL, &caught_exception); |
1345 } | 1345 } |
1346 | 1346 |
1347 | 1347 |
1348 Handle<Object> Debugger::event_listener_ = Handle<Object>(); | 1348 Handle<Object> Debugger::event_listener_ = Handle<Object>(); |
1349 Handle<Object> Debugger::event_listener_data_ = Handle<Object>(); | 1349 Handle<Object> Debugger::event_listener_data_ = Handle<Object>(); |
1350 bool Debugger::debugger_active_ = false; | 1350 bool Debugger::debugger_active_ = false; |
1351 bool Debugger::compiling_natives_ = false; | 1351 bool Debugger::compiling_natives_ = false; |
1352 bool Debugger::is_loading_debugger_ = false; | 1352 bool Debugger::is_loading_debugger_ = false; |
1353 DebugMessageThread* Debugger::message_thread_ = NULL; | 1353 DebugMessageThread* Debugger::message_thread_ = NULL; |
1354 v8::DebugMessageHandler Debugger::debug_message_handler_ = NULL; | 1354 v8::DebugMessageHandler Debugger::message_handler_ = NULL; |
1355 void* Debugger::debug_message_handler_data_ = NULL; | 1355 void* Debugger::message_handler_data_ = NULL; |
1356 v8::DebugHostDispatchHandler Debugger::host_dispatch_handler_ = NULL; | |
1357 void* Debugger::host_dispatch_handler_data_ = NULL; | |
1356 | 1358 |
1357 | 1359 |
1358 Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name, | 1360 Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name, |
1359 int argc, Object*** argv, | 1361 int argc, Object*** argv, |
1360 bool* caught_exception) { | 1362 bool* caught_exception) { |
1361 ASSERT(Top::context() == *Debug::debug_context()); | 1363 ASSERT(Top::context() == *Debug::debug_context()); |
1362 | 1364 |
1363 // Create the execution state object. | 1365 // Create the execution state object. |
1364 Handle<String> constructor_str = Factory::LookupSymbol(constructor_name); | 1366 Handle<String> constructor_str = Factory::LookupSymbol(constructor_name); |
1365 Handle<Object> constructor(Top::global()->GetProperty(*constructor_str)); | 1367 Handle<Object> constructor(Top::global()->GetProperty(*constructor_str)); |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1702 data = Factory::undefined_value(); | 1704 data = Factory::undefined_value(); |
1703 } | 1705 } |
1704 event_listener_data_ = Handle<Object>::cast(GlobalHandles::Create(*data)); | 1706 event_listener_data_ = Handle<Object>::cast(GlobalHandles::Create(*data)); |
1705 } | 1707 } |
1706 | 1708 |
1707 UpdateActiveDebugger(); | 1709 UpdateActiveDebugger(); |
1708 } | 1710 } |
1709 | 1711 |
1710 | 1712 |
1711 void Debugger::SetMessageHandler(v8::DebugMessageHandler handler, void* data) { | 1713 void Debugger::SetMessageHandler(v8::DebugMessageHandler handler, void* data) { |
1712 debug_message_handler_ = handler; | 1714 message_handler_ = handler; |
1713 debug_message_handler_data_ = data; | 1715 message_handler_data_ = data; |
1714 if (!message_thread_) { | 1716 if (!message_thread_) { |
1715 message_thread_ = new DebugMessageThread(); | 1717 message_thread_ = new DebugMessageThread(); |
1716 message_thread_->Start(); | 1718 message_thread_->Start(); |
1717 } | 1719 } |
1718 UpdateActiveDebugger(); | 1720 UpdateActiveDebugger(); |
1719 } | 1721 } |
1720 | 1722 |
1721 | 1723 |
1724 void Debugger::SetHostDispatchHandler(v8::DebugHostDispatchHandler handler, | |
1725 void* data) { | |
1726 host_dispatch_handler_ = handler; | |
1727 host_dispatch_handler_data_ = data; | |
1728 } | |
1729 | |
1730 | |
1722 // Posts an output message from the debugger to the debug_message_handler | 1731 // Posts an output message from the debugger to the debug_message_handler |
1723 // callback. This callback is part of the public API. Messages are | 1732 // callback. This callback is part of the public API. Messages are |
1724 // kept internally as Vector<uint16_t> strings, which are allocated in various | 1733 // kept internally as Vector<uint16_t> strings, which are allocated in various |
1725 // places and deallocated by the calling function sometime after this call. | 1734 // places and deallocated by the calling function sometime after this call. |
1726 void Debugger::SendMessage(Vector< uint16_t> message) { | 1735 void Debugger::SendMessage(Vector< uint16_t> message) { |
1727 if (debug_message_handler_ != NULL) { | 1736 if (message_handler_ != NULL) { |
1728 debug_message_handler_(message.start(), message.length(), | 1737 message_handler_(message.start(), message.length(), message_handler_data_); |
1729 debug_message_handler_data_); | |
1730 } | 1738 } |
1731 } | 1739 } |
1732 | 1740 |
1733 | 1741 |
1734 void Debugger::ProcessCommand(Vector<const uint16_t> command) { | 1742 void Debugger::ProcessCommand(Vector<const uint16_t> command) { |
1735 if (message_thread_ != NULL) { | 1743 if (message_thread_ != NULL) { |
1736 message_thread_->ProcessCommand( | 1744 message_thread_->ProcessCommand( |
1737 Vector<uint16_t>(const_cast<uint16_t *>(command.start()), | 1745 Vector<uint16_t>(const_cast<uint16_t *>(command.start()), |
1738 command.length())); | 1746 command.length())); |
1739 } | 1747 } |
1740 } | 1748 } |
1741 | 1749 |
1742 | 1750 |
1751 void Debugger::ProcessHostDispatch(void* dispatch) { | |
1752 if (message_thread_ != NULL) { | |
1753 message_thread_->ProcessHostDispatch(dispatch); | |
1754 } | |
1755 } | |
1756 | |
1757 | |
1743 void Debugger::UpdateActiveDebugger() { | 1758 void Debugger::UpdateActiveDebugger() { |
1744 set_debugger_active((message_thread_ != NULL && | 1759 set_debugger_active((message_thread_ != NULL && |
1745 debug_message_handler_ != NULL) || | 1760 message_handler_ != NULL) || |
1746 !event_listener_.is_null()); | 1761 !event_listener_.is_null()); |
1747 if (!debugger_active() && message_thread_) { | 1762 if (!debugger_active() && message_thread_) { |
1748 message_thread_->OnDebuggerInactive(); | 1763 message_thread_->OnDebuggerInactive(); |
1749 } | 1764 } |
1750 if (!debugger_active()) { | 1765 if (!debugger_active()) { |
1751 Debug::Unload(); | 1766 Debug::Unload(); |
1752 } | 1767 } |
1753 } | 1768 } |
1754 | 1769 |
1755 | 1770 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1907 while (true) { | 1922 while (true) { |
1908 command_received_->Wait(); | 1923 command_received_->Wait(); |
1909 Logger::DebugTag("Got request from command queue, in interactive loop."); | 1924 Logger::DebugTag("Got request from command queue, in interactive loop."); |
1910 Vector<uint16_t> command = command_queue_.Get(); | 1925 Vector<uint16_t> command = command_queue_.Get(); |
1911 ASSERT(!host_running_); | 1926 ASSERT(!host_running_); |
1912 if (!Debugger::debugger_active()) { | 1927 if (!Debugger::debugger_active()) { |
1913 host_running_ = true; | 1928 host_running_ = true; |
1914 return; | 1929 return; |
1915 } | 1930 } |
1916 | 1931 |
1932 // Check if the command is a host dispatch. | |
1933 if (command[0] == 0) { | |
1934 if (Debugger::host_dispatch_handler_) { | |
1935 int32_t dispatch = (command[1] << 16) | command[2]; | |
1936 Debugger::host_dispatch_handler_(reinterpret_cast<void*>(dispatch), | |
yurys
2009/02/19 14:44:18
why not just call dispatch with some dispatch data
| |
1937 Debugger::host_dispatch_handler_data_); | |
1938 } | |
1939 continue; | |
1940 } | |
1941 | |
1917 // Invoke the JavaScript to process the debug request. | 1942 // Invoke the JavaScript to process the debug request. |
1918 v8::Local<v8::String> fun_name; | 1943 v8::Local<v8::String> fun_name; |
1919 v8::Local<v8::Function> fun; | 1944 v8::Local<v8::Function> fun; |
1920 v8::Local<v8::Value> request; | 1945 v8::Local<v8::Value> request; |
1921 v8::TryCatch try_catch; | 1946 v8::TryCatch try_catch; |
1922 fun_name = v8::String::New("processDebugRequest"); | 1947 fun_name = v8::String::New("processDebugRequest"); |
1923 fun = v8::Function::Cast(*cmd_processor->Get(fun_name)); | 1948 fun = v8::Function::Cast(*cmd_processor->Get(fun_name)); |
1924 request = v8::String::New(reinterpret_cast<uint16_t*>(command.start()), | 1949 request = v8::String::New(reinterpret_cast<uint16_t*>(command.start()), |
1925 command.length()); | 1950 command.length()); |
1926 static const int kArgc = 1; | 1951 static const int kArgc = 1; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1984 // processing of the command to the DebugMessageThread thread. | 2009 // processing of the command to the DebugMessageThread thread. |
1985 // The new copy of the command is destroyed in HandleCommand(). | 2010 // The new copy of the command is destroyed in HandleCommand(). |
1986 void DebugMessageThread::ProcessCommand(Vector<uint16_t> command) { | 2011 void DebugMessageThread::ProcessCommand(Vector<uint16_t> command) { |
1987 Vector<uint16_t> command_copy = command.Clone(); | 2012 Vector<uint16_t> command_copy = command.Clone(); |
1988 Logger::DebugTag("Put command on command_queue."); | 2013 Logger::DebugTag("Put command on command_queue."); |
1989 command_queue_.Put(command_copy); | 2014 command_queue_.Put(command_copy); |
1990 command_received_->Signal(); | 2015 command_received_->Signal(); |
1991 } | 2016 } |
1992 | 2017 |
1993 | 2018 |
2019 // Puts a host dispatch comming from the public API on the queue. | |
2020 void DebugMessageThread::ProcessHostDispatch(void* dispatch) { | |
2021 uint16_t hack[3]; | |
2022 hack[0] = 0; | |
2023 hack[1] = reinterpret_cast<uint32_t>(dispatch) >> 16; | |
2024 hack[2] = reinterpret_cast<uint32_t>(dispatch) & 0xFFFF; | |
2025 Logger::DebugTag("Put dispatch on command_queue."); | |
2026 command_queue_.Put(Vector<uint16_t>(hack, 3).Clone()); | |
2027 command_received_->Signal(); | |
2028 } | |
2029 | |
2030 | |
1994 void DebugMessageThread::OnDebuggerInactive() { | 2031 void DebugMessageThread::OnDebuggerInactive() { |
1995 // Send an empty command to the debugger if in a break to make JavaScript run | 2032 // Send an empty command to the debugger if in a break to make JavaScript run |
1996 // again if the debugger is closed. | 2033 // again if the debugger is closed. |
1997 if (!host_running_) { | 2034 if (!host_running_) { |
1998 ProcessCommand(Vector<uint16_t>::empty()); | 2035 ProcessCommand(Vector<uint16_t>::empty()); |
1999 } | 2036 } |
2000 } | 2037 } |
2001 | 2038 |
2002 | 2039 |
2003 MessageQueue::MessageQueue(int size) : start_(0), end_(0), size_(size) { | 2040 MessageQueue::MessageQueue(int size) : start_(0), end_(0), size_(size) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2070 } | 2107 } |
2071 | 2108 |
2072 | 2109 |
2073 void LockingMessageQueue::Clear() { | 2110 void LockingMessageQueue::Clear() { |
2074 ScopedLock sl(lock_); | 2111 ScopedLock sl(lock_); |
2075 queue_.Clear(); | 2112 queue_.Clear(); |
2076 } | 2113 } |
2077 | 2114 |
2078 | 2115 |
2079 } } // namespace v8::internal | 2116 } } // namespace v8::internal |
OLD | NEW |