-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathdebugger-probe.js
More file actions
57 lines (49 loc) · 2.08 KB
/
debugger-probe.js
File metadata and controls
57 lines (49 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
const assert = require('assert');
const fixtures = require('./fixtures');
const path = require('path');
const probeTargetExitSignal = 'SIGSEGV';
const probeTargetExitMessage =
`Target exited with signal ${probeTargetExitSignal} before target completion`;
function debuggerFixturePath(name) {
return path.relative(process.cwd(), fixtures.path('debugger', name));
}
// Work around a pre-existing inspector issue: if the debuggee exits too quickly
// the inspector can segfault while tearing down. For now normalize the
// trailing segfault as completion until the upstream bug is fixed.
// See https://github.com/nodejs/node/issues/62765
// https://github.com/nodejs/node/issues/58245
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 &&
lastResult.error?.message === probeTargetExitMessage) {
// Log to facilitate debugging if this normalization is occurring.
console.log('Normalizing trailing SIGSEGV in JSON probe output');
normalized.results[normalized.results.length - 1] = { event: 'completed' };
}
assert.deepStrictEqual(normalized, expected);
}
function assertProbeText(output, expected) {
const idx = output.indexOf(probeTargetExitMessage);
let normalized;
if (idx !== -1) {
// Log to facilitate debugging if this normalization is occurring.
console.log('Normalizing trailing SIGSEGV in text probe output');
normalized = output.slice(0, output.lastIndexOf('\n', idx)) + '\nCompleted';
} else {
normalized = output;
}
assert.strictEqual(normalized, expected);
}
module.exports = {
assertProbeJson,
assertProbeText,
missScript: debuggerFixturePath('probe-miss.js'),
probeScript: debuggerFixturePath('probe.js'),
throwScript: debuggerFixturePath('probe-throw.js'),
probeTypesScript: debuggerFixturePath('probe-types.js'),
timeoutScript: debuggerFixturePath('probe-timeout.js'),
};