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