ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 28 | #ifndef V8_DEBUG_H_ |
| 29 | #define V8_DEBUG_H_ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 30 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 31 | #include "assembler.h" |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 32 | #include "debug-agent.h" |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 33 | #include "execution.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 34 | #include "factory.h" |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame^] | 35 | #include "flags.h" |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 36 | #include "hashmap.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 37 | #include "platform.h" |
| 38 | #include "string-stream.h" |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 39 | #include "v8threads.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 40 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 41 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 42 | #include "../include/v8-debug.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 43 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 44 | namespace v8 { |
| 45 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 46 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 47 | |
| 48 | // Forward declarations. |
| 49 | class EnterDebugger; |
| 50 | |
| 51 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 52 | // Step actions. NOTE: These values are in macros.py as well. |
| 53 | enum StepAction { |
| 54 | StepNone = -1, // Stepping not prepared. |
| 55 | StepOut = 0, // Step out of the current function. |
| 56 | StepNext = 1, // Step to the next statement in the current function. |
| 57 | StepIn = 2, // Step into new functions invoked or the next statement |
| 58 | // in the current function. |
| 59 | StepMin = 3, // Perform a minimum step in the current function. |
| 60 | StepInMin = 4 // Step into new functions invoked or perform a minimum step |
| 61 | // in the current function. |
| 62 | }; |
| 63 | |
| 64 | |
| 65 | // Type of exception break. NOTE: These values are in macros.py as well. |
| 66 | enum ExceptionBreakType { |
| 67 | BreakException = 0, |
| 68 | BreakUncaughtException = 1 |
| 69 | }; |
| 70 | |
| 71 | |
| 72 | // Type of exception break. NOTE: These values are in macros.py as well. |
| 73 | enum BreakLocatorType { |
| 74 | ALL_BREAK_LOCATIONS = 0, |
| 75 | SOURCE_BREAK_LOCATIONS = 1 |
| 76 | }; |
| 77 | |
| 78 | |
| 79 | // Class for iterating through the break points in a function and changing |
| 80 | // them. |
| 81 | class BreakLocationIterator { |
| 82 | public: |
| 83 | explicit BreakLocationIterator(Handle<DebugInfo> debug_info, |
| 84 | BreakLocatorType type); |
| 85 | virtual ~BreakLocationIterator(); |
| 86 | |
| 87 | void Next(); |
| 88 | void Next(int count); |
| 89 | void FindBreakLocationFromAddress(Address pc); |
| 90 | void FindBreakLocationFromPosition(int position); |
| 91 | void Reset(); |
| 92 | bool Done() const; |
| 93 | void SetBreakPoint(Handle<Object> break_point_object); |
| 94 | void ClearBreakPoint(Handle<Object> break_point_object); |
| 95 | void SetOneShot(); |
| 96 | void ClearOneShot(); |
| 97 | void PrepareStepIn(); |
| 98 | bool IsExit() const; |
| 99 | bool HasBreakPoint(); |
| 100 | bool IsDebugBreak(); |
| 101 | Object* BreakPointObjects(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 102 | void ClearAllDebugBreak(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 103 | |
| 104 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 105 | inline int code_position() { |
| 106 | return static_cast<int>(pc() - debug_info_->code()->entry()); |
| 107 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 108 | inline int break_point() { return break_point_; } |
| 109 | inline int position() { return position_; } |
| 110 | inline int statement_position() { return statement_position_; } |
| 111 | inline Address pc() { return reloc_iterator_->rinfo()->pc(); } |
| 112 | inline Code* code() { return debug_info_->code(); } |
| 113 | inline RelocInfo* rinfo() { return reloc_iterator_->rinfo(); } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 114 | inline RelocInfo::Mode rmode() const { |
| 115 | return reloc_iterator_->rinfo()->rmode(); |
| 116 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 117 | inline RelocInfo* original_rinfo() { |
| 118 | return reloc_iterator_original_->rinfo(); |
| 119 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 120 | inline RelocInfo::Mode original_rmode() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 121 | return reloc_iterator_original_->rinfo()->rmode(); |
| 122 | } |
| 123 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 124 | bool IsDebuggerStatement(); |
| 125 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 126 | protected: |
| 127 | bool RinfoDone() const; |
| 128 | void RinfoNext(); |
| 129 | |
| 130 | BreakLocatorType type_; |
| 131 | int break_point_; |
| 132 | int position_; |
| 133 | int statement_position_; |
| 134 | Handle<DebugInfo> debug_info_; |
| 135 | RelocIterator* reloc_iterator_; |
| 136 | RelocIterator* reloc_iterator_original_; |
| 137 | |
| 138 | private: |
| 139 | void SetDebugBreak(); |
| 140 | void ClearDebugBreak(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 141 | |
| 142 | void SetDebugBreakAtIC(); |
| 143 | void ClearDebugBreakAtIC(); |
| 144 | |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 145 | bool IsDebugBreakAtReturn(); |
| 146 | void SetDebugBreakAtReturn(); |
| 147 | void ClearDebugBreakAtReturn(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 148 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 149 | bool IsDebugBreakSlot(); |
| 150 | bool IsDebugBreakAtSlot(); |
| 151 | void SetDebugBreakAtSlot(); |
| 152 | void ClearDebugBreakAtSlot(); |
| 153 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 154 | DISALLOW_COPY_AND_ASSIGN(BreakLocationIterator); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 158 | // Cache of all script objects in the heap. When a script is added a weak handle |
| 159 | // to it is created and that weak handle is stored in the cache. The weak handle |
| 160 | // callback takes care of removing the script from the cache. The key used in |
| 161 | // the cache is the script id. |
| 162 | class ScriptCache : private HashMap { |
| 163 | public: |
| 164 | ScriptCache() : HashMap(ScriptMatch), collected_scripts_(10) {} |
| 165 | virtual ~ScriptCache() { Clear(); } |
| 166 | |
| 167 | // Add script to the cache. |
| 168 | void Add(Handle<Script> script); |
| 169 | |
| 170 | // Return the scripts in the cache. |
| 171 | Handle<FixedArray> GetScripts(); |
| 172 | |
| 173 | // Generate debugger events for collected scripts. |
| 174 | void ProcessCollectedScripts(); |
| 175 | |
| 176 | private: |
| 177 | // Calculate the hash value from the key (script id). |
| 178 | static uint32_t Hash(int key) { return ComputeIntegerHash(key); } |
| 179 | |
| 180 | // Scripts match if their keys (script id) match. |
| 181 | static bool ScriptMatch(void* key1, void* key2) { return key1 == key2; } |
| 182 | |
| 183 | // Clear the cache releasing all the weak handles. |
| 184 | void Clear(); |
| 185 | |
| 186 | // Weak handle callback for scripts in the cache. |
| 187 | static void HandleWeakScript(v8::Persistent<v8::Value> obj, void* data); |
| 188 | |
| 189 | // List used during GC to temporarily store id's of collected scripts. |
| 190 | List<int> collected_scripts_; |
| 191 | }; |
| 192 | |
| 193 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 194 | // Linked list holding debug info objects. The debug info objects are kept as |
| 195 | // weak handles to avoid a debug info object to keep a function alive. |
| 196 | class DebugInfoListNode { |
| 197 | public: |
| 198 | explicit DebugInfoListNode(DebugInfo* debug_info); |
| 199 | virtual ~DebugInfoListNode(); |
| 200 | |
| 201 | DebugInfoListNode* next() { return next_; } |
| 202 | void set_next(DebugInfoListNode* next) { next_ = next; } |
| 203 | Handle<DebugInfo> debug_info() { return debug_info_; } |
| 204 | |
| 205 | private: |
| 206 | // Global (weak) handle to the debug info object. |
| 207 | Handle<DebugInfo> debug_info_; |
| 208 | |
| 209 | // Next pointer for linked list. |
| 210 | DebugInfoListNode* next_; |
| 211 | }; |
| 212 | |
| 213 | |
| 214 | // This class contains the debugger support. The main purpose is to handle |
| 215 | // setting break points in the code. |
| 216 | // |
| 217 | // This class controls the debug info for all functions which currently have |
| 218 | // active breakpoints in them. This debug info is held in the heap root object |
| 219 | // debug_info which is a FixedArray. Each entry in this list is of class |
| 220 | // DebugInfo. |
| 221 | class Debug { |
| 222 | public: |
| 223 | static void Setup(bool create_heap_objects); |
| 224 | static bool Load(); |
| 225 | static void Unload(); |
| 226 | static bool IsLoaded() { return !debug_context_.is_null(); } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 227 | static bool InDebugger() { return thread_local_.debugger_entry_ != NULL; } |
| 228 | static void PreemptionWhileInDebugger(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 229 | static void Iterate(ObjectVisitor* v); |
| 230 | |
| 231 | static Object* Break(Arguments args); |
| 232 | static void SetBreakPoint(Handle<SharedFunctionInfo> shared, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 233 | Handle<Object> break_point_object, |
| 234 | int* source_position); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 235 | static void ClearBreakPoint(Handle<Object> break_point_object); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 236 | static void ClearAllBreakPoints(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 237 | static void FloodWithOneShot(Handle<SharedFunctionInfo> shared); |
| 238 | static void FloodHandlerWithOneShot(); |
| 239 | static void ChangeBreakOnException(ExceptionBreakType type, bool enable); |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 240 | static bool IsBreakOnException(ExceptionBreakType type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 241 | static void PrepareStep(StepAction step_action, int step_count); |
| 242 | static void ClearStepping(); |
| 243 | static bool StepNextContinue(BreakLocationIterator* break_location_iterator, |
| 244 | JavaScriptFrame* frame); |
| 245 | static Handle<DebugInfo> GetDebugInfo(Handle<SharedFunctionInfo> shared); |
| 246 | static bool HasDebugInfo(Handle<SharedFunctionInfo> shared); |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 247 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 248 | // Returns whether the operation succeeded. |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 249 | static bool EnsureDebugInfo(Handle<SharedFunctionInfo> shared); |
| 250 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 251 | // Returns true if the current stub call is patched to call the debugger. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 252 | static bool IsDebugBreak(Address addr); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 253 | // Returns true if the current return statement has been patched to be |
| 254 | // a debugger breakpoint. |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 255 | static bool IsDebugBreakAtReturn(RelocInfo* rinfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 256 | |
| 257 | // Check whether a code stub with the specified major key is a possible break |
| 258 | // point location. |
| 259 | static bool IsSourceBreakStub(Code* code); |
| 260 | static bool IsBreakStub(Code* code); |
| 261 | |
| 262 | // Find the builtin to use for invoking the debug break |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 263 | static Handle<Code> FindDebugBreak(Handle<Code> code, RelocInfo::Mode mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 264 | |
| 265 | static Handle<Object> GetSourceBreakLocations( |
| 266 | Handle<SharedFunctionInfo> shared); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 267 | |
| 268 | // Getter for the debug_context. |
| 269 | inline static Handle<Context> debug_context() { return debug_context_; } |
| 270 | |
| 271 | // Check whether a global object is the debug global object. |
| 272 | static bool IsDebugGlobal(GlobalObject* global); |
| 273 | |
ager@chromium.org | 2cc82ae | 2010-06-14 07:35:38 +0000 | [diff] [blame] | 274 | // Check whether this frame is just about to return. |
| 275 | static bool IsBreakAtReturn(JavaScriptFrame* frame); |
| 276 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 277 | // Fast check to see if any break points are active. |
| 278 | inline static bool has_break_points() { return has_break_points_; } |
| 279 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 280 | static void NewBreak(StackFrame::Id break_frame_id); |
| 281 | static void SetBreak(StackFrame::Id break_frame_id, int break_id); |
| 282 | static StackFrame::Id break_frame_id() { |
| 283 | return thread_local_.break_frame_id_; |
| 284 | } |
| 285 | static int break_id() { return thread_local_.break_id_; } |
| 286 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 287 | static bool StepInActive() { return thread_local_.step_into_fp_ != 0; } |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 288 | static void HandleStepIn(Handle<JSFunction> function, |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 289 | Handle<Object> holder, |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 290 | Address fp, |
| 291 | bool is_constructor); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 292 | static Address step_in_fp() { return thread_local_.step_into_fp_; } |
| 293 | static Address* step_in_fp_addr() { return &thread_local_.step_into_fp_; } |
| 294 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 295 | static bool StepOutActive() { return thread_local_.step_out_fp_ != 0; } |
| 296 | static Address step_out_fp() { return thread_local_.step_out_fp_; } |
| 297 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 298 | static EnterDebugger* debugger_entry() { |
| 299 | return thread_local_.debugger_entry_; |
| 300 | } |
| 301 | static void set_debugger_entry(EnterDebugger* entry) { |
| 302 | thread_local_.debugger_entry_ = entry; |
| 303 | } |
| 304 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 305 | // Check whether any of the specified interrupts are pending. |
| 306 | static bool is_interrupt_pending(InterruptFlag what) { |
| 307 | return (thread_local_.pending_interrupts_ & what) != 0; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 308 | } |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 309 | |
| 310 | // Set specified interrupts as pending. |
| 311 | static void set_interrupts_pending(InterruptFlag what) { |
| 312 | thread_local_.pending_interrupts_ |= what; |
| 313 | } |
| 314 | |
| 315 | // Clear specified interrupts from pending. |
| 316 | static void clear_interrupt_pending(InterruptFlag what) { |
| 317 | thread_local_.pending_interrupts_ &= ~static_cast<int>(what); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 318 | } |
| 319 | |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 320 | // Getter and setter for the disable break state. |
| 321 | static bool disable_break() { return disable_break_; } |
| 322 | static void set_disable_break(bool disable_break) { |
| 323 | disable_break_ = disable_break; |
| 324 | } |
| 325 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 326 | // Getters for the current exception break state. |
| 327 | static bool break_on_exception() { return break_on_exception_; } |
| 328 | static bool break_on_uncaught_exception() { |
| 329 | return break_on_uncaught_exception_; |
| 330 | } |
| 331 | |
| 332 | enum AddressId { |
| 333 | k_after_break_target_address, |
| 334 | k_debug_break_return_address, |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 335 | k_debug_break_slot_address, |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 336 | k_restarter_frame_function_pointer |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 337 | }; |
| 338 | |
| 339 | // Support for setting the address to jump to when returning from break point. |
| 340 | static Address* after_break_target_address() { |
| 341 | return reinterpret_cast<Address*>(&thread_local_.after_break_target_); |
| 342 | } |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 343 | static Address* restarter_frame_function_pointer_address() { |
| 344 | Object*** address = &thread_local_.restarter_frame_function_pointer_; |
| 345 | return reinterpret_cast<Address*>(address); |
| 346 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 347 | |
| 348 | // Support for saving/restoring registers when handling debug break calls. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 349 | static Object** register_address(int r) { |
| 350 | return ®isters_[r]; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 351 | } |
| 352 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 353 | // Access to the debug break on return code. |
| 354 | static Code* debug_break_return() { return debug_break_return_; } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 355 | static Code** debug_break_return_address() { |
| 356 | return &debug_break_return_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 357 | } |
| 358 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 359 | // Access to the debug break in debug break slot code. |
| 360 | static Code* debug_break_slot() { return debug_break_slot_; } |
| 361 | static Code** debug_break_slot_address() { |
| 362 | return &debug_break_slot_; |
| 363 | } |
| 364 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 365 | static const int kEstimatedNofDebugInfoEntries = 16; |
| 366 | static const int kEstimatedNofBreakPointsInFunction = 16; |
| 367 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 368 | static void HandleWeakDebugInfo(v8::Persistent<v8::Value> obj, void* data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 369 | |
| 370 | friend class Debugger; |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 371 | friend Handle<FixedArray> GetDebuggedFunctions(); // In test-debug.cc |
| 372 | friend void CheckDebuggerUnloaded(bool check_functions); // In test-debug.cc |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 373 | |
| 374 | // Threading support. |
| 375 | static char* ArchiveDebug(char* to); |
| 376 | static char* RestoreDebug(char* from); |
| 377 | static int ArchiveSpacePerThread(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 378 | static void FreeThreadResources() { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 379 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 380 | // Mirror cache handling. |
| 381 | static void ClearMirrorCache(); |
| 382 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 383 | // Script cache handling. |
| 384 | static void CreateScriptCache(); |
| 385 | static void DestroyScriptCache(); |
| 386 | static void AddScriptToScriptCache(Handle<Script> script); |
| 387 | static Handle<FixedArray> GetLoadedScripts(); |
| 388 | |
| 389 | // Garbage collection notifications. |
| 390 | static void AfterGarbageCollection(); |
| 391 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 392 | // Code generator routines. |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 393 | static void GenerateSlot(MacroAssembler* masm); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 394 | static void GenerateLoadICDebugBreak(MacroAssembler* masm); |
| 395 | static void GenerateStoreICDebugBreak(MacroAssembler* masm); |
| 396 | static void GenerateKeyedLoadICDebugBreak(MacroAssembler* masm); |
| 397 | static void GenerateKeyedStoreICDebugBreak(MacroAssembler* masm); |
| 398 | static void GenerateConstructCallDebugBreak(MacroAssembler* masm); |
| 399 | static void GenerateReturnDebugBreak(MacroAssembler* masm); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 400 | static void GenerateStubNoRegistersDebugBreak(MacroAssembler* masm); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 401 | static void GenerateSlotDebugBreak(MacroAssembler* masm); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 402 | static void GeneratePlainReturnLiveEdit(MacroAssembler* masm); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 403 | |
| 404 | // FrameDropper is a code replacement for a JavaScript frame with possibly |
| 405 | // several frames above. |
| 406 | // There is no calling conventions here, because it never actually gets |
| 407 | // called, it only gets returned to. |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 408 | static void GenerateFrameDropperLiveEdit(MacroAssembler* masm); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 409 | |
| 410 | // Called from stub-cache.cc. |
| 411 | static void GenerateCallICDebugBreak(MacroAssembler* masm); |
| 412 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 413 | // Describes how exactly a frame has been dropped from stack. |
| 414 | enum FrameDropMode { |
| 415 | // No frame has been dropped. |
| 416 | FRAMES_UNTOUCHED, |
| 417 | // The top JS frame had been calling IC stub. IC stub mustn't be called now. |
| 418 | FRAME_DROPPED_IN_IC_CALL, |
| 419 | // The top JS frame had been calling debug break slot stub. Patch the |
| 420 | // address this stub jumps to in the end. |
| 421 | FRAME_DROPPED_IN_DEBUG_SLOT_CALL, |
| 422 | // The top JS frame had been calling some C++ function. The return address |
| 423 | // gets patched automatically. |
| 424 | FRAME_DROPPED_IN_DIRECT_CALL |
| 425 | }; |
| 426 | |
| 427 | static void FramesHaveBeenDropped(StackFrame::Id new_break_frame_id, |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 428 | FrameDropMode mode, |
| 429 | Object** restarter_frame_function_pointer); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 430 | |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 431 | // Initializes an artificial stack frame. The data it contains is used for: |
| 432 | // a. successful work of frame dropper code which eventually gets control, |
| 433 | // b. being compatible with regular stack structure for various stack |
| 434 | // iterators. |
| 435 | // Returns address of stack allocated pointer to restarted function, |
| 436 | // the value that is called 'restarter_frame_function_pointer'. The value |
| 437 | // at this address (possibly updated by GC) may be used later when preparing |
| 438 | // 'step in' operation. |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 439 | static Object** SetUpFrameDropperFrame(StackFrame* bottom_js_frame, |
| 440 | Handle<Code> code); |
| 441 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 442 | static const int kFrameDropperFrameSize; |
| 443 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 444 | // Architecture-specific constant. |
| 445 | static const bool kFrameDropperSupported; |
| 446 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 447 | private: |
| 448 | static bool CompileDebuggerScript(int index); |
| 449 | static void ClearOneShot(); |
| 450 | static void ActivateStepIn(StackFrame* frame); |
| 451 | static void ClearStepIn(); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 452 | static void ActivateStepOut(StackFrame* frame); |
| 453 | static void ClearStepOut(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 454 | static void ClearStepNext(); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 455 | // Returns whether the compile succeeded. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 456 | static void RemoveDebugInfo(Handle<DebugInfo> debug_info); |
| 457 | static void SetAfterBreakTarget(JavaScriptFrame* frame); |
| 458 | static Handle<Object> CheckBreakPoints(Handle<Object> break_point); |
| 459 | static bool CheckBreakPoint(Handle<Object> break_point_object); |
| 460 | |
| 461 | // Global handle to debug context where all the debugger JavaScript code is |
| 462 | // loaded. |
| 463 | static Handle<Context> debug_context_; |
| 464 | |
| 465 | // Boolean state indicating whether any break points are set. |
| 466 | static bool has_break_points_; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 467 | |
| 468 | // Cache of all scripts in the heap. |
| 469 | static ScriptCache* script_cache_; |
| 470 | |
| 471 | // List of active debug info objects. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 472 | static DebugInfoListNode* debug_info_list_; |
| 473 | |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 474 | static bool disable_break_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 475 | static bool break_on_exception_; |
| 476 | static bool break_on_uncaught_exception_; |
| 477 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 478 | // Per-thread data. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 479 | class ThreadLocal { |
| 480 | public: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 481 | // Counter for generating next break id. |
| 482 | int break_count_; |
| 483 | |
| 484 | // Current break id. |
| 485 | int break_id_; |
| 486 | |
| 487 | // Frame id for the frame of the current break. |
| 488 | StackFrame::Id break_frame_id_; |
| 489 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 490 | // Step action for last step performed. |
| 491 | StepAction last_step_action_; |
| 492 | |
| 493 | // Source statement position from last step next action. |
| 494 | int last_statement_position_; |
| 495 | |
| 496 | // Number of steps left to perform before debug event. |
| 497 | int step_count_; |
| 498 | |
| 499 | // Frame pointer from last step next action. |
| 500 | Address last_fp_; |
| 501 | |
| 502 | // Frame pointer for frame from which step in was performed. |
| 503 | Address step_into_fp_; |
| 504 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 505 | // Frame pointer for the frame where debugger should be called when current |
| 506 | // step out action is completed. |
| 507 | Address step_out_fp_; |
| 508 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 509 | // Storage location for jump when exiting debug break calls. |
| 510 | Address after_break_target_; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 511 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 512 | // Stores the way how LiveEdit has patched the stack. It is used when |
| 513 | // debugger returns control back to user script. |
| 514 | FrameDropMode frame_drop_mode_; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 515 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 516 | // Top debugger entry. |
| 517 | EnterDebugger* debugger_entry_; |
| 518 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 519 | // Pending interrupts scheduled while debugging. |
| 520 | int pending_interrupts_; |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 521 | |
| 522 | // When restarter frame is on stack, stores the address |
| 523 | // of the pointer to function being restarted. Otherwise (most of the time) |
| 524 | // stores NULL. This pointer is used with 'step in' implementation. |
| 525 | Object** restarter_frame_function_pointer_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 526 | }; |
| 527 | |
| 528 | // Storage location for registers when handling debug break calls |
| 529 | static JSCallerSavedBuffer registers_; |
| 530 | static ThreadLocal thread_local_; |
| 531 | static void ThreadInit(); |
| 532 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 533 | // Code to call for handling debug break on return. |
| 534 | static Code* debug_break_return_; |
| 535 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 536 | // Code to call for handling debug break in debug break slots. |
| 537 | static Code* debug_break_slot_; |
| 538 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 539 | DISALLOW_COPY_AND_ASSIGN(Debug); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 540 | }; |
| 541 | |
| 542 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 543 | // Message delivered to the message handler callback. This is either a debugger |
| 544 | // event or the response to a command. |
| 545 | class MessageImpl: public v8::Debug::Message { |
| 546 | public: |
| 547 | // Create a message object for a debug event. |
| 548 | static MessageImpl NewEvent(DebugEvent event, |
| 549 | bool running, |
| 550 | Handle<JSObject> exec_state, |
| 551 | Handle<JSObject> event_data); |
| 552 | |
| 553 | // Create a message object for the response to a debug command. |
| 554 | static MessageImpl NewResponse(DebugEvent event, |
| 555 | bool running, |
| 556 | Handle<JSObject> exec_state, |
| 557 | Handle<JSObject> event_data, |
| 558 | Handle<String> response_json, |
| 559 | v8::Debug::ClientData* client_data); |
| 560 | |
| 561 | // Implementation of interface v8::Debug::Message. |
| 562 | virtual bool IsEvent() const; |
| 563 | virtual bool IsResponse() const; |
| 564 | virtual DebugEvent GetEvent() const; |
| 565 | virtual bool WillStartRunning() const; |
| 566 | virtual v8::Handle<v8::Object> GetExecutionState() const; |
| 567 | virtual v8::Handle<v8::Object> GetEventData() const; |
| 568 | virtual v8::Handle<v8::String> GetJSON() const; |
| 569 | virtual v8::Handle<v8::Context> GetEventContext() const; |
| 570 | virtual v8::Debug::ClientData* GetClientData() const; |
| 571 | |
| 572 | private: |
| 573 | MessageImpl(bool is_event, |
| 574 | DebugEvent event, |
| 575 | bool running, |
| 576 | Handle<JSObject> exec_state, |
| 577 | Handle<JSObject> event_data, |
| 578 | Handle<String> response_json, |
| 579 | v8::Debug::ClientData* client_data); |
| 580 | |
| 581 | bool is_event_; // Does this message represent a debug event? |
| 582 | DebugEvent event_; // Debug event causing the break. |
| 583 | bool running_; // Will the VM start running after this event? |
| 584 | Handle<JSObject> exec_state_; // Current execution state. |
| 585 | Handle<JSObject> event_data_; // Data associated with the event. |
| 586 | Handle<String> response_json_; // Response JSON if message holds a response. |
| 587 | v8::Debug::ClientData* client_data_; // Client data passed with the request. |
| 588 | }; |
| 589 | |
| 590 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 591 | // Details of the debug event delivered to the debug event listener. |
| 592 | class EventDetailsImpl : public v8::Debug::EventDetails { |
| 593 | public: |
| 594 | EventDetailsImpl(DebugEvent event, |
| 595 | Handle<JSObject> exec_state, |
| 596 | Handle<JSObject> event_data, |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 597 | Handle<Object> callback_data, |
| 598 | v8::Debug::ClientData* client_data); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 599 | virtual DebugEvent GetEvent() const; |
| 600 | virtual v8::Handle<v8::Object> GetExecutionState() const; |
| 601 | virtual v8::Handle<v8::Object> GetEventData() const; |
| 602 | virtual v8::Handle<v8::Context> GetEventContext() const; |
| 603 | virtual v8::Handle<v8::Value> GetCallbackData() const; |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 604 | virtual v8::Debug::ClientData* GetClientData() const; |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 605 | private: |
| 606 | DebugEvent event_; // Debug event causing the break. |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 607 | Handle<JSObject> exec_state_; // Current execution state. |
| 608 | Handle<JSObject> event_data_; // Data associated with the event. |
| 609 | Handle<Object> callback_data_; // User data passed with the callback |
| 610 | // when it was registered. |
| 611 | v8::Debug::ClientData* client_data_; // Data passed to DebugBreakForCommand. |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 612 | }; |
| 613 | |
| 614 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 615 | // Message send by user to v8 debugger or debugger output message. |
| 616 | // In addition to command text it may contain a pointer to some user data |
| 617 | // which are expected to be passed along with the command reponse to message |
| 618 | // handler. |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 619 | class CommandMessage { |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 620 | public: |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 621 | static CommandMessage New(const Vector<uint16_t>& command, |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 622 | v8::Debug::ClientData* data); |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 623 | CommandMessage(); |
| 624 | ~CommandMessage(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 625 | |
| 626 | // Deletes user data and disposes of the text. |
| 627 | void Dispose(); |
| 628 | Vector<uint16_t> text() const { return text_; } |
| 629 | v8::Debug::ClientData* client_data() const { return client_data_; } |
| 630 | private: |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 631 | CommandMessage(const Vector<uint16_t>& text, |
| 632 | v8::Debug::ClientData* data); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 633 | |
| 634 | Vector<uint16_t> text_; |
| 635 | v8::Debug::ClientData* client_data_; |
| 636 | }; |
| 637 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 638 | // A Queue of CommandMessage objects. A thread-safe version is |
| 639 | // LockingCommandMessageQueue, based on this class. |
| 640 | class CommandMessageQueue BASE_EMBEDDED { |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 641 | public: |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 642 | explicit CommandMessageQueue(int size); |
| 643 | ~CommandMessageQueue(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 644 | bool IsEmpty() const { return start_ == end_; } |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 645 | CommandMessage Get(); |
| 646 | void Put(const CommandMessage& message); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 647 | void Clear() { start_ = end_ = 0; } // Queue is empty after Clear(). |
| 648 | private: |
| 649 | // Doubles the size of the message queue, and copies the messages. |
| 650 | void Expand(); |
| 651 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 652 | CommandMessage* messages_; |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 653 | int start_; |
| 654 | int end_; |
| 655 | int size_; // The size of the queue buffer. Queue can hold size-1 messages. |
| 656 | }; |
| 657 | |
| 658 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 659 | class MessageDispatchHelperThread; |
| 660 | |
| 661 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 662 | // LockingCommandMessageQueue is a thread-safe circular buffer of CommandMessage |
| 663 | // messages. The message data is not managed by LockingCommandMessageQueue. |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 664 | // Pointers to the data are passed in and out. Implemented by adding a |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 665 | // Mutex to CommandMessageQueue. Includes logging of all puts and gets. |
| 666 | class LockingCommandMessageQueue BASE_EMBEDDED { |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 667 | public: |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 668 | explicit LockingCommandMessageQueue(int size); |
| 669 | ~LockingCommandMessageQueue(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 670 | bool IsEmpty() const; |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 671 | CommandMessage Get(); |
| 672 | void Put(const CommandMessage& message); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 673 | void Clear(); |
| 674 | private: |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 675 | CommandMessageQueue queue_; |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 676 | Mutex* lock_; |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 677 | DISALLOW_COPY_AND_ASSIGN(LockingCommandMessageQueue); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 678 | }; |
| 679 | |
| 680 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 681 | class Debugger { |
| 682 | public: |
| 683 | static void DebugRequest(const uint16_t* json_request, int length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 684 | |
| 685 | static Handle<Object> MakeJSObject(Vector<const char> constructor_name, |
| 686 | int argc, Object*** argv, |
| 687 | bool* caught_exception); |
| 688 | static Handle<Object> MakeExecutionState(bool* caught_exception); |
| 689 | static Handle<Object> MakeBreakEvent(Handle<Object> exec_state, |
| 690 | Handle<Object> break_points_hit, |
| 691 | bool* caught_exception); |
| 692 | static Handle<Object> MakeExceptionEvent(Handle<Object> exec_state, |
| 693 | Handle<Object> exception, |
| 694 | bool uncaught, |
| 695 | bool* caught_exception); |
| 696 | static Handle<Object> MakeNewFunctionEvent(Handle<Object> func, |
| 697 | bool* caught_exception); |
| 698 | static Handle<Object> MakeCompileEvent(Handle<Script> script, |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 699 | bool before, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 700 | bool* caught_exception); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 701 | static Handle<Object> MakeScriptCollectedEvent(int id, |
| 702 | bool* caught_exception); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 703 | static void OnDebugBreak(Handle<Object> break_points_hit, bool auto_continue); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 704 | static void OnException(Handle<Object> exception, bool uncaught); |
| 705 | static void OnBeforeCompile(Handle<Script> script); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 706 | |
| 707 | enum AfterCompileFlags { |
| 708 | NO_AFTER_COMPILE_FLAGS, |
| 709 | SEND_WHEN_DEBUGGING |
| 710 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 711 | static void OnAfterCompile(Handle<Script> script, |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 712 | AfterCompileFlags after_compile_flags); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 713 | static void OnNewFunction(Handle<JSFunction> fun); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 714 | static void OnScriptCollected(int id); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 715 | static void ProcessDebugEvent(v8::DebugEvent event, |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 716 | Handle<JSObject> event_data, |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 717 | bool auto_continue); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 718 | static void NotifyMessageHandler(v8::DebugEvent event, |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 719 | Handle<JSObject> exec_state, |
| 720 | Handle<JSObject> event_data, |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 721 | bool auto_continue); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 722 | static void SetEventListener(Handle<Object> callback, Handle<Object> data); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 723 | static void SetMessageHandler(v8::Debug::MessageHandler2 handler); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 724 | static void SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler, |
| 725 | int period); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 726 | static void SetDebugMessageDispatchHandler( |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 727 | v8::Debug::DebugMessageDispatchHandler handler, |
| 728 | bool provide_locker); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 729 | |
| 730 | // Invoke the message handler function. |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 731 | static void InvokeMessageHandler(MessageImpl message); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 732 | |
| 733 | // Add a debugger command to the command queue. |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 734 | static void ProcessCommand(Vector<const uint16_t> command, |
| 735 | v8::Debug::ClientData* client_data = NULL); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 736 | |
| 737 | // Check whether there are commands in the command queue. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 738 | static bool HasCommands(); |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 739 | |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 740 | // Enqueue a debugger command to the command queue for event listeners. |
| 741 | static void EnqueueDebugCommand(v8::Debug::ClientData* client_data = NULL); |
| 742 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 743 | static Handle<Object> Call(Handle<JSFunction> fun, |
| 744 | Handle<Object> data, |
| 745 | bool* pending_exception); |
| 746 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 747 | // Start the debugger agent listening on the provided port. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 748 | static bool StartAgent(const char* name, int port, |
| 749 | bool wait_for_connection = false); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 750 | |
| 751 | // Stop the debugger agent. |
| 752 | static void StopAgent(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 753 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 754 | // Blocks until the agent has started listening for connections |
| 755 | static void WaitForAgent(); |
| 756 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 757 | static void CallMessageDispatchHandler(); |
| 758 | |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 759 | static Handle<Context> GetDebugContext(); |
| 760 | |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 761 | // Unload the debugger if possible. Only called when no debugger is currently |
| 762 | // active. |
| 763 | static void UnloadDebugger(); |
lrn@chromium.org | c34f580 | 2010-04-28 12:53:43 +0000 | [diff] [blame] | 764 | friend void ForceUnloadDebugger(); // In test-debug.cc |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 765 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 766 | inline static bool EventActive(v8::DebugEvent event) { |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 767 | ScopedLock with(debugger_access_); |
| 768 | |
| 769 | // Check whether the message handler was been cleared. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 770 | if (debugger_unload_pending_) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 771 | if (Debug::debugger_entry() == NULL) { |
| 772 | UnloadDebugger(); |
| 773 | } |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 774 | } |
| 775 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame^] | 776 | if (((event == v8::BeforeCompile) || (event == v8::AfterCompile)) && |
| 777 | !FLAG_debug_compile_events) { |
| 778 | return false; |
| 779 | |
| 780 | } else if ((event == v8::ScriptCollected) && |
| 781 | !FLAG_debug_script_collected_events) { |
| 782 | return false; |
| 783 | } |
| 784 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 785 | // Currently argument event is not used. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 786 | return !compiling_natives_ && Debugger::IsDebuggerActive(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 787 | } |
| 788 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 789 | static void set_compiling_natives(bool compiling_natives) { |
| 790 | Debugger::compiling_natives_ = compiling_natives; |
| 791 | } |
| 792 | static bool compiling_natives() { return Debugger::compiling_natives_; } |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 793 | static void set_loading_debugger(bool v) { is_loading_debugger_ = v; } |
| 794 | static bool is_loading_debugger() { return Debugger::is_loading_debugger_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 795 | |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 796 | static bool IsDebuggerActive(); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 797 | |
| 798 | private: |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 799 | static void CallEventCallback(v8::DebugEvent event, |
| 800 | Handle<Object> exec_state, |
| 801 | Handle<Object> event_data, |
| 802 | v8::Debug::ClientData* client_data); |
| 803 | static void CallCEventCallback(v8::DebugEvent event, |
| 804 | Handle<Object> exec_state, |
| 805 | Handle<Object> event_data, |
| 806 | v8::Debug::ClientData* client_data); |
| 807 | static void CallJSEventCallback(v8::DebugEvent event, |
| 808 | Handle<Object> exec_state, |
| 809 | Handle<Object> event_data); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 810 | static void ListenersChanged(); |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 811 | |
| 812 | static Mutex* debugger_access_; // Mutex guarding debugger variables. |
| 813 | static Handle<Object> event_listener_; // Global handle to listener. |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 814 | static Handle<Object> event_listener_data_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 815 | static bool compiling_natives_; // Are we compiling natives? |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 816 | static bool is_loading_debugger_; // Are we loading the debugger? |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 817 | static bool never_unload_debugger_; // Can we unload the debugger? |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 818 | static v8::Debug::MessageHandler2 message_handler_; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 819 | static bool debugger_unload_pending_; // Was message handler cleared? |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 820 | static v8::Debug::HostDispatchHandler host_dispatch_handler_; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 821 | static Mutex* dispatch_handler_access_; // Mutex guarding dispatch handler. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 822 | static v8::Debug::DebugMessageDispatchHandler debug_message_dispatch_handler_; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 823 | static MessageDispatchHelperThread* message_dispatch_helper_thread_; |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 824 | static int host_dispatch_micros_; |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 825 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 826 | static DebuggerAgent* agent_; |
| 827 | |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 828 | static const int kQueueInitialSize = 4; |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 829 | static LockingCommandMessageQueue command_queue_; |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 830 | static Semaphore* command_received_; // Signaled for each command received. |
ager@chromium.org | 41826e7 | 2009-03-30 13:30:57 +0000 | [diff] [blame] | 831 | |
mikhail.naganov@gmail.com | 2276287 | 2010-07-14 09:29:05 +0000 | [diff] [blame] | 832 | static LockingCommandMessageQueue event_command_queue_; |
| 833 | |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 834 | friend class EnterDebugger; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 835 | }; |
| 836 | |
| 837 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 838 | // This class is used for entering the debugger. Create an instance in the stack |
| 839 | // to enter the debugger. This will set the current break state, make sure the |
| 840 | // debugger is loaded and switch to the debugger context. If the debugger for |
| 841 | // some reason could not be entered FailedToEnter will return true. |
| 842 | class EnterDebugger BASE_EMBEDDED { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 843 | public: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 844 | EnterDebugger() |
| 845 | : prev_(Debug::debugger_entry()), |
| 846 | has_js_frames_(!it_.done()) { |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 847 | ASSERT(prev_ != NULL || !Debug::is_interrupt_pending(PREEMPT)); |
| 848 | ASSERT(prev_ != NULL || !Debug::is_interrupt_pending(DEBUGBREAK)); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 849 | |
| 850 | // Link recursive debugger entry. |
| 851 | Debug::set_debugger_entry(this); |
| 852 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 853 | // Store the previous break id and frame id. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 854 | break_id_ = Debug::break_id(); |
| 855 | break_frame_id_ = Debug::break_frame_id(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 856 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 857 | // Create the new break info. If there is no JavaScript frames there is no |
| 858 | // break frame id. |
| 859 | if (has_js_frames_) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 860 | Debug::NewBreak(it_.frame()->id()); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 861 | } else { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 862 | Debug::NewBreak(StackFrame::NO_ID); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 863 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 864 | |
| 865 | // Make sure that debugger is loaded and enter the debugger context. |
| 866 | load_failed_ = !Debug::Load(); |
| 867 | if (!load_failed_) { |
| 868 | // NOTE the member variable save which saves the previous context before |
| 869 | // this change. |
| 870 | Top::set_context(*Debug::debug_context()); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 871 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 872 | } |
| 873 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 874 | ~EnterDebugger() { |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 875 | // Restore to the previous break state. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 876 | Debug::SetBreak(break_frame_id_, break_id_); |
| 877 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 878 | // Check for leaving the debugger. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 879 | if (prev_ == NULL) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 880 | // Clear mirror cache when leaving the debugger. Skip this if there is a |
| 881 | // pending exception as clearing the mirror cache calls back into |
| 882 | // JavaScript. This can happen if the v8::Debug::Call is used in which |
| 883 | // case the exception should end up in the calling code. |
| 884 | if (!Top::has_pending_exception()) { |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 885 | // Try to avoid any pending debug break breaking in the clear mirror |
| 886 | // cache JavaScript code. |
| 887 | if (StackGuard::IsDebugBreak()) { |
| 888 | Debug::set_interrupts_pending(DEBUGBREAK); |
| 889 | StackGuard::Continue(DEBUGBREAK); |
| 890 | } |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 891 | Debug::ClearMirrorCache(); |
| 892 | } |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 893 | |
| 894 | // Request preemption and debug break when leaving the last debugger entry |
| 895 | // if any of these where recorded while debugging. |
| 896 | if (Debug::is_interrupt_pending(PREEMPT)) { |
| 897 | // This re-scheduling of preemption is to avoid starvation in some |
| 898 | // debugging scenarios. |
| 899 | Debug::clear_interrupt_pending(PREEMPT); |
| 900 | StackGuard::Preempt(); |
| 901 | } |
| 902 | if (Debug::is_interrupt_pending(DEBUGBREAK)) { |
| 903 | Debug::clear_interrupt_pending(DEBUGBREAK); |
| 904 | StackGuard::DebugBreak(); |
| 905 | } |
| 906 | |
| 907 | // If there are commands in the queue when leaving the debugger request |
| 908 | // that these commands are processed. |
| 909 | if (Debugger::HasCommands()) { |
| 910 | StackGuard::DebugCommand(); |
| 911 | } |
| 912 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 913 | // If leaving the debugger with the debugger no longer active unload it. |
ager@chromium.org | 71daaf6 | 2009-04-01 07:22:49 +0000 | [diff] [blame] | 914 | if (!Debugger::IsDebuggerActive()) { |
| 915 | Debugger::UnloadDebugger(); |
| 916 | } |
| 917 | } |
| 918 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 919 | // Leaving this debugger entry. |
| 920 | Debug::set_debugger_entry(prev_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 921 | } |
| 922 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 923 | // Check whether the debugger could be entered. |
| 924 | inline bool FailedToEnter() { return load_failed_; } |
| 925 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 926 | // Check whether there are any JavaScript frames on the stack. |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 927 | inline bool HasJavaScriptFrames() { return has_js_frames_; } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 928 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 929 | // Get the active context from before entering the debugger. |
| 930 | inline Handle<Context> GetContext() { return save_.context(); } |
| 931 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 932 | private: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 933 | EnterDebugger* prev_; // Previous debugger entry if entered recursively. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 934 | JavaScriptFrameIterator it_; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 935 | const bool has_js_frames_; // Were there any JavaScript frames? |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 936 | StackFrame::Id break_frame_id_; // Previous break frame id. |
| 937 | int break_id_; // Previous break id. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 938 | bool load_failed_; // Did the debugger fail to load? |
| 939 | SaveContext save_; // Saves previous context. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 940 | }; |
| 941 | |
| 942 | |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 943 | // Stack allocated class for disabling break. |
| 944 | class DisableBreak BASE_EMBEDDED { |
| 945 | public: |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 946 | explicit DisableBreak(bool disable_break) { |
| 947 | prev_disable_break_ = Debug::disable_break(); |
| 948 | Debug::set_disable_break(disable_break); |
| 949 | } |
| 950 | ~DisableBreak() { |
| 951 | Debug::set_disable_break(prev_disable_break_); |
| 952 | } |
| 953 | |
| 954 | private: |
| 955 | // The previous state of the disable break used to restore the value when this |
| 956 | // object is destructed. |
| 957 | bool prev_disable_break_; |
| 958 | }; |
| 959 | |
| 960 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 961 | // Debug_Address encapsulates the Address pointers used in generating debug |
| 962 | // code. |
| 963 | class Debug_Address { |
| 964 | public: |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 965 | explicit Debug_Address(Debug::AddressId id) : id_(id) { } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 966 | |
| 967 | static Debug_Address AfterBreakTarget() { |
| 968 | return Debug_Address(Debug::k_after_break_target_address); |
| 969 | } |
| 970 | |
| 971 | static Debug_Address DebugBreakReturn() { |
| 972 | return Debug_Address(Debug::k_debug_break_return_address); |
| 973 | } |
| 974 | |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 975 | static Debug_Address RestarterFrameFunctionPointer() { |
| 976 | return Debug_Address(Debug::k_restarter_frame_function_pointer); |
| 977 | } |
| 978 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 979 | Address address() const { |
| 980 | switch (id_) { |
| 981 | case Debug::k_after_break_target_address: |
| 982 | return reinterpret_cast<Address>(Debug::after_break_target_address()); |
| 983 | case Debug::k_debug_break_return_address: |
| 984 | return reinterpret_cast<Address>(Debug::debug_break_return_address()); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 985 | case Debug::k_debug_break_slot_address: |
| 986 | return reinterpret_cast<Address>(Debug::debug_break_slot_address()); |
whesse@chromium.org | e90029b | 2010-08-02 11:52:17 +0000 | [diff] [blame] | 987 | case Debug::k_restarter_frame_function_pointer: |
| 988 | return reinterpret_cast<Address>( |
| 989 | Debug::restarter_frame_function_pointer_address()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 990 | default: |
| 991 | UNREACHABLE(); |
| 992 | return NULL; |
| 993 | } |
| 994 | } |
| 995 | private: |
| 996 | Debug::AddressId id_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 997 | }; |
| 998 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 999 | // The optional thread that Debug Agent may use to temporary call V8 to process |
| 1000 | // pending debug requests if debuggee is not running V8 at the moment. |
| 1001 | // Techincally it does not call V8 itself, rather it asks embedding program |
| 1002 | // to do this via v8::Debug::HostDispatchHandler |
| 1003 | class MessageDispatchHelperThread: public Thread { |
| 1004 | public: |
| 1005 | MessageDispatchHelperThread(); |
| 1006 | ~MessageDispatchHelperThread(); |
| 1007 | |
| 1008 | void Schedule(); |
| 1009 | |
| 1010 | private: |
| 1011 | void Run(); |
| 1012 | |
| 1013 | Semaphore* const sem_; |
| 1014 | Mutex* const mutex_; |
| 1015 | bool already_signalled_; |
| 1016 | |
| 1017 | DISALLOW_COPY_AND_ASSIGN(MessageDispatchHelperThread); |
| 1018 | }; |
| 1019 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1020 | |
| 1021 | } } // namespace v8::internal |
| 1022 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 1023 | #endif // ENABLE_DEBUGGER_SUPPORT |
| 1024 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1025 | #endif // V8_DEBUG_H_ |