GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage/nodes/benchmark/out/../src/inspector_agent.h Lines: 8 8 100.0 %
Date: 2019-01-07 12:15:22 Branches: 2 4 50.0 %

Line Branch Exec Source
1
#ifndef SRC_INSPECTOR_AGENT_H_
2
#define SRC_INSPECTOR_AGENT_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include <memory>
7
8
#include <stddef.h>
9
10
#if !HAVE_INSPECTOR
11
#error("This header can only be used when inspector is enabled")
12
#endif
13
14
#include "node_options-inl.h"
15
#include "node_persistent.h"
16
#include "v8.h"
17
18
namespace v8_inspector {
19
class StringView;
20
}  // namespace v8_inspector
21
22
namespace node {
23
// Forward declaration to break recursive dependency chain with src/env.h.
24
class Environment;
25
struct ContextInfo;
26
27
namespace inspector {
28
class InspectorIo;
29
class ParentInspectorHandle;
30
class NodeInspectorClient;
31
class WorkerManager;
32
33
224
class InspectorSession {
34
 public:
35
224
  virtual ~InspectorSession() {}
36
  virtual void Dispatch(const v8_inspector::StringView& message) = 0;
37
};
38
39
210
class InspectorSessionDelegate {
40
 public:
41
210
  virtual ~InspectorSessionDelegate() = default;
42
  virtual void SendMessageToFrontend(const v8_inspector::StringView& message)
43
                                     = 0;
44
};
45
46
class Agent {
47
 public:
48
  explicit Agent(node::Environment* env);
49
  ~Agent();
50
51
  // Create client_, may create io_ if option enabled
52
  bool Start(const std::string& path,
53
             const DebugOptions& options,
54
             std::shared_ptr<HostPort> host_port,
55
             bool is_main);
56
  // Stop and destroy io_
57
  void Stop();
58
59
3757
  bool IsListening() { return io_ != nullptr; }
60
  // Returns true if the Node inspector is actually in use. It will be true
61
  // if either the user explicitly opted into inspector (e.g. with the
62
  // --inspect command line flag) or if inspector JS API had been used.
63
  bool IsActive();
64
65
  // Option is set to wait for session connection
66
  bool WillWaitForConnect();
67
  // Blocks till frontend connects and sends "runIfWaitingForDebugger"
68
  void WaitForConnect();
69
  // Blocks till all the sessions with "WaitForDisconnectOnShutdown" disconnect
70
  void WaitForDisconnect();
71
  void FatalException(v8::Local<v8::Value> error,
72
                      v8::Local<v8::Message> message);
73
74
  // Async stack traces instrumentation.
75
  void AsyncTaskScheduled(const v8_inspector::StringView& taskName, void* task,
76
                          bool recurring);
77
  void AsyncTaskCanceled(void* task);
78
  void AsyncTaskStarted(void* task);
79
  void AsyncTaskFinished(void* task);
80
  void AllAsyncTasksCanceled();
81
82
  void RegisterAsyncHook(v8::Isolate* isolate,
83
    v8::Local<v8::Function> enable_function,
84
    v8::Local<v8::Function> disable_function);
85
  void EnableAsyncHook();
86
  void DisableAsyncHook();
87
88
  void AddWorkerInspector(int thread_id, const std::string& url, Agent* agent);
89
90
  // Called to create inspector sessions that can be used from the main thread.
91
  // The inspector responds by using the delegate to send messages back.
92
  std::unique_ptr<InspectorSession> Connect(
93
      std::unique_ptr<InspectorSessionDelegate> delegate,
94
      bool prevent_shutdown);
95
96
  void PauseOnNextJavascriptStatement(const std::string& reason);
97
98
5
  InspectorIo* io() {
99
5
    return io_.get();
100
  }
101
102
  // Can only be called from the main thread.
103
  bool StartIoThread();
104
105
  // Calls StartIoThread() from off the main thread.
106
  void RequestIoThreadStart();
107
108
  const DebugOptions& options() { return debug_options_; }
109
1
  std::shared_ptr<HostPort> host_port() { return host_port_; }
110
  void ContextCreated(v8::Local<v8::Context> context, const ContextInfo& info);
111
112
  // Interface for interacting with inspectors in worker threads
113
  std::shared_ptr<WorkerManager> GetWorkerManager();
114
115
 private:
116
  void ToggleAsyncHook(v8::Isolate* isolate,
117
                       const node::Persistent<v8::Function>& fn);
118
119
  node::Environment* parent_env_;
120
  // Encapsulates majority of the Inspector functionality
121
  std::shared_ptr<NodeInspectorClient> client_;
122
  // Interface for transports, e.g. WebSocket server
123
  std::unique_ptr<InspectorIo> io_;
124
  std::unique_ptr<ParentInspectorHandle> parent_handle_;
125
  std::string path_;
126
127
  // This is a copy of the debug options parsed from CLI in the Environment.
128
  // Do not use the host_port in that, instead manipulate the shared host_port_
129
  // pointer which is meant to store the actual host and port of the inspector
130
  // server.
131
  DebugOptions debug_options_;
132
  std::shared_ptr<HostPort> host_port_;
133
134
  bool pending_enable_async_hook_ = false;
135
  bool pending_disable_async_hook_ = false;
136
  node::Persistent<v8::Function> enable_async_hook_function_;
137
  node::Persistent<v8::Function> disable_async_hook_function_;
138
};
139
140
}  // namespace inspector
141
}  // namespace node
142
143
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
144
145
#endif  // SRC_INSPECTOR_AGENT_H_