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.

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>
  • Loading branch information
pavelfeldman authored and Fishrock123 committed Jul 5, 2016
1 parent 6210528 commit 7d4f038
Show file tree
Hide file tree
Showing 14 changed files with 2,358 additions and 5 deletions.
6 changes: 6 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,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('--without-inspector',
action='store_true',
dest='without_inspector',
help='disable 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 @@ -810,6 +815,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(not options.without_inspector)

if options.use_xcode and options.use_ninja:
raise Exception('--xcode and --ninja cannot be used together.')
Expand Down
14 changes: 14 additions & 0 deletions doc/api/debugger.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,18 @@ process or via URI reference to the listening debugger:
* `node debug <URI>` - Connects to the process via the URI such as
localhost:5858

## V8 Inspector Integration for Node.js

__NOTE: This is an experimental feature.__

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

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

To break on the first line of the application code, provide the `--debug-brk`
flag in addition to `--inspect`.

[TCP-based protocol]: https://github.com/v8/v8/wiki/Debugging-Protocol
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
39 changes: 39 additions & 0 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,28 @@
'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
],
}, {
'defines': [ 'HAVE_INSPECTOR=0' ]
}],
[ 'node_use_openssl=="true"', {
'defines': [ 'HAVE_OPENSSL=1' ],
'sources': [
Expand Down Expand Up @@ -690,7 +712,10 @@
'target_name': 'cctest',
'type': 'executable',
'dependencies': [
'deps/openssl/openssl.gyp:openssl',
'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 @@ -711,6 +736,20 @@
'sources': [
'test/cctest/util.cc',
],

'conditions': [
['v8_inspector=="true"', {
'dependencies': [
'deps/openssl/openssl.gyp:openssl',
'deps/http_parser/http_parser.gyp:http_parser',
'deps/uv/uv.gyp:libuv'
],
'sources': [
'src/inspector_socket.cc',
'test/cctest/test_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 @@ -225,6 +225,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 @@ -5,6 +5,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 @@ -549,6 +552,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 @@ -586,6 +595,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 7d4f038

Please sign in to comment.