2008-12-18 10:06:49 +00:00
|
|
|
// Copyright 2008 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-12-18 10:06:49 +00:00
|
|
|
|
|
|
|
#ifndef V8_D8_DEBUG_H_
|
|
|
|
#define V8_D8_DEBUG_H_
|
|
|
|
|
|
|
|
|
|
|
|
#include "d8.h"
|
|
|
|
#include "debug.h"
|
2014-03-24 13:04:20 +00:00
|
|
|
#include "platform/socket.h"
|
2008-12-18 10:06:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
|
|
|
|
|
2013-07-19 09:38:18 +00:00
|
|
|
void HandleDebugEvent(const Debug::EventDetails& event_details);
|
2008-12-18 10:06:49 +00:00
|
|
|
|
2009-03-04 09:42:51 +00:00
|
|
|
// Start the remove debugger connecting to a V8 debugger agent on the specified
|
|
|
|
// port.
|
2013-03-15 12:06:53 +00:00
|
|
|
void RunRemoteDebugger(Isolate* isolate, int port);
|
2009-03-04 09:42:51 +00:00
|
|
|
|
|
|
|
// Forward declerations.
|
|
|
|
class RemoteDebuggerEvent;
|
|
|
|
class ReceiverThread;
|
|
|
|
|
|
|
|
|
|
|
|
// Remote debugging class.
|
|
|
|
class RemoteDebugger {
|
|
|
|
public:
|
2013-03-15 12:06:53 +00:00
|
|
|
explicit RemoteDebugger(Isolate* isolate, int port)
|
|
|
|
: isolate_(isolate),
|
|
|
|
port_(port),
|
2013-09-02 12:26:06 +00:00
|
|
|
event_available_(0),
|
2011-06-10 12:41:35 +00:00
|
|
|
head_(NULL), tail_(NULL) {}
|
2009-03-04 09:42:51 +00:00
|
|
|
void Run();
|
|
|
|
|
|
|
|
// Handle events from the subordinate threads.
|
2011-09-09 22:39:47 +00:00
|
|
|
void MessageReceived(i::SmartArrayPointer<char> message);
|
|
|
|
void KeyboardCommand(i::SmartArrayPointer<char> command);
|
2009-03-04 09:42:51 +00:00
|
|
|
void ConnectionClosed();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Add new debugger event to the list.
|
|
|
|
void AddEvent(RemoteDebuggerEvent* event);
|
|
|
|
// Read next debugger event from the list.
|
|
|
|
RemoteDebuggerEvent* GetEvent();
|
|
|
|
|
|
|
|
// Handle a message from the debugged V8.
|
|
|
|
void HandleMessageReceived(char* message);
|
|
|
|
// Handle a keyboard command.
|
|
|
|
void HandleKeyboardCommand(char* command);
|
|
|
|
|
|
|
|
// Get connection to agent in debugged V8.
|
|
|
|
i::Socket* conn() { return conn_; }
|
|
|
|
|
2013-03-15 12:06:53 +00:00
|
|
|
Isolate* isolate_;
|
2009-03-04 09:42:51 +00:00
|
|
|
int port_; // Port used to connect to debugger V8.
|
|
|
|
i::Socket* conn_; // Connection to debugger agent in debugged V8.
|
|
|
|
|
|
|
|
// Linked list of events from debugged V8 and from keyboard input. Access to
|
|
|
|
// the list is guarded by a mutex and a semaphore signals new items in the
|
|
|
|
// list.
|
2013-08-29 09:58:30 +00:00
|
|
|
i::Mutex event_access_;
|
2013-09-02 12:26:06 +00:00
|
|
|
i::Semaphore event_available_;
|
2009-03-04 09:42:51 +00:00
|
|
|
RemoteDebuggerEvent* head_;
|
|
|
|
RemoteDebuggerEvent* tail_;
|
|
|
|
|
|
|
|
friend class ReceiverThread;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Thread reading from debugged V8 instance.
|
|
|
|
class ReceiverThread: public i::Thread {
|
|
|
|
public:
|
2011-06-10 12:41:43 +00:00
|
|
|
explicit ReceiverThread(RemoteDebugger* remote_debugger)
|
2011-06-10 12:41:26 +00:00
|
|
|
: Thread("d8:ReceiverThrd"),
|
2011-01-04 09:09:50 +00:00
|
|
|
remote_debugger_(remote_debugger) {}
|
2009-03-04 09:42:51 +00:00
|
|
|
~ReceiverThread() {}
|
|
|
|
|
|
|
|
void Run();
|
|
|
|
|
|
|
|
private:
|
|
|
|
RemoteDebugger* remote_debugger_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Thread reading keyboard input.
|
|
|
|
class KeyboardThread: public i::Thread {
|
|
|
|
public:
|
2011-06-10 12:41:35 +00:00
|
|
|
explicit KeyboardThread(RemoteDebugger* remote_debugger)
|
2011-06-10 12:41:26 +00:00
|
|
|
: Thread("d8:KeyboardThrd"),
|
2011-01-04 09:09:50 +00:00
|
|
|
remote_debugger_(remote_debugger) {}
|
2009-03-04 09:42:51 +00:00
|
|
|
~KeyboardThread() {}
|
|
|
|
|
|
|
|
void Run();
|
|
|
|
|
|
|
|
private:
|
|
|
|
RemoteDebugger* remote_debugger_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Events processed by the main deubgger thread.
|
|
|
|
class RemoteDebuggerEvent {
|
|
|
|
public:
|
2011-09-09 22:39:47 +00:00
|
|
|
RemoteDebuggerEvent(int type, i::SmartArrayPointer<char> data)
|
2009-03-04 09:42:51 +00:00
|
|
|
: type_(type), data_(data), next_(NULL) {
|
|
|
|
ASSERT(type == kMessage || type == kKeyboard || type == kDisconnect);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const int kMessage = 1;
|
|
|
|
static const int kKeyboard = 2;
|
|
|
|
static const int kDisconnect = 3;
|
|
|
|
|
|
|
|
int type() { return type_; }
|
2013-12-09 07:41:20 +00:00
|
|
|
char* data() { return data_.get(); }
|
2009-03-04 09:42:51 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void set_next(RemoteDebuggerEvent* event) { next_ = event; }
|
|
|
|
RemoteDebuggerEvent* next() { return next_; }
|
|
|
|
|
|
|
|
int type_;
|
2011-09-09 22:39:47 +00:00
|
|
|
i::SmartArrayPointer<char> data_;
|
2009-03-04 09:42:51 +00:00
|
|
|
RemoteDebuggerEvent* next_;
|
|
|
|
|
|
|
|
friend class RemoteDebugger;
|
|
|
|
};
|
|
|
|
|
2008-12-18 10:06:49 +00:00
|
|
|
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
|
|
|
|
#endif // V8_D8_DEBUG_H_
|