forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdebugger-probe.js
More file actions
58 lines (50 loc) · 2.11 KB
/
debugger-probe.js
File metadata and controls
58 lines (50 loc) · 2.11 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
58
'use strict';
const assert = require('assert');
const fixtures = require('./fixtures');
const path = require('path');
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 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[expected.results.length - 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,
missScript: debuggerFixturePath('probe-miss.js'),
probeScript: debuggerFixturePath('probe.js'),
throwScript: debuggerFixturePath('probe-throw.js'),
probeTypesScript: debuggerFixturePath('probe-types.js'),
timeoutScript: debuggerFixturePath('probe-timeout.js'),
};