My favorites | Sign in
v8
Project Home Downloads Wiki Issues Source Code Search
Checkout   Browse   Changes  
Changes to /trunk/src/debug-agent.h
r2050 vs. r3024 Compare: vs.  Format:
Revision r3024
Go to: 
Project members, sign in to write a code review
/trunk/src/debug-agent.h   r2050 /trunk/src/debug-agent.h   r3024
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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #ifndef V8_DEBUG_AGENT_H_ 28 #ifndef V8_DEBUG_AGENT_H_
29 #define V8_DEBUG_AGENT_H_ 29 #define V8_DEBUG_AGENT_H_
30 30
31 #ifdef ENABLE_DEBUGGER_SUPPORT 31 #ifdef ENABLE_DEBUGGER_SUPPORT
32 #include "../include/v8-debug.h" 32 #include "../include/v8-debug.h"
33 #include "platform.h" 33 #include "platform.h"
34 34
35 namespace v8 { 35 namespace v8 {
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 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
85 // Debugger agent session. The session receives requests from the remote 88 // Debugger agent session. The session receives requests from the remote
86 // debugger and sends debugger events/responses to the remote debugger. 89 // debugger and sends debugger events/responses to the remote debugger.
87 class DebuggerAgentSession: public Thread { 90 class DebuggerAgentSession: public Thread {
88 public: 91 public:
89 DebuggerAgentSession(DebuggerAgent* agent, Socket* client) 92 DebuggerAgentSession(DebuggerAgent* agent, Socket* client)
90 : agent_(agent), client_(client) {} 93 : agent_(agent), client_(client) {}
91 94
92 void DebuggerMessage(Vector<uint16_t> message); 95 void DebuggerMessage(Vector<uint16_t> message);
93 void Shutdown(); 96 void Shutdown();
94 97
95 private: 98 private:
96 void Run(); 99 void Run();
97 100
98 void DebuggerMessage(Vector<char> message); 101 void DebuggerMessage(Vector<char> message);
99 102
100 DebuggerAgent* agent_; 103 DebuggerAgent* agent_;
101 Socket* client_; 104 Socket* client_;
102 105
103 DISALLOW_COPY_AND_ASSIGN(DebuggerAgentSession); 106 DISALLOW_COPY_AND_ASSIGN(DebuggerAgentSession);
104 }; 107 };
105 108
106 109
107 // 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.
108 class DebuggerAgentUtil { 111 class DebuggerAgentUtil {
109 public: 112 public:
110 static const char* kContentLength; 113 static const char* kContentLength;
111 static int kContentLengthSize; 114 static int kContentLengthSize;
112 115
113 static SmartPointer<char> ReceiveMessage(const Socket* conn); 116 static SmartPointer<char> ReceiveMessage(const Socket* conn);
114 static bool SendConnectMessage(const Socket* conn, 117 static bool SendConnectMessage(const Socket* conn,
115 const char* embedding_host); 118 const char* embedding_host);
116 static bool SendMessage(const Socket* conn, const Vector<uint16_t> message); 119 static bool SendMessage(const Socket* conn, const Vector<uint16_t> message);
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_
Powered by Google Project Hosting