Skip to content

Commit bd4454f

Browse files
ofrobotsevanlucas
authored andcommitted
src,lib: minor --debug-brk cleanup
Minor cleanup of how --debug-brk works: * We no longer need to use command line flags to expose the debug object. * Do not depend on the existence of global.v8debug as a mechanism to determine if --debug-brk was specified. * We no longer need to set a dummy listener with --debug-brk. PR-URL: #6599 Reviewed-By: bnoordhuis - Ben Noordhuis <[email protected]> Reviewed-By: cjihrig - Colin Ihrig <[email protected]>
1 parent 04697a5 commit bd4454f

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

lib/internal/bootstrap_node.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136

137137
preloadModules();
138138

139-
if (global.v8debug &&
139+
if (process._debugWaitConnect &&
140140
process.execArgv.some(function(arg) {
141141
return arg.match(/^--debug-brk(=[0-9]*)?$/);
142142
})) {
@@ -149,7 +149,7 @@
149149
// breakpoint message on line 1.
150150
//
151151
// A better fix would be to somehow get a message from the
152-
// global.v8debug object about a connection, and runMain when
152+
// V8 debug object about a connection, and runMain when
153153
// that occurs. --isaacs
154154

155155
var debugTimeout = +process.env.NODE_DEBUG_TIMEOUT || 50;

lib/module.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const NativeModule = require('native_module');
44
const util = require('util');
55
const internalModule = require('internal/module');
66
const internalUtil = require('internal/util');
7-
const runInThisContext = require('vm').runInThisContext;
7+
const vm = require('vm');
88
const assert = require('assert').ok;
99
const fs = require('fs');
1010
const path = require('path');
@@ -508,13 +508,13 @@ Module.prototype._compile = function(content, filename) {
508508
// create wrapper function
509509
var wrapper = Module.wrap(content);
510510

511-
var compiledWrapper = runInThisContext(wrapper, {
511+
var compiledWrapper = vm.runInThisContext(wrapper, {
512512
filename: filename,
513513
lineOffset: 0,
514514
displayErrors: true
515515
});
516516

517-
if (global.v8debug) {
517+
if (process._debugWaitConnect) {
518518
if (!resolvedArgv) {
519519
// we enter the repl if we're not given a filename argument.
520520
if (process.argv[1]) {
@@ -526,11 +526,9 @@ Module.prototype._compile = function(content, filename) {
526526

527527
// Set breakpoint on module start
528528
if (filename === resolvedArgv) {
529-
// Installing this dummy debug event listener tells V8 to start
530-
// the debugger. Without it, the setBreakPoint() fails with an
531-
// 'illegal access' error.
532-
global.v8debug.Debug.setListener(function() {});
533-
global.v8debug.Debug.setBreakPoint(compiledWrapper, 0, 0);
529+
delete process._debugWaitConnect;
530+
const Debug = vm.runInDebugContext('Debug');
531+
Debug.setBreakPoint(compiledWrapper, 0, 0);
534532
}
535533
}
536534
var dirname = path.dirname(filename);

src/node.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3179,6 +3179,11 @@ void SetupProcessObject(Environment* env,
31793179
READONLY_PROPERTY(process, "traceDeprecation", True(env->isolate()));
31803180
}
31813181

3182+
// --debug-brk
3183+
if (debug_wait_connect) {
3184+
READONLY_PROPERTY(process, "_debugWaitConnect", True(env->isolate()));
3185+
}
3186+
31823187
// --security-revert flags
31833188
#define V(code, _, __) \
31843189
do { \
@@ -4087,11 +4092,6 @@ void Init(int* argc,
40874092
exit(9);
40884093
}
40894094

4090-
if (debug_wait_connect) {
4091-
const char expose_debug_as[] = "--expose_debug_as=v8debug";
4092-
V8::SetFlagsFromString(expose_debug_as, sizeof(expose_debug_as) - 1);
4093-
}
4094-
40954095
// Unconditionally force typed arrays to allocate outside the v8 heap. This
40964096
// is to prevent memory pointers from being moved around that are returned by
40974097
// Buffer::Data().

0 commit comments

Comments
 (0)