| 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 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 return; | 602 return; |
| 603 } | 603 } |
| 604 | 604 |
| 605 // Clear debugger context global handle. | 605 // Clear debugger context global handle. |
| 606 GlobalHandles::Destroy(reinterpret_cast<Object**>(debug_context_.location())); | 606 GlobalHandles::Destroy(reinterpret_cast<Object**>(debug_context_.location())); |
| 607 debug_context_ = Handle<Context>(); | 607 debug_context_ = Handle<Context>(); |
| 608 } | 608 } |
| 609 | 609 |
| 610 | 610 |
| 611 void Debug::Iterate(ObjectVisitor* v) { | 611 void Debug::Iterate(ObjectVisitor* v) { |
| 612 #define VISIT(field) v->VisitPointer(bit_cast<Object**, Code**>(&(field))); | 612 v->VisitPointer(bit_cast<Object**, Code**>(&(debug_break_return_entry_))); |
| 613 VISIT(debug_break_return_entry_); | 613 v->VisitPointer(bit_cast<Object**, Code**>(&(debug_break_return_))); |
| 614 VISIT(debug_break_return_); | |
| 615 #undef VISIT | |
| 616 } | 614 } |
| 617 | 615 |
| 618 | 616 |
| 619 Object* Debug::Break(Arguments args) { | 617 Object* Debug::Break(Arguments args) { |
| 620 HandleScope scope; | 618 HandleScope scope; |
| 621 ASSERT(args.length() == 0); | 619 ASSERT(args.length() == 0); |
| 622 | 620 |
| 623 // Get the top-most JavaScript frame. | 621 // Get the top-most JavaScript frame. |
| 624 JavaScriptFrameIterator it; | 622 JavaScriptFrameIterator it; |
| 625 JavaScriptFrame* frame = it.frame(); | 623 JavaScriptFrame* frame = it.frame(); |
| (...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1312 Handle<Object> fun(Top::global()->GetProperty(*function_name)); | 1310 Handle<Object> fun(Top::global()->GetProperty(*function_name)); |
| 1313 ASSERT(fun->IsJSFunction()); | 1311 ASSERT(fun->IsJSFunction()); |
| 1314 bool caught_exception; | 1312 bool caught_exception; |
| 1315 Handle<Object> js_object = Execution::TryCall( | 1313 Handle<Object> js_object = Execution::TryCall( |
| 1316 Handle<JSFunction>::cast(fun), | 1314 Handle<JSFunction>::cast(fun), |
| 1317 Handle<JSObject>(Debug::debug_context()->global()), | 1315 Handle<JSObject>(Debug::debug_context()->global()), |
| 1318 0, NULL, &caught_exception); | 1316 0, NULL, &caught_exception); |
| 1319 } | 1317 } |
| 1320 | 1318 |
| 1321 | 1319 |
| 1320 Handle<Object> Debugger::event_listener_ = Handle<Object>(); |
| 1321 Handle<Object> Debugger::event_listener_data_ = Handle<Object>(); |
| 1322 bool Debugger::debugger_active_ = false; | 1322 bool Debugger::debugger_active_ = false; |
| 1323 bool Debugger::compiling_natives_ = false; | 1323 bool Debugger::compiling_natives_ = false; |
| 1324 bool Debugger::is_loading_debugger_ = false; | 1324 bool Debugger::is_loading_debugger_ = false; |
| 1325 DebugMessageThread* Debugger::message_thread_ = NULL; | 1325 DebugMessageThread* Debugger::message_thread_ = NULL; |
| 1326 v8::DebugMessageHandler Debugger::debug_message_handler_ = NULL; | 1326 v8::DebugMessageHandler Debugger::debug_message_handler_ = NULL; |
| 1327 void* Debugger::debug_message_handler_data_ = NULL; | 1327 void* Debugger::debug_message_handler_data_ = NULL; |
| 1328 | 1328 |
| 1329 | 1329 |
| 1330 Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name, | 1330 Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name, |
| 1331 int argc, Object*** argv, | 1331 int argc, Object*** argv, |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1602 // Create the execution state. | 1602 // Create the execution state. |
| 1603 bool caught_exception = false; | 1603 bool caught_exception = false; |
| 1604 Handle<Object> exec_state = MakeExecutionState(&caught_exception); | 1604 Handle<Object> exec_state = MakeExecutionState(&caught_exception); |
| 1605 if (caught_exception) { | 1605 if (caught_exception) { |
| 1606 return; | 1606 return; |
| 1607 } | 1607 } |
| 1608 // First notify the builtin debugger. | 1608 // First notify the builtin debugger. |
| 1609 if (message_thread_ != NULL) { | 1609 if (message_thread_ != NULL) { |
| 1610 message_thread_->DebugEvent(event, exec_state, event_data); | 1610 message_thread_->DebugEvent(event, exec_state, event_data); |
| 1611 } | 1611 } |
| 1612 // Notify registered debug event listeners. The list can contain both C and | 1612 // Notify registered debug event listener. This can be either a C or a |
| 1613 // JavaScript functions. | 1613 // JavaScript function. |
| 1614 v8::NeanderArray listeners(Factory::debug_event_listeners()); | 1614 if (!event_listener_.is_null()) { |
| 1615 int length = listeners.length(); | 1615 if (event_listener_->IsProxy()) { |
| 1616 for (int i = 0; i < length; i++) { | |
| 1617 if (listeners.get(i)->IsUndefined()) continue; // Skip deleted ones. | |
| 1618 v8::NeanderObject listener(JSObject::cast(listeners.get(i))); | |
| 1619 Handle<Object> callback_data(listener.get(1)); | |
| 1620 if (listener.get(0)->IsProxy()) { | |
| 1621 // C debug event listener. | 1616 // C debug event listener. |
| 1622 Handle<Proxy> callback_obj(Proxy::cast(listener.get(0))); | 1617 Handle<Proxy> callback_obj(Handle<Proxy>::cast(event_listener_)); |
| 1623 v8::DebugEventCallback callback = | 1618 v8::DebugEventCallback callback = |
| 1624 FUNCTION_CAST<v8::DebugEventCallback>(callback_obj->proxy()); | 1619 FUNCTION_CAST<v8::DebugEventCallback>(callback_obj->proxy()); |
| 1625 callback(event, | 1620 callback(event, |
| 1626 v8::Utils::ToLocal(Handle<JSObject>::cast(exec_state)), | 1621 v8::Utils::ToLocal(Handle<JSObject>::cast(exec_state)), |
| 1627 v8::Utils::ToLocal(Handle<JSObject>::cast(event_data)), | 1622 v8::Utils::ToLocal(Handle<JSObject>::cast(event_data)), |
| 1628 v8::Utils::ToLocal(callback_data)); | 1623 v8::Utils::ToLocal(Handle<Object>::cast(event_listener_data_))); |
| 1629 } else { | 1624 } else { |
| 1630 // JavaScript debug event listener. | 1625 // JavaScript debug event listener. |
| 1631 ASSERT(listener.get(0)->IsJSFunction()); | 1626 ASSERT(event_listener_->IsJSFunction()); |
| 1632 Handle<JSFunction> fun(JSFunction::cast(listener.get(0))); | 1627 Handle<JSFunction> fun(Handle<JSFunction>::cast(event_listener_)); |
| 1633 | 1628 |
| 1634 // Invoke the JavaScript debug event listener. | 1629 // Invoke the JavaScript debug event listener. |
| 1635 const int argc = 4; | 1630 const int argc = 4; |
| 1636 Object** argv[argc] = { Handle<Object>(Smi::FromInt(event)).location(), | 1631 Object** argv[argc] = { Handle<Object>(Smi::FromInt(event)).location(), |
| 1637 exec_state.location(), | 1632 exec_state.location(), |
| 1638 event_data.location(), | 1633 event_data.location(), |
| 1639 callback_data.location() }; | 1634 event_listener_data_.location() }; |
| 1640 Handle<Object> result = Execution::TryCall(fun, Top::global(), | 1635 Handle<Object> result = Execution::TryCall(fun, Top::global(), |
| 1641 argc, argv, &caught_exception); | 1636 argc, argv, &caught_exception); |
| 1642 if (caught_exception) { | 1637 if (caught_exception) { |
| 1643 // Silently ignore exceptions from debug event listeners. | 1638 // Silently ignore exceptions from debug event listeners. |
| 1644 } | 1639 } |
| 1645 } | 1640 } |
| 1646 } | 1641 } |
| 1647 | 1642 |
| 1648 // Clear the mirror cache. | 1643 // Clear the mirror cache. |
| 1649 Debug::ClearMirrorCache(); | 1644 Debug::ClearMirrorCache(); |
| 1650 } | 1645 } |
| 1651 | 1646 |
| 1652 | 1647 |
| 1648 void Debugger::SetEventListener(Handle<Object> callback, |
| 1649 Handle<Object> data) { |
| 1650 HandleScope scope; |
| 1651 |
| 1652 // Clear the global handles for the event listener and the event listener data |
| 1653 // object. |
| 1654 if (!event_listener_.is_null()) { |
| 1655 GlobalHandles::Destroy( |
| 1656 reinterpret_cast<Object**>(event_listener_.location())); |
| 1657 event_listener_ = Handle<Object>(); |
| 1658 } |
| 1659 if (!event_listener_data_.is_null()) { |
| 1660 GlobalHandles::Destroy( |
| 1661 reinterpret_cast<Object**>(event_listener_data_.location())); |
| 1662 event_listener_data_ = Handle<Object>(); |
| 1663 } |
| 1664 |
| 1665 // If there is a new debug event listener register it together with its data |
| 1666 // object. |
| 1667 if (!callback->IsUndefined() && !callback->IsNull()) { |
| 1668 event_listener_ = Handle<Object>::cast(GlobalHandles::Create(*callback)); |
| 1669 if (data.is_null()) { |
| 1670 data = Factory::undefined_value(); |
| 1671 } |
| 1672 event_listener_data_ = Handle<Object>::cast(GlobalHandles::Create(*data)); |
| 1673 } |
| 1674 |
| 1675 UpdateActiveDebugger(); |
| 1676 } |
| 1677 |
| 1678 |
| 1653 void Debugger::SetMessageHandler(v8::DebugMessageHandler handler, void* data) { | 1679 void Debugger::SetMessageHandler(v8::DebugMessageHandler handler, void* data) { |
| 1654 debug_message_handler_ = handler; | 1680 debug_message_handler_ = handler; |
| 1655 debug_message_handler_data_ = data; | 1681 debug_message_handler_data_ = data; |
| 1656 if (!message_thread_) { | 1682 if (!message_thread_) { |
| 1657 message_thread_ = new DebugMessageThread(); | 1683 message_thread_ = new DebugMessageThread(); |
| 1658 message_thread_->Start(); | 1684 message_thread_->Start(); |
| 1659 } | 1685 } |
| 1660 UpdateActiveDebugger(); | 1686 UpdateActiveDebugger(); |
| 1661 } | 1687 } |
| 1662 | 1688 |
| 1663 | 1689 |
| 1664 // Posts an output message from the debugger to the debug_message_handler | 1690 // Posts an output message from the debugger to the debug_message_handler |
| 1665 // callback. This callback is part of the public API. Messages are | 1691 // callback. This callback is part of the public API. Messages are |
| 1666 // kept internally as Vector<uint16_t> strings, which are allocated in various | 1692 // kept internally as Vector<uint16_t> strings, which are allocated in various |
| 1667 // places and deallocated by the calling function sometime after this call. | 1693 // places and deallocated by the calling function sometime after this call. |
| 1668 void Debugger::SendMessage(Vector< uint16_t> message) { | 1694 void Debugger::SendMessage(Vector< uint16_t> message) { |
| 1669 if (debug_message_handler_ != NULL) { | 1695 if (debug_message_handler_ != NULL) { |
| 1670 debug_message_handler_(message.start(), message.length(), | 1696 debug_message_handler_(message.start(), message.length(), |
| 1671 debug_message_handler_data_); | 1697 debug_message_handler_data_); |
| 1672 } | 1698 } |
| 1673 } | 1699 } |
| 1674 | 1700 |
| 1675 | 1701 |
| 1676 void Debugger::ProcessCommand(Vector<const uint16_t> command) { | 1702 void Debugger::ProcessCommand(Vector<const uint16_t> command) { |
| 1677 if (message_thread_ != NULL) { | 1703 if (message_thread_ != NULL) { |
| 1678 message_thread_->ProcessCommand( | 1704 message_thread_->ProcessCommand( |
| 1679 Vector<uint16_t>(const_cast<uint16_t *>(command.start()), | 1705 Vector<uint16_t>(const_cast<uint16_t *>(command.start()), |
| 1680 command.length())); | 1706 command.length())); |
| 1681 } | 1707 } |
| 1682 } | 1708 } |
| 1683 | 1709 |
| 1684 | 1710 |
| 1685 void Debugger::UpdateActiveDebugger() { | 1711 void Debugger::UpdateActiveDebugger() { |
| 1686 v8::NeanderArray listeners(Factory::debug_event_listeners()); | 1712 set_debugger_active((message_thread_ != NULL && |
| 1687 int length = listeners.length(); | 1713 debug_message_handler_ != NULL) || |
| 1688 bool active_listener = false; | 1714 !event_listener_.is_null()); |
| 1689 for (int i = 0; i < length && !active_listener; i++) { | 1715 if (!debugger_active() && message_thread_) { |
| 1690 active_listener = !listeners.get(i)->IsUndefined(); | 1716 message_thread_->OnDebuggerInactive(); |
| 1691 } | 1717 } |
| 1692 set_debugger_active((Debugger::message_thread_ != NULL && | |
| 1693 Debugger::debug_message_handler_ != NULL) || | |
| 1694 active_listener); | |
| 1695 if (!debugger_active() && message_thread_) | |
| 1696 message_thread_->OnDebuggerInactive(); | |
| 1697 } | 1718 } |
| 1698 | 1719 |
| 1699 | 1720 |
| 1700 Handle<Object> Debugger::Call(Handle<JSFunction> fun, | 1721 Handle<Object> Debugger::Call(Handle<JSFunction> fun, |
| 1701 Handle<Object> data, | 1722 Handle<Object> data, |
| 1702 bool* pending_exception) { | 1723 bool* pending_exception) { |
| 1703 // Enter the debugger. | 1724 // Enter the debugger. |
| 1704 EnterDebugger debugger; | 1725 EnterDebugger debugger; |
| 1705 if (debugger.FailedToEnter() || !debugger.HasJavaScriptFrames()) { | 1726 if (debugger.FailedToEnter() || !debugger.HasJavaScriptFrames()) { |
| 1706 return Factory::undefined_value(); | 1727 return Factory::undefined_value(); |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2012 } | 2033 } |
| 2013 | 2034 |
| 2014 | 2035 |
| 2015 void LockingMessageQueue::Clear() { | 2036 void LockingMessageQueue::Clear() { |
| 2016 ScopedLock sl(lock_); | 2037 ScopedLock sl(lock_); |
| 2017 queue_.Clear(); | 2038 queue_.Clear(); |
| 2018 } | 2039 } |
| 2019 | 2040 |
| 2020 | 2041 |
| 2021 } } // namespace v8::internal | 2042 } } // namespace v8::internal |
| OLD | NEW |