Skip to content

Commit

Permalink
deps: update node-inspect to v1.11.2
Browse files Browse the repository at this point in the history
PR-URL: #12363
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
  • Loading branch information
Jan Krems authored and addaleax committed Apr 14, 2017
1 parent 7fd2923 commit 0217197
Show file tree
Hide file tree
Showing 19 changed files with 249 additions and 104 deletions.
26 changes: 26 additions & 0 deletions deps/node-inspect/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
### 1.11.2

* [`42e0cd1`](https://github.com/nodejs/node-inspect/commit/42e0cd111d89ed09faba1c0ec45089b0b44de011) **fix:** look for generic hint text


### 1.11.1

* Prefer --inspect-brk over --debug-brk - **[@ofrobots](https://github.com/ofrobots)** [#43](https://github.com/nodejs/node-inspect/pull/43)
- [`2c1ed27`](https://github.com/nodejs/node-inspect/commit/2c1ed27ee44d9aebb3c5ac50039abae8166a54e3) **fix:** use --inspect-brk with Node 8+


### 1.11.0

* doc: add profile and heap to help - **[@joshgav](https://github.com/joshgav)** [#39](https://github.com/nodejs/node-inspect/pull/39)
- [`f64c920`](https://github.com/nodejs/node-inspect/commit/f64c9205bd8382289660aa677d3ac192a9c81fd5) **doc:** add profile and heap to help
* Update test suite to pass on latest nightly - **[@jkrems](https://github.com/jkrems)** [#36](https://github.com/nodejs/node-inspect/pull/36)
- [`41148d7`](https://github.com/nodejs/node-inspect/commit/41148d74a2d563eea3b7ad5463622b6b9fd4c46e) **test:** Remove outdated test
- [`2c224c5`](https://github.com/nodejs/node-inspect/commit/2c224c551619e386e80fc3154cc14562cac063b9) **test:** Accept any kind of "break"
- [`22bf349`](https://github.com/nodejs/node-inspect/commit/22bf349bc86d7bf6fd449791c9d1e7eaf66c2681) **test:** Adjust for v8 5.7
- [`6ce8c16`](https://github.com/nodejs/node-inspect/commit/6ce8c165c45a491bea8cfb3c67d2ae80e7c34dcb) **test:** Revert to old assertions
* Verify custom port support - **[@jkrems](https://github.com/jkrems)** [#41](https://github.com/nodejs/node-inspect/pull/41)
- [`e3a489f`](https://github.com/nodejs/node-inspect/commit/e3a489f23b089d3d57a25d5efe40daf06de63e23) **test:** custom port
* Support for debugging a pid - **[@jkrems](https://github.com/jkrems)** [#37](https://github.com/nodejs/node-inspect/pull/37)
- [`4179506`](https://github.com/nodejs/node-inspect/commit/4179506a4d546bac2c93b2a7ff491b1fa4494fd9) **feat:** Support for debugging a pid


### 1.10.6

* chore: Fix usage text for embedded mode - **[@addaleax](https://github.com/addaleax)** [#20](https://github.com/nodejs/node-inspect/pull/20)
Expand Down
134 changes: 75 additions & 59 deletions deps/node-inspect/lib/_inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const [ InspectClient, createRepl ] =

const debuglog = util.debuglog('inspect');

const DEBUG_PORT_PATTERN = /^--(?:debug|inspect)-port=(\d+)$/;
const DEBUG_PORT_PATTERN = /^--(?:debug|inspect)(?:-port|-brk)?=(\d{1,5})$/;
function getDefaultPort() {
for (const arg of process.execArgv) {
const match = arg.match(DEBUG_PORT_PATTERN);
Expand All @@ -53,54 +53,6 @@ function getDefaultPort() {
return 9229;
}

function runScript(script, scriptArgs, inspectPort, childPrint) {
return new Promise((resolve) => {
const needDebugBrk = process.version.match(/^v(6|7)\./);
const args = (needDebugBrk ?
['--inspect', `--debug-brk=${inspectPort}`] :
[`--inspect-brk=${inspectPort}`])
.concat([script], scriptArgs);
const child = spawn(process.execPath, args);
child.stdout.setEncoding('utf8');
child.stderr.setEncoding('utf8');
child.stdout.on('data', childPrint);
child.stderr.on('data', childPrint);

let output = '';
function waitForListenHint(text) {
output += text;
if (/chrome-devtools:\/\//.test(output)) {
child.stderr.removeListener('data', waitForListenHint);
resolve(child);
}
}

child.stderr.on('data', waitForListenHint);
});
}

function createAgentProxy(domain, client) {
const agent = new EventEmitter();
agent.then = (...args) => {
// TODO: potentially fetch the protocol and pretty-print it here.
const descriptor = {
[util.inspect.custom](depth, { stylize }) {
return stylize(`[Agent ${domain}]`, 'special');
},
};
return Promise.resolve(descriptor).then(...args);
};

return new Proxy(agent, {
get(target, name) {
if (name in target) return target[name];
return function callVirtualMethod(params) {
return client.callMethod(`${domain}.${name}`, params);
};
},
});
}

function portIsFree(host, port, timeout = 2000) {
const retryDelay = 150;
let didTimeOut = false;
Expand Down Expand Up @@ -140,6 +92,57 @@ function portIsFree(host, port, timeout = 2000) {
});
}

function runScript(script, scriptArgs, inspectHost, inspectPort, childPrint) {
return portIsFree(inspectHost, inspectPort)
.then(() => {
return new Promise((resolve) => {
const needDebugBrk = process.version.match(/^v(6|7)\./);
const args = (needDebugBrk ?
['--inspect', `--debug-brk=${inspectPort}`] :
[`--inspect-brk=${inspectPort}`])
.concat([script], scriptArgs);
const child = spawn(process.execPath, args);
child.stdout.setEncoding('utf8');
child.stderr.setEncoding('utf8');
child.stdout.on('data', childPrint);
child.stderr.on('data', childPrint);

let output = '';
function waitForListenHint(text) {
output += text;
if (/Debugger listening on/.test(output)) {
child.stderr.removeListener('data', waitForListenHint);
resolve(child);
}
}

child.stderr.on('data', waitForListenHint);
});
});
}

function createAgentProxy(domain, client) {
const agent = new EventEmitter();
agent.then = (...args) => {
// TODO: potentially fetch the protocol and pretty-print it here.
const descriptor = {
[util.inspect.custom](depth, { stylize }) {
return stylize(`[Agent ${domain}]`, 'special');
},
};
return Promise.resolve(descriptor).then(...args);
};

return new Proxy(agent, {
get(target, name) {
if (name in target) return target[name];
return function callVirtualMethod(params) {
return client.callMethod(`${domain}.${name}`, params);
};
},
});
}

class NodeInspector {
constructor(options, stdin, stdout) {
this.options = options;
Expand All @@ -153,6 +156,7 @@ class NodeInspector {
this._runScript = runScript.bind(null,
options.script,
options.scriptArgs,
options.host,
options.port,
this.childPrint.bind(this));
} else {
Expand Down Expand Up @@ -221,12 +225,7 @@ class NodeInspector {
this.killChild();
const { host, port } = this.options;

const runOncePortIsFree = () => {
return portIsFree(host, port)
.then(() => this._runScript());
};

return runOncePortIsFree().then((child) => {
return this._runScript().then((child) => {
this.child = child;

let connectionAttempts = 0;
Expand Down Expand Up @@ -296,6 +295,7 @@ function parseArgv([target, ...args]) {

const hostMatch = target.match(/^([^:]+):(\d+)$/);
const portMatch = target.match(/^--port=(\d+)$/);

if (hostMatch) {
// Connecting to remote debugger
// `node-inspect localhost:9229`
Expand All @@ -304,16 +304,31 @@ function parseArgv([target, ...args]) {
isRemote = true;
script = null;
} else if (portMatch) {
// Start debugger on custom port
// `node debug --port=8058 app.js`
// start debugee on custom port
// `node inspect --port=9230 script.js`
port = parseInt(portMatch[1], 10);
script = args[0];
scriptArgs = args.slice(1);
} else if (args.length === 1 && /^\d+$/.test(args[0]) && target === '-p') {
// Start debugger against a given pid
const pid = parseInt(args[0], 10);
try {
process._debugProcess(pid);
} catch (e) {
if (e.code === 'ESRCH') {
/* eslint-disable no-console */
console.error(`Target process: ${pid} doesn't exist.`);
/* eslint-enable no-console */
process.exit(1);
}
throw e;
}
script = null;
isRemote = true;
}

return {
host, port,
isRemote, script, scriptArgs,
host, port, isRemote, script, scriptArgs,
};
}

Expand All @@ -328,6 +343,7 @@ function startInspect(argv = process.argv.slice(2),

console.error(`Usage: ${invokedAs} script.js`);
console.error(` ${invokedAs} <host>:<port>`);
console.error(` ${invokedAs} -p <pid>`);
process.exit(1);
}

Expand Down
9 changes: 9 additions & 0 deletions deps/node-inspect/lib/internal/inspect_repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ repl Enter a debug repl that works like exec
scripts List application scripts that are currently loaded
scripts(true) List all scripts (including node-internals)
profile Start CPU profiling session.
profileEnd Stop current CPU profiling session.
profiles Array of completed CPU profiling sessions.
profiles[n].save(filepath = 'node.cpuprofile')
Save CPU profiling session to disk as JSON.
takeHeapSnapshot(filepath = 'node.heapsnapshot')
Take a heap snapshot and save to disk as JSON.
`.trim();

const FUNCTION_NAME_PATTERN = /^(?:function\*? )?([^(\s]+)\(/;
Expand Down
4 changes: 2 additions & 2 deletions deps/node-inspect/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-inspect",
"version": "1.10.6",
"version": "1.11.2",
"description": "Node Inspect",
"license": "MIT",
"main": "lib/_inspect.js",
Expand All @@ -15,7 +15,7 @@
},
"scripts": {
"pretest": "eslint --rulesdir=tools/eslint-rules lib test",
"test": "tap \"test/**/*.test.js\"",
"test": "tap test",
"posttest": "nlm verify"
},
"nlm": {
Expand Down
2 changes: 1 addition & 1 deletion deps/node-inspect/test/cli/backtrace.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test('display and navigate backtrace', (t) => {
throw error;
}

return cli.waitFor(/break/)
return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => cli.stepCommand('c'))
.then(() => cli.command('bt'))
Expand Down
6 changes: 3 additions & 3 deletions deps/node-inspect/test/cli/break.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test('stepping through breakpoints', (t) => {
throw error;
}

return cli.waitFor(/break/)
return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => {
t.match(
Expand Down Expand Up @@ -132,7 +132,7 @@ test('sb before loading file', (t) => {
throw error;
}

return cli.waitFor(/break/)
return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => cli.command('sb("other.js", 3)'))
.then(() => {
Expand Down Expand Up @@ -161,7 +161,7 @@ test('clearBreakpoint', (t) => {
throw error;
}

return cli.waitFor(/break/)
return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => cli.command('sb("break.js", 3)'))
.then(() => cli.command('sb("break.js", 9)'))
Expand Down
11 changes: 8 additions & 3 deletions deps/node-inspect/test/cli/exceptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ test('break on (uncaught) exceptions', (t) => {
throw error;
}

return cli.waitFor(/break/)
return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => {
t.match(cli.output, `break in ${script}:1`);
})
// making sure it will die by default:
.then(() => cli.command('c'))
.then(() => cli.waitFor(/disconnect/))
// TODO: Remove FATAL ERROR once node doesn't show a FATAL ERROR anymore
.then(() => cli.waitFor(/disconnect|FATAL ERROR/))

// Next run: With `breakOnException` it pauses in both places
.then(() => cli.stepCommand('r'))
.then(() => cli.waitForInitialBreak())
.then(() => {
t.match(cli.output, `break in ${script}:1`);
})
Expand All @@ -41,6 +43,7 @@ test('break on (uncaught) exceptions', (t) => {
// Next run: With `breakOnUncaught` it only pauses on the 2nd exception
.then(() => cli.command('breakOnUncaught'))
.then(() => cli.stepCommand('r')) // also, the setting survives the restart
.then(() => cli.waitForInitialBreak())
.then(() => {
t.match(cli.output, `break in ${script}:1`);
})
Expand All @@ -52,11 +55,13 @@ test('break on (uncaught) exceptions', (t) => {
// Next run: Back to the initial state! It should die again.
.then(() => cli.command('breakOnNone'))
.then(() => cli.stepCommand('r'))
.then(() => cli.waitForInitialBreak())
.then(() => {
t.match(cli.output, `break in ${script}:1`);
})
.then(() => cli.command('c'))
.then(() => cli.waitFor(/disconnect/))
// TODO: Remove FATAL ERROR once node doesn't show a FATAL ERROR anymore
.then(() => cli.waitFor(/disconnect|FATAL ERROR/))

.then(() => cli.quit())
.then(null, onFatal);
Expand Down
4 changes: 2 additions & 2 deletions deps/node-inspect/test/cli/exec.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test('examples/alive.js', (t) => {
throw error;
}

return cli.waitFor(/break/)
return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => cli.command('exec [typeof heartbeat, typeof process.exit]'))
.then(() => {
Expand Down Expand Up @@ -60,7 +60,7 @@ test('exec .scope', (t) => {
throw error;
}

return cli.waitFor(/break/)
return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => cli.stepCommand('c'))
.then(() => cli.command('exec .scope'))
Expand Down
2 changes: 1 addition & 1 deletion deps/node-inspect/test/cli/help.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test('examples/empty.js', (t) => {
throw error;
}

return cli.waitFor(/break/)
return cli.waitForInitialBreak()
.then(() => cli.waitForPrompt())
.then(() => cli.command('help'))
.then(() => {
Expand Down
Loading

0 comments on commit 0217197

Please sign in to comment.