In probe mode, `--probe utils.js:10` can match multiple scripts
(e.g. `src/utils.js` and `lib/utils.js`) because the matcher uses
a path-separator-anchored URL suffix (similar to how e.g. gdb/lldb
behaves). Previously the report echoed only the user's request in
hit events, so a user seeing two hits at `utils.js:10` could not
tell which script each hit came from. In addition, previously
when the column was omitted we bound to 1 which was technically
different from how CDP binds omitted columns (to the first
executable column on the line).
This patch clarifies the semantics by tracking the scripts via
`Debugger.scriptParsed`, as recommended in the CDP docs, and
reports the actual execution location as `results[i].location`.
The same shape can be reused in the future for source maps or
additional events in attach mode.
This bumps the schema version because `target` is now
`{ suffix, line, column? }` instead of a positional array for
clarity. We picked `suffix` as the field name in case we
introduce other matching modes in the future. `column` is
omitted when the user did not supply one, and the actual
resolved column is reported in the hit event instead.
This patch also adds more tests for column-specific bindings,
multi-location resolution via require(cjs), and late script
binding via dynamic import(cjs) and require(esm).
Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/63286
Reviewed-By: Jan Martin <jan.krems@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
46 lines
1.6 KiB
JavaScript
46 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('assert');
|
|
|
|
// Work around a pre-existing inspector issue: if the debuggee exits too quickly
|
|
// the inspector can segfault while tearing down. For now normalize the segfault
|
|
// back to the expected terminal event (e.g. "completed" or "miss")
|
|
// until the upstream bug is fixed.
|
|
// See https://github.com/nodejs/node/issues/62765
|
|
// https://github.com/nodejs/node/issues/58245
|
|
const probeTargetExitSignal = 'SIGSEGV';
|
|
|
|
function assertProbeJson(output, expected) {
|
|
const normalized = JSON.parse(output);
|
|
const lastResult = normalized.results?.[normalized.results.length - 1];
|
|
|
|
if (lastResult?.event === 'error' &&
|
|
lastResult.error?.code === 'probe_target_exit' &&
|
|
lastResult.error?.signal === probeTargetExitSignal) {
|
|
// Log to facilitate debugging if this normalization is occurring.
|
|
console.log('Normalizing trailing SIGSEGV in JSON probe output');
|
|
normalized.results[normalized.results.length - 1] = expected.results.at(-1);
|
|
}
|
|
|
|
assert.deepStrictEqual(normalized, expected);
|
|
}
|
|
|
|
function assertProbeText(output, expected) {
|
|
const signalPrefix = `Target exited with signal ${probeTargetExitSignal}`;
|
|
const idx = output.indexOf(signalPrefix);
|
|
let normalized;
|
|
if (idx !== -1) {
|
|
// Log to facilitate debugging if this normalization is occurring.
|
|
console.log('Normalizing trailing SIGSEGV in text probe output');
|
|
const lineStart = output.lastIndexOf('\n', idx);
|
|
normalized = (lineStart === -1 ? '' : output.slice(0, lineStart)) + '\nCompleted';
|
|
} else {
|
|
normalized = output;
|
|
}
|
|
assert.strictEqual(normalized, expected);
|
|
}
|
|
|
|
module.exports = {
|
|
assertProbeJson,
|
|
assertProbeText,
|
|
};
|