2015-08-27 12:25:28 +08:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
|
|
|
// 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 "base/command_line.h"
|
2017-05-15 11:16:32 -07:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2017-05-15 09:30:55 -07:00
|
|
|
#include "libplatform/libplatform.h"
|
2017-05-16 14:50:49 -07:00
|
|
|
#include "native_mate/dictionary.h"
|
2017-06-13 00:23:11 +05:30
|
|
|
|
|
|
|
#include "atom/common/node_includes.h"
|
2015-08-27 12:25:28 +08:00
|
|
|
|
|
|
|
namespace atom {
|
|
|
|
|
2018-04-17 21:55:30 -04:00
|
|
|
NodeDebugger::NodeDebugger(node::Environment* env) : env_(env) {}
|
2015-08-27 12:25:28 +08:00
|
|
|
|
2018-04-17 21:55:30 -04:00
|
|
|
NodeDebugger::~NodeDebugger() {}
|
2015-08-27 12:25:28 +08:00
|
|
|
|
2018-01-06 07:58:24 -08:00
|
|
|
void NodeDebugger::Start(node::MultiIsolatePlatform* platform) {
|
2018-04-17 15:41:47 -07:00
|
|
|
auto* inspector = env_->inspector_agent();
|
2017-05-15 09:30:55 -07:00
|
|
|
if (inspector == nullptr)
|
2015-08-27 12:25:28 +08:00
|
|
|
return;
|
|
|
|
|
2017-05-15 09:30:55 -07:00
|
|
|
node::DebugOptions options;
|
2017-05-15 11:16:32 -07:00
|
|
|
for (auto& arg : base::CommandLine::ForCurrentProcess()->argv()) {
|
|
|
|
#if defined(OS_WIN)
|
2017-07-11 10:09:02 -07:00
|
|
|
options.ParseOption("Electron", base::UTF16ToUTF8(arg));
|
2017-05-15 11:16:32 -07:00
|
|
|
#else
|
2017-07-11 10:09:02 -07:00
|
|
|
options.ParseOption("Electron", arg);
|
2017-05-15 11:16:32 -07:00
|
|
|
#endif
|
|
|
|
}
|
2015-08-27 12:25:28 +08:00
|
|
|
|
2018-01-06 07:58:24 -08:00
|
|
|
// Set process._debugWaitConnect if --inspect-brk was specified to stop
|
|
|
|
// the debugger on the first line
|
|
|
|
if (options.wait_for_connect()) {
|
|
|
|
mate::Dictionary process(env_->isolate(), env_->process_object());
|
|
|
|
process.Set("_breakFirstLine", true);
|
2015-08-27 12:25:28 +08:00
|
|
|
}
|
2018-01-06 07:58:24 -08:00
|
|
|
|
|
|
|
inspector->Start(static_cast<node::NodePlatform*>(platform), nullptr,
|
|
|
|
options);
|
|
|
|
DCHECK(env_->inspector_agent()->IsStarted());
|
2015-08-27 12:25:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace atom
|