Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v10.x backport] inspector: workers debugging #22954

Closed
wants to merge 77 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
0718780
fs: implement mkdir recursive (mkdirp)
Aug 9, 2018
08411d8
test: add comment describing test-fs-mkdir
Aug 21, 2018
e22b0ed
url: provide pathToFileURL and fileURLToPath
guybedford Aug 24, 2018
8d64c40
test: check parameter type of fs.mkdir()
Aug 30, 2018
94b662a
test: refactor structure of common/index
jasnell Aug 24, 2018
52877ee
assert: align argument names
BridgeAR Sep 8, 2018
58d0833
doc: add history for withFileTypes in fs.readdir[Sync]()
tiendq Sep 10, 2018
1b6487c
crypto: fix public key encryption internals
tniessen Sep 9, 2018
350ef49
crypto: rename symbols to match guidelines
tniessen Sep 5, 2018
684705c
doc: add gabrielschulhof to TSC
Trott Sep 12, 2018
e0bc988
n-api: add generic finalizer callback
Aug 10, 2018
6e5cd4d
test: checks on napi factory wrap’s finalization
legendecas Aug 31, 2018
17733d3
lib: remove unnecessary symbols
Aug 22, 2018
00a8511
test: minor refactor in common/index.js
jasnell Sep 6, 2018
873ebeb
doc: document http2 timeouts
sagitsofan Sep 10, 2018
c8c922a
doc: add reference to guide for N-API additions
mhdawson Aug 29, 2018
3ec5a64
deps: cherry-pick 2363cdf from upstream V8
ofrobots Sep 11, 2018
ff60980
trace_events: avoid flusing uninitialized traces
ofrobots Sep 12, 2018
e9b5c34
fs: ensure readdir() callback is only called once
cjihrig Sep 10, 2018
2550015
lib: simplify 'processChunkSync'
Sep 11, 2018
ca0a92f
module: add createRequireFunction method
devsnek Mar 14, 2018
217fb2e
worker: correct (de)initialization order
addaleax Sep 9, 2018
e5d67f7
tools: implement update-authors in JS
addaleax Sep 9, 2018
e52ea8b
doc: update AUTHORS list
addaleax Sep 9, 2018
e268b64
src: move getActiveResources/Handles to node_process.cc
jasnell Sep 7, 2018
415eac8
src: move DebugPortGetter/Setter to node_process.cc
jasnell Sep 7, 2018
536c6ed
doc: fix typo in dns docs
MohammedEssehemy Sep 14, 2018
14d1b7a
doc: add withFileTypes option to fsPromises.readdir
bengl Sep 13, 2018
cfced0c
process: generate list of allowed env flags programmatically
addaleax Aug 31, 2018
60dc374
lib: generate allowedNodeEnvironmentFlags lazily
addaleax Aug 31, 2018
d723cbd
doc: add full deprecation history
tniessen Sep 8, 2018
1cf6e3e
fs: fix promisified fs.readdir withFileTypes
apapirovski Sep 13, 2018
466ed2e
src: fix `--prof-process` CLI argument handling
addaleax Sep 10, 2018
572d01c
tracing: remove shutdown-on-signal
addaleax Sep 6, 2018
2f5fad0
path: remove unnecessary if statement
wchargin Aug 11, 2018
75422ab
tools: update ESLint to 5.6.0
Trott Sep 16, 2018
3120dab
src: move no_async_hooks_checks to env
danbev Sep 10, 2018
dfef9a9
doc: add missing options for crypto sign.sign()
mbj36 Sep 12, 2018
5cb642e
assert: add default operator to `assert.fail()`
BridgeAR Sep 4, 2018
1433653
http2: add http2stream.endAfterHeaders property
jasnell Sep 13, 2018
56b17d2
doc: improve asymmetric crypto docs
addaleax Sep 12, 2018
721508d
src: refactor `Environment::GetCurrent()` usage
addaleax Sep 12, 2018
2f88373
build: skip cctest on Windows shared lib build
yhwang Jul 24, 2018
c17ba24
string_decoder: support typed array or data view
BeniCheni Aug 28, 2018
2a3dea5
doc: update 6.x to 8.x in backporting wiki
trivikr Sep 15, 2018
325b82a
inspector: enable Inspector JS API in workers
eugeneo Sep 9, 2018
9ca9e81
errors: add useOriginalName to internal/errors
joyeecheung Aug 27, 2018
e07e573
build: do not lint fixtures in make lint-md
joyeecheung Aug 27, 2018
97f6ff3
doc: add boneskull as collaborator
boneskull Sep 17, 2018
97979b7
tools,win: fix find_python error
kfarnung Sep 10, 2018
85fca5d
tools: merge custom cpplint with cpplint v1.3.0
boneskull Sep 13, 2018
6f66e49
deps: add missing HandleScope in FieldType::PrintTo
hashseed Sep 17, 2018
2b0ce98
crypto: remove unused scrypt validation parameter
tniessen Sep 17, 2018
6975e08
crypto: fix edge case in authenticated encryption
tniessen Sep 12, 2018
57f2c12
test: don't inspect values if not necessary
BridgeAR Sep 17, 2018
bf7d7cf
test: remove string literal message from assertion
Trott Sep 13, 2018
8595d90
test: remove string literal message in assertions
Trott Sep 13, 2018
b9af09d
test: improve assertion in test-inspector.js
Trott Sep 2, 2018
05bec3c
test: simplify assertion in http2 tests
Trott Sep 2, 2018
f04466e
test: refactor flag check
Trott Sep 13, 2018
4fe6034
test: remove string literal from assertion
Trott Sep 13, 2018
136c4a8
test: remove string literal message from assertion
Trott Sep 13, 2018
f2703b2
test: remove string literal arg from assertion
Trott Sep 13, 2018
bd24752
test: remove string literal from assertion
Trott Sep 13, 2018
6f23ec6
test: remove string literal from assertion
Trott Sep 13, 2018
3bf9c17
test: prepare test-assert for strictEqual linting
Trott Sep 13, 2018
0fd614d
tools: prevent string literals in some assertions
Trott Jul 30, 2018
6f02cc5
deps: cherry-pick dbfcc48 from upstream V8
alexkozy Aug 10, 2018
ce58979
src: added URL::FromFilePath method
alexkozy Aug 30, 2018
7f985da
inspector: implemented V8InspectorClient::resourceNameToUrl
alexkozy Aug 30, 2018
f297866
deps: cherry-pick 9a23bdd from upstream V8
Drieger Sep 17, 2018
c68addd
lib,doc: remove unused parameter, improve docs
Sep 14, 2018
89439ac
tools: synchronize deepStrictEqual() message rules
Trott Sep 17, 2018
d46ce65
doc: explain how to invoke gc
isurusiri Apr 30, 2018
d4278a0
doc, win: improve os.setPriority documentation
bzoz Sep 12, 2018
7107451
worker: only stop inspector if started
addaleax Sep 18, 2018
e6250f4
inspector: workers debugging
eugeneo Sep 9, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
inspector: workers debugging
Introduce a NodeTarget inspector domain modelled after ChromeDevTools
Target domain. It notifies inspector frontend attached to a main V8
isolate when workers are starting and allows passing messages to
inspectors on their isolates. All inspector functionality is enabled on
worker isolates.

