OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 2596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2607 compiling_natives_(false), | 2607 compiling_natives_(false), |
2608 is_loading_debugger_(false), | 2608 is_loading_debugger_(false), |
2609 live_edit_enabled_(true), | 2609 live_edit_enabled_(true), |
2610 never_unload_debugger_(false), | 2610 never_unload_debugger_(false), |
2611 force_debugger_active_(false), | 2611 force_debugger_active_(false), |
2612 message_handler_(NULL), | 2612 message_handler_(NULL), |
2613 debugger_unload_pending_(false), | 2613 debugger_unload_pending_(false), |
2614 host_dispatch_handler_(NULL), | 2614 host_dispatch_handler_(NULL), |
2615 debug_message_dispatch_handler_(NULL), | 2615 debug_message_dispatch_handler_(NULL), |
2616 message_dispatch_helper_thread_(NULL), | 2616 message_dispatch_helper_thread_(NULL), |
2617 host_dispatch_micros_(100 * 1000), | 2617 host_dispatch_period_(TimeDelta::FromMilliseconds(100)), |
2618 agent_(NULL), | 2618 agent_(NULL), |
2619 command_queue_(isolate->logger(), kQueueInitialSize), | 2619 command_queue_(isolate->logger(), kQueueInitialSize), |
2620 command_received_(OS::CreateSemaphore(0)), | 2620 command_received_(0), |
2621 event_command_queue_(isolate->logger(), kQueueInitialSize), | 2621 event_command_queue_(isolate->logger(), kQueueInitialSize), |
2622 isolate_(isolate) { | 2622 isolate_(isolate) { |
2623 } | 2623 } |
2624 | 2624 |
2625 | 2625 |
2626 Debugger::~Debugger() { | 2626 Debugger::~Debugger() {} |
2627 delete command_received_; | |
2628 command_received_ = 0; | |
2629 } | |
2630 | 2627 |
2631 | 2628 |
2632 Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name, | 2629 Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name, |
2633 int argc, | 2630 int argc, |
2634 Handle<Object> argv[], | 2631 Handle<Object> argv[], |
2635 bool* caught_exception) { | 2632 bool* caught_exception) { |
2636 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); | 2633 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); |
2637 | 2634 |
2638 // Create the execution state object. | 2635 // Create the execution state object. |
2639 Handle<String> constructor_str = | 2636 Handle<String> constructor_str = |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3142 } | 3139 } |
3143 } | 3140 } |
3144 | 3141 |
3145 bool running = auto_continue; | 3142 bool running = auto_continue; |
3146 | 3143 |
3147 // Process requests from the debugger. | 3144 // Process requests from the debugger. |
3148 while (true) { | 3145 while (true) { |
3149 // Wait for new command in the queue. | 3146 // Wait for new command in the queue. |
3150 if (Debugger::host_dispatch_handler_) { | 3147 if (Debugger::host_dispatch_handler_) { |
3151 // In case there is a host dispatch - do periodic dispatches. | 3148 // In case there is a host dispatch - do periodic dispatches. |
3152 if (!command_received_->Wait(host_dispatch_micros_)) { | 3149 if (!command_received_.WaitFor(host_dispatch_period_)) { |
3153 // Timout expired, do the dispatch. | 3150 // Timout expired, do the dispatch. |
3154 Debugger::host_dispatch_handler_(); | 3151 Debugger::host_dispatch_handler_(); |
3155 continue; | 3152 continue; |
3156 } | 3153 } |
3157 } else { | 3154 } else { |
3158 // In case there is no host dispatch - just wait. | 3155 // In case there is no host dispatch - just wait. |
3159 command_received_->Wait(); | 3156 command_received_.Wait(); |
3160 } | 3157 } |
3161 | 3158 |
3162 // Get the command from the queue. | 3159 // Get the command from the queue. |
3163 CommandMessage command = command_queue_.Get(); | 3160 CommandMessage command = command_queue_.Get(); |
3164 isolate_->logger()->DebugTag( | 3161 isolate_->logger()->DebugTag( |
3165 "Got request from command queue, in interactive loop."); | 3162 "Got request from command queue, in interactive loop."); |
3166 if (!Debugger::IsDebuggerActive()) { | 3163 if (!Debugger::IsDebuggerActive()) { |
3167 // Delete command text and user data. | 3164 // Delete command text and user data. |
3168 command.Dispose(); | 3165 command.Dispose(); |
3169 return; | 3166 return; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3291 } else { | 3288 } else { |
3292 isolate_->compilation_cache()->Enable(); | 3289 isolate_->compilation_cache()->Enable(); |
3293 // Unload the debugger if event listener and message handler cleared. | 3290 // Unload the debugger if event listener and message handler cleared. |
3294 // Schedule this for later, because we may be in non-V8 thread. | 3291 // Schedule this for later, because we may be in non-V8 thread. |
3295 debugger_unload_pending_ = true; | 3292 debugger_unload_pending_ = true; |
3296 } | 3293 } |
3297 } | 3294 } |
3298 | 3295 |
3299 | 3296 |
3300 void Debugger::SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler, | 3297 void Debugger::SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler, |
3301 int period) { | 3298 TimeDelta period) { |
3302 host_dispatch_handler_ = handler; | 3299 host_dispatch_handler_ = handler; |
3303 host_dispatch_micros_ = period * 1000; | 3300 host_dispatch_period_ = period; |
3304 } | 3301 } |
3305 | 3302 |
3306 | 3303 |
3307 void Debugger::SetDebugMessageDispatchHandler( | 3304 void Debugger::SetDebugMessageDispatchHandler( |
3308 v8::Debug::DebugMessageDispatchHandler handler, bool provide_locker) { | 3305 v8::Debug::DebugMessageDispatchHandler handler, bool provide_locker) { |
3309 LockGuard<Mutex> lock_guard(&dispatch_handler_access_); | 3306 LockGuard<Mutex> lock_guard(&dispatch_handler_access_); |
3310 debug_message_dispatch_handler_ = handler; | 3307 debug_message_dispatch_handler_ = handler; |
3311 | 3308 |
3312 if (provide_locker && message_dispatch_helper_thread_ == NULL) { | 3309 if (provide_locker && message_dispatch_helper_thread_ == NULL) { |
3313 message_dispatch_helper_thread_ = new MessageDispatchHelperThread(isolate_); | 3310 message_dispatch_helper_thread_ = new MessageDispatchHelperThread(isolate_); |
(...skipping 19 matching lines...) Expand all Loading... |
3333 // by the API client thread. | 3330 // by the API client thread. |
3334 void Debugger::ProcessCommand(Vector<const uint16_t> command, | 3331 void Debugger::ProcessCommand(Vector<const uint16_t> command, |
3335 v8::Debug::ClientData* client_data) { | 3332 v8::Debug::ClientData* client_data) { |
3336 // Need to cast away const. | 3333 // Need to cast away const. |
3337 CommandMessage message = CommandMessage::New( | 3334 CommandMessage message = CommandMessage::New( |
3338 Vector<uint16_t>(const_cast<uint16_t*>(command.start()), | 3335 Vector<uint16_t>(const_cast<uint16_t*>(command.start()), |
3339 command.length()), | 3336 command.length()), |
3340 client_data); | 3337 client_data); |
3341 isolate_->logger()->DebugTag("Put command on command_queue."); | 3338 isolate_->logger()->DebugTag("Put command on command_queue."); |
3342 command_queue_.Put(message); | 3339 command_queue_.Put(message); |
3343 command_received_->Signal(); | 3340 command_received_.Signal(); |
3344 | 3341 |
3345 // Set the debug command break flag to have the command processed. | 3342 // Set the debug command break flag to have the command processed. |
3346 if (!isolate_->debug()->InDebugger()) { | 3343 if (!isolate_->debug()->InDebugger()) { |
3347 isolate_->stack_guard()->DebugCommand(); | 3344 isolate_->stack_guard()->DebugCommand(); |
3348 } | 3345 } |
3349 | 3346 |
3350 MessageDispatchHelperThread* dispatch_thread; | 3347 MessageDispatchHelperThread* dispatch_thread; |
3351 { | 3348 { |
3352 LockGuard<Mutex> lock_guard(&dispatch_handler_access_); | 3349 LockGuard<Mutex> lock_guard(&dispatch_handler_access_); |
3353 dispatch_thread = message_dispatch_helper_thread_; | 3350 dispatch_thread = message_dispatch_helper_thread_; |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3815 | 3812 |
3816 | 3813 |
3817 void LockingCommandMessageQueue::Clear() { | 3814 void LockingCommandMessageQueue::Clear() { |
3818 LockGuard<Mutex> lock_guard(&mutex_); | 3815 LockGuard<Mutex> lock_guard(&mutex_); |
3819 queue_.Clear(); | 3816 queue_.Clear(); |
3820 } | 3817 } |
3821 | 3818 |
3822 | 3819 |
3823 MessageDispatchHelperThread::MessageDispatchHelperThread(Isolate* isolate) | 3820 MessageDispatchHelperThread::MessageDispatchHelperThread(Isolate* isolate) |
3824 : Thread("v8:MsgDispHelpr"), | 3821 : Thread("v8:MsgDispHelpr"), |
3825 isolate_(isolate), sem_(OS::CreateSemaphore(0)), | 3822 isolate_(isolate), sem_(0), |
3826 already_signalled_(false) { | 3823 already_signalled_(false) { |
3827 } | 3824 } |
3828 | 3825 |
3829 | 3826 |
3830 MessageDispatchHelperThread::~MessageDispatchHelperThread() { | |
3831 delete sem_; | |
3832 } | |
3833 | |
3834 | |
3835 void MessageDispatchHelperThread::Schedule() { | 3827 void MessageDispatchHelperThread::Schedule() { |
3836 { | 3828 { |
3837 LockGuard<Mutex> lock_guard(&mutex_); | 3829 LockGuard<Mutex> lock_guard(&mutex_); |
3838 if (already_signalled_) { | 3830 if (already_signalled_) { |
3839 return; | 3831 return; |
3840 } | 3832 } |
3841 already_signalled_ = true; | 3833 already_signalled_ = true; |
3842 } | 3834 } |
3843 sem_->Signal(); | 3835 sem_.Signal(); |
3844 } | 3836 } |
3845 | 3837 |
3846 | 3838 |
3847 void MessageDispatchHelperThread::Run() { | 3839 void MessageDispatchHelperThread::Run() { |
3848 while (true) { | 3840 while (true) { |
3849 sem_->Wait(); | 3841 sem_.Wait(); |
3850 { | 3842 { |
3851 LockGuard<Mutex> lock_guard(&mutex_); | 3843 LockGuard<Mutex> lock_guard(&mutex_); |
3852 already_signalled_ = false; | 3844 already_signalled_ = false; |
3853 } | 3845 } |
3854 { | 3846 { |
3855 Locker locker(reinterpret_cast<v8::Isolate*>(isolate_)); | 3847 Locker locker(reinterpret_cast<v8::Isolate*>(isolate_)); |
3856 isolate_->debugger()->CallMessageDispatchHandler(); | 3848 isolate_->debugger()->CallMessageDispatchHandler(); |
3857 } | 3849 } |
3858 } | 3850 } |
3859 } | 3851 } |
3860 | 3852 |
3861 #endif // ENABLE_DEBUGGER_SUPPORT | 3853 #endif // ENABLE_DEBUGGER_SUPPORT |
3862 | 3854 |
3863 } } // namespace v8::internal | 3855 } } // namespace v8::internal |
OLD | NEW |