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_H_ | 5 #ifndef V8_DEBUG_H_ |
6 #define V8_DEBUG_H_ | 6 #define V8_DEBUG_H_ |
7 | 7 |
8 #include "allocation.h" | 8 #include "allocation.h" |
9 #include "arguments.h" | 9 #include "arguments.h" |
10 #include "assembler.h" | 10 #include "assembler.h" |
11 #include "debug-agent.h" | |
12 #include "execution.h" | 11 #include "execution.h" |
13 #include "factory.h" | 12 #include "factory.h" |
14 #include "flags.h" | 13 #include "flags.h" |
15 #include "frames-inl.h" | 14 #include "frames-inl.h" |
16 #include "hashmap.h" | 15 #include "hashmap.h" |
17 #include "platform.h" | 16 #include "platform.h" |
18 #include "string-stream.h" | 17 #include "string-stream.h" |
19 #include "v8threads.h" | 18 #include "v8threads.h" |
20 | 19 |
21 #include "../include/v8-debug.h" | 20 #include "../include/v8-debug.h" |
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 void OnScriptCollected(int id); | 775 void OnScriptCollected(int id); |
777 void ProcessDebugEvent(v8::DebugEvent event, | 776 void ProcessDebugEvent(v8::DebugEvent event, |
778 Handle<JSObject> event_data, | 777 Handle<JSObject> event_data, |
779 bool auto_continue); | 778 bool auto_continue); |
780 void NotifyMessageHandler(v8::DebugEvent event, | 779 void NotifyMessageHandler(v8::DebugEvent event, |
781 Handle<JSObject> exec_state, | 780 Handle<JSObject> exec_state, |
782 Handle<JSObject> event_data, | 781 Handle<JSObject> event_data, |
783 bool auto_continue); | 782 bool auto_continue); |
784 void SetEventListener(Handle<Object> callback, Handle<Object> data); | 783 void SetEventListener(Handle<Object> callback, Handle<Object> data); |
785 void SetMessageHandler(v8::Debug::MessageHandler2 handler); | 784 void SetMessageHandler(v8::Debug::MessageHandler2 handler); |
786 void SetDebugMessageDispatchHandler( | |
787 v8::Debug::DebugMessageDispatchHandler handler, | |
788 bool provide_locker); | |
789 | |
790 // Invoke the message handler function. | |
791 void InvokeMessageHandler(MessageImpl message); | |
792 | 785 |
793 // Add a debugger command to the command queue. | 786 // Add a debugger command to the command queue. |
794 void ProcessCommand(Vector<const uint16_t> command, | 787 void EnqueueCommandMessage(Vector<const uint16_t> command, |
795 v8::Debug::ClientData* client_data = NULL); | 788 v8::Debug::ClientData* client_data = NULL); |
796 | 789 |
797 // Check whether there are commands in the command queue. | 790 // Check whether there are commands in the command queue. |
798 bool HasCommands(); | 791 bool HasCommands(); |
799 | 792 |
800 // Enqueue a debugger command to the command queue for event listeners. | 793 // Enqueue a debugger command to the command queue for event listeners. |
801 void EnqueueDebugCommand(v8::Debug::ClientData* client_data = NULL); | 794 void EnqueueDebugCommand(v8::Debug::ClientData* client_data = NULL); |
802 | 795 |
803 MUST_USE_RESULT MaybeHandle<Object> Call(Handle<JSFunction> fun, | 796 MUST_USE_RESULT MaybeHandle<Object> Call(Handle<JSFunction> fun, |
804 Handle<Object> data); | 797 Handle<Object> data); |
805 | 798 |
806 // Start the debugger agent listening on the provided port. | |
807 bool StartAgent(const char* name, int port, | |
808 bool wait_for_connection = false); | |
809 | |
810 // Stop the debugger agent. | |
811 void StopAgent(); | |
812 | |
813 // Blocks until the agent has started listening for connections | |
814 void WaitForAgent(); | |
815 | |
816 void CallMessageDispatchHandler(); | |
817 | |
818 Handle<Context> GetDebugContext(); | 799 Handle<Context> GetDebugContext(); |
819 | 800 |
820 // Unload the debugger if possible. Only called when no debugger is currently | 801 // Unload the debugger if possible. Only called when no debugger is currently |
821 // active. | 802 // active. |
822 void UnloadDebugger(); | 803 void UnloadDebugger(); |
823 friend void ForceUnloadDebugger(); // In test-debug.cc | 804 friend void ForceUnloadDebugger(); // In test-debug.cc |
824 | 805 |
825 inline bool EventActive() { | 806 inline bool EventActive() { |
826 LockGuard<RecursiveMutex> lock_guard(&debugger_access_); | 807 LockGuard<RecursiveMutex> lock_guard(&debugger_access_); |
827 | 808 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 v8::Debug::ClientData* client_data); | 856 v8::Debug::ClientData* client_data); |
876 void CallCEventCallback(v8::DebugEvent event, | 857 void CallCEventCallback(v8::DebugEvent event, |
877 Handle<Object> exec_state, | 858 Handle<Object> exec_state, |
878 Handle<Object> event_data, | 859 Handle<Object> event_data, |
879 v8::Debug::ClientData* client_data); | 860 v8::Debug::ClientData* client_data); |
880 void CallJSEventCallback(v8::DebugEvent event, | 861 void CallJSEventCallback(v8::DebugEvent event, |
881 Handle<Object> exec_state, | 862 Handle<Object> exec_state, |
882 Handle<Object> event_data); | 863 Handle<Object> event_data); |
883 void ListenersChanged(); | 864 void ListenersChanged(); |
884 | 865 |
| 866 // Invoke the message handler function. |
| 867 void InvokeMessageHandler(MessageImpl message); |
| 868 |
885 RecursiveMutex debugger_access_; // Mutex guarding debugger variables. | 869 RecursiveMutex debugger_access_; // Mutex guarding debugger variables. |
886 Handle<Object> event_listener_; // Global handle to listener. | 870 Handle<Object> event_listener_; // Global handle to listener. |
887 Handle<Object> event_listener_data_; | 871 Handle<Object> event_listener_data_; |
888 bool is_active_; | 872 bool is_active_; |
889 bool ignore_debugger_; // Are we temporarily ignoring the debugger? | 873 bool ignore_debugger_; // Are we temporarily ignoring the debugger? |
890 bool live_edit_enabled_; // Enable LiveEdit. | 874 bool live_edit_enabled_; // Enable LiveEdit. |
891 bool never_unload_debugger_; // Can we unload the debugger? | 875 bool never_unload_debugger_; // Can we unload the debugger? |
892 v8::Debug::MessageHandler2 message_handler_; | 876 v8::Debug::MessageHandler2 message_handler_; |
893 bool debugger_unload_pending_; // Was message handler cleared? | 877 bool debugger_unload_pending_; // Was message handler cleared? |
894 | 878 |
895 Mutex dispatch_handler_access_; // Mutex guarding dispatch handler. | |
896 v8::Debug::DebugMessageDispatchHandler debug_message_dispatch_handler_; | |
897 MessageDispatchHelperThread* message_dispatch_helper_thread_; | |
898 | |
899 DebuggerAgent* agent_; | |
900 | |
901 static const int kQueueInitialSize = 4; | 879 static const int kQueueInitialSize = 4; |
902 LockingCommandMessageQueue command_queue_; | 880 LockingCommandMessageQueue command_queue_; |
903 Semaphore command_received_; // Signaled for each command received. | 881 Semaphore command_received_; // Signaled for each command received. |
904 LockingCommandMessageQueue event_command_queue_; | 882 LockingCommandMessageQueue event_command_queue_; |
905 | 883 |
906 Isolate* isolate_; | 884 Isolate* isolate_; |
907 | 885 |
908 friend class EnterDebugger; | 886 friend class EnterDebugger; |
909 friend class Isolate; | 887 friend class Isolate; |
910 | 888 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 default: | 965 default: |
988 UNREACHABLE(); | 966 UNREACHABLE(); |
989 return NULL; | 967 return NULL; |
990 } | 968 } |
991 } | 969 } |
992 | 970 |
993 private: | 971 private: |
994 Debug::AddressId id_; | 972 Debug::AddressId id_; |
995 }; | 973 }; |
996 | 974 |
997 // The optional thread that Debug Agent may use to temporary call V8 to process | |
998 // pending debug requests if debuggee is not running V8 at the moment. | |
999 // Techincally it does not call V8 itself, rather it asks embedding program | |
1000 // to do this via v8::Debug::HostDispatchHandler | |
1001 class MessageDispatchHelperThread: public Thread { | |
1002 public: | |
1003 explicit MessageDispatchHelperThread(Isolate* isolate); | |
1004 ~MessageDispatchHelperThread() {} | |
1005 | |
1006 void Schedule(); | |
1007 | |
1008 private: | |
1009 void Run(); | |
1010 | |
1011 Isolate* isolate_; | |
1012 Semaphore sem_; | |
1013 Mutex mutex_; | |
1014 bool already_signalled_; | |
1015 | |
1016 DISALLOW_COPY_AND_ASSIGN(MessageDispatchHelperThread); | |
1017 }; | |
1018 | |
1019 | |
1020 } } // namespace v8::internal | 975 } } // namespace v8::internal |
1021 | 976 |
1022 #endif // V8_DEBUG_H_ | 977 #endif // V8_DEBUG_H_ |
OLD | NEW |