PR-URL: #21364
Reviewed-By: Aleksei Koziatinskii <ak239spb@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
eugeneo committed Sep 19, 2018
commit e6250f421f02f095fb0fa5d871f0245c9c804938
6 changes: 6 additions & 0 deletions node.gyp
Original file line number Diff line number Diff line change
@@ -508,14 +508,18 @@
'src/inspector_socket.cc',
'src/inspector_socket_server.cc',
'src/inspector/main_thread_interface.cc',
'src/inspector/worker_inspector.cc',
'src/inspector/node_string.cc',
'src/inspector/worker_agent.cc',
'src/inspector/tracing_agent.cc',
'src/inspector_agent.h',
'src/inspector_io.h',
'src/inspector_socket.h',
'src/inspector_socket_server.h',
'src/inspector/main_thread_interface.h',
'src/inspector/worker_inspector.h',
'src/inspector/node_string.h',
'src/inspector/worker_agent.h',
'src/inspector/tracing_agent.h',
'<@(node_inspector_generated_sources)'
],
@@ -1065,6 +1069,8 @@
'<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/Forward.h',
'<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/Protocol.cpp',
'<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/Protocol.h',
'<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/NodeWorker.cpp',
'<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/NodeWorker.h',
'<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/NodeTracing.cpp',
'<(SHARED_INTERMEDIATE_DIR)/src/node/inspector/protocol/NodeTracing.h',
],
55 changes: 55 additions & 0 deletions src/inspector/node_protocol.pdl
Original file line number Diff line number Diff line change
@@ -37,3 +37,58 @@ experimental domain NodeTracing
# Signals that tracing is stopped and there is no trace buffers pending flush, all data were
# delivered via dataCollected events.
event tracingComplete

