Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(262)

Side by Side Diff: src/debug.cc

Issue 261253005: Clean up debugger flags. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/debug.h ('k') | src/execution.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "v8.h" 5 #include "v8.h"
6 6
7 #include "api.h" 7 #include "api.h"
8 #include "arguments.h" 8 #include "arguments.h"
9 #include "bootstrapper.h" 9 #include "bootstrapper.h"
10 #include "code-stubs.h" 10 #include "code-stubs.h"
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 759
760 760
761 bool Debug::Load() { 761 bool Debug::Load() {
762 // Return if debugger is already loaded. 762 // Return if debugger is already loaded.
763 if (IsLoaded()) return true; 763 if (IsLoaded()) return true;
764 764
765 Debugger* debugger = isolate_->debugger(); 765 Debugger* debugger = isolate_->debugger();
766 766
767 // Bail out if we're already in the process of compiling the native 767 // Bail out if we're already in the process of compiling the native
768 // JavaScript source code for the debugger. 768 // JavaScript source code for the debugger.
769 if (debugger->compiling_natives() || 769 if (debugger->ignore_debugger()) return false;
770 debugger->is_loading_debugger())
771 return false;
772 debugger->set_loading_debugger(true);
773 770
771 Debugger::IgnoreScope during_load(debugger);
774 // Disable breakpoints and interrupts while compiling and running the 772 // Disable breakpoints and interrupts while compiling and running the
775 // debugger scripts including the context creation code. 773 // debugger scripts including the context creation code.
776 DisableBreak disable(isolate_, true); 774 DisableBreak disable(isolate_, true);
777 PostponeInterruptsScope postpone(isolate_); 775 PostponeInterruptsScope postpone(isolate_);
778 776
779 // Create the debugger context. 777 // Create the debugger context.
780 HandleScope scope(isolate_); 778 HandleScope scope(isolate_);
781 ExtensionConfiguration no_extensions; 779 ExtensionConfiguration no_extensions;
782 Handle<Context> context = 780 Handle<Context> context =
783 isolate_->bootstrapper()->CreateEnvironment( 781 isolate_->bootstrapper()->CreateEnvironment(
(...skipping 15 matching lines...) Expand all
799 RETURN_ON_EXCEPTION_VALUE( 797 RETURN_ON_EXCEPTION_VALUE(
800 isolate_, 798 isolate_,
801 JSReceiver::SetProperty(global, 799 JSReceiver::SetProperty(global,
802 key, 800 key,
803 Handle<Object>(global->builtins(), isolate_), 801 Handle<Object>(global->builtins(), isolate_),
804 NONE, 802 NONE,
805 SLOPPY), 803 SLOPPY),
806 false); 804 false);
807 805
808 // Compile the JavaScript for the debugger in the debugger context. 806 // Compile the JavaScript for the debugger in the debugger context.
809 debugger->set_compiling_natives(true);
810 bool caught_exception = 807 bool caught_exception =
811 !CompileDebuggerScript(isolate_, Natives::GetIndex("mirror")) || 808 !CompileDebuggerScript(isolate_, Natives::GetIndex("mirror")) ||
812 !CompileDebuggerScript(isolate_, Natives::GetIndex("debug")); 809 !CompileDebuggerScript(isolate_, Natives::GetIndex("debug"));
813 810
814 if (FLAG_enable_liveedit) { 811 if (FLAG_enable_liveedit) {
815 caught_exception = caught_exception || 812 caught_exception = caught_exception ||
816 !CompileDebuggerScript(isolate_, Natives::GetIndex("liveedit")); 813 !CompileDebuggerScript(isolate_, Natives::GetIndex("liveedit"));
817 } 814 }
818 815
819 debugger->set_compiling_natives(false);
820
821 // Make sure we mark the debugger as not loading before we might 816 // Make sure we mark the debugger as not loading before we might
822 // return. 817 // return.
823 debugger->set_loading_debugger(false);
824 818
825 // Check for caught exceptions. 819 // Check for caught exceptions.
826 if (caught_exception) return false; 820 if (caught_exception) return false;
827 821
828 // Debugger loaded, create debugger context global handle. 822 // Debugger loaded, create debugger context global handle.
829 debug_context_ = Handle<Context>::cast( 823 debug_context_ = Handle<Context>::cast(
830 isolate_->global_handles()->Create(*context)); 824 isolate_->global_handles()->Create(*context));
831 825
832 return true; 826 return true;
833 } 827 }
(...skipping 1157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1991 1985
1992 1986
1993 class ActiveFunctionsRedirector : public ThreadVisitor { 1987 class ActiveFunctionsRedirector : public ThreadVisitor {
1994 public: 1988 public:
1995 void VisitThread(Isolate* isolate, ThreadLocalTop* top) { 1989 void VisitThread(Isolate* isolate, ThreadLocalTop* top) {
1996 RedirectActivationsToRecompiledCodeOnThread(isolate, top); 1990 RedirectActivationsToRecompiledCodeOnThread(isolate, top);
1997 } 1991 }
1998 }; 1992 };
1999 1993
2000 1994
2001 class ForceDebuggerActive {
2002 public:
2003 explicit ForceDebuggerActive(Isolate *isolate) {
2004 isolate_ = isolate;
2005 old_state_ = isolate->debugger()->force_debugger_active();
2006 isolate_->debugger()->set_force_debugger_active(true);
2007 }
2008
2009 ~ForceDebuggerActive() {
2010 isolate_->debugger()->set_force_debugger_active(old_state_);
2011 }
2012
2013 private:
2014 Isolate *isolate_;
2015 bool old_state_;
2016
2017 DISALLOW_COPY_AND_ASSIGN(ForceDebuggerActive);
2018 };
2019
2020
2021 void Debug::EnsureFunctionHasDebugBreakSlots(Handle<JSFunction> function) { 1995 void Debug::EnsureFunctionHasDebugBreakSlots(Handle<JSFunction> function) {
2022 if (function->code()->kind() == Code::FUNCTION && 1996 if (function->code()->kind() == Code::FUNCTION &&
2023 function->code()->has_debug_break_slots()) { 1997 function->code()->has_debug_break_slots()) {
2024 // Nothing to do. Function code already had debug break slots. 1998 // Nothing to do. Function code already had debug break slots.
2025 return; 1999 return;
2026 } 2000 }
2027
2028 // Make sure that the shared full code is compiled with debug 2001 // Make sure that the shared full code is compiled with debug
2029 // break slots. 2002 // break slots.
2030 if (!function->shared()->code()->has_debug_break_slots()) { 2003 if (!function->shared()->code()->has_debug_break_slots()) {
2031 ForceDebuggerActive force_debugger_active(isolate_);
2032 MaybeHandle<Code> code = Compiler::GetCodeForDebugging(function); 2004 MaybeHandle<Code> code = Compiler::GetCodeForDebugging(function);
2033 // Recompilation can fail. In that case leave the code as it was. 2005 // Recompilation can fail. In that case leave the code as it was.
2034 if (!code.is_null()) function->ReplaceCode(*code.ToHandleChecked()); 2006 if (!code.is_null()) function->ReplaceCode(*code.ToHandleChecked());
2035 } else { 2007 } else {
2036 // Simply use shared code if it has debug break slots. 2008 // Simply use shared code if it has debug break slots.
2037 function->ReplaceCode(function->shared()->code()); 2009 function->ReplaceCode(function->shared()->code());
2038 } 2010 }
2039 } 2011 }
2040 2012
2041 2013
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
2645 2617
2646 void Debug::AfterGarbageCollection() { 2618 void Debug::AfterGarbageCollection() {
2647 // Generate events for collected scripts. 2619 // Generate events for collected scripts.
2648 if (script_cache_ != NULL) { 2620 if (script_cache_ != NULL) {
2649 script_cache_->ProcessCollectedScripts(); 2621 script_cache_->ProcessCollectedScripts();
2650 } 2622 }
2651 } 2623 }
2652 2624
2653 2625
2654 Debugger::Debugger(Isolate* isolate) 2626 Debugger::Debugger(Isolate* isolate)
2655 : debugger_access_(isolate->debugger_access()), 2627 : event_listener_(Handle<Object>()),
2656 event_listener_(Handle<Object>()),
2657 event_listener_data_(Handle<Object>()), 2628 event_listener_data_(Handle<Object>()),
2658 compiling_natives_(false), 2629 is_active_(false),
2659 is_loading_debugger_(false), 2630 ignore_debugger_(false),
2660 live_edit_enabled_(true), 2631 live_edit_enabled_(true),
2661 never_unload_debugger_(false), 2632 never_unload_debugger_(false),
2662 force_debugger_active_(false),
2663 message_handler_(NULL), 2633 message_handler_(NULL),
2664 debugger_unload_pending_(false), 2634 debugger_unload_pending_(false),
2665 debug_message_dispatch_handler_(NULL), 2635 debug_message_dispatch_handler_(NULL),
2666 message_dispatch_helper_thread_(NULL), 2636 message_dispatch_helper_thread_(NULL),
2667 agent_(NULL), 2637 agent_(NULL),
2668 command_queue_(isolate->logger(), kQueueInitialSize), 2638 command_queue_(isolate->logger(), kQueueInitialSize),
2669 command_received_(0), 2639 command_received_(0),
2670 event_command_queue_(isolate->logger(), kQueueInitialSize), 2640 event_command_queue_(isolate->logger(), kQueueInitialSize),
2671 isolate_(isolate) { 2641 isolate_(isolate) {
2672 } 2642 }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
2753 CStrVector("MakeScriptCollectedEvent"), ARRAY_SIZE(argv), argv); 2723 CStrVector("MakeScriptCollectedEvent"), ARRAY_SIZE(argv), argv);
2754 } 2724 }
2755 2725
2756 2726
2757 void Debugger::OnException(Handle<Object> exception, bool uncaught) { 2727 void Debugger::OnException(Handle<Object> exception, bool uncaught) {
2758 HandleScope scope(isolate_); 2728 HandleScope scope(isolate_);
2759 Debug* debug = isolate_->debug(); 2729 Debug* debug = isolate_->debug();
2760 2730
2761 // Bail out based on state or if there is no listener for this event 2731 // Bail out based on state or if there is no listener for this event
2762 if (debug->InDebugger()) return; 2732 if (debug->InDebugger()) return;
2763 if (!Debugger::EventActive(v8::Exception)) return; 2733 if (!Debugger::EventActive()) return;
2764 2734
2765 Handle<Object> promise = debug->GetPromiseForUncaughtException(); 2735 Handle<Object> promise = debug->GetPromiseForUncaughtException();
2766 uncaught |= !promise->IsUndefined(); 2736 uncaught |= !promise->IsUndefined();
2767 2737
2768 // Bail out if exception breaks are not active 2738 // Bail out if exception breaks are not active
2769 if (uncaught) { 2739 if (uncaught) {
2770 // Uncaught exceptions are reported by either flags. 2740 // Uncaught exceptions are reported by either flags.
2771 if (!(debug->break_on_uncaught_exception() || 2741 if (!(debug->break_on_uncaught_exception() ||
2772 debug->break_on_exception())) return; 2742 debug->break_on_exception())) return;
2773 } else { 2743 } else {
(...skipping 23 matching lines...) Expand all
2797 2767
2798 2768
2799 void Debugger::OnDebugBreak(Handle<Object> break_points_hit, 2769 void Debugger::OnDebugBreak(Handle<Object> break_points_hit,
2800 bool auto_continue) { 2770 bool auto_continue) {
2801 HandleScope scope(isolate_); 2771 HandleScope scope(isolate_);
2802 2772
2803 // Debugger has already been entered by caller. 2773 // Debugger has already been entered by caller.
2804 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); 2774 ASSERT(isolate_->context() == *isolate_->debug()->debug_context());
2805 2775
2806 // Bail out if there is no listener for this event 2776 // Bail out if there is no listener for this event
2807 if (!Debugger::EventActive(v8::Break)) return; 2777 if (!Debugger::EventActive()) return;
2808 2778
2809 // Debugger must be entered in advance. 2779 // Debugger must be entered in advance.
2810 ASSERT(isolate_->context() == *isolate_->debug()->debug_context()); 2780 ASSERT(isolate_->context() == *isolate_->debug()->debug_context());
2811 2781
2812 // Create the event data object. 2782 // Create the event data object.
2813 Handle<Object> event_data; 2783 Handle<Object> event_data;
2814 // Bail out and don't call debugger if exception. 2784 // Bail out and don't call debugger if exception.
2815 if (!MakeBreakEvent(break_points_hit).ToHandle(&event_data)) return; 2785 if (!MakeBreakEvent(break_points_hit).ToHandle(&event_data)) return;
2816 2786
2817 // Process debug event. 2787 // Process debug event.
2818 ProcessDebugEvent(v8::Break, 2788 ProcessDebugEvent(v8::Break,
2819 Handle<JSObject>::cast(event_data), 2789 Handle<JSObject>::cast(event_data),
2820 auto_continue); 2790 auto_continue);
2821 } 2791 }
2822 2792
2823 2793
2824 void Debugger::OnBeforeCompile(Handle<Script> script) { 2794 void Debugger::OnBeforeCompile(Handle<Script> script) {
2825 HandleScope scope(isolate_); 2795 HandleScope scope(isolate_);
2826 2796
2827 // Bail out based on state or if there is no listener for this event 2797 // Bail out based on state or if there is no listener for this event
2828 if (isolate_->debug()->InDebugger()) return; 2798 if (isolate_->debug()->InDebugger()) return;
2829 if (compiling_natives()) return; 2799 if (!EventActive()) return;
2830 if (!EventActive(v8::BeforeCompile)) return;
2831 2800
2832 // Enter the debugger. 2801 // Enter the debugger.
2833 EnterDebugger debugger(isolate_); 2802 EnterDebugger debugger(isolate_);
2834 if (debugger.FailedToEnter()) return; 2803 if (debugger.FailedToEnter()) return;
2835 2804
2836 // Create the event data object. 2805 // Create the event data object.
2837 Handle<Object> event_data; 2806 Handle<Object> event_data;
2838 // Bail out and don't call debugger if exception. 2807 // Bail out and don't call debugger if exception.
2839 if (!MakeCompileEvent(script, true).ToHandle(&event_data)) return; 2808 if (!MakeCompileEvent(script, true).ToHandle(&event_data)) return;
2840 2809
2841 // Process debug event. 2810 // Process debug event.
2842 ProcessDebugEvent(v8::BeforeCompile, 2811 ProcessDebugEvent(v8::BeforeCompile,
2843 Handle<JSObject>::cast(event_data), 2812 Handle<JSObject>::cast(event_data),
2844 true); 2813 true);
2845 } 2814 }
2846 2815
2847 2816
2848 // Handle debugger actions when a new script is compiled. 2817 // Handle debugger actions when a new script is compiled.
2849 void Debugger::OnAfterCompile(Handle<Script> script, 2818 void Debugger::OnAfterCompile(Handle<Script> script,
2850 AfterCompileFlags after_compile_flags) { 2819 AfterCompileFlags after_compile_flags) {
2851 HandleScope scope(isolate_); 2820 HandleScope scope(isolate_);
2852 Debug* debug = isolate_->debug(); 2821 Debug* debug = isolate_->debug();
2853 2822
2854 // Add the newly compiled script to the script cache. 2823 // Add the newly compiled script to the script cache.
2855 debug->AddScriptToScriptCache(script); 2824 debug->AddScriptToScriptCache(script);
2856 2825
2857 // No more to do if not debugging. 2826 // No more to do if not debugging.
2858 if (!IsDebuggerActive()) return; 2827 if (!Debugger::EventActive()) return;
2859
2860 // No compile events while compiling natives.
2861 if (compiling_natives()) return;
2862 2828
2863 // Store whether in debugger before entering debugger. 2829 // Store whether in debugger before entering debugger.
2864 bool in_debugger = debug->InDebugger(); 2830 bool in_debugger = debug->InDebugger();
2865 2831
2866 // Enter the debugger. 2832 // Enter the debugger.
2867 EnterDebugger debugger(isolate_); 2833 EnterDebugger debugger(isolate_);
2868 if (debugger.FailedToEnter()) return; 2834 if (debugger.FailedToEnter()) return;
2869 2835
2870 // If debugging there might be script break points registered for this 2836 // If debugging there might be script break points registered for this
2871 // script. Make sure that these break points are set. 2837 // script. Make sure that these break points are set.
(...skipping 18 matching lines...) Expand all
2890 // Call UpdateScriptBreakPoints expect no exceptions. 2856 // Call UpdateScriptBreakPoints expect no exceptions.
2891 Handle<Object> argv[] = { wrapper }; 2857 Handle<Object> argv[] = { wrapper };
2892 if (Execution::TryCall(Handle<JSFunction>::cast(update_script_break_points), 2858 if (Execution::TryCall(Handle<JSFunction>::cast(update_script_break_points),
2893 isolate_->js_builtins_object(), 2859 isolate_->js_builtins_object(),
2894 ARRAY_SIZE(argv), 2860 ARRAY_SIZE(argv),
2895 argv).is_null()) { 2861 argv).is_null()) {
2896 return; 2862 return;
2897 } 2863 }
2898 // Bail out based on state or if there is no listener for this event 2864 // Bail out based on state or if there is no listener for this event
2899 if (in_debugger && (after_compile_flags & SEND_WHEN_DEBUGGING) == 0) return; 2865 if (in_debugger && (after_compile_flags & SEND_WHEN_DEBUGGING) == 0) return;
2900 if (!Debugger::EventActive(v8::AfterCompile)) return;
2901 2866
2902 // Create the compile state object. 2867 // Create the compile state object.
2903 Handle<Object> event_data; 2868 Handle<Object> event_data;
2904 // Bail out and don't call debugger if exception. 2869 // Bail out and don't call debugger if exception.
2905 if (!MakeCompileEvent(script, false).ToHandle(&event_data)) return; 2870 if (!MakeCompileEvent(script, false).ToHandle(&event_data)) return;
2906 2871
2907 // Process debug event. 2872 // Process debug event.
2908 ProcessDebugEvent(v8::AfterCompile, Handle<JSObject>::cast(event_data), true); 2873 ProcessDebugEvent(v8::AfterCompile, Handle<JSObject>::cast(event_data), true);
2909 } 2874 }
2910 2875
2911 2876
2912 void Debugger::OnScriptCollected(int id) { 2877 void Debugger::OnScriptCollected(int id) {
2913 HandleScope scope(isolate_); 2878 HandleScope scope(isolate_);
2914 2879
2915 // No more to do if not debugging. 2880 // No more to do if not debugging.
2916 if (isolate_->debug()->InDebugger()) return; 2881 if (isolate_->debug()->InDebugger()) return;
2917 if (!IsDebuggerActive()) return; 2882 if (!Debugger::EventActive()) return;
2918 if (!Debugger::EventActive(v8::ScriptCollected)) return;
2919 2883
2920 // Enter the debugger. 2884 // Enter the debugger.
2921 EnterDebugger debugger(isolate_); 2885 EnterDebugger debugger(isolate_);
2922 if (debugger.FailedToEnter()) return; 2886 if (debugger.FailedToEnter()) return;
2923 2887
2924 // Create the script collected state object. 2888 // Create the script collected state object.
2925 Handle<Object> event_data; 2889 Handle<Object> event_data;
2926 // Bail out and don't call debugger if exception. 2890 // Bail out and don't call debugger if exception.
2927 if (!MakeScriptCollectedEvent(id).ToHandle(&event_data)) return; 2891 if (!MakeScriptCollectedEvent(id).ToHandle(&event_data)) return;
2928 2892
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
3122 3086
3123 // Process requests from the debugger. 3087 // Process requests from the debugger.
3124 do { 3088 do {
3125 // Wait for new command in the queue. 3089 // Wait for new command in the queue.
3126 command_received_.Wait(); 3090 command_received_.Wait();
3127 3091
3128 // Get the command from the queue. 3092 // Get the command from the queue.
3129 CommandMessage command = command_queue_.Get(); 3093 CommandMessage command = command_queue_.Get();
3130 isolate_->logger()->DebugTag( 3094 isolate_->logger()->DebugTag(
3131 "Got request from command queue, in interactive loop."); 3095 "Got request from command queue, in interactive loop.");
3132 if (!Debugger::IsDebuggerActive()) { 3096 if (!Debugger::is_active()) {
3133 // Delete command text and user data. 3097 // Delete command text and user data.
3134 command.Dispose(); 3098 command.Dispose();
3135 return; 3099 return;
3136 } 3100 }
3137 3101
3138 Vector<const uc16> command_text( 3102 Vector<const uc16> command_text(
3139 const_cast<const uc16*>(command.text().start()), 3103 const_cast<const uc16*>(command.text().start()),
3140 command.text().length()); 3104 command.text().length());
3141 Handle<String> request_text = isolate_->factory()->NewStringFromTwoByte( 3105 Handle<String> request_text = isolate_->factory()->NewStringFromTwoByte(
3142 command_text).ToHandleChecked(); 3106 command_text).ToHandleChecked();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
3210 } 3174 }
3211 event_listener_data_ = Handle<Object>::cast( 3175 event_listener_data_ = Handle<Object>::cast(
3212 global_handles->Create(*data)); 3176 global_handles->Create(*data));
3213 } 3177 }
3214 3178
3215 ListenersChanged(); 3179 ListenersChanged();
3216 } 3180 }
3217 3181
3218 3182
3219 void Debugger::SetMessageHandler(v8::Debug::MessageHandler2 handler) { 3183 void Debugger::SetMessageHandler(v8::Debug::MessageHandler2 handler) {
3220 LockGuard<RecursiveMutex> with(debugger_access_); 3184 LockGuard<RecursiveMutex> with(&debugger_access_);
3221 3185
3222 message_handler_ = handler; 3186 message_handler_ = handler;
3223 ListenersChanged(); 3187 ListenersChanged();
3224 if (handler == NULL) { 3188 if (handler == NULL) {
3225 // Send an empty command to the debugger if in a break to make JavaScript 3189 // Send an empty command to the debugger if in a break to make JavaScript
3226 // run again if the debugger is closed. 3190 // run again if the debugger is closed.
3227 if (isolate_->debug()->InDebugger()) { 3191 if (isolate_->debug()->InDebugger()) {
3228 ProcessCommand(Vector<const uint16_t>::empty()); 3192 ProcessCommand(Vector<const uint16_t>::empty());
3229 } 3193 }
3230 } 3194 }
3231 } 3195 }
3232 3196
3233 3197
3234 void Debugger::ListenersChanged() { 3198 void Debugger::ListenersChanged() {
3235 bool active = IsDebuggerActive(); 3199 LockGuard<RecursiveMutex> with(&debugger_access_);
3236 if (active) { 3200 is_active_ = message_handler_ != NULL || !event_listener_.is_null();
3201 if (is_active_) {
3237 // Disable the compilation cache when the debugger is active. 3202 // Disable the compilation cache when the debugger is active.
3238 isolate_->compilation_cache()->Disable(); 3203 isolate_->compilation_cache()->Disable();
3239 debugger_unload_pending_ = false; 3204 debugger_unload_pending_ = false;
3240 } else { 3205 } else {
3241 isolate_->compilation_cache()->Enable(); 3206 isolate_->compilation_cache()->Enable();
3242 // Unload the debugger if event listener and message handler cleared. 3207 // Unload the debugger if event listener and message handler cleared.
3243 // Schedule this for later, because we may be in non-V8 thread. 3208 // Schedule this for later, because we may be in non-V8 thread.
3244 debugger_unload_pending_ = true; 3209 debugger_unload_pending_ = true;
3245 } 3210 }
3246 } 3211 }
3247 3212
3248 3213
3249 void Debugger::SetDebugMessageDispatchHandler( 3214 void Debugger::SetDebugMessageDispatchHandler(
3250 v8::Debug::DebugMessageDispatchHandler handler, bool provide_locker) { 3215 v8::Debug::DebugMessageDispatchHandler handler, bool provide_locker) {
3251 LockGuard<Mutex> lock_guard(&dispatch_handler_access_); 3216 LockGuard<Mutex> lock_guard(&dispatch_handler_access_);
3252 debug_message_dispatch_handler_ = handler; 3217 debug_message_dispatch_handler_ = handler;
3253 3218
3254 if (provide_locker && message_dispatch_helper_thread_ == NULL) { 3219 if (provide_locker && message_dispatch_helper_thread_ == NULL) {
3255 message_dispatch_helper_thread_ = new MessageDispatchHelperThread(isolate_); 3220 message_dispatch_helper_thread_ = new MessageDispatchHelperThread(isolate_);
3256 message_dispatch_helper_thread_->Start(); 3221 message_dispatch_helper_thread_->Start();
3257 } 3222 }
3258 } 3223 }
3259 3224
3260 3225
3261 // Calls the registered debug message handler. This callback is part of the 3226 // Calls the registered debug message handler. This callback is part of the
3262 // public API. 3227 // public API.
3263 void Debugger::InvokeMessageHandler(MessageImpl message) { 3228 void Debugger::InvokeMessageHandler(MessageImpl message) {
3264 LockGuard<RecursiveMutex> with(debugger_access_); 3229 LockGuard<RecursiveMutex> with(&debugger_access_);
3265 3230
3266 if (message_handler_ != NULL) { 3231 if (message_handler_ != NULL) {
3267 message_handler_(message); 3232 message_handler_(message);
3268 } 3233 }
3269 } 3234 }
3270 3235
3271 3236
3272 // Puts a command coming from the public API on the queue. Creates 3237 // Puts a command coming from the public API on the queue. Creates
3273 // a copy of the command string managed by the debugger. Up to this 3238 // a copy of the command string managed by the debugger. Up to this
3274 // point, the command data was managed by the API client. Called 3239 // point, the command data was managed by the API client. Called
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3312 CommandMessage message = CommandMessage::New(Vector<uint16_t>(), client_data); 3277 CommandMessage message = CommandMessage::New(Vector<uint16_t>(), client_data);
3313 event_command_queue_.Put(message); 3278 event_command_queue_.Put(message);
3314 3279
3315 // Set the debug command break flag to have the command processed. 3280 // Set the debug command break flag to have the command processed.
3316 if (!isolate_->debug()->InDebugger()) { 3281 if (!isolate_->debug()->InDebugger()) {
3317 isolate_->stack_guard()->RequestDebugCommand(); 3282 isolate_->stack_guard()->RequestDebugCommand();
3318 } 3283 }
3319 } 3284 }
3320 3285
3321 3286
3322 bool Debugger::IsDebuggerActive() {
3323 LockGuard<RecursiveMutex> with(debugger_access_);
3324
3325 return message_handler_ != NULL ||
3326 !event_listener_.is_null() ||
3327 force_debugger_active_;
3328 }
3329
3330
3331 MaybeHandle<Object> Debugger::Call(Handle<JSFunction> fun, 3287 MaybeHandle<Object> Debugger::Call(Handle<JSFunction> fun,
3332 Handle<Object> data) { 3288 Handle<Object> data) {
3333 // When calling functions in the debugger prevent it from beeing unloaded. 3289 // When calling functions in the debugger prevent it from beeing unloaded.
3334 Debugger::never_unload_debugger_ = true; 3290 Debugger::never_unload_debugger_ = true;
3335 3291
3336 // Enter the debugger. 3292 // Enter the debugger.
3337 EnterDebugger debugger(isolate_); 3293 EnterDebugger debugger(isolate_);
3338 if (debugger.FailedToEnter()) { 3294 if (debugger.FailedToEnter()) {
3339 return isolate_->factory()->undefined_value(); 3295 return isolate_->factory()->undefined_value();
3340 } 3296 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
3471 isolate_->stack_guard()->RequestDebugBreak(); 3427 isolate_->stack_guard()->RequestDebugBreak();
3472 } 3428 }
3473 3429
3474 // If there are commands in the queue when leaving the debugger request 3430 // If there are commands in the queue when leaving the debugger request
3475 // that these commands are processed. 3431 // that these commands are processed.
3476 if (isolate_->debugger()->HasCommands()) { 3432 if (isolate_->debugger()->HasCommands()) {
3477 isolate_->stack_guard()->RequestDebugCommand(); 3433 isolate_->stack_guard()->RequestDebugCommand();
3478 } 3434 }
3479 3435
3480 // If leaving the debugger with the debugger no longer active unload it. 3436 // If leaving the debugger with the debugger no longer active unload it.
3481 if (!isolate_->debugger()->IsDebuggerActive()) { 3437 if (!isolate_->debugger()->is_active()) {
3482 isolate_->debugger()->UnloadDebugger(); 3438 isolate_->debugger()->UnloadDebugger();
3483 } 3439 }
3484 } 3440 }
3485 3441
3486 // Leaving this debugger entry. 3442 // Leaving this debugger entry.
3487 debug->set_debugger_entry(prev_); 3443 debug->set_debugger_entry(prev_);
3488 } 3444 }
3489 3445
3490 3446
3491 MessageImpl MessageImpl::NewEvent(DebugEvent event, 3447 MessageImpl MessageImpl::NewEvent(DebugEvent event,
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
3775 already_signalled_ = false; 3731 already_signalled_ = false;
3776 } 3732 }
3777 { 3733 {
3778 Locker locker(reinterpret_cast<v8::Isolate*>(isolate_)); 3734 Locker locker(reinterpret_cast<v8::Isolate*>(isolate_));
3779 isolate_->debugger()->CallMessageDispatchHandler(); 3735 isolate_->debugger()->CallMessageDispatchHandler();
3780 } 3736 }
3781 } 3737 }
3782 } 3738 }
3783 3739
3784 } } // namespace v8::internal 3740 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/debug.h ('k') | src/execution.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698