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 1743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1754 | 1754 |
1755 Mutex* Debugger::debugger_access_ = OS::CreateMutex(); | 1755 Mutex* Debugger::debugger_access_ = OS::CreateMutex(); |
1756 Handle<Object> Debugger::event_listener_ = Handle<Object>(); | 1756 Handle<Object> Debugger::event_listener_ = Handle<Object>(); |
1757 Handle<Object> Debugger::event_listener_data_ = Handle<Object>(); | 1757 Handle<Object> Debugger::event_listener_data_ = Handle<Object>(); |
1758 bool Debugger::compiling_natives_ = false; | 1758 bool Debugger::compiling_natives_ = false; |
1759 bool Debugger::is_loading_debugger_ = false; | 1759 bool Debugger::is_loading_debugger_ = false; |
1760 bool Debugger::never_unload_debugger_ = false; | 1760 bool Debugger::never_unload_debugger_ = false; |
1761 v8::Debug::MessageHandler2 Debugger::message_handler_ = NULL; | 1761 v8::Debug::MessageHandler2 Debugger::message_handler_ = NULL; |
1762 bool Debugger::debugger_unload_pending_ = false; | 1762 bool Debugger::debugger_unload_pending_ = false; |
1763 v8::Debug::HostDispatchHandler Debugger::host_dispatch_handler_ = NULL; | 1763 v8::Debug::HostDispatchHandler Debugger::host_dispatch_handler_ = NULL; |
| 1764 Mutex* Debugger::dispatch_handler_access_ = OS::CreateMutex(); |
1764 v8::Debug::DebugMessageDispatchHandler | 1765 v8::Debug::DebugMessageDispatchHandler |
1765 Debugger::debug_message_dispatch_handler_ = NULL; | 1766 Debugger::debug_message_dispatch_handler_ = NULL; |
| 1767 MessageDispatchHelperThread* Debugger::message_dispatch_helper_thread_ = NULL; |
1766 int Debugger::host_dispatch_micros_ = 100 * 1000; | 1768 int Debugger::host_dispatch_micros_ = 100 * 1000; |
1767 DebuggerAgent* Debugger::agent_ = NULL; | 1769 DebuggerAgent* Debugger::agent_ = NULL; |
1768 LockingCommandMessageQueue Debugger::command_queue_(kQueueInitialSize); | 1770 LockingCommandMessageQueue Debugger::command_queue_(kQueueInitialSize); |
1769 Semaphore* Debugger::command_received_ = OS::CreateSemaphore(0); | 1771 Semaphore* Debugger::command_received_ = OS::CreateSemaphore(0); |
1770 | 1772 |
1771 | 1773 |
1772 Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name, | 1774 Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name, |
1773 int argc, Object*** argv, | 1775 int argc, Object*** argv, |
1774 bool* caught_exception) { | 1776 bool* caught_exception) { |
1775 ASSERT(Top::context() == *Debug::debug_context()); | 1777 ASSERT(Top::context() == *Debug::debug_context()); |
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2392 | 2394 |
2393 | 2395 |
2394 void Debugger::SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler, | 2396 void Debugger::SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler, |
2395 int period) { | 2397 int period) { |
2396 host_dispatch_handler_ = handler; | 2398 host_dispatch_handler_ = handler; |
2397 host_dispatch_micros_ = period * 1000; | 2399 host_dispatch_micros_ = period * 1000; |
2398 } | 2400 } |
2399 | 2401 |
2400 | 2402 |
2401 void Debugger::SetDebugMessageDispatchHandler( | 2403 void Debugger::SetDebugMessageDispatchHandler( |
2402 v8::Debug::DebugMessageDispatchHandler handler) { | 2404 v8::Debug::DebugMessageDispatchHandler handler, bool provide_locker) { |
| 2405 ScopedLock with(dispatch_handler_access_); |
2403 debug_message_dispatch_handler_ = handler; | 2406 debug_message_dispatch_handler_ = handler; |
| 2407 |
| 2408 if (provide_locker && message_dispatch_helper_thread_ == NULL) { |
| 2409 message_dispatch_helper_thread_ = new MessageDispatchHelperThread; |
| 2410 message_dispatch_helper_thread_->Start(); |
| 2411 } |
2404 } | 2412 } |
2405 | 2413 |
2406 | 2414 |
2407 // Calls the registered debug message handler. This callback is part of the | 2415 // Calls the registered debug message handler. This callback is part of the |
2408 // public API. | 2416 // public API. |
2409 void Debugger::InvokeMessageHandler(MessageImpl message) { | 2417 void Debugger::InvokeMessageHandler(MessageImpl message) { |
2410 ScopedLock with(debugger_access_); | 2418 ScopedLock with(debugger_access_); |
2411 | 2419 |
2412 if (message_handler_ != NULL) { | 2420 if (message_handler_ != NULL) { |
2413 message_handler_(message); | 2421 message_handler_(message); |
(...skipping 14 matching lines...) Expand all Loading... |
2428 client_data); | 2436 client_data); |
2429 Logger::DebugTag("Put command on command_queue."); | 2437 Logger::DebugTag("Put command on command_queue."); |
2430 command_queue_.Put(message); | 2438 command_queue_.Put(message); |
2431 command_received_->Signal(); | 2439 command_received_->Signal(); |
2432 | 2440 |
2433 // Set the debug command break flag to have the command processed. | 2441 // Set the debug command break flag to have the command processed. |
2434 if (!Debug::InDebugger()) { | 2442 if (!Debug::InDebugger()) { |
2435 StackGuard::DebugCommand(); | 2443 StackGuard::DebugCommand(); |
2436 } | 2444 } |
2437 | 2445 |
2438 if (Debugger::debug_message_dispatch_handler_ != NULL) { | 2446 MessageDispatchHelperThread* dispatch_thread; |
2439 Debugger::debug_message_dispatch_handler_(); | 2447 { |
| 2448 ScopedLock with(dispatch_handler_access_); |
| 2449 dispatch_thread = message_dispatch_helper_thread_; |
| 2450 } |
| 2451 |
| 2452 if (dispatch_thread == NULL) { |
| 2453 CallMessageDispatchHandler(); |
| 2454 } else { |
| 2455 dispatch_thread->Schedule(); |
2440 } | 2456 } |
2441 } | 2457 } |
2442 | 2458 |
2443 | 2459 |
2444 bool Debugger::HasCommands() { | 2460 bool Debugger::HasCommands() { |
2445 return !command_queue_.IsEmpty(); | 2461 return !command_queue_.IsEmpty(); |
2446 } | 2462 } |
2447 | 2463 |
2448 | 2464 |
2449 bool Debugger::IsDebuggerActive() { | 2465 bool Debugger::IsDebuggerActive() { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2516 agent_ = NULL; | 2532 agent_ = NULL; |
2517 } | 2533 } |
2518 } | 2534 } |
2519 | 2535 |
2520 | 2536 |
2521 void Debugger::WaitForAgent() { | 2537 void Debugger::WaitForAgent() { |
2522 if (agent_ != NULL) | 2538 if (agent_ != NULL) |
2523 agent_->WaitUntilListening(); | 2539 agent_->WaitUntilListening(); |
2524 } | 2540 } |
2525 | 2541 |
| 2542 |
| 2543 void Debugger::CallMessageDispatchHandler() { |
| 2544 v8::Debug::DebugMessageDispatchHandler handler; |
| 2545 { |
| 2546 ScopedLock with(dispatch_handler_access_); |
| 2547 handler = Debugger::debug_message_dispatch_handler_; |
| 2548 } |
| 2549 if (handler != NULL) { |
| 2550 handler(); |
| 2551 } |
| 2552 } |
| 2553 |
| 2554 |
2526 MessageImpl MessageImpl::NewEvent(DebugEvent event, | 2555 MessageImpl MessageImpl::NewEvent(DebugEvent event, |
2527 bool running, | 2556 bool running, |
2528 Handle<JSObject> exec_state, | 2557 Handle<JSObject> exec_state, |
2529 Handle<JSObject> event_data) { | 2558 Handle<JSObject> event_data) { |
2530 MessageImpl message(true, event, running, | 2559 MessageImpl message(true, event, running, |
2531 exec_state, event_data, Handle<String>(), NULL); | 2560 exec_state, event_data, Handle<String>(), NULL); |
2532 return message; | 2561 return message; |
2533 } | 2562 } |
2534 | 2563 |
2535 | 2564 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2736 queue_.Put(message); | 2765 queue_.Put(message); |
2737 Logger::DebugEvent("Put", message.text()); | 2766 Logger::DebugEvent("Put", message.text()); |
2738 } | 2767 } |
2739 | 2768 |
2740 | 2769 |
2741 void LockingCommandMessageQueue::Clear() { | 2770 void LockingCommandMessageQueue::Clear() { |
2742 ScopedLock sl(lock_); | 2771 ScopedLock sl(lock_); |
2743 queue_.Clear(); | 2772 queue_.Clear(); |
2744 } | 2773 } |
2745 | 2774 |
| 2775 |
| 2776 MessageDispatchHelperThread::MessageDispatchHelperThread() |
| 2777 : sem_(OS::CreateSemaphore(0)), mutex_(OS::CreateMutex()), |
| 2778 already_signalled_(false) { |
| 2779 } |
| 2780 |
| 2781 |
| 2782 MessageDispatchHelperThread::~MessageDispatchHelperThread() { |
| 2783 delete mutex_; |
| 2784 delete sem_; |
| 2785 } |
| 2786 |
| 2787 |
| 2788 void MessageDispatchHelperThread::Schedule() { |
| 2789 { |
| 2790 ScopedLock lock(mutex_); |
| 2791 if (already_signalled_) { |
| 2792 return; |
| 2793 } |
| 2794 already_signalled_ = true; |
| 2795 } |
| 2796 sem_->Signal(); |
| 2797 } |
| 2798 |
| 2799 |
| 2800 void MessageDispatchHelperThread::Run() { |
| 2801 while (true) { |
| 2802 sem_->Wait(); |
| 2803 { |
| 2804 ScopedLock lock(mutex_); |
| 2805 already_signalled_ = false; |
| 2806 } |
| 2807 { |
| 2808 Locker locker; |
| 2809 Debugger::CallMessageDispatchHandler(); |
| 2810 } |
| 2811 } |
| 2812 } |
| 2813 |
2746 #endif // ENABLE_DEBUGGER_SUPPORT | 2814 #endif // ENABLE_DEBUGGER_SUPPORT |
2747 | 2815 |
2748 } } // namespace v8::internal | 2816 } } // namespace v8::internal |
OLD | NEW |