Add support for --debug switch.
This commit is contained in:
parent
0f617c3d3c
commit
1207dfde4c
5 changed files with 107 additions and 0 deletions
2
atom.gyp
2
atom.gyp
|
@ -121,6 +121,8 @@
|
|||
'atom/browser/net/atom_url_request_job_factory.h',
|
||||
'atom/browser/net/url_request_string_job.cc',
|
||||
'atom/browser/net/url_request_string_job.h',
|
||||
'atom/browser/node_debugger.cc',
|
||||
'atom/browser/node_debugger.h',
|
||||
'atom/browser/ui/accelerator_util.cc',
|
||||
'atom/browser/ui/accelerator_util.h',
|
||||
'atom/browser/ui/accelerator_util_mac.mm',
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "atom/browser/browser.h"
|
||||
#include "atom/browser/javascript_environment.h"
|
||||
#include "atom/browser/node_debugger.h"
|
||||
#include "atom/common/api/atom_bindings.h"
|
||||
#include "atom/common/node_bindings.h"
|
||||
#include "base/command_line.h"
|
||||
|
@ -57,6 +58,9 @@ void AtomBrowserMainParts::PostEarlyInitialization() {
|
|||
|
||||
node_bindings_->Initialize();
|
||||
|
||||
// Support the "--debug" switch.
|
||||
node_debugger_.reset(new NodeDebugger);
|
||||
|
||||
// Create the global environment.
|
||||
global_env = node_bindings_->CreateEnvironment(js_env_->context());
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ class AtomBindings;
|
|||
class Browser;
|
||||
class JavascriptEnvironment;
|
||||
class NodeBindings;
|
||||
class NodeDebugger;
|
||||
|
||||
class AtomBrowserMainParts : public brightray::BrowserMainParts {
|
||||
public:
|
||||
|
@ -40,6 +41,7 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts {
|
|||
scoped_ptr<JavascriptEnvironment> js_env_;
|
||||
scoped_ptr<NodeBindings> node_bindings_;
|
||||
scoped_ptr<AtomBindings> atom_bindings_;
|
||||
scoped_ptr<NodeDebugger> node_debugger_;
|
||||
|
||||
static AtomBrowserMainParts* self_;
|
||||
|
||||
|
|
69
atom/browser/node_debugger.cc
Normal file
69
atom/browser/node_debugger.cc
Normal file
|
@ -0,0 +1,69 @@
|
|||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/node_debugger.h"
|
||||
|
||||
#include "atom/common/atom_version.h"
|
||||
#include "base/command_line.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "v8/include/v8.h"
|
||||
#include "v8/include/v8-debug.h"
|
||||
|
||||
#include "atom/common/node_includes.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
// static
|
||||
uv_async_t NodeDebugger::dispatch_debug_messages_async_;
|
||||
|
||||
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;
|
||||
int port = 5858;
|
||||
bool wait_for_connection = false;
|
||||
|
||||
std::string port_str;
|
||||
base::CommandLine* cmd = base::CommandLine::ForCurrentProcess();
|
||||
if (cmd->HasSwitch("debug")) {
|
||||
use_debug_agent = true;
|
||||
port_str = cmd->GetSwitchValueASCII("debug");
|
||||
}
|
||||
if (cmd->HasSwitch("debug-brk")) {
|
||||
use_debug_agent = true;
|
||||
wait_for_connection = true;
|
||||
port_str = cmd->GetSwitchValueASCII("debug-brk");
|
||||
}
|
||||
|
||||
if (use_debug_agent) {
|
||||
if (!port_str.empty())
|
||||
base::StringToInt(port_str, &port);
|
||||
v8::Debug::EnableAgent("atom-shell " ATOM_VERSION, port,
|
||||
wait_for_connection);
|
||||
v8::Debug::SetDebugMessageDispatchHandler(DispatchDebugMessagesInMsgThread,
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
||||
NodeDebugger::~NodeDebugger() {
|
||||
}
|
||||
|
||||
// static
|
||||
void NodeDebugger::DispatchDebugMessagesInMainThread(uv_async_t* handle) {
|
||||
if (!global_env)
|
||||
return;
|
||||
|
||||
v8::Isolate::Scope isolate_scope(global_env->isolate());
|
||||
v8::Debug::ProcessDebugMessages();
|
||||
}
|
||||
|
||||
// static
|
||||
void NodeDebugger::DispatchDebugMessagesInMsgThread() {
|
||||
uv_async_send(&dispatch_debug_messages_async_);
|
||||
}
|
||||
|
||||
} // namespace atom
|
30
atom/browser/node_debugger.h
Normal file
30
atom/browser/node_debugger.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef ATOM_BROWSER_NODE_DEBUGGER_H_
|
||||
#define ATOM_BROWSER_NODE_DEBUGGER_H_
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "vendor/node/deps/uv/include/uv.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
// Add support for node's "--debug" switch.
|
||||
class NodeDebugger {
|
||||
public:
|
||||
NodeDebugger();
|
||||
virtual ~NodeDebugger();
|
||||
|
||||
private:
|
||||
static void DispatchDebugMessagesInMainThread(uv_async_t* handle);
|
||||
static void DispatchDebugMessagesInMsgThread();
|
||||
|
||||
static uv_async_t dispatch_debug_messages_async_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(NodeDebugger);
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
||||
#endif // ATOM_BROWSER_NODE_DEBUGGER_H_
|
Loading…
Add table
Reference in a new issue