inspector: break in eval script
Fixes: https://github.com/nodejs/node/issues/14577 PR-URL: https://github.com/nodejs/node/pull/14581 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
6c38ab34a3
commit
75606c4f69
9
lib/internal/bootstrap_node.js
vendored
9
lib/internal/bootstrap_node.js
vendored
@ -434,6 +434,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wrapForBreakOnFirstLine(source) {
|
||||||
|
if (!process._breakFirstLine)
|
||||||
|
return source;
|
||||||
|
const fn = `function() {\n\n${source};\n\n}`;
|
||||||
|
return `process.binding('inspector').callAndPauseOnStart(${fn}, {})`;
|
||||||
|
}
|
||||||
|
|
||||||
function evalScript(name) {
|
function evalScript(name) {
|
||||||
const Module = NativeModule.require('module');
|
const Module = NativeModule.require('module');
|
||||||
const path = NativeModule.require('path');
|
const path = NativeModule.require('path');
|
||||||
@ -442,7 +449,7 @@
|
|||||||
const module = new Module(name);
|
const module = new Module(name);
|
||||||
module.filename = path.join(cwd, name);
|
module.filename = path.join(cwd, name);
|
||||||
module.paths = Module._nodeModulePaths(cwd);
|
module.paths = Module._nodeModulePaths(cwd);
|
||||||
const body = process._eval;
|
const body = wrapForBreakOnFirstLine(process._eval);
|
||||||
const script = `global.__filename = ${JSON.stringify(name)};\n` +
|
const script = `global.__filename = ${JSON.stringify(name)};\n` +
|
||||||
'global.exports = exports;\n' +
|
'global.exports = exports;\n' +
|
||||||
'global.module = module;\n' +
|
'global.module = module;\n' +
|
||||||
|
@ -13,9 +13,14 @@ setTimeout(() => {
|
|||||||
}, 50);
|
}, 50);
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
async function skipBreakpointAtStart(session) {
|
||||||
|
await session.waitForBreakOnLine(0, '[eval]');
|
||||||
|
await session.send({ 'method': 'Debugger.resume' });
|
||||||
|
}
|
||||||
|
|
||||||
async function checkAsyncStackTrace(session) {
|
async function checkAsyncStackTrace(session) {
|
||||||
console.error('[test]', 'Verify basic properties of asyncStackTrace');
|
console.error('[test]', 'Verify basic properties of asyncStackTrace');
|
||||||
const paused = await session.waitForBreakOnLine(2, '[eval]');
|
const paused = await session.waitForBreakOnLine(4, '[eval]');
|
||||||
assert(paused.params.asyncStackTrace,
|
assert(paused.params.asyncStackTrace,
|
||||||
`${Object.keys(paused.params)} contains "asyncStackTrace" property`);
|
`${Object.keys(paused.params)} contains "asyncStackTrace" property`);
|
||||||
assert(paused.params.asyncStackTrace.description, 'Timeout');
|
assert(paused.params.asyncStackTrace.description, 'Timeout');
|
||||||
@ -35,7 +40,7 @@ async function runTests() {
|
|||||||
'params': { 'patterns': [] } },
|
'params': { 'patterns': [] } },
|
||||||
{ 'method': 'Runtime.runIfWaitingForDebugger' }
|
{ 'method': 'Runtime.runIfWaitingForDebugger' }
|
||||||
]);
|
]);
|
||||||
|
await skipBreakpointAtStart(session);
|
||||||
await checkAsyncStackTrace(session);
|
await checkAsyncStackTrace(session);
|
||||||
|
|
||||||
await session.runToCompletion();
|
await session.runToCompletion();
|
||||||
|
@ -31,15 +31,18 @@ async function runTests() {
|
|||||||
{ 'method': 'Runtime.runIfWaitingForDebugger' }
|
{ 'method': 'Runtime.runIfWaitingForDebugger' }
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
await session.waitForBreakOnLine(0, '[eval]');
|
||||||
|
await session.send({ 'method': 'Debugger.resume' });
|
||||||
|
|
||||||
console.error('[test] Waiting for break1');
|
console.error('[test] Waiting for break1');
|
||||||
debuggerPausedAt(await session.waitForBreakOnLine(4, '[eval]'),
|
debuggerPausedAt(await session.waitForBreakOnLine(6, '[eval]'),
|
||||||
'break1', 'runTest:3');
|
'break1', 'runTest:5');
|
||||||
|
|
||||||
await session.send({ 'method': 'Debugger.resume' });
|
await session.send({ 'method': 'Debugger.resume' });
|
||||||
|
|
||||||
console.error('[test] Waiting for break2');
|
console.error('[test] Waiting for break2');
|
||||||
debuggerPausedAt(await session.waitForBreakOnLine(7, '[eval]'),
|
debuggerPausedAt(await session.waitForBreakOnLine(9, '[eval]'),
|
||||||
'break2', 'runTest:6');
|
'break2', 'runTest:8');
|
||||||
|
|
||||||
await session.runToCompletion();
|
await session.runToCompletion();
|
||||||
assert.strictEqual(0, (await instance.expectShutdown()).exitCode);
|
assert.strictEqual(0, (await instance.expectShutdown()).exitCode);
|
||||||
|
@ -8,9 +8,15 @@ const assert = require('assert');
|
|||||||
|
|
||||||
const script = 'setInterval(() => { debugger; }, 50);';
|
const script = 'setInterval(() => { debugger; }, 50);';
|
||||||
|
|
||||||
|
async function skipFirstBreakpoint(session) {
|
||||||
|
console.log('[test]', 'Skipping the first breakpoint in the eval script');
|
||||||
|
await session.waitForBreakOnLine(0, '[eval]');
|
||||||
|
await session.send({ 'method': 'Debugger.resume' });
|
||||||
|
}
|
||||||
|
|
||||||
async function checkAsyncStackTrace(session) {
|
async function checkAsyncStackTrace(session) {
|
||||||
console.error('[test]', 'Verify basic properties of asyncStackTrace');
|
console.error('[test]', 'Verify basic properties of asyncStackTrace');
|
||||||
const paused = await session.waitForBreakOnLine(0, '[eval]');
|
const paused = await session.waitForBreakOnLine(2, '[eval]');
|
||||||
assert(paused.params.asyncStackTrace,
|
assert(paused.params.asyncStackTrace,
|
||||||
`${Object.keys(paused.params)} contains "asyncStackTrace" property`);
|
`${Object.keys(paused.params)} contains "asyncStackTrace" property`);
|
||||||
assert(paused.params.asyncStackTrace.description, 'Timeout');
|
assert(paused.params.asyncStackTrace.description, 'Timeout');
|
||||||
@ -31,6 +37,7 @@ async function runTests() {
|
|||||||
{ 'method': 'Runtime.runIfWaitingForDebugger' }
|
{ 'method': 'Runtime.runIfWaitingForDebugger' }
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
await skipFirstBreakpoint(session);
|
||||||
await checkAsyncStackTrace(session);
|
await checkAsyncStackTrace(session);
|
||||||
|
|
||||||
console.error('[test]', 'Stopping child instance');
|
console.error('[test]', 'Stopping child instance');
|
||||||
|
22
test/inspector/test-inspector-break-e.js
Normal file
22
test/inspector/test-inspector-break-e.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
'use strict';
|
||||||
|
const common = require('../common');
|
||||||
|
|
||||||
|
common.skipIfInspectorDisabled();
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
const { NodeInstance } = require('./inspector-helper.js');
|
||||||
|
|
||||||
|
async function runTests() {
|
||||||
|
const instance = new NodeInstance(undefined, 'console.log(10)');
|
||||||
|
const session = await instance.connectInspectorSession();
|
||||||
|
await session.send([
|
||||||
|
{ 'method': 'Runtime.enable' },
|
||||||
|
{ 'method': 'Debugger.enable' },
|
||||||
|
{ 'method': 'Runtime.runIfWaitingForDebugger' }
|
||||||
|
]);
|
||||||
|
await session.waitForBreakOnLine(0, '[eval]');
|
||||||
|
await session.runToCompletion();
|
||||||
|
assert.strictEqual(0, (await instance.expectShutdown()).exitCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
runTests();
|
@ -10,8 +10,6 @@ const script = `
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const vm = require('vm');
|
const vm = require('vm');
|
||||||
const { kParsingContext } = process.binding('contextify');
|
const { kParsingContext } = process.binding('contextify');
|
||||||
debugger;
|
|
||||||
|
|
||||||
global.outer = true;
|
global.outer = true;
|
||||||
global.inner = false;
|
global.inner = false;
|
||||||
const context = vm.createContext({
|
const context = vm.createContext({
|
||||||
@ -61,7 +59,7 @@ async function runTests() {
|
|||||||
{ 'method': 'Debugger.enable' },
|
{ 'method': 'Debugger.enable' },
|
||||||
{ 'method': 'Runtime.runIfWaitingForDebugger' }
|
{ 'method': 'Runtime.runIfWaitingForDebugger' }
|
||||||
]);
|
]);
|
||||||
await session.waitForBreakOnLine(5, '[eval]');
|
await session.waitForBreakOnLine(0, '[eval]');
|
||||||
|
|
||||||
await session.send({ 'method': 'Runtime.enable' });
|
await session.send({ 'method': 'Runtime.enable' });
|
||||||
const topContext = await getContext(session);
|
const topContext = await getContext(session);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user