Skip to content

Commit

Permalink
src,lib: v8-inspector support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pavelfeldman authored and ofrobots committed May 16, 2016
1 parent 477d358 commit 0995140
Show file tree
Hide file tree
Showing 15 changed files with 2,313 additions and 6 deletions.
19 changes: 19 additions & 0 deletions INSPECTOR_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
V8 Inspector Integration for Node.js

This comment has been minimized.

Copy link
@rvagg

rvagg May 25, 2016

Member

The contents of this file can go in to BUILDING.md, it's similar to ICU and FIPS instructions.

This comment has been minimized.

Copy link
@ofrobots

ofrobots May 25, 2016

Contributor

Fixed. Moved to doc/api/debugger.md.

====================================

V8 Inspector integration allows attaching Chrome DevTools to Node.js
instances for debugging and profiling.

## Building

To enable V8 Inspector integration, run configure script with `--with-inspector`
flag. Afterwards, use `make` to build Node.js as usual.

## Running

V8 Inspector can be enabled by passing `--inspect` flag when starting Node.js
application. It is also possible to supply a custom port with that flag, e.g.
`--inspect=9222` will expect DevTools connection on the port 9222.

To break on the first line of the application code, provide the `--debug-brk`
flag in addition to `--inspect`.
2 changes: 2 additions & 0 deletions common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@
['_type!="static_library"', {
'xcode_settings': {
'OTHER_LDFLAGS': [
'-stdlib=libc++',
'-Wl,-no_pie',
'-Wl,-search_paths_first',
],
Expand All @@ -341,6 +342,7 @@
'xcode_settings': {
'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0',
'CLANG_CXX_LANGUAGE_STANDARD': 'gnu++0x', # -std=gnu++0x
'OTHER_CPLUSPLUSFLAGS' : ['-stdlib=libc++'],
},
}],
],
Expand Down
6 changes: 6 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,11 @@ parser.add_option('--no-browser-globals',
help='do not export browser globals like setTimeout, console, etc. ' +
'(This mode is not officially supported for regular applications)')

parser.add_option('--with-inspector',
action='store_true',
dest='inspector',
help='enable experimental V8 inspector support')

(options, args) = parser.parse_args()

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

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

def configure_library(lib, output):
shared_lib = 'shared_' + lib
Expand Down
4 changes: 4 additions & 0 deletions lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@
// Start the debugger agent
NativeModule.require('_debugger').start();

} else if (process.argv[1] == '--remote_debugging_server') {
// Start the debugging server
NativeModule.require('internal/inspector/remote_debugging_server');

} else if (process.argv[1] == '--debug-agent') {
// Start the debugger agent
NativeModule.require('_debug_agent').start();
Expand Down
27 changes: 26 additions & 1 deletion node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
'tools/msvs/genfiles',
'deps/uv/src/ares',
'<(SHARED_INTERMEDIATE_DIR)', # for node_natives.h
'deps/v8' # include/v8_platform.h
'deps/v8', # include/v8_platform.h
],

'sources': [
Expand Down Expand Up @@ -250,6 +250,26 @@
'deps/v8/src/third_party/vtune/v8vtune.gyp:v8_vtune'
],
}],
[ 'v8_inspector=="true"', {
'defines': [
'HAVE_INSPECTOR=1',
'V8_INSPECTOR_USE_STL=1',
],
'sources': [
'src/inspector_agent.cc',
'src/inspector_socket.cc',
'src/inspector_socket.h',
'src/inspector-agent.h',
],
'dependencies': [
'deps/v8_inspector/v8_inspector.gyp:v8_inspector',
],
'include_dirs': [
'deps/v8_inspector',
'deps/v8_inspector/deps/wtf', # temporary
'<(SHARED_INTERMEDIATE_DIR)/blink', # for inspector
],
}],
[ 'node_use_openssl=="true"', {
'defines': [ 'HAVE_OPENSSL=1' ],
'sources': [
Expand Down Expand Up @@ -690,7 +710,10 @@
'target_name': 'cctest',
'type': 'executable',
'dependencies': [
'deps/openssl/openssl.gyp:openssl',

This comment has been minimized.

Copy link
@rvagg

rvagg May 25, 2016

Member

shouldn't these changes (from this line and below) also be behind a 'v8_inspector=="true"' condition? if you configure this branch without inspector enabled, will cctest compile?

This comment has been minimized.

Copy link
@ofrobots

ofrobots May 25, 2016

Contributor

Done.

'deps/http_parser/http_parser.gyp:http_parser',
'deps/gtest/gtest.gyp:gtest',
'deps/uv/uv.gyp:libuv',
'deps/v8/tools/gyp/v8.gyp:v8',
'deps/v8/tools/gyp/v8.gyp:v8_libplatform'
],
Expand All @@ -708,7 +731,9 @@
'GTEST_DONT_DEFINE_ASSERT_NE=1',
],
'sources': [
'src/inspector_socket.cc',
'test/cctest/util.cc',
'test/cctest/inspector_socket.cc',
],
}
], # end targets
Expand Down
3 changes: 3 additions & 0 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ inline Environment::Environment(v8::Local<v8::Context> context,
makecallback_cntr_(0),
async_wrap_uid_(0),
debugger_agent_(this),
#if HAVE_INSPECTOR
inspector_agent_(this),
#endif
http_parser_buffer_(nullptr),
context_(context->GetIsolate(), context) {
// We'll be creating new objects so make sure we've entered the context.
Expand Down
12 changes: 12 additions & 0 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include "ares.h"
#include "debug-agent.h"
#if HAVE_INSPECTOR
#include "inspector_agent.h"
#endif
#include "handle_wrap.h"
#include "req-wrap.h"
#include "tree.h"
Expand Down Expand Up @@ -547,6 +550,12 @@ class Environment {
return &debugger_agent_;
}

#if HAVE_INSPECTOR
inline inspector::Agent* inspector_agent() {
return &inspector_agent_;
}
#endif

typedef ListHead<HandleWrap, &HandleWrap::handle_wrap_queue_> HandleWrapQueue;
typedef ListHead<ReqWrap<uv_req_t>, &ReqWrap<uv_req_t>::req_wrap_queue_>
ReqWrapQueue;
Expand Down Expand Up @@ -584,6 +593,9 @@ class Environment {
size_t makecallback_cntr_;
int64_t async_wrap_uid_;
debugger::Agent debugger_agent_;
#if HAVE_INSPECTOR
inspector::Agent inspector_agent_;
#endif

HandleWrapQueue handle_wrap_queue_;
ReqWrapQueue req_wrap_queue_;
Expand Down
Loading

0 comments on commit 0995140

Please sign in to comment.