From 6f18215ad968ddb80bbaa6c3c2e75db098741d6e Mon Sep 17 00:00:00 2001 From: cjihrig Date: Wed, 26 Apr 2017 12:20:57 -0400 Subject: [PATCH] src,inspector: add --inspect-silent option --- src/inspector_io.cc | 15 +++++++++++---- src/node_debug_options.cc | 7 ++++++- src/node_debug_options.h | 4 ++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/inspector_io.cc b/src/inspector_io.cc index 613e2f70c253f0..e71ffb11a9a2b9 100644 --- a/src/inspector_io.cc +++ b/src/inspector_io.cc @@ -198,8 +198,11 @@ void InspectorIo::WaitForDisconnect() { if (state_ == State::kConnected) { shutting_down_ = true; Write(TransportAction::kStop, 0, StringView()); - fprintf(stderr, "Waiting for the debugger to disconnect...\n"); - fflush(stderr); + + if (options_.out() != NULL) { + fprintf(options_.out(), "Waiting for the debugger to disconnect...\n"); + fflush(options_.out()); + } parent_env_->inspector_agent()->RunMessageLoop(); } } @@ -257,7 +260,8 @@ void InspectorIo::WorkerRunIO() { delegate_ = &delegate; InspectorSocketServer server(&delegate, options_.host_name(), - options_.port()); + options_.port(), + options_.out()); TransportAndIo queue_transport(&server, this); io_thread_req_.data = &queue_transport; if (!server.Start(&loop)) { @@ -337,7 +341,10 @@ void InspectorIo::DispatchMessages() { CHECK_EQ(session_delegate_, nullptr); session_id_ = std::get<1>(task); state_ = State::kConnected; - fprintf(stderr, "Debugger attached.\n"); + + if (options_.out() != NULL) + fprintf(options_.out(), "Debugger attached.\n"); + session_delegate_ = std::unique_ptr( new IoSessionDelegate(this)); parent_env_->inspector_agent()->Connect(session_delegate_.get()); diff --git a/src/node_debug_options.cc b/src/node_debug_options.cc index b4a819e096f68a..95e6e0dbdc535b 100644 --- a/src/node_debug_options.cc +++ b/src/node_debug_options.cc @@ -61,7 +61,8 @@ DebugOptions::DebugOptions() : debugger_enabled_(false), inspector_enabled_(false), #endif // HAVE_INSPECTOR wait_connect_(false), http_enabled_(false), - host_name_("127.0.0.1"), port_(-1) { } + host_name_("127.0.0.1"), port_(-1), + out_(stderr) { } void DebugOptions::EnableDebugAgent(DebugAgentType tool) { switch (tool) { @@ -101,6 +102,10 @@ bool DebugOptions::ParseOption(const std::string& option) { debugger_enabled_ = true; enable_inspector = true; wait_connect_ = true; + } else if (option_name == "--inspect-silent") { + debugger_enabled_ = true; + enable_inspector = true; + out_ = NULL; } else if ((option_name != "--debug-port" && option_name != "--inspect-port") || !has_argument) { diff --git a/src/node_debug_options.h b/src/node_debug_options.h index d03bdb15497bbf..06ac47f0e85983 100644 --- a/src/node_debug_options.h +++ b/src/node_debug_options.h @@ -34,6 +34,7 @@ class DebugOptions { std::string host_name() const { return host_name_; } int port() const; void set_port(int port) { port_ = port; } + FILE* out() const { return out_; } private: bool debugger_enabled_; @@ -44,6 +45,9 @@ class DebugOptions { bool http_enabled_; std::string host_name_; int port_; +#if HAVE_INSPECTOR + FILE* out_; +#endif // HAVE_INSPECTOR }; } // namespace node