# Support for sending messages to Node worker Inspector instances.
experimental domain NodeWorker

type WorkerID extends string

# Unique identifier of attached debugging session.
type SessionID extends string

type WorkerInfo extends object
properties
WorkerID workerId
string type
string title
string url

# Sends protocol message over session with given id.
command sendMessageToWorker
parameters
string message
# Identifier of the session.
SessionID sessionId

# Instructs the inspector to attach to running workers. Will also attach to new workers
# as they start
command enable
parameters
# Whether to new workers should be paused until the frontend sends `Runtime.runIfWaitingForDebugger`
# message to run them.
boolean waitForDebuggerOnStart

# Detaches from all running workers and disables attaching to new workers as they are started.
command disable

# Issued when attached to a worker.
event attachedToWorker
parameters
# Identifier assigned to the session used to send/receive messages.
SessionID sessionId
WorkerInfo workerInfo
boolean waitingForDebugger

# Issued when detached from the worker.
event detachedFromWorker
parameters
# Detached session identifier.
SessionID sessionId

# Notifies about a new protocol message received from the session
# (session ID is provided in attachedToWorker notification).
event receivedMessageFromWorker
parameters
# Identifier of a session which sends a message.
SessionID sessionId
string message
7 changes: 1 addition & 6 deletions src/inspector/node_protocol_config.json
Original file line number Diff line number Diff line change
@@ -3,12 +3,7 @@
"path": "node_protocol.json",
"package": "src/node/inspector/protocol",
"output": "node/inspector/protocol",
"namespace": ["node", "inspector", "protocol"],
"options": [
{
"domain": "NodeTracing"
}
]
"namespace": ["node", "inspector", "protocol"]
},
"exported": {
"package": "include/inspector",
154 changes: 154 additions & 0 deletions src/inspector/worker_agent.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#include "worker_agent.h"

#include "main_thread_interface.h"
#include "worker_inspector.h"

namespace node {
namespace inspector {
namespace protocol {

class NodeWorkers
: public std::enable_shared_from_this<NodeWorkers> {
public:
explicit NodeWorkers(std::weak_ptr<NodeWorker::Frontend> frontend,
std::shared_ptr<MainThreadHandle> thread)
: frontend_(frontend), thread_(thread) {}
void WorkerCreated(const std::string& title,
const std::string& url,
bool waiting,
std::shared_ptr<MainThreadHandle> target);
void Receive(const std::string& id, const std::string& message);
void Send(const std::string& id, const std::string& message);
void Detached(const std::string& id);

private:
std::weak_ptr<NodeWorker::Frontend> frontend_;
std::shared_ptr<MainThreadHandle> thread_;
std::unordered_map<std::string, std::unique_ptr<InspectorSession>> sessions_;
int next_target_id_ = 0;
};

namespace {
class AgentWorkerInspectorDelegate : public WorkerDelegate {
public:
explicit AgentWorkerInspectorDelegate(std::shared_ptr<NodeWorkers> workers)
: workers_(workers) {}

void WorkerCreated(const std::string& title,
const std::string& url,
bool waiting,
std::shared_ptr<MainThreadHandle> target) override {
workers_->WorkerCreated(title, url, waiting, target);
}

private:
std::shared_ptr<NodeWorkers> workers_;
};

class ParentInspectorSessionDelegate : public InspectorSessionDelegate {
public:
ParentInspectorSessionDelegate(const std::string& id,
std::shared_ptr<NodeWorkers> workers)
: id_(id), workers_(workers) {}

~ParentInspectorSessionDelegate() override {
workers_->Detached(id_);
}

void SendMessageToFrontend(const v8_inspector::StringView& msg) override {
std::string message = protocol::StringUtil::StringViewToUtf8(msg);
workers_->Send(id_, message);
}

private:
std::string id_;
std::shared_ptr<NodeWorkers> workers_;
};

std::unique_ptr<NodeWorker::WorkerInfo> WorkerInfo(const std::string& id,
const std::string& title,
const std::string& url) {
return NodeWorker::WorkerInfo::create()
.setWorkerId(id)
.setTitle(title)
.setUrl(url)
.setType("worker").build();
}
} // namespace

WorkerAgent::WorkerAgent(std::weak_ptr<WorkerManager> manager)
: manager_(manager) {}


void WorkerAgent::Wire(UberDispatcher* dispatcher) {
frontend_.reset(new NodeWorker::Frontend(dispatcher->channel()));
NodeWorker::Dispatcher::wire(dispatcher, this);
auto manager = manager_.lock();
CHECK_NOT_NULL(manager);
workers_ =
std::make_shared<NodeWorkers>(frontend_, manager->MainThread());
}

DispatchResponse WorkerAgent::sendMessageToWorker(const String& message,
const String& sessionId) {
workers_->Receive(sessionId, message);
return DispatchResponse::OK();
}

DispatchResponse WorkerAgent::enable(bool waitForDebuggerOnStart) {
auto manager = manager_.lock();
if (!manager) {
return DispatchResponse::OK();
}
if (!event_handle_) {
std::unique_ptr<AgentWorkerInspectorDelegate> delegate(
new AgentWorkerInspectorDelegate(workers_));
event_handle_ = manager->SetAutoAttach(std::move(delegate));
}
event_handle_->SetWaitOnStart(waitForDebuggerOnStart);
return DispatchResponse::OK();
}

DispatchResponse WorkerAgent::disable() {
event_handle_.reset();
return DispatchResponse::OK();
}

void NodeWorkers::WorkerCreated(const std::string& title,
const std::string& url,
bool waiting,
std::shared_ptr<MainThreadHandle> target) {
auto frontend = frontend_.lock();
if (!frontend)
return;
std::string id = std::to_string(++next_target_id_);
auto delegate = thread_->MakeDelegateThreadSafe(
std::unique_ptr<InspectorSessionDelegate>(
new ParentInspectorSessionDelegate(id, shared_from_this())));
sessions_[id] = target->Connect(std::move(delegate), true);
frontend->attachedToWorker(id, WorkerInfo(id, title, url), waiting);
}

void NodeWorkers::Send(const std::string& id, const std::string& message) {
auto frontend = frontend_.lock();
if (frontend)
frontend->receivedMessageFromWorker(id, message);
}

void NodeWorkers::Receive(const std::string& id, const std::string& message) {
auto it = sessions_.find(id);
if (it != sessions_.end())
it->second->Dispatch(Utf8ToStringView(message)->string());
}

void NodeWorkers::Detached(const std::string& id) {
if (sessions_.erase(id) == 0)
return;
auto frontend = frontend_.lock();
if (frontend) {
frontend->detachedFromWorker(id);
}
}
} // namespace protocol
} // namespace inspector
} // namespace node
39 changes: 39 additions & 0 deletions src/inspector/worker_agent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef SRC_INSPECTOR_WORKER_AGENT_H_
#define SRC_INSPECTOR_WORKER_AGENT_H_

#include "node/inspector/protocol/NodeWorker.h"
#include "v8.h"


namespace node {
namespace inspector {
class WorkerManagerEventHandle;
class WorkerManager;

namespace protocol {
class NodeWorkers;

class WorkerAgent : public NodeWorker::Backend {
public:
explicit WorkerAgent(std::weak_ptr<WorkerManager> manager);
~WorkerAgent() override = default;

void Wire(UberDispatcher* dispatcher);

DispatchResponse sendMessageToWorker(const String& message,
const String& sessionId) override;

DispatchResponse enable(bool waitForDebuggerOnStart) override;
DispatchResponse disable() override;

private:
std::shared_ptr<NodeWorker::Frontend> frontend_;
std::weak_ptr<WorkerManager> manager_;
std::unique_ptr<WorkerManagerEventHandle> event_handle_;
std::shared_ptr<NodeWorkers> workers_;
};
} // namespace protocol
} // namespace inspector
} // namespace node

#endif // SRC_INSPECTOR_WORKER_AGENT_H_
Loading