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