| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_DEBUG_DEBUG_H_ | 5 #ifndef V8_DEBUG_DEBUG_H_ |
| 6 #define V8_DEBUG_DEBUG_H_ | 6 #define V8_DEBUG_DEBUG_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/arguments.h" | 9 #include "src/arguments.h" |
| 10 #include "src/assembler.h" | 10 #include "src/assembler.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 LastStepAction = StepIn | 43 LastStepAction = StepIn |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 // Type of exception break. NOTE: These values are in macros.py as well. | 46 // Type of exception break. NOTE: These values are in macros.py as well. |
| 47 enum ExceptionBreakType { | 47 enum ExceptionBreakType { |
| 48 BreakException = 0, | 48 BreakException = 0, |
| 49 BreakUncaughtException = 1 | 49 BreakUncaughtException = 1 |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 | 52 |
| 53 // Type of exception break. | |
| 54 enum BreakLocatorType { ALL_BREAK_LOCATIONS, CALLS_AND_RETURNS }; | |
| 55 | |
| 56 | |
| 57 // The different types of breakpoint position alignments. | 53 // The different types of breakpoint position alignments. |
| 58 // Must match Debug.BreakPositionAlignment in debug.js | 54 // Must match Debug.BreakPositionAlignment in debug.js |
| 59 enum BreakPositionAlignment { | 55 enum BreakPositionAlignment { |
| 60 STATEMENT_ALIGNED = 0, | 56 STATEMENT_ALIGNED = 0, |
| 61 BREAK_POSITION_ALIGNED = 1 | 57 BREAK_POSITION_ALIGNED = 1 |
| 62 }; | 58 }; |
| 63 | 59 |
| 64 enum DebugBreakType { | 60 enum DebugBreakType { |
| 65 NOT_DEBUG_BREAK, | 61 NOT_DEBUG_BREAK, |
| 66 DEBUGGER_STATEMENT, | 62 DEBUGGER_STATEMENT, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 DebugBreakType type_; | 111 DebugBreakType type_; |
| 116 int position_; | 112 int position_; |
| 117 | 113 |
| 118 friend class CodeBreakIterator; | 114 friend class CodeBreakIterator; |
| 119 friend class BytecodeArrayBreakIterator; | 115 friend class BytecodeArrayBreakIterator; |
| 120 }; | 116 }; |
| 121 | 117 |
| 122 class BreakIterator { | 118 class BreakIterator { |
| 123 public: | 119 public: |
| 124 static std::unique_ptr<BreakIterator> GetIterator( | 120 static std::unique_ptr<BreakIterator> GetIterator( |
| 125 Handle<DebugInfo> debug_info, Handle<AbstractCode> abstract_code, | 121 Handle<DebugInfo> debug_info, Handle<AbstractCode> abstract_code); |
| 126 BreakLocatorType type = ALL_BREAK_LOCATIONS); | |
| 127 | 122 |
| 128 virtual ~BreakIterator() {} | 123 virtual ~BreakIterator() {} |
| 129 | 124 |
| 130 virtual BreakLocation GetBreakLocation() = 0; | 125 virtual BreakLocation GetBreakLocation() = 0; |
| 131 virtual bool Done() const = 0; | 126 virtual bool Done() const = 0; |
| 132 virtual void Next() = 0; | 127 virtual void Next() = 0; |
| 133 | 128 |
| 134 void SkipTo(int count) { | 129 void SkipTo(int count) { |
| 135 while (count-- > 0) Next(); | 130 while (count-- > 0) Next(); |
| 136 } | 131 } |
| 137 | 132 |
| 138 virtual int code_offset() = 0; | 133 virtual int code_offset() = 0; |
| 139 int break_index() const { return break_index_; } | 134 int break_index() const { return break_index_; } |
| 140 inline int position() const { return position_; } | 135 inline int position() const { return position_; } |
| 141 inline int statement_position() const { return statement_position_; } | 136 inline int statement_position() const { return statement_position_; } |
| 142 | 137 |
| 143 virtual bool IsDebugBreak() = 0; | 138 virtual bool IsDebugBreak() = 0; |
| 144 virtual void ClearDebugBreak() = 0; | 139 virtual void ClearDebugBreak() = 0; |
| 145 virtual void SetDebugBreak() = 0; | 140 virtual void SetDebugBreak() = 0; |
| 146 | 141 |
| 147 protected: | 142 protected: |
| 148 explicit BreakIterator(Handle<DebugInfo> debug_info, | 143 explicit BreakIterator(Handle<DebugInfo> debug_info); |
| 149 BreakLocatorType break_locator_type); | |
| 150 | 144 |
| 151 int BreakIndexFromPosition(int position, BreakPositionAlignment alignment); | 145 int BreakIndexFromPosition(int position, BreakPositionAlignment alignment); |
| 152 | 146 |
| 153 Isolate* isolate() { return debug_info_->GetIsolate(); } | 147 Isolate* isolate() { return debug_info_->GetIsolate(); } |
| 154 | 148 |
| 155 Handle<DebugInfo> debug_info_; | 149 Handle<DebugInfo> debug_info_; |
| 156 int break_index_; | 150 int break_index_; |
| 157 int position_; | 151 int position_; |
| 158 int statement_position_; | 152 int statement_position_; |
| 159 BreakLocatorType break_locator_type_; | |
| 160 | 153 |
| 161 private: | 154 private: |
| 162 DisallowHeapAllocation no_gc_; | 155 DisallowHeapAllocation no_gc_; |
| 163 DISALLOW_COPY_AND_ASSIGN(BreakIterator); | 156 DISALLOW_COPY_AND_ASSIGN(BreakIterator); |
| 164 }; | 157 }; |
| 165 | 158 |
| 166 class CodeBreakIterator : public BreakIterator { | 159 class CodeBreakIterator : public BreakIterator { |
| 167 public: | 160 public: |
| 168 CodeBreakIterator(Handle<DebugInfo> debug_info, BreakLocatorType type); | 161 explicit CodeBreakIterator(Handle<DebugInfo> debug_info); |
| 169 ~CodeBreakIterator() override {} | 162 ~CodeBreakIterator() override {} |
| 170 | 163 |
| 171 BreakLocation GetBreakLocation() override; | 164 BreakLocation GetBreakLocation() override; |
| 172 bool Done() const override { return reloc_iterator_.done(); } | 165 bool Done() const override { return reloc_iterator_.done(); } |
| 173 void Next() override; | 166 void Next() override; |
| 174 | 167 |
| 175 bool IsDebugBreak() override; | 168 bool IsDebugBreak() override; |
| 176 void ClearDebugBreak() override; | 169 void ClearDebugBreak() override; |
| 177 void SetDebugBreak() override; | 170 void SetDebugBreak() override; |
| 178 | 171 |
| 179 void SkipToPosition(int position, BreakPositionAlignment alignment); | 172 void SkipToPosition(int position, BreakPositionAlignment alignment); |
| 180 | 173 |
| 181 int code_offset() override { | 174 int code_offset() override { |
| 182 return static_cast<int>(rinfo()->pc() - | 175 return static_cast<int>(rinfo()->pc() - |
| 183 debug_info_->DebugCode()->instruction_start()); | 176 debug_info_->DebugCode()->instruction_start()); |
| 184 } | 177 } |
| 185 | 178 |
| 186 private: | 179 private: |
| 187 int GetModeMask(BreakLocatorType type); | 180 int GetModeMask(); |
| 188 DebugBreakType GetDebugBreakType(); | 181 DebugBreakType GetDebugBreakType(); |
| 189 | 182 |
| 190 RelocInfo::Mode rmode() { return reloc_iterator_.rinfo()->rmode(); } | 183 RelocInfo::Mode rmode() { return reloc_iterator_.rinfo()->rmode(); } |
| 191 RelocInfo* rinfo() { return reloc_iterator_.rinfo(); } | 184 RelocInfo* rinfo() { return reloc_iterator_.rinfo(); } |
| 192 | 185 |
| 193 RelocIterator reloc_iterator_; | 186 RelocIterator reloc_iterator_; |
| 194 SourcePositionTableIterator source_position_iterator_; | 187 SourcePositionTableIterator source_position_iterator_; |
| 195 DISALLOW_COPY_AND_ASSIGN(CodeBreakIterator); | 188 DISALLOW_COPY_AND_ASSIGN(CodeBreakIterator); |
| 196 }; | 189 }; |
| 197 | 190 |
| 198 class BytecodeArrayBreakIterator : public BreakIterator { | 191 class BytecodeArrayBreakIterator : public BreakIterator { |
| 199 public: | 192 public: |
| 200 BytecodeArrayBreakIterator(Handle<DebugInfo> debug_info, | 193 explicit BytecodeArrayBreakIterator(Handle<DebugInfo> debug_info); |
| 201 BreakLocatorType type); | |
| 202 ~BytecodeArrayBreakIterator() override {} | 194 ~BytecodeArrayBreakIterator() override {} |
| 203 | 195 |
| 204 BreakLocation GetBreakLocation() override; | 196 BreakLocation GetBreakLocation() override; |
| 205 bool Done() const override { return source_position_iterator_.done(); } | 197 bool Done() const override { return source_position_iterator_.done(); } |
| 206 void Next() override; | 198 void Next() override; |
| 207 | 199 |
| 208 bool IsDebugBreak() override; | 200 bool IsDebugBreak() override; |
| 209 void ClearDebugBreak() override; | 201 void ClearDebugBreak() override; |
| 210 void SetDebugBreak() override; | 202 void SetDebugBreak() override; |
| 211 | 203 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 | 342 |
| 351 void RunPromiseHook(PromiseHookType type, Handle<JSPromise> promise, | 343 void RunPromiseHook(PromiseHookType type, Handle<JSPromise> promise, |
| 352 Handle<Object> parent); | 344 Handle<Object> parent); |
| 353 | 345 |
| 354 int NextAsyncTaskId(Handle<JSObject> promise); | 346 int NextAsyncTaskId(Handle<JSObject> promise); |
| 355 | 347 |
| 356 bool IsBlackboxed(Handle<SharedFunctionInfo> shared); | 348 bool IsBlackboxed(Handle<SharedFunctionInfo> shared); |
| 357 | 349 |
| 358 void SetDebugDelegate(debug::DebugDelegate* delegate); | 350 void SetDebugDelegate(debug::DebugDelegate* delegate); |
| 359 | 351 |
| 360 // Returns whether the operation succeeded. Compilation can only be triggered | 352 // Returns whether the operation succeeded. |
| 361 // if a valid closure is passed as the second argument, otherwise the shared | 353 bool EnsureDebugInfo(Handle<SharedFunctionInfo> shared); |
| 362 // function needs to be compiled already. | |
| 363 bool EnsureDebugInfo(Handle<SharedFunctionInfo> shared, | |
| 364 Handle<JSFunction> function); | |
| 365 void CreateDebugInfo(Handle<SharedFunctionInfo> shared); | 354 void CreateDebugInfo(Handle<SharedFunctionInfo> shared); |
| 366 static Handle<DebugInfo> GetDebugInfo(Handle<SharedFunctionInfo> shared); | 355 static Handle<DebugInfo> GetDebugInfo(Handle<SharedFunctionInfo> shared); |
| 367 | 356 |
| 368 template <typename C> | 357 template <typename C> |
| 369 bool CompileToRevealInnerFunctions(C* compilable); | 358 bool CompileToRevealInnerFunctions(C* compilable); |
| 370 | 359 |
| 371 // This function is used in FunctionNameUsing* tests. | 360 // This function is used in FunctionNameUsing* tests. |
| 372 Handle<Object> FindSharedFunctionInfoInScript(Handle<Script> script, | 361 Handle<Object> FindSharedFunctionInfoInScript(Handle<Script> script, |
| 373 int position); | 362 int position); |
| 374 | 363 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 private: | 448 private: |
| 460 explicit Debug(Isolate* isolate); | 449 explicit Debug(Isolate* isolate); |
| 461 | 450 |
| 462 void UpdateState(); | 451 void UpdateState(); |
| 463 void UpdateHookOnFunctionCall(); | 452 void UpdateHookOnFunctionCall(); |
| 464 void Unload(); | 453 void Unload(); |
| 465 void SetNextBreakId() { | 454 void SetNextBreakId() { |
| 466 thread_local_.break_id_ = ++thread_local_.break_count_; | 455 thread_local_.break_id_ = ++thread_local_.break_count_; |
| 467 } | 456 } |
| 468 | 457 |
| 458 // Return the number of virtual frames below debugger entry. |
| 459 int CurrentFrameCount(); |
| 460 |
| 469 inline bool ignore_events() const { | 461 inline bool ignore_events() const { |
| 470 return is_suppressed_ || !is_active_ || isolate_->needs_side_effect_check(); | 462 return is_suppressed_ || !is_active_ || isolate_->needs_side_effect_check(); |
| 471 } | 463 } |
| 472 inline bool break_disabled() const { | 464 inline bool break_disabled() const { |
| 473 return break_disabled_ || in_debug_event_listener_; | 465 return break_disabled_ || in_debug_event_listener_; |
| 474 } | 466 } |
| 475 | 467 |
| 476 void clear_suspended_generator() { | 468 void clear_suspended_generator() { |
| 477 thread_local_.suspended_generator_ = Smi::kZero; | 469 thread_local_.suspended_generator_ = Smi::kZero; |
| 478 } | 470 } |
| 479 | 471 |
| 480 bool has_suspended_generator() const { | 472 bool has_suspended_generator() const { |
| 481 return thread_local_.suspended_generator_ != Smi::kZero; | 473 return thread_local_.suspended_generator_ != Smi::kZero; |
| 482 } | 474 } |
| 483 | 475 |
| 484 // There are three types of event listeners: C++ message_handler, | 476 // There are three types of event listeners: C++ message_handler, |
| 485 // JavaScript event listener and C++ event listener. | 477 // JavaScript event listener and C++ event listener. |
| 486 // Currently inspector still uses C++ event listener and installs | 478 // Currently inspector still uses C++ event listener and installs |
| 487 // more specific event listeners for part of events. Calling of | 479 // more specific event listeners for part of events. Calling of |
| 488 // C++ event listener is redundant when more specific event listener | 480 // C++ event listener is redundant when more specific event listener |
| 489 // is presented. Other clients can install JavaScript event listener | 481 // is presented. Other clients can install JavaScript event listener |
| 490 // (e.g. some of NodeJS module). | 482 // (e.g. some of NodeJS module). |
| 491 bool non_inspector_listener_exists() const { | 483 bool non_inspector_listener_exists() const { |
| 492 return !event_listener_.is_null() && !event_listener_->IsForeign(); | 484 return !event_listener_.is_null() && !event_listener_->IsForeign(); |
| 493 } | 485 } |
| 494 | 486 |
| 495 bool IsBlackboxed(SharedFunctionInfo* shared); | |
| 496 bool IsExceptionBlackboxed(bool uncaught); | 487 bool IsExceptionBlackboxed(bool uncaught); |
| 497 | 488 |
| 498 void OnException(Handle<Object> exception, Handle<Object> promise); | 489 void OnException(Handle<Object> exception, Handle<Object> promise); |
| 499 | 490 |
| 500 // Constructors for debug event objects. | 491 // Constructors for debug event objects. |
| 501 MUST_USE_RESULT MaybeHandle<Object> MakeExecutionState(); | 492 MUST_USE_RESULT MaybeHandle<Object> MakeExecutionState(); |
| 502 MUST_USE_RESULT MaybeHandle<Object> MakeBreakEvent( | 493 MUST_USE_RESULT MaybeHandle<Object> MakeBreakEvent( |
| 503 Handle<Object> break_points_hit); | 494 Handle<Object> break_points_hit); |
| 504 MUST_USE_RESULT MaybeHandle<Object> MakeExceptionEvent( | 495 MUST_USE_RESULT MaybeHandle<Object> MakeExceptionEvent( |
| 505 Handle<Object> exception, | 496 Handle<Object> exception, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 519 // Find the closest source position for a break point for a given position. | 510 // Find the closest source position for a break point for a given position. |
| 520 int FindBreakablePosition(Handle<DebugInfo> debug_info, int source_position, | 511 int FindBreakablePosition(Handle<DebugInfo> debug_info, int source_position, |
| 521 BreakPositionAlignment alignment); | 512 BreakPositionAlignment alignment); |
| 522 // Instrument code to break at break points. | 513 // Instrument code to break at break points. |
| 523 void ApplyBreakPoints(Handle<DebugInfo> debug_info); | 514 void ApplyBreakPoints(Handle<DebugInfo> debug_info); |
| 524 // Clear code from instrumentation. | 515 // Clear code from instrumentation. |
| 525 void ClearBreakPoints(Handle<DebugInfo> debug_info); | 516 void ClearBreakPoints(Handle<DebugInfo> debug_info); |
| 526 // Clear all code from instrumentation. | 517 // Clear all code from instrumentation. |
| 527 void ClearAllBreakPoints(); | 518 void ClearAllBreakPoints(); |
| 528 // Instrument a function with one-shots. | 519 // Instrument a function with one-shots. |
| 529 void FloodWithOneShot(Handle<JSFunction> function, | 520 void FloodWithOneShot(Handle<SharedFunctionInfo> function); |
| 530 BreakLocatorType type = ALL_BREAK_LOCATIONS); | |
| 531 // Clear all one-shot instrumentations, but restore break points. | 521 // Clear all one-shot instrumentations, but restore break points. |
| 532 void ClearOneShot(); | 522 void ClearOneShot(); |
| 533 | 523 |
| 534 void ActivateStepOut(StackFrame* frame); | 524 void ActivateStepOut(StackFrame* frame); |
| 535 void RemoveDebugInfoAndClearFromShared(Handle<DebugInfo> debug_info); | 525 void RemoveDebugInfoAndClearFromShared(Handle<DebugInfo> debug_info); |
| 536 MaybeHandle<FixedArray> CheckBreakPoints(Handle<DebugInfo> debug_info, | 526 MaybeHandle<FixedArray> CheckBreakPoints(Handle<DebugInfo> debug_info, |
| 537 BreakLocation* location, | 527 BreakLocation* location, |
| 538 bool* has_break_points = nullptr); | 528 bool* has_break_points = nullptr); |
| 539 bool IsMutedAtCurrentLocation(JavaScriptFrame* frame); | 529 bool IsMutedAtCurrentLocation(JavaScriptFrame* frame); |
| 540 bool CheckBreakPoint(Handle<Object> break_point_object); | 530 bool CheckBreakPoint(Handle<Object> break_point_object); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 // Frame id for the frame of the current break. | 590 // Frame id for the frame of the current break. |
| 601 StackFrame::Id break_frame_id_; | 591 StackFrame::Id break_frame_id_; |
| 602 | 592 |
| 603 // Step action for last step performed. | 593 // Step action for last step performed. |
| 604 StepAction last_step_action_; | 594 StepAction last_step_action_; |
| 605 | 595 |
| 606 // Source statement position from last step next action. | 596 // Source statement position from last step next action. |
| 607 int last_statement_position_; | 597 int last_statement_position_; |
| 608 | 598 |
| 609 // Frame pointer from last step next or step frame action. | 599 // Frame pointer from last step next or step frame action. |
| 610 Address last_fp_; | 600 int last_frame_count_; |
| 611 | 601 |
| 612 // Frame pointer of the target frame we want to arrive at. | 602 // Frame pointer of the target frame we want to arrive at. |
| 613 Address target_fp_; | 603 int target_frame_count_; |
| 614 | 604 |
| 615 // Value of the accumulator at the point of entering the debugger. | 605 // Value of the accumulator at the point of entering the debugger. |
| 616 Object* return_value_; | 606 Object* return_value_; |
| 617 | 607 |
| 618 // The suspended generator object to track when stepping. | 608 // The suspended generator object to track when stepping. |
| 619 Object* suspended_generator_; | 609 Object* suspended_generator_; |
| 620 | 610 |
| 621 // The new frame pointer to drop to when restarting a frame. | 611 // The new frame pointer to drop to when restarting a frame. |
| 622 Address restart_fp_; | 612 Address restart_fp_; |
| 623 | 613 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 Handle<Code> code); | 740 Handle<Code> code); |
| 751 static bool DebugBreakSlotIsPatched(Address pc); | 741 static bool DebugBreakSlotIsPatched(Address pc); |
| 752 static void ClearDebugBreakSlot(Isolate* isolate, Address pc); | 742 static void ClearDebugBreakSlot(Isolate* isolate, Address pc); |
| 753 }; | 743 }; |
| 754 | 744 |
| 755 | 745 |
| 756 } // namespace internal | 746 } // namespace internal |
| 757 } // namespace v8 | 747 } // namespace v8 |
| 758 | 748 |
| 759 #endif // V8_DEBUG_DEBUG_H_ | 749 #endif // V8_DEBUG_DEBUG_H_ |
| OLD | NEW |