ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 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 | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 28 | #ifndef V8_V8_DEBUG_H_ |
| 29 | #define V8_V8_DEBUG_H_ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 30 | |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 31 | #include "../include/v8-debug.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 32 | #include "assembler.h" |
| 33 | #include "code-stubs.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" |
| 37 | #include "platform.h" |
| 38 | #include "string-stream.h" |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 39 | #include "v8threads.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 40 | |
| 41 | |
| 42 | namespace v8 { namespace internal { |
| 43 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 44 | |
| 45 | // Forward declarations. |
| 46 | class EnterDebugger; |
| 47 | |
| 48 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 49 | // Step actions. NOTE: These values are in macros.py as well. |
| 50 | enum StepAction { |
| 51 | StepNone = -1, // Stepping not prepared. |
| 52 | StepOut = 0, // Step out of the current function. |
| 53 | StepNext = 1, // Step to the next statement in the current function. |
| 54 | StepIn = 2, // Step into new functions invoked or the next statement |
| 55 | // in the current function. |
| 56 | StepMin = 3, // Perform a minimum step in the current function. |
| 57 | StepInMin = 4 // Step into new functions invoked or perform a minimum step |
| 58 | // in the current function. |
| 59 | }; |
| 60 | |
| 61 | |
| 62 | // Type of exception break. NOTE: These values are in macros.py as well. |
| 63 | enum ExceptionBreakType { |
| 64 | BreakException = 0, |
| 65 | BreakUncaughtException = 1 |
| 66 | }; |
| 67 | |
| 68 | |
| 69 | // Type of exception break. NOTE: These values are in macros.py as well. |
| 70 | enum BreakLocatorType { |
| 71 | ALL_BREAK_LOCATIONS = 0, |
| 72 | SOURCE_BREAK_LOCATIONS = 1 |
| 73 | }; |
| 74 | |
| 75 | |
| 76 | // Class for iterating through the break points in a function and changing |
| 77 | // them. |
| 78 | class BreakLocationIterator { |
| 79 | public: |
| 80 | explicit BreakLocationIterator(Handle<DebugInfo> debug_info, |
| 81 | BreakLocatorType type); |
| 82 | virtual ~BreakLocationIterator(); |
| 83 | |
| 84 | void Next(); |
| 85 | void Next(int count); |
| 86 | void FindBreakLocationFromAddress(Address pc); |
| 87 | void FindBreakLocationFromPosition(int position); |
| 88 | void Reset(); |
| 89 | bool Done() const; |
| 90 | void SetBreakPoint(Handle<Object> break_point_object); |
| 91 | void ClearBreakPoint(Handle<Object> break_point_object); |
| 92 | void SetOneShot(); |
| 93 | void ClearOneShot(); |
| 94 | void PrepareStepIn(); |
| 95 | bool IsExit() const; |
| 96 | bool HasBreakPoint(); |
| 97 | bool IsDebugBreak(); |
| 98 | Object* BreakPointObjects(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 99 | void ClearAllDebugBreak(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 100 | |
| 101 | |
| 102 | inline int code_position() { return pc() - debug_info_->code()->entry(); } |
| 103 | inline int break_point() { return break_point_; } |
| 104 | inline int position() { return position_; } |
| 105 | inline int statement_position() { return statement_position_; } |
| 106 | inline Address pc() { return reloc_iterator_->rinfo()->pc(); } |
| 107 | inline Code* code() { return debug_info_->code(); } |
| 108 | inline RelocInfo* rinfo() { return reloc_iterator_->rinfo(); } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 109 | inline RelocInfo::Mode rmode() const { |
| 110 | return reloc_iterator_->rinfo()->rmode(); |
| 111 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 112 | inline RelocInfo* original_rinfo() { |
| 113 | return reloc_iterator_original_->rinfo(); |
| 114 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 115 | inline RelocInfo::Mode original_rmode() const { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 116 | return reloc_iterator_original_->rinfo()->rmode(); |
| 117 | } |
| 118 | |
| 119 | protected: |
| 120 | bool RinfoDone() const; |
| 121 | void RinfoNext(); |
| 122 | |
| 123 | BreakLocatorType type_; |
| 124 | int break_point_; |
| 125 | int position_; |
| 126 | int statement_position_; |
| 127 | Handle<DebugInfo> debug_info_; |
| 128 | RelocIterator* reloc_iterator_; |
| 129 | RelocIterator* reloc_iterator_original_; |
| 130 | |
| 131 | private: |
| 132 | void SetDebugBreak(); |
| 133 | void ClearDebugBreak(); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 134 | bool IsDebugBreakAtReturn(); |
| 135 | void SetDebugBreakAtReturn(); |
| 136 | void ClearDebugBreakAtReturn(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 137 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 138 | DISALLOW_COPY_AND_ASSIGN(BreakLocationIterator); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | |
| 142 | // Linked list holding debug info objects. The debug info objects are kept as |
| 143 | // weak handles to avoid a debug info object to keep a function alive. |
| 144 | class DebugInfoListNode { |
| 145 | public: |
| 146 | explicit DebugInfoListNode(DebugInfo* debug_info); |
| 147 | virtual ~DebugInfoListNode(); |
| 148 | |
| 149 | DebugInfoListNode* next() { return next_; } |
| 150 | void set_next(DebugInfoListNode* next) { next_ = next; } |
| 151 | Handle<DebugInfo> debug_info() { return debug_info_; } |
| 152 | |
| 153 | private: |
| 154 | // Global (weak) handle to the debug info object. |
| 155 | Handle<DebugInfo> debug_info_; |
| 156 | |
| 157 | // Next pointer for linked list. |
| 158 | DebugInfoListNode* next_; |
| 159 | }; |
| 160 | |
| 161 | |
| 162 | // This class contains the debugger support. The main purpose is to handle |
| 163 | // setting break points in the code. |
| 164 | // |
| 165 | // This class controls the debug info for all functions which currently have |
| 166 | // active breakpoints in them. This debug info is held in the heap root object |
| 167 | // debug_info which is a FixedArray. Each entry in this list is of class |
| 168 | // DebugInfo. |
| 169 | class Debug { |
| 170 | public: |
| 171 | static void Setup(bool create_heap_objects); |
| 172 | static bool Load(); |
| 173 | static void Unload(); |
| 174 | static bool IsLoaded() { return !debug_context_.is_null(); } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 175 | static bool InDebugger() { return thread_local_.debugger_entry_ != NULL; } |
| 176 | static void PreemptionWhileInDebugger(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 177 | static void Iterate(ObjectVisitor* v); |
| 178 | |
| 179 | static Object* Break(Arguments args); |
| 180 | static void SetBreakPoint(Handle<SharedFunctionInfo> shared, |
| 181 | int source_position, |
| 182 | Handle<Object> break_point_object); |
| 183 | static void ClearBreakPoint(Handle<Object> break_point_object); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 184 | static void ClearAllBreakPoints(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 185 | static void FloodWithOneShot(Handle<SharedFunctionInfo> shared); |
| 186 | static void FloodHandlerWithOneShot(); |
| 187 | static void ChangeBreakOnException(ExceptionBreakType type, bool enable); |
| 188 | static void PrepareStep(StepAction step_action, int step_count); |
| 189 | static void ClearStepping(); |
| 190 | static bool StepNextContinue(BreakLocationIterator* break_location_iterator, |
| 191 | JavaScriptFrame* frame); |
| 192 | static Handle<DebugInfo> GetDebugInfo(Handle<SharedFunctionInfo> shared); |
| 193 | static bool HasDebugInfo(Handle<SharedFunctionInfo> shared); |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 194 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 195 | // Returns whether the operation succeeded. |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 196 | static bool EnsureDebugInfo(Handle<SharedFunctionInfo> shared); |
| 197 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 198 | static bool IsDebugBreak(Address addr); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 199 | static bool IsDebugBreakAtReturn(RelocInfo* rinfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 200 | |
| 201 | // Check whether a code stub with the specified major key is a possible break |
| 202 | // point location. |
| 203 | static bool IsSourceBreakStub(Code* code); |
| 204 | static bool IsBreakStub(Code* code); |
| 205 | |
| 206 | // Find the builtin to use for invoking the debug break |
| 207 | static Handle<Code> FindDebugBreak(RelocInfo* rinfo); |
| 208 | |
| 209 | static Handle<Object> GetSourceBreakLocations( |
| 210 | Handle<SharedFunctionInfo> shared); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 211 | |
| 212 | // Getter for the debug_context. |
| 213 | inline static Handle<Context> debug_context() { return debug_context_; } |
| 214 | |
| 215 | // Check whether a global object is the debug global object. |
| 216 | static bool IsDebugGlobal(GlobalObject* global); |
| 217 | |
| 218 | // Fast check to see if any break points are active. |
| 219 | inline static bool has_break_points() { return has_break_points_; } |
| 220 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 221 | static void NewBreak(StackFrame::Id break_frame_id); |
| 222 | static void SetBreak(StackFrame::Id break_frame_id, int break_id); |
| 223 | static StackFrame::Id break_frame_id() { |
| 224 | return thread_local_.break_frame_id_; |
| 225 | } |
| 226 | static int break_id() { return thread_local_.break_id_; } |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 231 | static bool StepInActive() { return thread_local_.step_into_fp_ != 0; } |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 232 | static void HandleStepIn(Handle<JSFunction> function, |
| 233 | Address fp, |
| 234 | bool is_constructor); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 235 | static Address step_in_fp() { return thread_local_.step_into_fp_; } |
| 236 | static Address* step_in_fp_addr() { return &thread_local_.step_into_fp_; } |
| 237 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 238 | static EnterDebugger* debugger_entry() { |
| 239 | return thread_local_.debugger_entry_; |
| 240 | } |
| 241 | static void set_debugger_entry(EnterDebugger* entry) { |
| 242 | thread_local_.debugger_entry_ = entry; |
| 243 | } |
| 244 | |
| 245 | static bool preemption_pending() { |
| 246 | return thread_local_.preemption_pending_; |
| 247 | } |
| 248 | static void set_preemption_pending(bool preemption_pending) { |
| 249 | thread_local_.preemption_pending_ = preemption_pending; |
| 250 | } |
| 251 | |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 252 | // Getter and setter for the disable break state. |
| 253 | static bool disable_break() { return disable_break_; } |
| 254 | static void set_disable_break(bool disable_break) { |
| 255 | disable_break_ = disable_break; |
| 256 | } |
| 257 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 258 | // Getters for the current exception break state. |
| 259 | static bool break_on_exception() { return break_on_exception_; } |
| 260 | static bool break_on_uncaught_exception() { |
| 261 | return break_on_uncaught_exception_; |
| 262 | } |
| 263 | |
| 264 | enum AddressId { |
| 265 | k_after_break_target_address, |
| 266 | k_debug_break_return_address, |
| 267 | k_register_address |
| 268 | }; |
| 269 | |
| 270 | // Support for setting the address to jump to when returning from break point. |
| 271 | static Address* after_break_target_address() { |
| 272 | return reinterpret_cast<Address*>(&thread_local_.after_break_target_); |
| 273 | } |
| 274 | |
| 275 | // Support for saving/restoring registers when handling debug break calls. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 276 | static Object** register_address(int r) { |
| 277 | return ®isters_[r]; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 278 | } |
| 279 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 280 | // Address of the debug break return entry code. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 281 | static Code* debug_break_return_entry() { return debug_break_return_entry_; } |
| 282 | |
| 283 | // Support for getting the address of the debug break on return code. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 284 | static Code** debug_break_return_address() { |
| 285 | return &debug_break_return_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | static const int kEstimatedNofDebugInfoEntries = 16; |
| 289 | static const int kEstimatedNofBreakPointsInFunction = 16; |
| 290 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 291 | static void HandleWeakDebugInfo(v8::Persistent<v8::Value> obj, void* data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 292 | |
| 293 | friend class Debugger; |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 294 | friend Handle<FixedArray> GetDebuggedFunctions(); // In test-debug.cc |
| 295 | friend void CheckDebuggerUnloaded(bool check_functions); // In test-debug.cc |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 296 | |
| 297 | // Threading support. |
| 298 | static char* ArchiveDebug(char* to); |
| 299 | static char* RestoreDebug(char* from); |
| 300 | static int ArchiveSpacePerThread(); |
| 301 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 302 | // Mirror cache handling. |
| 303 | static void ClearMirrorCache(); |
| 304 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 305 | // Code generation assumptions. |
| 306 | static const int kIa32CallInstructionLength = 5; |
| 307 | static const int kIa32JSReturnSequenceLength = 6; |
| 308 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 309 | // Code generator routines. |
| 310 | static void GenerateLoadICDebugBreak(MacroAssembler* masm); |
| 311 | static void GenerateStoreICDebugBreak(MacroAssembler* masm); |
| 312 | static void GenerateKeyedLoadICDebugBreak(MacroAssembler* masm); |
| 313 | static void GenerateKeyedStoreICDebugBreak(MacroAssembler* masm); |
| 314 | static void GenerateConstructCallDebugBreak(MacroAssembler* masm); |
| 315 | static void GenerateReturnDebugBreak(MacroAssembler* masm); |
| 316 | static void GenerateReturnDebugBreakEntry(MacroAssembler* masm); |
| 317 | static void GenerateStubNoRegistersDebugBreak(MacroAssembler* masm); |
| 318 | |
| 319 | // Called from stub-cache.cc. |
| 320 | static void GenerateCallICDebugBreak(MacroAssembler* masm); |
| 321 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 322 | private: |
| 323 | static bool CompileDebuggerScript(int index); |
| 324 | static void ClearOneShot(); |
| 325 | static void ActivateStepIn(StackFrame* frame); |
| 326 | static void ClearStepIn(); |
| 327 | static void ClearStepNext(); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 328 | // Returns whether the compile succeeded. |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 329 | static bool EnsureCompiled(Handle<SharedFunctionInfo> shared); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 330 | static void RemoveDebugInfo(Handle<DebugInfo> debug_info); |
| 331 | static void SetAfterBreakTarget(JavaScriptFrame* frame); |
| 332 | static Handle<Object> CheckBreakPoints(Handle<Object> break_point); |
| 333 | static bool CheckBreakPoint(Handle<Object> break_point_object); |
| 334 | |
| 335 | // Global handle to debug context where all the debugger JavaScript code is |
| 336 | // loaded. |
| 337 | static Handle<Context> debug_context_; |
| 338 | |
| 339 | // Boolean state indicating whether any break points are set. |
| 340 | static bool has_break_points_; |
| 341 | static DebugInfoListNode* debug_info_list_; |
| 342 | |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 343 | static bool disable_break_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 344 | static bool break_on_exception_; |
| 345 | static bool break_on_uncaught_exception_; |
| 346 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 347 | // Per-thread data. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 348 | class ThreadLocal { |
| 349 | public: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 350 | // Counter for generating next break id. |
| 351 | int break_count_; |
| 352 | |
| 353 | // Current break id. |
| 354 | int break_id_; |
| 355 | |
| 356 | // Frame id for the frame of the current break. |
| 357 | StackFrame::Id break_frame_id_; |
| 358 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 359 | // Step action for last step performed. |
| 360 | StepAction last_step_action_; |
| 361 | |
| 362 | // Source statement position from last step next action. |
| 363 | int last_statement_position_; |
| 364 | |
| 365 | // Number of steps left to perform before debug event. |
| 366 | int step_count_; |
| 367 | |
| 368 | // Frame pointer from last step next action. |
| 369 | Address last_fp_; |
| 370 | |
| 371 | // Frame pointer for frame from which step in was performed. |
| 372 | Address step_into_fp_; |
| 373 | |
| 374 | // Storage location for jump when exiting debug break calls. |
| 375 | Address after_break_target_; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 376 | |
| 377 | // Top debugger entry. |
| 378 | EnterDebugger* debugger_entry_; |
| 379 | |
| 380 | // Preemption happened while debugging. |
| 381 | bool preemption_pending_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 382 | }; |
| 383 | |
| 384 | // Storage location for registers when handling debug break calls |
| 385 | static JSCallerSavedBuffer registers_; |
| 386 | static ThreadLocal thread_local_; |
| 387 | static void ThreadInit(); |
| 388 | |
| 389 | // Code object for debug break return entry code. |
| 390 | static Code* debug_break_return_entry_; |
| 391 | |
| 392 | // Code to call for handling debug break on return. |
| 393 | static Code* debug_break_return_; |
| 394 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 395 | DISALLOW_COPY_AND_ASSIGN(Debug); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 396 | }; |
| 397 | |
| 398 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 399 | class DebugMessageThread; |
| 400 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 401 | class Debugger { |
| 402 | public: |
| 403 | static void DebugRequest(const uint16_t* json_request, int length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 404 | |
| 405 | static Handle<Object> MakeJSObject(Vector<const char> constructor_name, |
| 406 | int argc, Object*** argv, |
| 407 | bool* caught_exception); |
| 408 | static Handle<Object> MakeExecutionState(bool* caught_exception); |
| 409 | static Handle<Object> MakeBreakEvent(Handle<Object> exec_state, |
| 410 | Handle<Object> break_points_hit, |
| 411 | bool* caught_exception); |
| 412 | static Handle<Object> MakeExceptionEvent(Handle<Object> exec_state, |
| 413 | Handle<Object> exception, |
| 414 | bool uncaught, |
| 415 | bool* caught_exception); |
| 416 | static Handle<Object> MakeNewFunctionEvent(Handle<Object> func, |
| 417 | bool* caught_exception); |
| 418 | static Handle<Object> MakeCompileEvent(Handle<Script> script, |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 419 | bool before, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 420 | bool* caught_exception); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame^] | 421 | static void OnDebugBreak(Handle<Object> break_points_hit, bool auto_continue); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 422 | static void OnException(Handle<Object> exception, bool uncaught); |
| 423 | static void OnBeforeCompile(Handle<Script> script); |
| 424 | static void OnAfterCompile(Handle<Script> script, |
| 425 | Handle<JSFunction> fun); |
| 426 | static void OnNewFunction(Handle<JSFunction> fun); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 427 | static void ProcessDebugEvent(v8::DebugEvent event, |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame^] | 428 | Handle<Object> event_data, |
| 429 | bool auto_continue); |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 430 | static void SetEventListener(Handle<Object> callback, Handle<Object> data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 431 | static void SetMessageHandler(v8::DebugMessageHandler handler, void* data); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 432 | static void SetHostDispatchHandler(v8::DebugHostDispatchHandler handler, |
| 433 | void* data); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 434 | static void SendMessage(Vector<uint16_t> message); |
| 435 | static void ProcessCommand(Vector<const uint16_t> command); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame^] | 436 | static bool HasCommands(); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 437 | static void ProcessHostDispatch(void* dispatch); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 438 | static void UpdateActiveDebugger(); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 439 | static Handle<Object> Call(Handle<JSFunction> fun, |
| 440 | Handle<Object> data, |
| 441 | bool* pending_exception); |
| 442 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 443 | // Start the debugger agent listening on the provided port. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame^] | 444 | static bool StartAgent(const char* name, int port); |
| 445 | |
| 446 | // Stop the debugger agent. |
| 447 | static void StopAgent(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 448 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 449 | inline static bool EventActive(v8::DebugEvent event) { |
| 450 | // Currently argument event is not used. |
| 451 | return !Debugger::compiling_natives_ && Debugger::debugger_active_; |
| 452 | } |
| 453 | |
| 454 | static void set_debugger_active(bool debugger_active) { |
| 455 | Debugger::debugger_active_ = debugger_active; |
| 456 | } |
| 457 | static bool debugger_active() { return Debugger::debugger_active_; } |
| 458 | static void set_compiling_natives(bool compiling_natives) { |
| 459 | Debugger::compiling_natives_ = compiling_natives; |
| 460 | } |
| 461 | static bool compiling_natives() { return Debugger::compiling_natives_; } |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 462 | static void set_loading_debugger(bool v) { is_loading_debugger_ = v; } |
| 463 | static bool is_loading_debugger() { return Debugger::is_loading_debugger_; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 464 | |
| 465 | private: |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 466 | static Handle<Object> event_listener_; // Global handle to listener |
| 467 | static Handle<Object> event_listener_data_; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 468 | static bool debugger_active_; // Are there any active debugger? |
| 469 | static bool compiling_natives_; // Are we compiling natives? |
mads.s.ager | cbaa060 | 2008-08-14 13:41:48 +0000 | [diff] [blame] | 470 | static bool is_loading_debugger_; // Are we loading the debugger? |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 471 | static DebugMessageThread* message_thread_; |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 472 | static v8::DebugMessageHandler message_handler_; |
| 473 | static void* message_handler_data_; |
| 474 | static v8::DebugHostDispatchHandler host_dispatch_handler_; |
| 475 | static void* host_dispatch_handler_data_; |
| 476 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 477 | static DebuggerAgent* agent_; |
| 478 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 479 | friend class DebugMessageThread; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 480 | }; |
| 481 | |
| 482 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 483 | // A Queue of Vector<uint16_t> objects. A thread-safe version is |
| 484 | // LockingMessageQueue, based on this class. |
| 485 | class MessageQueue BASE_EMBEDDED { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 486 | public: |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 487 | explicit MessageQueue(int size); |
| 488 | ~MessageQueue(); |
| 489 | bool IsEmpty() const { return start_ == end_; } |
| 490 | Vector<uint16_t> Get(); |
| 491 | void Put(const Vector<uint16_t>& message); |
| 492 | void Clear() { start_ = end_ = 0; } // Queue is empty after Clear(). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 493 | private: |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 494 | // Doubles the size of the message queue, and copies the messages. |
| 495 | void Expand(); |
| 496 | |
| 497 | Vector<uint16_t>* messages_; |
| 498 | int start_; |
| 499 | int end_; |
| 500 | int size_; // The size of the queue buffer. Queue can hold size-1 messages. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 501 | }; |
| 502 | |
| 503 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 504 | // LockingMessageQueue is a thread-safe circular buffer of Vector<uint16_t> |
| 505 | // messages. The message data is not managed by LockingMessageQueue. |
| 506 | // Pointers to the data are passed in and out. Implemented by adding a |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 507 | // Mutex to MessageQueue. Includes logging of all puts and gets. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 508 | class LockingMessageQueue BASE_EMBEDDED { |
| 509 | public: |
| 510 | explicit LockingMessageQueue(int size); |
| 511 | ~LockingMessageQueue(); |
| 512 | bool IsEmpty() const; |
| 513 | Vector<uint16_t> Get(); |
| 514 | void Put(const Vector<uint16_t>& message); |
| 515 | void Clear(); |
| 516 | private: |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 517 | MessageQueue queue_; |
| 518 | Mutex* lock_; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 519 | DISALLOW_COPY_AND_ASSIGN(LockingMessageQueue); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 520 | }; |
| 521 | |
| 522 | |
| 523 | /* This class is the data for a running thread that serializes |
| 524 | * event messages and command processing for the debugger. |
| 525 | * All uncommented methods are called only from this message thread. |
| 526 | */ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 527 | class DebugMessageThread: public Thread { |
| 528 | public: |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 529 | DebugMessageThread(); // Called from API thread. |
| 530 | virtual ~DebugMessageThread(); // Never called. |
| 531 | // Called by V8 thread. Reports events from V8 VM. |
| 532 | // Also handles command processing in stopped state of V8, |
| 533 | // when host_running_ is false. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 534 | void DebugEvent(v8::DebugEvent, |
| 535 | Handle<Object> exec_state, |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame^] | 536 | Handle<Object> event_data, |
| 537 | bool auto_continue); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 538 | // Puts event on the output queue. Called by V8. |
| 539 | // This is where V8 hands off |
| 540 | // processing of the event to the DebugMessageThread thread, |
| 541 | // which forwards it to the debug_message_handler set by the API. |
| 542 | void SendMessage(Vector<uint16_t> event_json); |
| 543 | // Formats an event into JSON, and calls SendMessage. |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 544 | bool SetEventJSONFromEvent(Handle<Object> event_data); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 545 | // Puts a command coming from the public API on the queue. Called |
| 546 | // by the API client thread. This is where the API client hands off |
| 547 | // processing of the command to the DebugMessageThread thread. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 548 | void ProcessCommand(Vector<uint16_t> command); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 549 | void ProcessHostDispatch(void* dispatch); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 550 | void OnDebuggerInactive(); |
| 551 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 552 | // Main function of DebugMessageThread thread. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 553 | void Run(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 554 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame^] | 555 | // Check whether there are commands in the queue. |
| 556 | bool HasCommands() { return !command_queue_.IsEmpty(); } |
| 557 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 558 | bool host_running_; // Is the debugging host running or stopped? |
| 559 | Semaphore* command_received_; // Non-zero when command queue is non-empty. |
| 560 | Semaphore* message_received_; // Exactly equal to message queue length. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 561 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 562 | bool TwoByteEqualsAscii(Vector<uint16_t> two_byte, const char* ascii); |
| 563 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 564 | static const int kQueueInitialSize = 4; |
| 565 | LockingMessageQueue command_queue_; |
| 566 | LockingMessageQueue message_queue_; |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 567 | DISALLOW_COPY_AND_ASSIGN(DebugMessageThread); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 568 | }; |
| 569 | |
| 570 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 571 | // This class is used for entering the debugger. Create an instance in the stack |
| 572 | // to enter the debugger. This will set the current break state, make sure the |
| 573 | // debugger is loaded and switch to the debugger context. If the debugger for |
| 574 | // some reason could not be entered FailedToEnter will return true. |
| 575 | class EnterDebugger BASE_EMBEDDED { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 576 | public: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 577 | EnterDebugger() |
| 578 | : prev_(Debug::debugger_entry()), |
| 579 | has_js_frames_(!it_.done()) { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame^] | 580 | ASSERT(prev_ == NULL ? !Debug::preemption_pending() : true); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 581 | |
| 582 | // Link recursive debugger entry. |
| 583 | Debug::set_debugger_entry(this); |
| 584 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 585 | // Store the previous break id and frame id. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 586 | break_id_ = Debug::break_id(); |
| 587 | break_frame_id_ = Debug::break_frame_id(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 588 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 589 | // Create the new break info. If there is no JavaScript frames there is no |
| 590 | // break frame id. |
| 591 | if (has_js_frames_) { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 592 | Debug::NewBreak(it_.frame()->id()); |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 593 | } else { |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 594 | Debug::NewBreak(StackFrame::NO_ID); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 595 | } |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 596 | |
| 597 | // Make sure that debugger is loaded and enter the debugger context. |
| 598 | load_failed_ = !Debug::Load(); |
| 599 | if (!load_failed_) { |
| 600 | // NOTE the member variable save which saves the previous context before |
| 601 | // this change. |
| 602 | Top::set_context(*Debug::debug_context()); |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 603 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 604 | } |
| 605 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 606 | ~EnterDebugger() { |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 607 | // Restore to the previous break state. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 608 | Debug::SetBreak(break_frame_id_, break_id_); |
| 609 | |
| 610 | // Request preemption when leaving the last debugger entry and a preemption |
| 611 | // had been recorded while debugging. This is to avoid starvation in some |
| 612 | // debugging scenarios. |
| 613 | if (prev_ == NULL && Debug::preemption_pending()) { |
| 614 | StackGuard::Preempt(); |
| 615 | Debug::set_preemption_pending(false); |
| 616 | } |
| 617 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame^] | 618 | // If there are commands in the queue when leaving the debugger request that |
| 619 | // these commands are processed. |
| 620 | if (prev_ == NULL && Debugger::HasCommands()) { |
| 621 | StackGuard::DebugCommand(); |
| 622 | } |
| 623 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 624 | // Leaving this debugger entry. |
| 625 | Debug::set_debugger_entry(prev_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 626 | } |
| 627 | |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 628 | // Check whether the debugger could be entered. |
| 629 | inline bool FailedToEnter() { return load_failed_; } |
| 630 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 631 | // Check whether there are any JavaScript frames on the stack. |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 632 | inline bool HasJavaScriptFrames() { return has_js_frames_; } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 633 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 634 | private: |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 635 | EnterDebugger* prev_; // Previous debugger entry if entered recursively. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 636 | JavaScriptFrameIterator it_; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 637 | const bool has_js_frames_; // Were there any JavaScript frames? |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 638 | StackFrame::Id break_frame_id_; // Previous break frame id. |
| 639 | int break_id_; // Previous break id. |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 640 | bool load_failed_; // Did the debugger fail to load? |
| 641 | SaveContext save_; // Saves previous context. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 642 | }; |
| 643 | |
| 644 | |
kasper.lund | bd3ec4e | 2008-07-09 11:06:54 +0000 | [diff] [blame] | 645 | // Stack allocated class for disabling break. |
| 646 | class DisableBreak BASE_EMBEDDED { |
| 647 | public: |
| 648 | // Enter the debugger by storing the previous top context and setting the |
| 649 | // current top context to the debugger context. |
| 650 | explicit DisableBreak(bool disable_break) { |
| 651 | prev_disable_break_ = Debug::disable_break(); |
| 652 | Debug::set_disable_break(disable_break); |
| 653 | } |
| 654 | ~DisableBreak() { |
| 655 | Debug::set_disable_break(prev_disable_break_); |
| 656 | } |
| 657 | |
| 658 | private: |
| 659 | // The previous state of the disable break used to restore the value when this |
| 660 | // object is destructed. |
| 661 | bool prev_disable_break_; |
| 662 | }; |
| 663 | |
| 664 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 665 | // Debug_Address encapsulates the Address pointers used in generating debug |
| 666 | // code. |
| 667 | class Debug_Address { |
| 668 | public: |
| 669 | Debug_Address(Debug::AddressId id, int reg = 0) |
| 670 | : id_(id), reg_(reg) { |
| 671 | ASSERT(reg == 0 || id == Debug::k_register_address); |
| 672 | } |
| 673 | |
| 674 | static Debug_Address AfterBreakTarget() { |
| 675 | return Debug_Address(Debug::k_after_break_target_address); |
| 676 | } |
| 677 | |
| 678 | static Debug_Address DebugBreakReturn() { |
| 679 | return Debug_Address(Debug::k_debug_break_return_address); |
| 680 | } |
| 681 | |
| 682 | static Debug_Address Register(int reg) { |
| 683 | return Debug_Address(Debug::k_register_address, reg); |
| 684 | } |
| 685 | |
| 686 | Address address() const { |
| 687 | switch (id_) { |
| 688 | case Debug::k_after_break_target_address: |
| 689 | return reinterpret_cast<Address>(Debug::after_break_target_address()); |
| 690 | case Debug::k_debug_break_return_address: |
| 691 | return reinterpret_cast<Address>(Debug::debug_break_return_address()); |
| 692 | case Debug::k_register_address: |
| 693 | return reinterpret_cast<Address>(Debug::register_address(reg_)); |
| 694 | default: |
| 695 | UNREACHABLE(); |
| 696 | return NULL; |
| 697 | } |
| 698 | } |
| 699 | private: |
| 700 | Debug::AddressId id_; |
| 701 | int reg_; |
| 702 | }; |
| 703 | |
| 704 | |
| 705 | } } // namespace v8::internal |
| 706 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 707 | #endif // V8_V8_DEBUG_H_ |