Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inspector: break in eval script #14581

Merged
merged 1 commit into from
Sep 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
const Module = NativeModule.require('module');
const path = NativeModule.require('path');
Expand All @@ -442,7 +449,7 @@
const module = new Module(name);
module.filename = path.join(cwd, name);
module.paths = Module._nodeModulePaths(cwd);
const body = process._eval;
const body = wrapForBreakOnFirstLine(process._eval);
const script = `global.__filename = ${JSON.stringify(name)};\n` +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it work better if you applied wrapForBreakOnFirstLine to script, not to body?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the entire block will be reported as source and actual user code will be a string - e.g. it will not be possible to set a breakpoint there. Stepping into the vm module will be required in order to step into the user code.

'global.exports = exports;\n' +
'global.module = module;\n' +
Expand Down
9 changes: 7 additions & 2 deletions test/inspector/test-async-hook-setup-at-inspect-brk.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ setTimeout(() => {
}, 50);
`;

async function skipBreakpointAtStart(session) {
await session.waitForBreakOnLine(0, '[eval]');
await session.send({ 'method': 'Debugger.resume' });
}

async function checkAsyncStackTrace(session) {
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,
`${Object.keys(paused.params)} contains "asyncStackTrace" property`);
assert(paused.params.asyncStackTrace.description, 'Timeout');
Expand All @@ -35,7 +40,7 @@ async function runTests() {
'params': { 'patterns': [] } },
{ 'method': 'Runtime.runIfWaitingForDebugger' }
]);

await skipBreakpointAtStart(session);
await checkAsyncStackTrace(session);

await session.runToCompletion();
Expand Down
11 changes: 7 additions & 4 deletions test/inspector/test-async-stack-traces-promise-then.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,18 @@ async function runTests() {
{ 'method': 'Runtime.runIfWaitingForDebugger' }
]);

await session.waitForBreakOnLine(0, '[eval]');
await session.send({ 'method': 'Debugger.resume' });

console.error('[test] Waiting for break1');
debuggerPausedAt(await session.waitForBreakOnLine(4, '[eval]'),
'break1', 'runTest:3');
debuggerPausedAt(await session.waitForBreakOnLine(6, '[eval]'),
'break1', 'runTest:5');

await session.send({ 'method': 'Debugger.resume' });

console.error('[test] Waiting for break2');
debuggerPausedAt(await session.waitForBreakOnLine(7, '[eval]'),
'break2', 'runTest:6');
debuggerPausedAt(await session.waitForBreakOnLine(9, '[eval]'),
'break2', 'runTest:8');

await session.runToCompletion();
assert.strictEqual(0, (await instance.expectShutdown()).exitCode);
Expand Down
9 changes: 8 additions & 1 deletion test/inspector/test-async-stack-traces-set-interval.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ const assert = require('assert');

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) {
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,
`${Object.keys(paused.params)} contains "asyncStackTrace" property`);
assert(paused.params.asyncStackTrace.description, 'Timeout');
Expand All @@ -31,6 +37,7 @@ async function runTests() {
{ 'method': 'Runtime.runIfWaitingForDebugger' }
]);

await skipFirstBreakpoint(session);
await checkAsyncStackTrace(session);

console.error('[test]', 'Stopping child instance');
Expand Down
22 changes: 22 additions & 0 deletions test/inspector/test-inspector-break-e.js
Original file line number Diff line number Diff line change
@@ -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();
4 changes: 1 addition & 3 deletions test/inspector/test-scriptparsed-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ const script = `
const assert = require('assert');
const vm = require('vm');
const { kParsingContext } = process.binding('contextify');
debugger;

global.outer = true;
global.inner = false;
const context = vm.createContext({
Expand Down Expand Up @@ -61,7 +59,7 @@ async function runTests() {
{ 'method': 'Debugger.enable' },
{ 'method': 'Runtime.runIfWaitingForDebugger' }
]);
await session.waitForBreakOnLine(5, '[eval]');
await session.waitForBreakOnLine(0, '[eval]');

await session.send({ 'method': 'Runtime.enable' });
const topContext = await getContext(session);
Expand Down