OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 2406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2417 int offset = static_cast<int>( | 2417 int offset = static_cast<int>( |
2418 it.frame()->pc() - code->instruction_start()); | 2418 it.frame()->pc() - code->instruction_start()); |
2419 script->set_eval_from_instructions_offset(Smi::FromInt(offset)); | 2419 script->set_eval_from_instructions_offset(Smi::FromInt(offset)); |
2420 } | 2420 } |
2421 } | 2421 } |
2422 | 2422 |
2423 | 2423 |
2424 MaybeHandle<Object> Debug::MakeJSObject(const char* constructor_name, | 2424 MaybeHandle<Object> Debug::MakeJSObject(const char* constructor_name, |
2425 int argc, | 2425 int argc, |
2426 Handle<Object> argv[]) { | 2426 Handle<Object> argv[]) { |
2427 AssertDebugContext(); | 2427 if (in_debug_scope()) { |
| 2428 Handle<GlobalObject> debug_global(debug_context()->global_object()); |
| 2429 Factory* factory = isolate_->factory(); |
| 2430 Handle<JSFunction> constructor = |
| 2431 Handle<JSFunction>::cast(Object::GetProperty( |
| 2432 debug_global, factory->InternalizeUtf8String(constructor_name)).ToHand
leChecked()); |
| 2433 PostponeInterruptsScope no_interrupts(isolate_); |
| 2434 return Execution::TryCall(constructor, |
| 2435 handle(debug_context()->global_proxy()), |
| 2436 argc, |
| 2437 argv); |
| 2438 } |
| 2439 |
2428 // Create the execution state object. | 2440 // Create the execution state object. |
2429 Handle<GlobalObject> global(isolate_->global_object()); | 2441 Handle<GlobalObject> global(isolate_->global_object()); |
2430 Handle<Object> constructor = Object::GetProperty( | 2442 Handle<Object> constructor = Object::GetProperty( |
2431 isolate_, global, constructor_name).ToHandleChecked(); | 2443 isolate_, global, constructor_name).ToHandleChecked(); |
2432 DCHECK(constructor->IsJSFunction()); | 2444 DCHECK(constructor->IsJSFunction()); |
2433 if (!constructor->IsJSFunction()) return MaybeHandle<Object>(); | 2445 if (!constructor->IsJSFunction()) return MaybeHandle<Object>(); |
2434 // We do not handle interrupts here. In particular, termination interrupts. | 2446 // We do not handle interrupts here. In particular, termination interrupts. |
2435 PostponeInterruptsScope no_interrupts(isolate_); | 2447 PostponeInterruptsScope no_interrupts(isolate_); |
2436 return Execution::TryCall(Handle<JSFunction>::cast(constructor), | 2448 return Execution::TryCall(Handle<JSFunction>::cast(constructor), |
2437 handle(debug_context()->global_proxy()), | 2449 handle(debug_context()->global_proxy()), |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2567 } | 2579 } |
2568 | 2580 |
2569 // Process debug event. | 2581 // Process debug event. |
2570 ProcessDebugEvent(v8::Exception, Handle<JSObject>::cast(event_data), false); | 2582 ProcessDebugEvent(v8::Exception, Handle<JSObject>::cast(event_data), false); |
2571 // Return to continue execution from where the exception was thrown. | 2583 // Return to continue execution from where the exception was thrown. |
2572 } | 2584 } |
2573 | 2585 |
2574 | 2586 |
2575 void Debug::OnCompileError(Handle<Script> script) { | 2587 void Debug::OnCompileError(Handle<Script> script) { |
2576 // No more to do if not debugging. | 2588 // No more to do if not debugging. |
2577 if (in_debug_scope() || ignore_events()) return; | 2589 if (ignore_events()) return; |
2578 | 2590 |
2579 HandleScope scope(isolate_); | 2591 HandleScope scope(isolate_); |
2580 DebugScope debug_scope(this); | 2592 DebugScope debug_scope(this); |
2581 if (debug_scope.failed()) return; | 2593 if (debug_scope.failed()) return; |
2582 | 2594 |
2583 // Create the compile state object. | 2595 // Create the compile state object. |
2584 Handle<Object> event_data; | 2596 Handle<Object> event_data; |
2585 // Bail out and don't call debugger if exception. | 2597 // Bail out and don't call debugger if exception. |
2586 if (!MakeCompileEvent(script, v8::CompileError).ToHandle(&event_data)) return; | 2598 if (!MakeCompileEvent(script, v8::CompileError).ToHandle(&event_data)) return; |
2587 | 2599 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2629 true); | 2641 true); |
2630 } | 2642 } |
2631 | 2643 |
2632 | 2644 |
2633 // Handle debugger actions when a new script is compiled. | 2645 // Handle debugger actions when a new script is compiled. |
2634 void Debug::OnAfterCompile(Handle<Script> script) { | 2646 void Debug::OnAfterCompile(Handle<Script> script) { |
2635 // Add the newly compiled script to the script cache. | 2647 // Add the newly compiled script to the script cache. |
2636 if (script_cache_ != NULL) script_cache_->Add(script); | 2648 if (script_cache_ != NULL) script_cache_->Add(script); |
2637 | 2649 |
2638 // No more to do if not debugging. | 2650 // No more to do if not debugging. |
2639 if (in_debug_scope() || ignore_events()) return; | 2651 if (ignore_events()) return; |
| 2652 if (in_debug_scope()) { |
| 2653 // Create the compile state object. |
| 2654 Handle<Object> event_data; |
| 2655 // Bail out and don't call debugger if exception. |
| 2656 if (!MakeCompileEvent(script, v8::AfterCompile).ToHandle(&event_data)) retur
n; |
| 2657 |
| 2658 // Process debug event. |
| 2659 ProcessDebugEvent(v8::AfterCompile, Handle<JSObject>::cast(event_data), true
); |
| 2660 return; |
| 2661 } |
2640 | 2662 |
2641 HandleScope scope(isolate_); | 2663 HandleScope scope(isolate_); |
2642 DebugScope debug_scope(this); | 2664 DebugScope debug_scope(this); |
2643 if (debug_scope.failed()) return; | 2665 if (debug_scope.failed()) return; |
2644 | 2666 |
2645 // If debugging there might be script break points registered for this | 2667 // If debugging there might be script break points registered for this |
2646 // script. Make sure that these break points are set. | 2668 // script. Make sure that these break points are set. |
2647 | 2669 |
2648 // Get the function UpdateScriptBreakPoints (defined in debug-debugger.js). | 2670 // Get the function UpdateScriptBreakPoints (defined in debug-debugger.js). |
2649 Handle<String> update_script_break_points_string = | 2671 Handle<String> update_script_break_points_string = |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2822 case v8::NewFunction: | 2844 case v8::NewFunction: |
2823 break; | 2845 break; |
2824 default: | 2846 default: |
2825 UNREACHABLE(); | 2847 UNREACHABLE(); |
2826 } | 2848 } |
2827 | 2849 |
2828 // The debug command interrupt flag might have been set when the command was | 2850 // The debug command interrupt flag might have been set when the command was |
2829 // added. It should be enough to clear the flag only once while we are in the | 2851 // added. It should be enough to clear the flag only once while we are in the |
2830 // debugger. | 2852 // debugger. |
2831 DCHECK(in_debug_scope()); | 2853 DCHECK(in_debug_scope()); |
2832 isolate_->stack_guard()->ClearDebugCommand(); | 2854 if (!(in_debug_scope() && (event == v8::AfterCompile || event == v8::CompileEr
ror))) |
| 2855 isolate_->stack_guard()->ClearDebugCommand(); |
2833 | 2856 |
2834 // Notify the debugger that a debug event has occurred unless auto continue is | 2857 // Notify the debugger that a debug event has occurred unless auto continue is |
2835 // active in which case no event is send. | 2858 // active in which case no event is send. |
2836 if (sendEventMessage) { | 2859 if (sendEventMessage) { |
2837 MessageImpl message = MessageImpl::NewEvent( | 2860 MessageImpl message = MessageImpl::NewEvent( |
2838 event, | 2861 event, |
2839 auto_continue, | 2862 auto_continue, |
2840 Handle<JSObject>::cast(exec_state), | 2863 Handle<JSObject>::cast(exec_state), |
2841 Handle<JSObject>::cast(event_data)); | 2864 Handle<JSObject>::cast(event_data)); |
2842 InvokeMessageHandler(message); | 2865 InvokeMessageHandler(message); |
2843 } | 2866 } |
2844 | 2867 |
2845 // If auto continue don't make the event cause a break, but process messages | 2868 // If auto continue don't make the event cause a break, but process messages |
2846 // in the queue if any. For script collected events don't even process | 2869 // in the queue if any. For script collected events don't even process |
2847 // messages in the queue as the execution state might not be what is expected | 2870 // messages in the queue as the execution state might not be what is expected |
2848 // by the client. | 2871 // by the client. |
2849 if (auto_continue && !has_commands()) return; | 2872 if (auto_continue && !has_commands()) return; |
| 2873 if (in_debug_scope() && (event == v8::AfterCompile || event == v8::CompileErro
r)) return; |
2850 | 2874 |
2851 // DebugCommandProcessor goes here. | 2875 // DebugCommandProcessor goes here. |
2852 bool running = auto_continue; | 2876 bool running = auto_continue; |
2853 | 2877 |
2854 Handle<Object> cmd_processor_ctor = Object::GetProperty( | 2878 Handle<Object> cmd_processor_ctor = Object::GetProperty( |
2855 isolate_, exec_state, "debugCommandProcessor").ToHandleChecked(); | 2879 isolate_, exec_state, "debugCommandProcessor").ToHandleChecked(); |
2856 Handle<Object> ctor_args[] = { isolate_->factory()->ToBoolean(running) }; | 2880 Handle<Object> ctor_args[] = { isolate_->factory()->ToBoolean(running) }; |
2857 Handle<Object> cmd_processor = Execution::Call( | 2881 Handle<Object> cmd_processor = Execution::Call( |
2858 isolate_, cmd_processor_ctor, exec_state, 1, ctor_args).ToHandleChecked(); | 2882 isolate_, cmd_processor_ctor, exec_state, 1, ctor_args).ToHandleChecked(); |
2859 Handle<JSFunction> process_debug_request = Handle<JSFunction>::cast( | 2883 Handle<JSFunction> process_debug_request = Handle<JSFunction>::cast( |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3385 logger_->DebugEvent("Put", message.text()); | 3409 logger_->DebugEvent("Put", message.text()); |
3386 } | 3410 } |
3387 | 3411 |
3388 | 3412 |
3389 void LockingCommandMessageQueue::Clear() { | 3413 void LockingCommandMessageQueue::Clear() { |
3390 base::LockGuard<base::Mutex> lock_guard(&mutex_); | 3414 base::LockGuard<base::Mutex> lock_guard(&mutex_); |
3391 queue_.Clear(); | 3415 queue_.Clear(); |
3392 } | 3416 } |
3393 | 3417 |
3394 } } // namespace v8::internal | 3418 } } // namespace v8::internal |
OLD | NEW |