Skip to content

Commit 0995140

Browse files
pavelfeldmanofrobots
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. This code is currently behind a --with-inspector configure flag.
1 parent 477d358 commit 0995140

15 files changed

+2313
-6
lines changed

INSPECTOR_README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
V8 Inspector Integration for Node.js
2+
====================================
3+
4+
V8 Inspector integration allows attaching Chrome DevTools to Node.js
5+
instances for debugging and profiling.
6+
7+
## Building
8+
9+
To enable V8 Inspector integration, run configure script with `--with-inspector`
10+
flag. Afterwards, use `make` to build Node.js as usual.
11+
12+
## Running
13+
14+
V8 Inspector can be enabled by passing `--inspect` flag when starting Node.js
15+
application. It is also possible to supply a custom port with that flag, e.g.
16+
`--inspect=9222` will expect DevTools connection on the port 9222.
17+
18+
To break on the first line of the application code, provide the `--debug-brk`
19+
flag in addition to `--inspect`.

common.gypi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@
324324
['_type!="static_library"', {
325325
'xcode_settings': {
326326
'OTHER_LDFLAGS': [
327+
'-stdlib=libc++',
327328
'-Wl,-no_pie',
328329
'-Wl,-search_paths_first',
329330
],
@@ -341,6 +342,7 @@
341342
'xcode_settings': {
342343
'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0',
343344
'CLANG_CXX_LANGUAGE_STANDARD': 'gnu++0x', # -std=gnu++0x
345+
'OTHER_CPLUSPLUSFLAGS' : ['-stdlib=libc++'],
344346
},
345347
}],
346348
],

configure

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

411+
parser.add_option('--with-inspector',
412+
action='store_true',
413+
dest='inspector',
414+
help='enable experimental V8 inspector support')
415+
411416
(options, args) = parser.parse_args()
412417

413418
# Expand ~ in the install prefix now, it gets written to multiple files.
@@ -806,6 +811,7 @@ def configure_node(o):
806811
o['variables']['library_files'] = options.linked_module
807812

808813
o['variables']['asan'] = int(options.enable_asan or 0)
814+
o['variables']['v8_inspector'] = b(options.inspector)
809815

810816
def configure_library(lib, output):
811817
shared_lib = 'shared_' + lib

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: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
'tools/msvs/genfiles',
118118
'deps/uv/src/ares',
119119
'<(SHARED_INTERMEDIATE_DIR)', # for node_natives.h
120-
'deps/v8' # include/v8_platform.h
120+
'deps/v8', # include/v8_platform.h
121121
],
122122

123123
'sources': [
@@ -250,6 +250,26 @@
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+
}],
253273
[ 'node_use_openssl=="true"', {
254274
'defines': [ 'HAVE_OPENSSL=1' ],
255275
'sources': [
@@ -690,7 +710,10 @@
690710
'target_name': 'cctest',
691711
'type': 'executable',
692712
'dependencies': [
713+
'deps/openssl/openssl.gyp:openssl',
714+
'deps/http_parser/http_parser.gyp:http_parser',
693715
'deps/gtest/gtest.gyp:gtest',
716+
'deps/uv/uv.gyp:libuv',
694717
'deps/v8/tools/gyp/v8.gyp:v8',
695718
'deps/v8/tools/gyp/v8.gyp:v8_libplatform'
696719
],
@@ -708,7 +731,9 @@
708731
'GTEST_DONT_DEFINE_ASSERT_NE=1',
709732
],
710733
'sources': [
734+
'src/inspector_socket.cc',
711735
'test/cctest/util.cc',
736+
'test/cctest/inspector_socket.cc',
712737
],
713738
}
714739
], # end targets

src/env-inl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ inline Environment::Environment(v8::Local<v8::Context> context,
223223
makecallback_cntr_(0),
224224
async_wrap_uid_(0),
225225
debugger_agent_(this),
226+
#if HAVE_INSPECTOR
227+
inspector_agent_(this),
228+
#endif
226229
http_parser_buffer_(nullptr),
227230
context_(context->GetIsolate(), context) {
228231
// 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
@@ -3,6 +3,9 @@
33

44
#include "ares.h"
55
#include "debug-agent.h"
6+
#if HAVE_INSPECTOR
7+
#include "inspector_agent.h"
8+
#endif
69
#include "handle_wrap.h"
710
#include "req-wrap.h"
811
#include "tree.h"
@@ -547,6 +550,12 @@ class Environment {
547550
return &debugger_agent_;
548551
}
549552

553+
#if HAVE_INSPECTOR
554+
inline inspector::Agent* inspector_agent() {
555+
return &inspector_agent_;
556+
}
557+
#endif
558+
550559
typedef ListHead<HandleWrap, &HandleWrap::handle_wrap_queue_> HandleWrapQueue;
551560
typedef ListHead<ReqWrap<uv_req_t>, &ReqWrap<uv_req_t>::req_wrap_queue_>
552561
ReqWrapQueue;
@@ -584,6 +593,9 @@ class Environment {
584593
size_t makecallback_cntr_;
585594
int64_t async_wrap_uid_;
586595
debugger::Agent debugger_agent_;
596+
#if HAVE_INSPECTOR
597+
inspector::Agent inspector_agent_;
598+
#endif
587599

588600
HandleWrapQueue handle_wrap_queue_;
589601
ReqWrapQueue req_wrap_queue_;

0 commit comments

Comments
 (0)