11
22
33import * as child from 'child_process' ;
4- import { LineHandler , DapHandler , DataSource } from './debugRuntime' ;
4+ import { LineHandler , DataSource , DapHandler } from './debugRuntime' ;
55import { RStartupArguments } from './debugProtocolModifications' ;
66import { config , getPortNumber } from './utils' ;
77import * as net from 'net' ;
@@ -16,9 +16,10 @@ import kill = require('tree-kill');
1616export class RSession {
1717 private cp ?: child . ChildProcessWithoutNullStreams ;
1818 private handleLine : LineHandler ;
19- private handleDapString : DapHandler ;
19+ private handleDapData : DapHandler ;
2020 private echoStdin : ( text : string ) => void ;
2121 private restOfLine : { [ k in DataSource ] ?: string } = { } ;
22+ private restOfDap : Buffer = Buffer . from ( '' ) ;
2223
2324 public ignoreOutput : boolean = false ;
2425
@@ -32,12 +33,12 @@ export class RSession {
3233
3334 constructor (
3435 handleLine : LineHandler ,
35- handleDapString : DapHandler ,
36+ handleDapData : DapHandler ,
3637 echoStdin ?: ( text : string ) => void
3738 ) {
3839 // store line/json handlers (are called by this.handleData)
3940 this . handleLine = handleLine ;
40- this . handleDapString = handleDapString ;
41+ this . handleDapData = handleDapData ;
4142 this . echoStdin = echoStdin || ( ( text : string ) => { /* dummy */ } ) ;
4243 }
4344
@@ -66,7 +67,7 @@ export class RSession {
6667 this . dapServer = net . createServer ( ( socket ) => {
6768 socket . on ( 'data' , ( data ) => {
6869 this . handleData ( data , 'dapSocket' ) ;
69- logger . log ( 'dapOut ' , data ) ;
70+ logger . log ( 'dapIn ' , data ) ;
7071 } ) ;
7172 this . dapSocket = socket ;
7273 } ) ;
@@ -138,22 +139,24 @@ export class RSession {
138139
139140 public handleData ( data : Buffer , from : DataSource ) : void {
140141
141- let text : string = data . toString ( ) ;
142- // text = text.replace(/\r/g,''); //keep only \n as linebreak
143- text = ( this . restOfLine [ from ] || '' ) + text ; // append to rest of line from previouse call
144- const lines = text . split ( / \n / ) ; // split into lines
145-
146142 // logger.debug(`data from ${from}: ${text}`);
147143 //
148144 if ( from === 'dapSocket' ) {
149- const restOfLine = this . handleDapString ( text ) ;
150- this . restOfLine [ from ] = restOfLine ;
145+ data = Buffer . concat ( [ this . restOfDap , data ] ) ;
146+ const restOfLine = this . handleDapData ( data ) ;
147+ this . restOfDap = restOfLine ;
151148 return ;
152149 }
153150
151+
152+ let text : string = data . toString ( ) ;
153+ // text = text.replace(/\r/g,''); //keep only \n as linebreak
154+ text = ( this . restOfLine [ from ] || '' ) + text ; // append to rest of line from previouse call
155+ const lines = text . split ( / \n / ) ; // split into lines
156+
154157 for ( let i = 0 ; i < lines . length ; i ++ ) {
155- // abort output handling if ignoreOutput has been set to true
156- // used to avoid handling remaining output after debugging has been stopped
158+ // abort output handling if ignoreOutput has been set to true
159+ // used to avoid handling remaining output after debugging has been stopped
157160 if ( this . ignoreOutput ) {
158161 return ;
159162 }
0 commit comments