Browse Source

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: https://github.com/nodejs/node/pull/6599
Reviewed-By: bnoordhuis - Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: cjihrig - Colin Ihrig <cjihrig@gmail.com>
v6.x
Ali Ijaz Sheikh 9 years ago
committed by Evan Lucas
parent
commit
bd4454fa0f
  1. 4
      lib/internal/bootstrap_node.js
  2. 14
      lib/module.js
  3. 10
      src/node.cc

4
lib/internal/bootstrap_node.js

@ -136,7 +136,7 @@
preloadModules(); preloadModules();
if (global.v8debug && if (process._debugWaitConnect &&
process.execArgv.some(function(arg) { process.execArgv.some(function(arg) {
return arg.match(/^--debug-brk(=[0-9]*)?$/); return arg.match(/^--debug-brk(=[0-9]*)?$/);
})) { })) {
@ -149,7 +149,7 @@
// breakpoint message on line 1. // breakpoint message on line 1.
// //
// A better fix would be to somehow get a message from the // A better fix would be to somehow get a message from the
// global.v8debug object about a connection, and runMain when // V8 debug object about a connection, and runMain when
// that occurs. --isaacs // that occurs. --isaacs
var debugTimeout = +process.env.NODE_DEBUG_TIMEOUT || 50; var debugTimeout = +process.env.NODE_DEBUG_TIMEOUT || 50;

14
lib/module.js

@ -4,7 +4,7 @@ const NativeModule = require('native_module');
const util = require('util'); const util = require('util');
const internalModule = require('internal/module'); const internalModule = require('internal/module');
const internalUtil = require('internal/util'); const internalUtil = require('internal/util');
const runInThisContext = require('vm').runInThisContext; const vm = require('vm');
const assert = require('assert').ok; const assert = require('assert').ok;
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
@ -508,13 +508,13 @@ Module.prototype._compile = function(content, filename) {
// create wrapper function // create wrapper function
var wrapper = Module.wrap(content); var wrapper = Module.wrap(content);
var compiledWrapper = runInThisContext(wrapper, { var compiledWrapper = vm.runInThisContext(wrapper, {
filename: filename, filename: filename,
lineOffset: 0, lineOffset: 0,
displayErrors: true displayErrors: true
}); });
if (global.v8debug) { if (process._debugWaitConnect) {
if (!resolvedArgv) { if (!resolvedArgv) {
// we enter the repl if we're not given a filename argument. // we enter the repl if we're not given a filename argument.
if (process.argv[1]) { if (process.argv[1]) {
@ -526,11 +526,9 @@ Module.prototype._compile = function(content, filename) {
// Set breakpoint on module start // Set breakpoint on module start
if (filename === resolvedArgv) { if (filename === resolvedArgv) {
// Installing this dummy debug event listener tells V8 to start delete process._debugWaitConnect;
// the debugger. Without it, the setBreakPoint() fails with an const Debug = vm.runInDebugContext('Debug');
// 'illegal access' error. Debug.setBreakPoint(compiledWrapper, 0, 0);
global.v8debug.Debug.setListener(function() {});
global.v8debug.Debug.setBreakPoint(compiledWrapper, 0, 0);
} }
} }
var dirname = path.dirname(filename); var dirname = path.dirname(filename);

10
src/node.cc

@ -3179,6 +3179,11 @@ void SetupProcessObject(Environment* env,
READONLY_PROPERTY(process, "traceDeprecation", True(env->isolate())); READONLY_PROPERTY(process, "traceDeprecation", True(env->isolate()));
} }
// --debug-brk
if (debug_wait_connect) {
READONLY_PROPERTY(process, "_debugWaitConnect", True(env->isolate()));
}
// --security-revert flags // --security-revert flags
#define V(code, _, __) \ #define V(code, _, __) \
do { \ do { \
@ -4087,11 +4092,6 @@ void Init(int* argc,
exit(9); exit(9);
} }
if (debug_wait_connect) {
const char expose_debug_as[] = "--expose_debug_as=v8debug";
V8::SetFlagsFromString(expose_debug_as, sizeof(expose_debug_as) - 1);
}
// Unconditionally force typed arrays to allocate outside the v8 heap. This // Unconditionally force typed arrays to allocate outside the v8 heap. This
// is to prevent memory pointers from being moved around that are returned by // is to prevent memory pointers from being moved around that are returned by
// Buffer::Data(). // Buffer::Data().

Loading…
Cancel
Save