| 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 DebuggerAgent(Isolate* isolate, const char* name, int port) | 46 DebuggerAgent(const char* name, int port) |
| 47 : Thread(isolate, name), | 47 : Thread(name), |
| 48 isolate_(Isolate::Current()), |
| 48 name_(StrDup(name)), port_(port), | 49 name_(StrDup(name)), port_(port), |
| 49 server_(OS::CreateSocket()), terminate_(false), | 50 server_(OS::CreateSocket()), terminate_(false), |
| 50 session_access_(OS::CreateMutex()), session_(NULL), | 51 session_access_(OS::CreateMutex()), session_(NULL), |
| 51 terminate_now_(OS::CreateSemaphore(0)), | 52 terminate_now_(OS::CreateSemaphore(0)), |
| 52 listening_(OS::CreateSemaphore(0)) { | 53 listening_(OS::CreateSemaphore(0)) { |
| 53 ASSERT(Isolate::Current()->debugger_agent_instance() == NULL); | 54 ASSERT(isolate_->debugger_agent_instance() == NULL); |
| 54 Isolate::Current()->set_debugger_agent_instance(this); | 55 isolate_->set_debugger_agent_instance(this); |
| 55 } | 56 } |
| 56 ~DebuggerAgent() { | 57 ~DebuggerAgent() { |
| 57 Isolate::Current()->set_debugger_agent_instance(NULL); | 58 isolate_->set_debugger_agent_instance(NULL); |
| 58 delete server_; | 59 delete server_; |
| 59 } | 60 } |
| 60 | 61 |
| 61 void Shutdown(); | 62 void Shutdown(); |
| 62 void WaitUntilListening(); | 63 void WaitUntilListening(); |
| 63 | 64 |
| 65 Isolate* isolate() { return isolate_; } |
| 66 |
| 64 private: | 67 private: |
| 65 void Run(); | 68 void Run(); |
| 66 void CreateSession(Socket* socket); | 69 void CreateSession(Socket* socket); |
| 67 void DebuggerMessage(const v8::Debug::Message& message); | 70 void DebuggerMessage(const v8::Debug::Message& message); |
| 68 void CloseSession(); | 71 void CloseSession(); |
| 69 void OnSessionClosed(DebuggerAgentSession* session); | 72 void OnSessionClosed(DebuggerAgentSession* session); |
| 70 | 73 |
| 74 Isolate* isolate_; |
| 71 SmartPointer<const char> name_; // Name of the embedding application. | 75 SmartPointer<const char> name_; // Name of the embedding application. |
| 72 int port_; // Port to use for the agent. | 76 int port_; // Port to use for the agent. |
| 73 Socket* server_; // Server socket for listen/accept. | 77 Socket* server_; // Server socket for listen/accept. |
| 74 bool terminate_; // Termination flag. | 78 bool terminate_; // Termination flag. |
| 75 Mutex* session_access_; // Mutex guarging access to session_. | 79 Mutex* session_access_; // Mutex guarging access to session_. |
| 76 DebuggerAgentSession* session_; // Current active session if any. | 80 DebuggerAgentSession* session_; // Current active session if any. |
| 77 Semaphore* terminate_now_; // Semaphore to signal termination. | 81 Semaphore* terminate_now_; // Semaphore to signal termination. |
| 78 Semaphore* listening_; | 82 Semaphore* listening_; |
| 79 | 83 |
| 80 friend class DebuggerAgentSession; | 84 friend class DebuggerAgentSession; |
| 81 friend void DebuggerAgentMessageHandler(const v8::Debug::Message& message); | 85 friend void DebuggerAgentMessageHandler(const v8::Debug::Message& message); |
| 82 | 86 |
| 83 DISALLOW_COPY_AND_ASSIGN(DebuggerAgent); | 87 DISALLOW_COPY_AND_ASSIGN(DebuggerAgent); |
| 84 }; | 88 }; |
| 85 | 89 |
| 86 | 90 |
| 87 // Debugger agent session. The session receives requests from the remote | 91 // Debugger agent session. The session receives requests from the remote |
| 88 // debugger and sends debugger events/responses to the remote debugger. | 92 // debugger and sends debugger events/responses to the remote debugger. |
| 89 class DebuggerAgentSession: public Thread { | 93 class DebuggerAgentSession: public Thread { |
| 90 public: | 94 public: |
| 91 DebuggerAgentSession(Isolate* isolate, DebuggerAgent* agent, Socket* client) | 95 DebuggerAgentSession(DebuggerAgent* agent, Socket* client) |
| 92 : Thread(isolate, "v8:DbgAgntSessn"), | 96 : Thread("v8:DbgAgntSessn"), |
| 93 agent_(agent), client_(client) {} | 97 agent_(agent), client_(client) {} |
| 94 | 98 |
| 95 void DebuggerMessage(Vector<uint16_t> message); | 99 void DebuggerMessage(Vector<uint16_t> message); |
| 96 void Shutdown(); | 100 void Shutdown(); |
| 97 | 101 |
| 98 private: | 102 private: |
| 99 void Run(); | 103 void Run(); |
| 100 | 104 |
| 101 void DebuggerMessage(Vector<char> message); | 105 void DebuggerMessage(Vector<char> message); |
| 102 | 106 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 120 static bool SendMessage(const Socket* conn, | 124 static bool SendMessage(const Socket* conn, |
| 121 const v8::Handle<v8::String> message); | 125 const v8::Handle<v8::String> message); |
| 122 static int ReceiveAll(const Socket* conn, char* data, int len); | 126 static int ReceiveAll(const Socket* conn, char* data, int len); |
| 123 }; | 127 }; |
| 124 | 128 |
| 125 } } // namespace v8::internal | 129 } } // namespace v8::internal |
| 126 | 130 |
| 127 #endif // ENABLE_DEBUGGER_SUPPORT | 131 #endif // ENABLE_DEBUGGER_SUPPORT |
| 128 | 132 |
| 129 #endif // V8_DEBUG_AGENT_H_ | 133 #endif // V8_DEBUG_AGENT_H_ |
| OLD | NEW |