| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 DISALLOW_COPY_AND_ASSIGN(Debugger); | 862 DISALLOW_COPY_AND_ASSIGN(Debugger); |
| 863 }; | 863 }; |
| 864 | 864 |
| 865 | 865 |
| 866 // This class is used for entering the debugger. Create an instance in the stack | 866 // This class is used for entering the debugger. Create an instance in the stack |
| 867 // to enter the debugger. This will set the current break state, make sure the | 867 // to enter the debugger. This will set the current break state, make sure the |
| 868 // debugger is loaded and switch to the debugger context. If the debugger for | 868 // debugger is loaded and switch to the debugger context. If the debugger for |
| 869 // some reason could not be entered FailedToEnter will return true. | 869 // some reason could not be entered FailedToEnter will return true. |
| 870 class EnterDebugger BASE_EMBEDDED { | 870 class EnterDebugger BASE_EMBEDDED { |
| 871 public: | 871 public: |
| 872 EnterDebugger() | 872 EnterDebugger(); |
| 873 : isolate_(Isolate::Current()), | 873 ~EnterDebugger(); |
| 874 prev_(isolate_->debug()->debugger_entry()), | |
| 875 it_(isolate_), | |
| 876 has_js_frames_(!it_.done()), | |
| 877 save_(isolate_) { | |
| 878 Debug* debug = isolate_->debug(); | |
| 879 ASSERT(prev_ != NULL || !debug->is_interrupt_pending(PREEMPT)); | |
| 880 ASSERT(prev_ != NULL || !debug->is_interrupt_pending(DEBUGBREAK)); | |
| 881 | |
| 882 // Link recursive debugger entry. | |
| 883 debug->set_debugger_entry(this); | |
| 884 | |
| 885 // Store the previous break id and frame id. | |
| 886 break_id_ = debug->break_id(); | |
| 887 break_frame_id_ = debug->break_frame_id(); | |
| 888 | |
| 889 // Create the new break info. If there is no JavaScript frames there is no | |
| 890 // break frame id. | |
| 891 if (has_js_frames_) { | |
| 892 debug->NewBreak(it_.frame()->id()); | |
| 893 } else { | |
| 894 debug->NewBreak(StackFrame::NO_ID); | |
| 895 } | |
| 896 | |
| 897 // Make sure that debugger is loaded and enter the debugger context. | |
| 898 load_failed_ = !debug->Load(); | |
| 899 if (!load_failed_) { | |
| 900 // NOTE the member variable save which saves the previous context before | |
| 901 // this change. | |
| 902 isolate_->set_context(*debug->debug_context()); | |
| 903 } | |
| 904 } | |
| 905 | |
| 906 ~EnterDebugger() { | |
| 907 ASSERT(Isolate::Current() == isolate_); | |
| 908 Debug* debug = isolate_->debug(); | |
| 909 | |
| 910 // Restore to the previous break state. | |
| 911 debug->SetBreak(break_frame_id_, break_id_); | |
| 912 | |
| 913 // Check for leaving the debugger. | |
| 914 if (prev_ == NULL) { | |
| 915 // Clear mirror cache when leaving the debugger. Skip this if there is a | |
| 916 // pending exception as clearing the mirror cache calls back into | |
| 917 // JavaScript. This can happen if the v8::Debug::Call is used in which | |
| 918 // case the exception should end up in the calling code. | |
| 919 if (!isolate_->has_pending_exception()) { | |
| 920 // Try to avoid any pending debug break breaking in the clear mirror | |
| 921 // cache JavaScript code. | |
| 922 if (isolate_->stack_guard()->IsDebugBreak()) { | |
| 923 debug->set_interrupts_pending(DEBUGBREAK); | |
| 924 isolate_->stack_guard()->Continue(DEBUGBREAK); | |
| 925 } | |
| 926 debug->ClearMirrorCache(); | |
| 927 } | |
| 928 | |
| 929 // Request preemption and debug break when leaving the last debugger entry | |
| 930 // if any of these where recorded while debugging. | |
| 931 if (debug->is_interrupt_pending(PREEMPT)) { | |
| 932 // This re-scheduling of preemption is to avoid starvation in some | |
| 933 // debugging scenarios. | |
| 934 debug->clear_interrupt_pending(PREEMPT); | |
| 935 isolate_->stack_guard()->Preempt(); | |
| 936 } | |
| 937 if (debug->is_interrupt_pending(DEBUGBREAK)) { | |
| 938 debug->clear_interrupt_pending(DEBUGBREAK); | |
| 939 isolate_->stack_guard()->DebugBreak(); | |
| 940 } | |
| 941 | |
| 942 // If there are commands in the queue when leaving the debugger request | |
| 943 // that these commands are processed. | |
| 944 if (isolate_->debugger()->HasCommands()) { | |
| 945 isolate_->stack_guard()->DebugCommand(); | |
| 946 } | |
| 947 | |
| 948 // If leaving the debugger with the debugger no longer active unload it. | |
| 949 if (!isolate_->debugger()->IsDebuggerActive()) { | |
| 950 isolate_->debugger()->UnloadDebugger(); | |
| 951 } | |
| 952 } | |
| 953 | |
| 954 // Leaving this debugger entry. | |
| 955 debug->set_debugger_entry(prev_); | |
| 956 } | |
| 957 | 874 |
| 958 // Check whether the debugger could be entered. | 875 // Check whether the debugger could be entered. |
| 959 inline bool FailedToEnter() { return load_failed_; } | 876 inline bool FailedToEnter() { return load_failed_; } |
| 960 | 877 |
| 961 // Check whether there are any JavaScript frames on the stack. | 878 // Check whether there are any JavaScript frames on the stack. |
| 962 inline bool HasJavaScriptFrames() { return has_js_frames_; } | 879 inline bool HasJavaScriptFrames() { return has_js_frames_; } |
| 963 | 880 |
| 964 // Get the active context from before entering the debugger. | 881 // Get the active context from before entering the debugger. |
| 965 inline Handle<Context> GetContext() { return save_.context(); } | 882 inline Handle<Context> GetContext() { return save_.context(); } |
| 966 | 883 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1056 | 973 |
| 1057 DISALLOW_COPY_AND_ASSIGN(MessageDispatchHelperThread); | 974 DISALLOW_COPY_AND_ASSIGN(MessageDispatchHelperThread); |
| 1058 }; | 975 }; |
| 1059 | 976 |
| 1060 | 977 |
| 1061 } } // namespace v8::internal | 978 } } // namespace v8::internal |
| 1062 | 979 |
| 1063 #endif // ENABLE_DEBUGGER_SUPPORT | 980 #endif // ENABLE_DEBUGGER_SUPPORT |
| 1064 | 981 |
| 1065 #endif // V8_DEBUG_H_ | 982 #endif // V8_DEBUG_H_ |
| OLD | NEW |