Skip to content

Commit 7d4f038

Browse files
pavelfeldmanFishrock123
authored andcommitted
src,lib: v8-inspector support
This change introduces experimental v8-inspector support. This brings the DevTools debug protocol allowing Node.js to be debugged with Chrome DevTools native, or through other debuggers supporting that protocol. Partial WebSocket support, to the extent required by DevTools, is included. This is derived from the implementation in Blink. v8-inspector support can be disabled by the --without-inspector configure flag. PR-URL: #6792 Reviewed-By: jasnell - James M Snell <jasnell@gmail.com> Reviewed-By: addaleax - Anna Henningsen <anna@addaleax.net> Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
1 parent 6210528 commit 7d4f038

14 files changed

+2358
-5
lines changed

configure

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,11 @@ parser.add_option('--no-browser-globals',
415415
help='do not export browser globals like setTimeout, console, etc. ' +
416416
'(This mode is not officially supported for regular applications)')
417417

418+
parser.add_option('--without-inspector',
419+
action='store_true',
420+
dest='without_inspector',
421+
help='disable experimental V8 inspector support')
422+
418423
(options, args) = parser.parse_args()
419424

420425
# Expand ~ in the install prefix now, it gets written to multiple files.
@@ -810,6 +815,7 @@ def configure_node(o):
810815
o['variables']['library_files'] = options.linked_module
811816

812817
o['variables']['asan'] = int(options.enable_asan or 0)
818+
o['variables']['v8_inspector'] = b(not options.without_inspector)
813819

814820
if options.use_xcode and options.use_ninja:
815821
raise Exception('--xcode and --ninja cannot be used together.')

doc/api/debugger.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,18 @@ process or via URI reference to the listening debugger:
179179
* `node debug <URI>` - Connects to the process via the URI such as
180180
localhost:5858
181181

182+
## V8 Inspector Integration for Node.js
183+
184+
__NOTE: This is an experimental feature.__
185+
186+
V8 Inspector integration allows attaching Chrome DevTools to Node.js
187+
instances for debugging and profiling.
188+
189+
V8 Inspector can be enabled by passing the `--inspect` flag when starting a
190+
Node.js application. It is also possible to supply a custom port with that flag,
191+
e.g. `--inspect=9222` will accept DevTools connections on port 9222.
192+
193+
To break on the first line of the application code, provide the `--debug-brk`
194+
flag in addition to `--inspect`.
195+
182196
[TCP-based protocol]: https://github.com/v8/v8/wiki/Debugging-Protocol

lib/internal/bootstrap_node.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@
8181
// Start the debugger agent
8282
NativeModule.require('_debugger').start();
8383

84+
} else if (process.argv[1] == '--remote_debugging_server') {
85+
// Start the debugging server
86+
NativeModule.require('internal/inspector/remote_debugging_server');
87+
8488
} else if (process.argv[1] == '--debug-agent') {
8589
// Start the debugger agent
8690
NativeModule.require('_debug_agent').start();

node.gyp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,28 @@
250250
'deps/v8/src/third_party/vtune/v8vtune.gyp:v8_vtune'
251251
],
252252
}],
253+
[ 'v8_inspector=="true"', {
254+
'defines': [
255+
'HAVE_INSPECTOR=1',
256+
'V8_INSPECTOR_USE_STL=1',
257+
],
258+
'sources': [
259+
'src/inspector_agent.cc',
260+
'src/inspector_socket.cc',
261+
'src/inspector_socket.h',
262+
'src/inspector-agent.h',
263+
],
264+
'dependencies': [
265+
'deps/v8_inspector/v8_inspector.gyp:v8_inspector',
266+
],
267+
'include_dirs': [
268+
'deps/v8_inspector',
269+
'deps/v8_inspector/deps/wtf', # temporary
270+
'<(SHARED_INTERMEDIATE_DIR)/blink', # for inspector
271+
],
272+
}, {
273+
'defines': [ 'HAVE_INSPECTOR=0' ]
274+
}],
253275
[ 'node_use_openssl=="true"', {
254276
'defines': [ 'HAVE_OPENSSL=1' ],
255277
'sources': [
@@ -690,7 +712,10 @@
690712
'target_name': 'cctest',
691713
'type': 'executable',
692714
'dependencies': [
715+
'deps/openssl/openssl.gyp:openssl',
716+
'deps/http_parser/http_parser.gyp:http_parser',
693717
'deps/gtest/gtest.gyp:gtest',
718+
'deps/uv/uv.gyp:libuv',
694719
'deps/v8/tools/gyp/v8.gyp:v8',
695720
'deps/v8/tools/gyp/v8.gyp:v8_libplatform'
696721
],
@@ -711,6 +736,20 @@
711736
'sources': [
712737
'test/cctest/util.cc',
713738
],
739+
740+
'conditions': [
741+
['v8_inspector=="true"', {
742+
'dependencies': [
743+
'deps/openssl/openssl.gyp:openssl',
744+
'deps/http_parser/http_parser.gyp:http_parser',
745+
'deps/uv/uv.gyp:libuv'
746+
],
747+
'sources': [
748+
'src/inspector_socket.cc',
749+
'test/cctest/test_inspector_socket.cc'
750+
]
751+
}]
752+
]
714753
}
715754
], # end targets
716755

src/env-inl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ inline Environment::Environment(v8::Local<v8::Context> context,
225225
makecallback_cntr_(0),
226226
async_wrap_uid_(0),
227227
debugger_agent_(this),
228+
#if HAVE_INSPECTOR
229+
inspector_agent_(this),
230+
#endif
228231
http_parser_buffer_(nullptr),
229232
context_(context->GetIsolate(), context) {
230233
// We'll be creating new objects so make sure we've entered the context.

src/env.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
#include "ares.h"
77
#include "debug-agent.h"
8+
#if HAVE_INSPECTOR
9+
#include "inspector_agent.h"
10+
#endif
811
#include "handle_wrap.h"
912
#include "req-wrap.h"
1013
#include "tree.h"
@@ -549,6 +552,12 @@ class Environment {
549552
return &debugger_agent_;
550553
}
551554

555+
#if HAVE_INSPECTOR
556+
inline inspector::Agent* inspector_agent() {
557+
return &inspector_agent_;
558+
}
559+
#endif
560+
552561
typedef ListHead<HandleWrap, &HandleWrap::handle_wrap_queue_> HandleWrapQueue;
553562
typedef ListHead<ReqWrap<uv_req_t>, &ReqWrap<uv_req_t>::req_wrap_queue_>
554563
ReqWrapQueue;
@@ -586,6 +595,9 @@ class Environment {
586595
size_t makecallback_cntr_;
587596
int64_t async_wrap_uid_;
588597
debugger::Agent debugger_agent_;
598+
#if HAVE_INSPECTOR
599+
inspector::Agent inspector_agent_;
600+
#endif
589601

590602
HandleWrapQueue handle_wrap_queue_;
591603
ReqWrapQueue req_wrap_queue_;

0 commit comments

Comments
 (0)