mirror of
https://github.com/nodejs/node.git
synced 2026-11-15 10:36:53 -05:00
debugger: accommodate line chunking in Windows
PR-URL: https://github.com/nodejs/node/pull/38161 Refs: https://github.com/nodejs/node/discussions/36481 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
1 parent
b0713b4186
commit
807ede70fa
2 files changed
+31
-22
No files matched your search
@@ -97,8 +97,8 @@ function runScript(script, scriptArgs, inspectHost, inspectPort, childPrint) {
|
||||
const child = spawn(process.execPath, args);
|
||||
child.stdout.setEncoding('utf8');
|
||||
child.stderr.setEncoding('utf8');
|
||||
child.stdout.on('data', childPrint);
|
||||
child.stderr.on('data', childPrint);
|
||||
child.stdout.on('data', (chunk) => childPrint(chunk, 'stdout'));
|
||||
child.stderr.on('data', (chunk) => childPrint(chunk, 'stderr'));
|
||||
|
||||
let output = '';
|
||||
function waitForListenHint(text) {
|
||||
@@ -231,7 +231,7 @@ class NodeInspector {
|
||||
return this.client.connect(port, host)
|
||||
.then(() => {
|
||||
debuglog('connection established');
|
||||
this.stdout.write(' ok');
|
||||
this.stdout.write(' ok\n');
|
||||
}, (error) => {
|
||||
debuglog('connect failed', error);
|
||||
// If it's failed to connect 10 times then print failed message
|
||||
@@ -245,7 +245,7 @@ class NodeInspector {
|
||||
});
|
||||
};
|
||||
|
||||
this.print(`connecting to ${host}:${port} ..`, true);
|
||||
this.print(`connecting to ${host}:${port} ..`, false);
|
||||
return attemptConnect();
|
||||
});
|
||||
}
|
||||
@@ -259,23 +259,32 @@ class NodeInspector {
|
||||
}
|
||||
}
|
||||
|
||||
print(text, oneline = false) {
|
||||
print(text, appendNewline = false) {
|
||||
this.clearLine();
|
||||
this.stdout.write(oneline ? text : `${text}\n`);
|
||||
this.stdout.write(appendNewline ? `${text}\n` : text);
|
||||
}
|
||||
|
||||
childPrint(text) {
|
||||
this.print(
|
||||
text.toString()
|
||||
.split(/\r\n|\r|\n/g)
|
||||
.filter((chunk) => !!chunk)
|
||||
.map((chunk) => `< ${chunk}`)
|
||||
.join('\n')
|
||||
);
|
||||
if (!this.paused) {
|
||||
this.repl.displayPrompt(true);
|
||||
#stdioBuffers = {stdout: '', stderr: ''};
|
||||
childPrint(text, which) {
|
||||
const lines = (this.#stdioBuffers[which] + text)
|
||||
.split(/\r\n|\r|\n/g);
|
||||
|
||||
this.#stdioBuffers[which] = '';
|
||||
|
||||
if (lines[lines.length - 1] !== '') {
|
||||
this.#stdioBuffers[which] = lines.pop();
|
||||
}
|
||||
if (/Waiting for the debugger to disconnect\.\.\.\n$/.test(text)) {
|
||||
|
||||
const textToPrint = lines.map((chunk) => `< ${chunk}`).join('\n');
|
||||
|
||||
if (lines.length) {
|
||||
this.print(textToPrint, true);
|
||||
if (!this.paused) {
|
||||
this.repl.displayPrompt(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (textToPrint.endsWith('Waiting for the debugger to disconnect...\n')) {
|
||||
this.killChild();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,9 +320,9 @@ function createRepl(inspector) {
|
||||
return util.inspect(value, INSPECT_OPTIONS);
|
||||
}
|
||||
|
||||
function print(value, oneline = false) {
|
||||
function print(value, addNewline = true) {
|
||||
const text = typeof value === 'string' ? value : inspect(value);
|
||||
return inspector.print(text, oneline);
|
||||
return inspector.print(text, addNewline);
|
||||
}
|
||||
|
||||
function getCurrentLocation() {
|
||||
@@ -928,13 +928,13 @@ function createRepl(inspector) {
|
||||
if (finished) {
|
||||
print('Heap snaphost prepared.');
|
||||
} else {
|
||||
print(`Heap snapshot: ${done}/${total}`, true);
|
||||
print(`Heap snapshot: ${done}/${total}`, false);
|
||||
}
|
||||
}
|
||||
function onChunk({ chunk }) {
|
||||
sizeWritten += chunk.length;
|
||||
writer.write(chunk);
|
||||
print(`Writing snapshot: ${sizeWritten}`, true);
|
||||
print(`Writing snapshot: ${sizeWritten}`, false);
|
||||
}
|
||||
function onResolve() {
|
||||
writer.end(() => {
|
||||
@@ -956,7 +956,7 @@ function createRepl(inspector) {
|
||||
HeapProfiler.on('reportHeapSnapshotProgress', onProgress);
|
||||
HeapProfiler.on('addHeapSnapshotChunk', onChunk);
|
||||
|
||||
print('Heap snapshot: 0/0', true);
|
||||
print('Heap snapshot: 0/0', false);
|
||||
HeapProfiler.takeHeapSnapshot({ reportProgress: true })
|
||||
.then(onResolve, onReject);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user