Start a new debugger thread to listen for commands.
This commit is contained in:
parent
ca881c5aaf
commit
a584ca3678
2 changed files with 40 additions and 31 deletions
|
@ -7,24 +7,18 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "atom/common/atom_version.h"
|
#include "atom/common/atom_version.h"
|
||||||
|
#include "base/bind.h"
|
||||||
#include "base/command_line.h"
|
#include "base/command_line.h"
|
||||||
#include "base/strings/string_number_conversions.h"
|
#include "base/strings/string_number_conversions.h"
|
||||||
#include "v8/include/v8.h"
|
#include "net/socket/stream_socket.h"
|
||||||
|
#include "net/socket/tcp_server_socket.h"
|
||||||
#include "v8/include/v8-debug.h"
|
#include "v8/include/v8-debug.h"
|
||||||
|
|
||||||
#include "atom/common/node_includes.h"
|
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
// static
|
NodeDebugger::NodeDebugger()
|
||||||
uv_async_t NodeDebugger::dispatch_debug_messages_async_;
|
: thread_("NodeDebugger"),
|
||||||
|
weak_factory_(this) {
|
||||||
NodeDebugger::NodeDebugger() {
|
|
||||||
uv_async_init(uv_default_loop(),
|
|
||||||
&dispatch_debug_messages_async_,
|
|
||||||
DispatchDebugMessagesInMainThread);
|
|
||||||
uv_unref(reinterpret_cast<uv_handle_t*>(&dispatch_debug_messages_async_));
|
|
||||||
|
|
||||||
bool use_debug_agent = false;
|
bool use_debug_agent = false;
|
||||||
int port = 5858;
|
int port = 5858;
|
||||||
bool wait_for_connection = false;
|
bool wait_for_connection = false;
|
||||||
|
@ -44,26 +38,32 @@ NodeDebugger::NodeDebugger() {
|
||||||
if (use_debug_agent) {
|
if (use_debug_agent) {
|
||||||
if (!port_str.empty())
|
if (!port_str.empty())
|
||||||
base::StringToInt(port_str, &port);
|
base::StringToInt(port_str, &port);
|
||||||
#if 0
|
|
||||||
v8::Debug::EnableAgent("atom-shell " ATOM_VERSION, port,
|
if (!thread_.Start()) {
|
||||||
wait_for_connection);
|
LOG(ERROR) << "Unable to start debugger thread";
|
||||||
v8::Debug::SetDebugMessageDispatchHandler(DispatchDebugMessagesInMsgThread,
|
return;
|
||||||
false);
|
}
|
||||||
#endif
|
|
||||||
|
net::IPAddressNumber ip_number;
|
||||||
|
if (!net::ParseIPLiteralToNumber("127.0.0.1", &ip_number)) {
|
||||||
|
LOG(ERROR) << "Unable to convert ip address";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
server_socket_.reset(new net::TCPServerSocket(NULL, net::NetLog::Source()));
|
||||||
|
server_socket_->Listen(net::IPEndPoint(ip_number, port), 1);
|
||||||
|
|
||||||
|
thread_.message_loop()->PostTask(
|
||||||
|
FROM_HERE,
|
||||||
|
base::Bind(&NodeDebugger::DoAcceptLoop, weak_factory_.GetWeakPtr()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeDebugger::~NodeDebugger() {
|
NodeDebugger::~NodeDebugger() {
|
||||||
|
thread_.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
void NodeDebugger::DoAcceptLoop() {
|
||||||
void NodeDebugger::DispatchDebugMessagesInMainThread(uv_async_t* handle) {
|
|
||||||
v8::Debug::ProcessDebugMessages();
|
|
||||||
}
|
|
||||||
|
|
||||||
// static
|
|
||||||
void NodeDebugger::DispatchDebugMessagesInMsgThread() {
|
|
||||||
uv_async_send(&dispatch_debug_messages_async_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -5,8 +5,14 @@
|
||||||
#ifndef ATOM_BROWSER_NODE_DEBUGGER_H_
|
#ifndef ATOM_BROWSER_NODE_DEBUGGER_H_
|
||||||
#define ATOM_BROWSER_NODE_DEBUGGER_H_
|
#define ATOM_BROWSER_NODE_DEBUGGER_H_
|
||||||
|
|
||||||
#include "base/basictypes.h"
|
#include "base/memory/scoped_ptr.h"
|
||||||
#include "vendor/node/deps/uv/include/uv.h"
|
#include "base/memory/weak_ptr.h"
|
||||||
|
#include "base/threading/thread.h"
|
||||||
|
|
||||||
|
namespace net {
|
||||||
|
class StreamSocket;
|
||||||
|
class TCPServerSocket;
|
||||||
|
}
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -17,10 +23,13 @@ class NodeDebugger {
|
||||||
virtual ~NodeDebugger();
|
virtual ~NodeDebugger();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void DispatchDebugMessagesInMainThread(uv_async_t* handle);
|
void DoAcceptLoop();
|
||||||
static void DispatchDebugMessagesInMsgThread();
|
|
||||||
|
|
||||||
static uv_async_t dispatch_debug_messages_async_;
|
base::Thread thread_;
|
||||||
|
scoped_ptr<net::TCPServerSocket> server_socket_;
|
||||||
|
scoped_ptr<net::StreamSocket> accepted_socket_;
|
||||||
|
|
||||||
|
base::WeakPtrFactory<NodeDebugger> weak_factory_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(NodeDebugger);
|
DISALLOW_COPY_AND_ASSIGN(NodeDebugger);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue