Skip to content

Commit def85da

Browse files
Trotttargos
authored andcommitted
debugger: accommodate line chunking in Windows
PR-URL: #38161 Refs: https://github.com/nodejs/node/discussions/36481 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Jan Krems <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 07361e6 commit def85da

File tree

2 files changed

+31
-22
lines changed

2 files changed

+31
-22
lines changed

‎lib/internal/inspector/_inspect.js‎

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ function runScript(script, scriptArgs, inspectHost, inspectPort, childPrint){
9797
constchild=spawn(process.execPath,args);
9898
child.stdout.setEncoding('utf8');
9999
child.stderr.setEncoding('utf8');
100-
child.stdout.on('data',childPrint);
101-
child.stderr.on('data',childPrint);
100+
child.stdout.on('data',(chunk)=>childPrint(chunk,'stdout'));
101+
child.stderr.on('data',(chunk)=>childPrint(chunk,'stderr'));
102102

103103
letoutput='';
104104
functionwaitForListenHint(text){
@@ -231,7 +231,7 @@ class NodeInspector{
231231
returnthis.client.connect(port,host)
232232
.then(()=>{
233233
debuglog('connection established');
234-
this.stdout.write(' ok');
234+
this.stdout.write(' ok\n');
235235
},(error)=>{
236236
debuglog('connect failed',error);
237237
// If it's failed to connect 10 times then print failed message
@@ -245,7 +245,7 @@ class NodeInspector{
245245
});
246246
};
247247

248-
this.print(`connecting to ${host}:${port} ..`,true);
248+
this.print(`connecting to ${host}:${port} ..`,false);
249249
returnattemptConnect();
250250
});
251251
}
@@ -259,23 +259,32 @@ class NodeInspector{
259259
}
260260
}
261261

262-
print(text,oneline=false){
262+
print(text,appendNewline=false){
263263
this.clearLine();
264-
this.stdout.write(oneline ? text : `${text}\n`);
264+
this.stdout.write(appendNewline ? `${text}\n` : text);
265265
}
266266

267-
childPrint(text){
268-
this.print(
269-
text.toString()
270-
.split(/\r\n|\r|\n/g)
271-
.filter((chunk)=>!!chunk)
272-
.map((chunk)=>`< ${chunk}`)
273-
.join('\n')
274-
);
275-
if(!this.paused){
276-
this.repl.displayPrompt(true);
267+
#stdioBuffers ={stdout: '',stderr: ''};
268+
childPrint(text,which){
269+
constlines=(this.#stdioBuffers[which]+text)
270+
.split(/\r\n|\r|\n/g);
271+
272+
this.#stdioBuffers[which]='';
273+
274+
if(lines[lines.length-1]!==''){
275+
this.#stdioBuffers[which]=lines.pop();
276+
}
277+
278+
consttextToPrint=lines.map((chunk)=>`< ${chunk}`).join('\n');
279+
280+
if(lines.length){
281+
this.print(textToPrint,true);
282+
if(!this.paused){
283+
this.repl.displayPrompt(true);
284+
}
277285
}
278-
if(/Waitingforthedebuggertodisconnect\.\.\.\n$/.test(text)){
286+
287+
if(textToPrint.endsWith('Waiting for the debugger to disconnect...\n')){
279288
this.killChild();
280289
}
281290
}

‎lib/internal/inspector/inspect_repl.js‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,9 @@ function createRepl(inspector){
320320
returnutil.inspect(value,INSPECT_OPTIONS);
321321
}
322322

323-
functionprint(value,oneline=false){
323+
functionprint(value,addNewline=true){
324324
consttext=typeofvalue==='string' ? value : inspect(value);
325-
returninspector.print(text,oneline);
325+
returninspector.print(text,addNewline);
326326
}
327327

328328
functiongetCurrentLocation(){
@@ -928,13 +928,13 @@ function createRepl(inspector){
928928
if(finished){
929929
print('Heap snaphost prepared.');
930930
}else{
931-
print(`Heap snapshot: ${done}/${total}`,true);
931+
print(`Heap snapshot: ${done}/${total}`,false);
932932
}
933933
}
934934
functiononChunk({ chunk }){
935935
sizeWritten+=chunk.length;
936936
writer.write(chunk);
937-
print(`Writing snapshot: ${sizeWritten}`,true);
937+
print(`Writing snapshot: ${sizeWritten}`,false);
938938
}
939939
functiononResolve(){
940940
writer.end(()=>{
@@ -956,7 +956,7 @@ function createRepl(inspector){
956956
HeapProfiler.on('reportHeapSnapshotProgress',onProgress);
957957
HeapProfiler.on('addHeapSnapshotChunk',onChunk);
958958

959-
print('Heap snapshot: 0/0',true);
959+
print('Heap snapshot: 0/0',false);
960960
HeapProfiler.takeHeapSnapshot({reportProgress: true})
961961
.then(onResolve,onReject);
962962
});

0 commit comments

Comments
(0)