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