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