OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 25 matching lines...) Expand all Loading... |
36 namespace internal { | 36 namespace internal { |
37 | 37 |
38 // Forward decelrations. | 38 // Forward decelrations. |
39 class DebuggerAgentSession; | 39 class DebuggerAgentSession; |
40 | 40 |
41 | 41 |
42 // Debugger agent which starts a socket listener on the debugger port and | 42 // Debugger agent which starts a socket listener on the debugger port and |
43 // handles connection from a remote debugger. | 43 // handles connection from a remote debugger. |
44 class DebuggerAgent: public Thread { | 44 class DebuggerAgent: public Thread { |
45 public: | 45 public: |
46 explicit DebuggerAgent(const char* name, int port) | 46 DebuggerAgent(Isolate* isolate, const char* name, int port) |
47 : Thread(name), | 47 : Thread(isolate, name), |
48 name_(StrDup(name)), port_(port), | 48 name_(StrDup(name)), port_(port), |
49 server_(OS::CreateSocket()), terminate_(false), | 49 server_(OS::CreateSocket()), terminate_(false), |
50 session_access_(OS::CreateMutex()), session_(NULL), | 50 session_access_(OS::CreateMutex()), session_(NULL), |
51 terminate_now_(OS::CreateSemaphore(0)), | 51 terminate_now_(OS::CreateSemaphore(0)), |
52 listening_(OS::CreateSemaphore(0)) { | 52 listening_(OS::CreateSemaphore(0)) { |
53 ASSERT(instance_ == NULL); | 53 ASSERT(Isolate::Current()->debugger_agent_instance() == NULL); |
54 instance_ = this; | 54 Isolate::Current()->set_debugger_agent_instance(this); |
55 } | 55 } |
56 ~DebuggerAgent() { | 56 ~DebuggerAgent() { |
57 instance_ = NULL; | 57 Isolate::Current()->set_debugger_agent_instance(NULL); |
58 delete server_; | 58 delete server_; |
59 } | 59 } |
60 | 60 |
61 void Shutdown(); | 61 void Shutdown(); |
62 void WaitUntilListening(); | 62 void WaitUntilListening(); |
63 | 63 |
64 private: | 64 private: |
65 void Run(); | 65 void Run(); |
66 void CreateSession(Socket* socket); | 66 void CreateSession(Socket* socket); |
67 void DebuggerMessage(const v8::Debug::Message& message); | 67 void DebuggerMessage(const v8::Debug::Message& message); |
68 void CloseSession(); | 68 void CloseSession(); |
69 void OnSessionClosed(DebuggerAgentSession* session); | 69 void OnSessionClosed(DebuggerAgentSession* session); |
70 | 70 |
71 SmartPointer<const char> name_; // Name of the embedding application. | 71 SmartPointer<const char> name_; // Name of the embedding application. |
72 int port_; // Port to use for the agent. | 72 int port_; // Port to use for the agent. |
73 Socket* server_; // Server socket for listen/accept. | 73 Socket* server_; // Server socket for listen/accept. |
74 bool terminate_; // Termination flag. | 74 bool terminate_; // Termination flag. |
75 Mutex* session_access_; // Mutex guarging access to session_. | 75 Mutex* session_access_; // Mutex guarging access to session_. |
76 DebuggerAgentSession* session_; // Current active session if any. | 76 DebuggerAgentSession* session_; // Current active session if any. |
77 Semaphore* terminate_now_; // Semaphore to signal termination. | 77 Semaphore* terminate_now_; // Semaphore to signal termination. |
78 Semaphore* listening_; | 78 Semaphore* listening_; |
79 | 79 |
80 static DebuggerAgent* instance_; | |
81 | |
82 friend class DebuggerAgentSession; | 80 friend class DebuggerAgentSession; |
83 friend void DebuggerAgentMessageHandler(const v8::Debug::Message& message); | 81 friend void DebuggerAgentMessageHandler(const v8::Debug::Message& message); |
84 | 82 |
85 DISALLOW_COPY_AND_ASSIGN(DebuggerAgent); | 83 DISALLOW_COPY_AND_ASSIGN(DebuggerAgent); |
86 }; | 84 }; |
87 | 85 |
88 | 86 |
89 // Debugger agent session. The session receives requests from the remote | 87 // Debugger agent session. The session receives requests from the remote |
90 // debugger and sends debugger events/responses to the remote debugger. | 88 // debugger and sends debugger events/responses to the remote debugger. |
91 class DebuggerAgentSession: public Thread { | 89 class DebuggerAgentSession: public Thread { |
92 public: | 90 public: |
93 DebuggerAgentSession(DebuggerAgent* agent, Socket* client) | 91 DebuggerAgentSession(Isolate* isolate, DebuggerAgent* agent, Socket* client) |
94 : Thread("v8:DbgAgntSessn"), | 92 : Thread(isolate, "v8:DbgAgntSessn"), |
95 agent_(agent), client_(client) {} | 93 agent_(agent), client_(client) {} |
96 | 94 |
97 void DebuggerMessage(Vector<uint16_t> message); | 95 void DebuggerMessage(Vector<uint16_t> message); |
98 void Shutdown(); | 96 void Shutdown(); |
99 | 97 |
100 private: | 98 private: |
101 void Run(); | 99 void Run(); |
102 | 100 |
103 void DebuggerMessage(Vector<char> message); | 101 void DebuggerMessage(Vector<char> message); |
104 | 102 |
105 DebuggerAgent* agent_; | 103 DebuggerAgent* agent_; |
106 Socket* client_; | 104 Socket* client_; |
107 | 105 |
108 DISALLOW_COPY_AND_ASSIGN(DebuggerAgentSession); | 106 DISALLOW_COPY_AND_ASSIGN(DebuggerAgentSession); |
109 }; | 107 }; |
110 | 108 |
111 | 109 |
112 // Utility methods factored out to be used by the D8 shell as well. | 110 // Utility methods factored out to be used by the D8 shell as well. |
113 class DebuggerAgentUtil { | 111 class DebuggerAgentUtil { |
114 public: | 112 public: |
115 static const char* kContentLength; | 113 static const char* const kContentLength; |
116 static int kContentLengthSize; | 114 static const int kContentLengthSize; |
117 | 115 |
118 static SmartPointer<char> ReceiveMessage(const Socket* conn); | 116 static SmartPointer<char> ReceiveMessage(const Socket* conn); |
119 static bool SendConnectMessage(const Socket* conn, | 117 static bool SendConnectMessage(const Socket* conn, |
120 const char* embedding_host); | 118 const char* embedding_host); |
121 static bool SendMessage(const Socket* conn, const Vector<uint16_t> message); | 119 static bool SendMessage(const Socket* conn, const Vector<uint16_t> message); |
122 static bool SendMessage(const Socket* conn, | 120 static bool SendMessage(const Socket* conn, |
123 const v8::Handle<v8::String> message); | 121 const v8::Handle<v8::String> message); |
124 static int ReceiveAll(const Socket* conn, char* data, int len); | 122 static int ReceiveAll(const Socket* conn, char* data, int len); |
125 }; | 123 }; |
126 | 124 |
127 } } // namespace v8::internal | 125 } } // namespace v8::internal |
128 | 126 |
129 #endif // ENABLE_DEBUGGER_SUPPORT | 127 #endif // ENABLE_DEBUGGER_SUPPORT |
130 | 128 |
131 #endif // V8_DEBUG_AGENT_H_ | 129 #endif // V8_DEBUG_AGENT_H_ |
OLD | NEW |