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 29 matching lines...) Expand all Loading... |
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 explicit DebuggerAgent(const char* name, int port) |
47 : name_(StrDup(name)), port_(port), | 47 : name_(StrDup(name)), port_(port), |
48 server_(OS::CreateSocket()), terminate_(false), | 48 server_(OS::CreateSocket()), terminate_(false), |
49 session_access_(OS::CreateMutex()), session_(NULL), | 49 session_access_(OS::CreateMutex()), session_(NULL), |
50 terminate_now_(OS::CreateSemaphore(0)) { | 50 terminate_now_(OS::CreateSemaphore(0)), |
| 51 listening_(OS::CreateSemaphore(0)) { |
51 ASSERT(instance_ == NULL); | 52 ASSERT(instance_ == NULL); |
52 instance_ = this; | 53 instance_ = this; |
53 } | 54 } |
54 ~DebuggerAgent() { | 55 ~DebuggerAgent() { |
55 instance_ = NULL; | 56 instance_ = NULL; |
56 delete server_; | 57 delete server_; |
57 } | 58 } |
58 | 59 |
59 void Shutdown(); | 60 void Shutdown(); |
| 61 void WaitUntilListening(); |
60 | 62 |
61 private: | 63 private: |
62 void Run(); | 64 void Run(); |
63 void CreateSession(Socket* socket); | 65 void CreateSession(Socket* socket); |
64 void DebuggerMessage(const v8::Debug::Message& message); | 66 void DebuggerMessage(const v8::Debug::Message& message); |
65 void CloseSession(); | 67 void CloseSession(); |
66 void OnSessionClosed(DebuggerAgentSession* session); | 68 void OnSessionClosed(DebuggerAgentSession* session); |
67 | 69 |
68 SmartPointer<const char> name_; // Name of the embedding application. | 70 SmartPointer<const char> name_; // Name of the embedding application. |
69 int port_; // Port to use for the agent. | 71 int port_; // Port to use for the agent. |
70 Socket* server_; // Server socket for listen/accept. | 72 Socket* server_; // Server socket for listen/accept. |
71 bool terminate_; // Termination flag. | 73 bool terminate_; // Termination flag. |
72 Mutex* session_access_; // Mutex guarging access to session_. | 74 Mutex* session_access_; // Mutex guarging access to session_. |
73 DebuggerAgentSession* session_; // Current active session if any. | 75 DebuggerAgentSession* session_; // Current active session if any. |
74 Semaphore* terminate_now_; // Semaphore to signal termination. | 76 Semaphore* terminate_now_; // Semaphore to signal termination. |
| 77 Semaphore* listening_; |
75 | 78 |
76 static DebuggerAgent* instance_; | 79 static DebuggerAgent* instance_; |
77 | 80 |
78 friend class DebuggerAgentSession; | 81 friend class DebuggerAgentSession; |
79 friend void DebuggerAgentMessageHandler(const v8::Debug::Message& message); | 82 friend void DebuggerAgentMessageHandler(const v8::Debug::Message& message); |
80 | 83 |
81 DISALLOW_COPY_AND_ASSIGN(DebuggerAgent); | 84 DISALLOW_COPY_AND_ASSIGN(DebuggerAgent); |
82 }; | 85 }; |
83 | 86 |
84 | 87 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 static bool SendMessage(const Socket* conn, | 120 static bool SendMessage(const Socket* conn, |
118 const v8::Handle<v8::String> message); | 121 const v8::Handle<v8::String> message); |
119 static int ReceiveAll(const Socket* conn, char* data, int len); | 122 static int ReceiveAll(const Socket* conn, char* data, int len); |
120 }; | 123 }; |
121 | 124 |
122 } } // namespace v8::internal | 125 } } // namespace v8::internal |
123 | 126 |
124 #endif // ENABLE_DEBUGGER_SUPPORT | 127 #endif // ENABLE_DEBUGGER_SUPPORT |
125 | 128 |
126 #endif // V8_DEBUG_AGENT_H_ | 129 #endif // V8_DEBUG_AGENT_H_ |
OLD | NEW |