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