| 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 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 | 36 |
| 37 // Forward decelrations. | 37 // Forward decelrations. |
| 38 class DebuggerAgentSession; | 38 class DebuggerAgentSession; |
| 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(int port) | 45 explicit DebuggerAgent(const char* name, int port) |
| 46 : port_(port), server_(OS::CreateSocket()), terminate_(false), | 46 : port_(port), name_(StrDup(name)), |
| 47 server_(OS::CreateSocket()), terminate_(false), |
| 47 session_access_(OS::CreateMutex()), session_(NULL), | 48 session_access_(OS::CreateMutex()), session_(NULL), |
| 48 terminate_now_(OS::CreateSemaphore(0)) {} | 49 terminate_now_(OS::CreateSemaphore(0)) {} |
| 49 ~DebuggerAgent() { delete server_; } | 50 ~DebuggerAgent() { delete server_; } |
| 50 | 51 |
| 51 void Shutdown(); | 52 void Shutdown(); |
| 52 | 53 |
| 53 private: | 54 private: |
| 54 void Run(); | 55 void Run(); |
| 55 void CreateSession(Socket* socket); | 56 void CreateSession(Socket* socket); |
| 56 void DebuggerMessage(const uint16_t* message, int length); | 57 void DebuggerMessage(const uint16_t* message, int length); |
| 57 void CloseSession(); | 58 void CloseSession(); |
| 58 void OnSessionClosed(DebuggerAgentSession* session); | 59 void OnSessionClosed(DebuggerAgentSession* session); |
| 59 | 60 |
| 61 SmartPointer<const char> name_; // Name of the embedding application. |
| 60 int port_; // Port to use for the agent. | 62 int port_; // Port to use for the agent. |
| 61 Socket* server_; // Server socket for listen/accept. | 63 Socket* server_; // Server socket for listen/accept. |
| 62 bool terminate_; // Termination flag. | 64 bool terminate_; // Termination flag. |
| 63 Mutex* session_access_; // Mutex guarging access to session_. | 65 Mutex* session_access_; // Mutex guarging access to session_. |
| 64 DebuggerAgentSession* session_; // Current active session if any. | 66 DebuggerAgentSession* session_; // Current active session if any. |
| 65 Semaphore* terminate_now_; // Semaphore to signal termination. | 67 Semaphore* terminate_now_; // Semaphore to signal termination. |
| 66 | 68 |
| 67 friend class DebuggerAgentSession; | 69 friend class DebuggerAgentSession; |
| 68 friend void DebuggerAgentMessageHandler(const uint16_t* message, int length, | 70 friend void DebuggerAgentMessageHandler(const uint16_t* message, int length, |
| 69 void *data); | 71 void *data); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 94 }; | 96 }; |
| 95 | 97 |
| 96 | 98 |
| 97 // Utility methods factored out to be used by the D8 shell as well. | 99 // Utility methods factored out to be used by the D8 shell as well. |
| 98 class DebuggerAgentUtil { | 100 class DebuggerAgentUtil { |
| 99 public: | 101 public: |
| 100 static const char* kContentLength; | 102 static const char* kContentLength; |
| 101 static int kContentLengthSize; | 103 static int kContentLengthSize; |
| 102 | 104 |
| 103 static SmartPointer<char> ReceiveMessage(const Socket* conn); | 105 static SmartPointer<char> ReceiveMessage(const Socket* conn); |
| 106 static bool SendConnectMessage(const Socket* conn, |
| 107 const char* embedding_host); |
| 104 static bool SendMessage(const Socket* conn, const Vector<uint16_t> message); | 108 static bool SendMessage(const Socket* conn, const Vector<uint16_t> message); |
| 105 static bool SendMessage(const Socket* conn, | 109 static bool SendMessage(const Socket* conn, |
| 106 const v8::Handle<v8::String> message); | 110 const v8::Handle<v8::String> message); |
| 107 static int ReceiveAll(const Socket* conn, char* data, int len); | 111 static int ReceiveAll(const Socket* conn, char* data, int len); |
| 108 }; | 112 }; |
| 109 | 113 |
| 110 | 114 |
| 111 } } // namespace v8::internal | 115 } } // namespace v8::internal |
| 112 | 116 |
| 113 #endif // V8_V8_DEBUG_AGENT_H_ | 117 #endif // V8_V8_DEBUG_AGENT_H_ |
| OLD | NEW |