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 28 matching lines...) Expand all Loading... |
39 | 39 |
40 | 40 |
41 // Debugger agent which starts a socket listener on the debugger port and | 41 // Debugger agent which starts a socket listener on the debugger port and |
42 // handles connection from a remote debugger. | 42 // handles connection from a remote debugger. |
43 class DebuggerAgent: public Thread { | 43 class DebuggerAgent: public Thread { |
44 public: | 44 public: |
45 explicit DebuggerAgent(const char* name, int port) | 45 explicit DebuggerAgent(const char* name, int port) |
46 : name_(StrDup(name)), port_(port), | 46 : name_(StrDup(name)), port_(port), |
47 server_(OS::CreateSocket()), terminate_(false), | 47 server_(OS::CreateSocket()), terminate_(false), |
48 session_access_(OS::CreateMutex()), session_(NULL), | 48 session_access_(OS::CreateMutex()), session_(NULL), |
49 terminate_now_(OS::CreateSemaphore(0)) {} | 49 terminate_now_(OS::CreateSemaphore(0)) { |
50 ~DebuggerAgent() { delete server_; } | 50 ASSERT(instance_ == NULL); |
| 51 instance_ = this; |
| 52 } |
| 53 ~DebuggerAgent() { |
| 54 instance_ = NULL; |
| 55 delete server_; |
| 56 } |
51 | 57 |
52 void Shutdown(); | 58 void Shutdown(); |
53 | 59 |
54 private: | 60 private: |
55 void Run(); | 61 void Run(); |
56 void CreateSession(Socket* socket); | 62 void CreateSession(Socket* socket); |
57 void DebuggerMessage(const uint16_t* message, int length); | 63 void DebuggerMessage(const uint16_t* message, int length); |
58 void CloseSession(); | 64 void CloseSession(); |
59 void OnSessionClosed(DebuggerAgentSession* session); | 65 void OnSessionClosed(DebuggerAgentSession* session); |
60 | 66 |
61 SmartPointer<const char> name_; // Name of the embedding application. | 67 SmartPointer<const char> name_; // Name of the embedding application. |
62 int port_; // Port to use for the agent. | 68 int port_; // Port to use for the agent. |
63 Socket* server_; // Server socket for listen/accept. | 69 Socket* server_; // Server socket for listen/accept. |
64 bool terminate_; // Termination flag. | 70 bool terminate_; // Termination flag. |
65 Mutex* session_access_; // Mutex guarging access to session_. | 71 Mutex* session_access_; // Mutex guarging access to session_. |
66 DebuggerAgentSession* session_; // Current active session if any. | 72 DebuggerAgentSession* session_; // Current active session if any. |
67 Semaphore* terminate_now_; // Semaphore to signal termination. | 73 Semaphore* terminate_now_; // Semaphore to signal termination. |
68 | 74 |
| 75 static DebuggerAgent* instance_; |
| 76 |
69 friend class DebuggerAgentSession; | 77 friend class DebuggerAgentSession; |
70 friend void DebuggerAgentMessageHandler(const uint16_t* message, int length, | 78 friend void DebuggerAgentMessageHandler(const uint16_t* message, int length, |
71 void *data); | 79 v8::Debug::ClientData* client_data); |
72 | 80 |
73 DISALLOW_COPY_AND_ASSIGN(DebuggerAgent); | 81 DISALLOW_COPY_AND_ASSIGN(DebuggerAgent); |
74 }; | 82 }; |
75 | 83 |
76 | 84 |
77 // Debugger agent session. The session receives requests from the remote | 85 // Debugger agent session. The session receives requests from the remote |
78 // debugger and sends debugger events/responses to the remote debugger. | 86 // debugger and sends debugger events/responses to the remote debugger. |
79 class DebuggerAgentSession: public Thread { | 87 class DebuggerAgentSession: public Thread { |
80 public: | 88 public: |
81 DebuggerAgentSession(DebuggerAgent* agent, Socket* client) | 89 DebuggerAgentSession(DebuggerAgent* agent, Socket* client) |
(...skipping 27 matching lines...) Expand all Loading... |
109 static bool SendMessage(const Socket* conn, | 117 static bool SendMessage(const Socket* conn, |
110 const v8::Handle<v8::String> message); | 118 const v8::Handle<v8::String> message); |
111 static int ReceiveAll(const Socket* conn, char* data, int len); | 119 static int ReceiveAll(const Socket* conn, char* data, int len); |
112 }; | 120 }; |
113 | 121 |
114 } } // namespace v8::internal | 122 } } // namespace v8::internal |
115 | 123 |
116 #endif // ENABLE_DEBUGGER_SUPPORT | 124 #endif // ENABLE_DEBUGGER_SUPPORT |
117 | 125 |
118 #endif // V8_V8_DEBUG_AGENT_H_ | 126 #endif // V8_V8_DEBUG_AGENT_H_ |
OLD | NEW |