1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
11 #include "platform/socket.h"
17 void HandleDebugEvent(const Debug::EventDetails& event_details);
19 // Start the remove debugger connecting to a V8 debugger agent on the specified
21 void RunRemoteDebugger(Isolate* isolate, int port);
23 // Forward declerations.
24 class RemoteDebuggerEvent;
28 // Remote debugging class.
29 class RemoteDebugger {
31 explicit RemoteDebugger(Isolate* isolate, int port)
35 head_(NULL), tail_(NULL) {}
38 // Handle events from the subordinate threads.
39 void MessageReceived(i::SmartArrayPointer<char> message);
40 void KeyboardCommand(i::SmartArrayPointer<char> command);
41 void ConnectionClosed();
44 // Add new debugger event to the list.
45 void AddEvent(RemoteDebuggerEvent* event);
46 // Read next debugger event from the list.
47 RemoteDebuggerEvent* GetEvent();
49 // Handle a message from the debugged V8.
50 void HandleMessageReceived(char* message);
51 // Handle a keyboard command.
52 void HandleKeyboardCommand(char* command);
54 // Get connection to agent in debugged V8.
55 i::Socket* conn() { return conn_; }
58 int port_; // Port used to connect to debugger V8.
59 i::Socket* conn_; // Connection to debugger agent in debugged V8.
61 // Linked list of events from debugged V8 and from keyboard input. Access to
62 // the list is guarded by a mutex and a semaphore signals new items in the
64 i::Mutex event_access_;
65 i::Semaphore event_available_;
66 RemoteDebuggerEvent* head_;
67 RemoteDebuggerEvent* tail_;
69 friend class ReceiverThread;
73 // Thread reading from debugged V8 instance.
74 class ReceiverThread: public i::Thread {
76 explicit ReceiverThread(RemoteDebugger* remote_debugger)
77 : Thread("d8:ReceiverThrd"),
78 remote_debugger_(remote_debugger) {}
84 RemoteDebugger* remote_debugger_;
88 // Thread reading keyboard input.
89 class KeyboardThread: public i::Thread {
91 explicit KeyboardThread(RemoteDebugger* remote_debugger)
92 : Thread("d8:KeyboardThrd"),
93 remote_debugger_(remote_debugger) {}
99 RemoteDebugger* remote_debugger_;
103 // Events processed by the main deubgger thread.
104 class RemoteDebuggerEvent {
106 RemoteDebuggerEvent(int type, i::SmartArrayPointer<char> data)
107 : type_(type), data_(data), next_(NULL) {
108 ASSERT(type == kMessage || type == kKeyboard || type == kDisconnect);
111 static const int kMessage = 1;
112 static const int kKeyboard = 2;
113 static const int kDisconnect = 3;
115 int type() { return type_; }
116 char* data() { return data_.get(); }
119 void set_next(RemoteDebuggerEvent* event) { next_ = event; }
120 RemoteDebuggerEvent* next() { return next_; }
123 i::SmartArrayPointer<char> data_;
124 RemoteDebuggerEvent* next_;
126 friend class RemoteDebugger;
133 #endif // V8_D8_DEBUG_H_