| 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 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1605 | 1605 |
| 1606 // Create the event data object. | 1606 // Create the event data object. |
| 1607 bool caught_exception = false; | 1607 bool caught_exception = false; |
| 1608 Handle<Object> event_data = MakeCompileEvent(script, true, &caught_exception); | 1608 Handle<Object> event_data = MakeCompileEvent(script, true, &caught_exception); |
| 1609 // Bail out and don't call debugger if exception. | 1609 // Bail out and don't call debugger if exception. |
| 1610 if (caught_exception) { | 1610 if (caught_exception) { |
| 1611 return; | 1611 return; |
| 1612 } | 1612 } |
| 1613 | 1613 |
| 1614 // Process debug event | 1614 // Process debug event |
| 1615 ProcessDebugEvent(v8::BeforeCompile, event_data, false); | 1615 ProcessDebugEvent(v8::BeforeCompile, event_data, true); |
| 1616 } | 1616 } |
| 1617 | 1617 |
| 1618 | 1618 |
| 1619 // Handle debugger actions when a new script is compiled. | 1619 // Handle debugger actions when a new script is compiled. |
| 1620 void Debugger::OnAfterCompile(Handle<Script> script, Handle<JSFunction> fun) { | 1620 void Debugger::OnAfterCompile(Handle<Script> script, Handle<JSFunction> fun) { |
| 1621 HandleScope scope; | 1621 HandleScope scope; |
| 1622 | 1622 |
| 1623 // No compile events while compiling natives. | 1623 // No compile events while compiling natives. |
| 1624 if (compiling_natives()) return; | 1624 if (compiling_natives()) return; |
| 1625 | 1625 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1666 | 1666 |
| 1667 // Create the compile state object. | 1667 // Create the compile state object. |
| 1668 Handle<Object> event_data = MakeCompileEvent(script, | 1668 Handle<Object> event_data = MakeCompileEvent(script, |
| 1669 false, | 1669 false, |
| 1670 &caught_exception); | 1670 &caught_exception); |
| 1671 // Bail out and don't call debugger if exception. | 1671 // Bail out and don't call debugger if exception. |
| 1672 if (caught_exception) { | 1672 if (caught_exception) { |
| 1673 return; | 1673 return; |
| 1674 } | 1674 } |
| 1675 // Process debug event | 1675 // Process debug event |
| 1676 ProcessDebugEvent(v8::AfterCompile, event_data, false); | 1676 ProcessDebugEvent(v8::AfterCompile, event_data, true); |
| 1677 } | 1677 } |
| 1678 | 1678 |
| 1679 | 1679 |
| 1680 void Debugger::OnNewFunction(Handle<JSFunction> function) { | 1680 void Debugger::OnNewFunction(Handle<JSFunction> function) { |
| 1681 return; | 1681 return; |
| 1682 HandleScope scope; | 1682 HandleScope scope; |
| 1683 | 1683 |
| 1684 // Bail out based on state or if there is no listener for this event | 1684 // Bail out based on state or if there is no listener for this event |
| 1685 if (Debug::InDebugger()) return; | 1685 if (Debug::InDebugger()) return; |
| 1686 if (compiling_natives()) return; | 1686 if (compiling_natives()) return; |
| 1687 if (!Debugger::EventActive(v8::NewFunction)) return; | 1687 if (!Debugger::EventActive(v8::NewFunction)) return; |
| 1688 | 1688 |
| 1689 // Enter the debugger. | 1689 // Enter the debugger. |
| 1690 EnterDebugger debugger; | 1690 EnterDebugger debugger; |
| 1691 if (debugger.FailedToEnter()) return; | 1691 if (debugger.FailedToEnter()) return; |
| 1692 | 1692 |
| 1693 // Create the event object. | 1693 // Create the event object. |
| 1694 bool caught_exception = false; | 1694 bool caught_exception = false; |
| 1695 Handle<Object> event_data = MakeNewFunctionEvent(function, &caught_exception); | 1695 Handle<Object> event_data = MakeNewFunctionEvent(function, &caught_exception); |
| 1696 // Bail out and don't call debugger if exception. | 1696 // Bail out and don't call debugger if exception. |
| 1697 if (caught_exception) { | 1697 if (caught_exception) { |
| 1698 return; | 1698 return; |
| 1699 } | 1699 } |
| 1700 // Process debug event. | 1700 // Process debug event. |
| 1701 ProcessDebugEvent(v8::NewFunction, event_data, false); | 1701 ProcessDebugEvent(v8::NewFunction, event_data, true); |
| 1702 } | 1702 } |
| 1703 | 1703 |
| 1704 | 1704 |
| 1705 void Debugger::ProcessDebugEvent(v8::DebugEvent event, | 1705 void Debugger::ProcessDebugEvent(v8::DebugEvent event, |
| 1706 Handle<Object> event_data, | 1706 Handle<Object> event_data, |
| 1707 bool auto_continue) { | 1707 bool auto_continue) { |
| 1708 HandleScope scope; | 1708 HandleScope scope; |
| 1709 | 1709 |
| 1710 // Create the execution state. | 1710 // Create the execution state. |
| 1711 bool caught_exception = false; | 1711 bool caught_exception = false; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1769 | 1769 |
| 1770 void Debugger::NotifyMessageHandler(v8::DebugEvent event, | 1770 void Debugger::NotifyMessageHandler(v8::DebugEvent event, |
| 1771 Handle<Object> exec_state, | 1771 Handle<Object> exec_state, |
| 1772 Handle<Object> event_data, | 1772 Handle<Object> event_data, |
| 1773 bool auto_continue) { | 1773 bool auto_continue) { |
| 1774 HandleScope scope; | 1774 HandleScope scope; |
| 1775 | 1775 |
| 1776 if (!Debug::Load()) return; | 1776 if (!Debug::Load()) return; |
| 1777 | 1777 |
| 1778 // Process the individual events. | 1778 // Process the individual events. |
| 1779 bool interactive = false; | 1779 bool sendEventMessage = false; |
| 1780 switch (event) { | 1780 switch (event) { |
| 1781 case v8::Break: | 1781 case v8::Break: |
| 1782 interactive = true; // Break event is always interactive | 1782 sendEventMessage = !auto_continue; |
| 1783 break; | 1783 break; |
| 1784 case v8::Exception: | 1784 case v8::Exception: |
| 1785 interactive = true; // Exception event is always interactive | 1785 sendEventMessage = true; |
| 1786 break; | 1786 break; |
| 1787 case v8::BeforeCompile: | 1787 case v8::BeforeCompile: |
| 1788 break; | 1788 break; |
| 1789 case v8::AfterCompile: | 1789 case v8::AfterCompile: |
| 1790 sendEventMessage = true; |
| 1790 break; | 1791 break; |
| 1791 case v8::NewFunction: | 1792 case v8::NewFunction: |
| 1792 break; | 1793 break; |
| 1793 default: | 1794 default: |
| 1794 UNREACHABLE(); | 1795 UNREACHABLE(); |
| 1795 } | 1796 } |
| 1796 | 1797 |
| 1797 // Done if not interactive. | 1798 // The debug command interrupt flag might have been set when the command was |
| 1798 if (!interactive) return; | 1799 // added. It should be enough to clear the flag only once while we are in the |
| 1800 // debugger. |
| 1801 ASSERT(Debug::InDebugger()); |
| 1802 StackGuard::Continue(DEBUGCOMMAND); |
| 1803 |
| 1804 // Notify the debugger that a debug event has occurred unless auto continue is |
| 1805 // active in which case no event is send. |
| 1806 if (sendEventMessage) { |
| 1807 InvokeMessageHandlerWithEvent(event_data); |
| 1808 } |
| 1809 if (auto_continue && !HasCommands()) { |
| 1810 return; |
| 1811 } |
| 1799 | 1812 |
| 1800 // Get the DebugCommandProcessor. | 1813 // Get the DebugCommandProcessor. |
| 1801 v8::Local<v8::Object> api_exec_state = | 1814 v8::Local<v8::Object> api_exec_state = |
| 1802 v8::Utils::ToLocal(Handle<JSObject>::cast(exec_state)); | 1815 v8::Utils::ToLocal(Handle<JSObject>::cast(exec_state)); |
| 1803 v8::Local<v8::String> fun_name = | 1816 v8::Local<v8::String> fun_name = |
| 1804 v8::String::New("debugCommandProcessor"); | 1817 v8::String::New("debugCommandProcessor"); |
| 1805 v8::Local<v8::Function> fun = | 1818 v8::Local<v8::Function> fun = |
| 1806 v8::Function::Cast(*api_exec_state->Get(fun_name)); | 1819 v8::Function::Cast(*api_exec_state->Get(fun_name)); |
| 1807 v8::TryCatch try_catch; | 1820 v8::TryCatch try_catch; |
| 1808 v8::Local<v8::Object> cmd_processor = | 1821 v8::Local<v8::Object> cmd_processor = |
| 1809 v8::Object::Cast(*fun->Call(api_exec_state, 0, NULL)); | 1822 v8::Object::Cast(*fun->Call(api_exec_state, 0, NULL)); |
| 1810 if (try_catch.HasCaught()) { | 1823 if (try_catch.HasCaught()) { |
| 1811 PrintLn(try_catch.Exception()); | 1824 PrintLn(try_catch.Exception()); |
| 1812 return; | 1825 return; |
| 1813 } | 1826 } |
| 1814 | 1827 |
| 1815 // Notify the debugger that a debug event has occurred unless auto continue is | |
| 1816 // active in which case no event is send. | |
| 1817 if (!auto_continue) { | |
| 1818 bool success = InvokeMessageHandlerWithEvent(event_data); | |
| 1819 if (!success) { | |
| 1820 // If failed to notify debugger just continue running. | |
| 1821 return; | |
| 1822 } | |
| 1823 } | |
| 1824 | |
| 1825 // Process requests from the debugger. | 1828 // Process requests from the debugger. |
| 1826 while (true) { | 1829 while (true) { |
| 1827 // Wait for new command in the queue. | 1830 // Wait for new command in the queue. |
| 1828 if (Debugger::host_dispatch_handler_) { | 1831 if (Debugger::host_dispatch_handler_) { |
| 1829 // In case there is a host dispatch - do periodic dispatches. | 1832 // In case there is a host dispatch - do periodic dispatches. |
| 1830 if (!command_received_->Wait(host_dispatch_micros_)) { | 1833 if (!command_received_->Wait(host_dispatch_micros_)) { |
| 1831 // Timout expired, do the dispatch. | 1834 // Timout expired, do the dispatch. |
| 1832 Debugger::host_dispatch_handler_(); | 1835 Debugger::host_dispatch_handler_(); |
| 1833 continue; | 1836 continue; |
| 1834 } | 1837 } |
| 1835 } else { | 1838 } else { |
| 1836 // In case there is no host dispatch - just wait. | 1839 // In case there is no host dispatch - just wait. |
| 1837 command_received_->Wait(); | 1840 command_received_->Wait(); |
| 1838 } | 1841 } |
| 1839 | 1842 |
| 1840 // The debug command interrupt flag might have been set when the command was | |
| 1841 // added. | |
| 1842 StackGuard::Continue(DEBUGCOMMAND); | |
| 1843 | |
| 1844 // Get the command from the queue. | 1843 // Get the command from the queue. |
| 1845 CommandMessage command = command_queue_.Get(); | 1844 CommandMessage command = command_queue_.Get(); |
| 1846 Logger::DebugTag("Got request from command queue, in interactive loop."); | 1845 Logger::DebugTag("Got request from command queue, in interactive loop."); |
| 1847 if (!Debugger::IsDebuggerActive()) { | 1846 if (!Debugger::IsDebuggerActive()) { |
| 1848 // Delete command text and user data. | 1847 // Delete command text and user data. |
| 1849 command.Dispose(); | 1848 command.Dispose(); |
| 1850 return; | 1849 return; |
| 1851 } | 1850 } |
| 1852 | 1851 |
| 1853 // Invoke JavaScript to process the debug request. | 1852 // Invoke JavaScript to process the debug request. |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2209 | 2208 |
| 2210 | 2209 |
| 2211 void LockingCommandMessageQueue::Clear() { | 2210 void LockingCommandMessageQueue::Clear() { |
| 2212 ScopedLock sl(lock_); | 2211 ScopedLock sl(lock_); |
| 2213 queue_.Clear(); | 2212 queue_.Clear(); |
| 2214 } | 2213 } |
| 2215 | 2214 |
| 2216 #endif // ENABLE_DEBUGGER_SUPPORT | 2215 #endif // ENABLE_DEBUGGER_SUPPORT |
| 2217 | 2216 |
| 2218 } } // namespace v8::internal | 2217 } } // namespace v8::internal |
| OLD | NEW |