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 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 void Iterate(ObjectVisitor* v); | 511 void Iterate(ObjectVisitor* v); |
512 | 512 |
513 bool CheckExecutionState(int id) { | 513 bool CheckExecutionState(int id) { |
514 return CheckExecutionState() && break_id() == id; | 514 return CheckExecutionState() && break_id() == id; |
515 } | 515 } |
516 | 516 |
517 bool CheckExecutionState() { | 517 bool CheckExecutionState() { |
518 return is_active() && !debug_context().is_null() && break_id() != 0; | 518 return is_active() && !debug_context().is_null() && break_id() != 0; |
519 } | 519 } |
520 | 520 |
| 521 bool PerformSideEffectCheck(Handle<JSFunction> function); |
| 522 bool PerformSideEffectCheckForCallback(Address function); |
| 523 |
521 // Flags and states. | 524 // Flags and states. |
522 DebugScope* debugger_entry() { | 525 DebugScope* debugger_entry() { |
523 return reinterpret_cast<DebugScope*>( | 526 return reinterpret_cast<DebugScope*>( |
524 base::NoBarrier_Load(&thread_local_.current_debug_scope_)); | 527 base::NoBarrier_Load(&thread_local_.current_debug_scope_)); |
525 } | 528 } |
526 inline Handle<Context> debug_context() { return debug_context_; } | 529 inline Handle<Context> debug_context() { return debug_context_; } |
527 | 530 |
528 void set_live_edit_enabled(bool v) { live_edit_enabled_ = v; } | 531 void set_live_edit_enabled(bool v) { live_edit_enabled_ = v; } |
529 bool live_edit_enabled() const { | 532 bool live_edit_enabled() const { |
530 return FLAG_enable_liveedit && live_edit_enabled_; | 533 return FLAG_enable_liveedit && live_edit_enabled_; |
(...skipping 13 matching lines...) Expand all Loading... |
544 Handle<Object> return_value() { return thread_local_.return_value_; } | 547 Handle<Object> return_value() { return thread_local_.return_value_; } |
545 void set_return_value(Handle<Object> value) { | 548 void set_return_value(Handle<Object> value) { |
546 thread_local_.return_value_ = value; | 549 thread_local_.return_value_ = value; |
547 } | 550 } |
548 | 551 |
549 // Support for embedding into generated code. | 552 // Support for embedding into generated code. |
550 Address is_active_address() { | 553 Address is_active_address() { |
551 return reinterpret_cast<Address>(&is_active_); | 554 return reinterpret_cast<Address>(&is_active_); |
552 } | 555 } |
553 | 556 |
| 557 Address hook_on_function_call_address() { |
| 558 return reinterpret_cast<Address>(&hook_on_function_call_); |
| 559 } |
| 560 |
554 Address after_break_target_address() { | 561 Address after_break_target_address() { |
555 return reinterpret_cast<Address>(&after_break_target_); | 562 return reinterpret_cast<Address>(&after_break_target_); |
556 } | 563 } |
557 | 564 |
558 Address last_step_action_address() { | 565 Address last_step_action_address() { |
559 return reinterpret_cast<Address>(&thread_local_.last_step_action_); | 566 return reinterpret_cast<Address>(&thread_local_.last_step_action_); |
560 } | 567 } |
561 | 568 |
562 Address suspended_generator_address() { | 569 Address suspended_generator_address() { |
563 return reinterpret_cast<Address>(&thread_local_.suspended_generator_); | 570 return reinterpret_cast<Address>(&thread_local_.suspended_generator_); |
564 } | 571 } |
565 | 572 |
566 StepAction last_step_action() { return thread_local_.last_step_action_; } | 573 StepAction last_step_action() { return thread_local_.last_step_action_; } |
567 | 574 |
568 DebugFeatureTracker* feature_tracker() { return &feature_tracker_; } | 575 DebugFeatureTracker* feature_tracker() { return &feature_tracker_; } |
569 | 576 |
570 private: | 577 private: |
571 explicit Debug(Isolate* isolate); | 578 explicit Debug(Isolate* isolate); |
572 | 579 |
573 void UpdateState(); | 580 void UpdateState(); |
| 581 void UpdateHookOnFunctionCall(); |
574 void Unload(); | 582 void Unload(); |
575 void SetNextBreakId() { | 583 void SetNextBreakId() { |
576 thread_local_.break_id_ = ++thread_local_.break_count_; | 584 thread_local_.break_id_ = ++thread_local_.break_count_; |
577 } | 585 } |
578 | 586 |
579 // Check whether there are commands in the command queue. | 587 // Check whether there are commands in the command queue. |
580 inline bool has_commands() const { return !command_queue_.IsEmpty(); } | 588 inline bool has_commands() const { return !command_queue_.IsEmpty(); } |
581 inline bool ignore_events() const { return is_suppressed_ || !is_active_; } | 589 inline bool ignore_events() const { return is_suppressed_ || !is_active_; } |
582 inline bool break_disabled() const { | 590 inline bool break_disabled() const { |
583 return break_disabled_ || in_debug_event_listener_; | 591 return break_disabled_ || in_debug_event_listener_; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 Handle<Context> debug_context_; | 667 Handle<Context> debug_context_; |
660 Handle<Object> event_listener_; | 668 Handle<Object> event_listener_; |
661 Handle<Object> event_listener_data_; | 669 Handle<Object> event_listener_data_; |
662 | 670 |
663 v8::Debug::MessageHandler message_handler_; | 671 v8::Debug::MessageHandler message_handler_; |
664 | 672 |
665 static const int kQueueInitialSize = 4; | 673 static const int kQueueInitialSize = 4; |
666 base::Semaphore command_received_; // Signaled for each command received. | 674 base::Semaphore command_received_; // Signaled for each command received. |
667 LockingCommandMessageQueue command_queue_; | 675 LockingCommandMessageQueue command_queue_; |
668 | 676 |
| 677 // Debugger is active, i.e. there is a debug event listener attached. |
669 bool is_active_; | 678 bool is_active_; |
| 679 // Debugger needs to be notified on every new function call. |
| 680 // Used for stepping and read-only checks |
| 681 bool hook_on_function_call_; |
| 682 // Suppress debug events. |
670 bool is_suppressed_; | 683 bool is_suppressed_; |
| 684 // LiveEdit is enabled. |
671 bool live_edit_enabled_; | 685 bool live_edit_enabled_; |
| 686 // Do not trigger debug break events. |
672 bool break_disabled_; | 687 bool break_disabled_; |
| 688 // Do not break on break points. |
673 bool break_points_active_; | 689 bool break_points_active_; |
| 690 // Nested inside a debug event listener. |
674 bool in_debug_event_listener_; | 691 bool in_debug_event_listener_; |
| 692 // Trigger debug break events for all exceptions. |
675 bool break_on_exception_; | 693 bool break_on_exception_; |
| 694 // Trigger debug break events for uncaught exceptions. |
676 bool break_on_uncaught_exception_; | 695 bool break_on_uncaught_exception_; |
| 696 // Termination exception because side effect check has failed. |
| 697 bool side_effect_check_failed_; |
677 | 698 |
678 DebugInfoListNode* debug_info_list_; // List of active debug info objects. | 699 // List of active debug info objects. |
| 700 DebugInfoListNode* debug_info_list_; |
679 | 701 |
680 // Storage location for jump when exiting debug break calls. | 702 // Storage location for jump when exiting debug break calls. |
681 // Note that this address is not GC safe. It should be computed immediately | 703 // Note that this address is not GC safe. It should be computed immediately |
682 // before returning to the DebugBreakCallHelper. | 704 // before returning to the DebugBreakCallHelper. |
683 Address after_break_target_; | 705 Address after_break_target_; |
684 | 706 |
685 // Used to collect histogram data on debugger feature usage. | 707 // Used to collect histogram data on debugger feature usage. |
686 DebugFeatureTracker feature_tracker_; | 708 DebugFeatureTracker feature_tracker_; |
687 | 709 |
688 // Per-thread data. | 710 // Per-thread data. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 // Storage location for registers when handling debug break calls | 748 // Storage location for registers when handling debug break calls |
727 ThreadLocal thread_local_; | 749 ThreadLocal thread_local_; |
728 | 750 |
729 Isolate* isolate_; | 751 Isolate* isolate_; |
730 | 752 |
731 friend class Isolate; | 753 friend class Isolate; |
732 friend class DebugScope; | 754 friend class DebugScope; |
733 friend class DisableBreak; | 755 friend class DisableBreak; |
734 friend class LiveEdit; | 756 friend class LiveEdit; |
735 friend class SuppressDebug; | 757 friend class SuppressDebug; |
| 758 friend class NoSideEffectScope; |
736 | 759 |
737 friend Handle<FixedArray> GetDebuggedFunctions(); // In test-debug.cc | 760 friend Handle<FixedArray> GetDebuggedFunctions(); // In test-debug.cc |
738 friend void CheckDebuggerUnloaded(bool check_functions); // In test-debug.cc | 761 friend void CheckDebuggerUnloaded(bool check_functions); // In test-debug.cc |
739 | 762 |
740 DISALLOW_COPY_AND_ASSIGN(Debug); | 763 DISALLOW_COPY_AND_ASSIGN(Debug); |
741 }; | 764 }; |
742 | 765 |
743 | 766 |
744 // This scope is used to load and enter the debug context and create a new | 767 // This scope is used to load and enter the debug context and create a new |
745 // break state. Leaving the scope will restore the previous state. | 768 // break state. Leaving the scope will restore the previous state. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 debug_->is_suppressed_ = true; | 822 debug_->is_suppressed_ = true; |
800 } | 823 } |
801 ~SuppressDebug() { debug_->is_suppressed_ = old_state_; } | 824 ~SuppressDebug() { debug_->is_suppressed_ = old_state_; } |
802 | 825 |
803 private: | 826 private: |
804 Debug* debug_; | 827 Debug* debug_; |
805 bool old_state_; | 828 bool old_state_; |
806 DISALLOW_COPY_AND_ASSIGN(SuppressDebug); | 829 DISALLOW_COPY_AND_ASSIGN(SuppressDebug); |
807 }; | 830 }; |
808 | 831 |
| 832 class NoSideEffectScope { |
| 833 public: |
| 834 NoSideEffectScope(Isolate* isolate, bool disallow_side_effects) |
| 835 : isolate_(isolate), |
| 836 old_needs_side_effect_check_(isolate->needs_side_effect_check()) { |
| 837 isolate->set_needs_side_effect_check(old_needs_side_effect_check_ || |
| 838 disallow_side_effects); |
| 839 isolate->debug()->UpdateHookOnFunctionCall(); |
| 840 isolate->debug()->side_effect_check_failed_ = false; |
| 841 } |
| 842 ~NoSideEffectScope(); |
| 843 |
| 844 private: |
| 845 Isolate* isolate_; |
| 846 bool old_needs_side_effect_check_; |
| 847 DISALLOW_COPY_AND_ASSIGN(NoSideEffectScope); |
| 848 }; |
809 | 849 |
810 // Code generator routines. | 850 // Code generator routines. |
811 class DebugCodegen : public AllStatic { | 851 class DebugCodegen : public AllStatic { |
812 public: | 852 public: |
813 enum DebugBreakCallHelperMode { | 853 enum DebugBreakCallHelperMode { |
814 SAVE_RESULT_REGISTER, | 854 SAVE_RESULT_REGISTER, |
815 IGNORE_RESULT_REGISTER | 855 IGNORE_RESULT_REGISTER |
816 }; | 856 }; |
817 | 857 |
818 static void GenerateDebugBreakStub(MacroAssembler* masm, | 858 static void GenerateDebugBreakStub(MacroAssembler* masm, |
(...skipping 12 matching lines...) Expand all Loading... |
831 Handle<Code> code); | 871 Handle<Code> code); |
832 static bool DebugBreakSlotIsPatched(Address pc); | 872 static bool DebugBreakSlotIsPatched(Address pc); |
833 static void ClearDebugBreakSlot(Isolate* isolate, Address pc); | 873 static void ClearDebugBreakSlot(Isolate* isolate, Address pc); |
834 }; | 874 }; |
835 | 875 |
836 | 876 |
837 } // namespace internal | 877 } // namespace internal |
838 } // namespace v8 | 878 } // namespace v8 |
839 | 879 |
840 #endif // V8_DEBUG_DEBUG_H_ | 880 #endif // V8_DEBUG_DEBUG_H_ |
OLD | NEW |