@@ -10,7 +10,7 @@ import { greenFormat } from '../frontend/ansi-helpers';
1010
1111export let GdbPid = - 1 ;
1212
13- let ServerLogFilePath : string = null ;
13+ let ServerLogFilePath : string | null = null ;
1414export function getServerLogFilePath ( ) : string {
1515 if ( ! ServerLogFilePath ) {
1616 const tmpDirName = os . tmpdir ( ) ;
@@ -39,19 +39,19 @@ export function ServerConsoleLog(str: string, usePid?: number) {
3939
4040let currentServers : GDBServer [ ] = [ ] ;
4141export class GDBServer extends EventEmitter {
42- private process : ChildProcess . ChildProcess ;
42+ private process : ChildProcess . ChildProcess | null = null ;
4343 private outBuffer : string = '' ;
4444 private errBuffer : string = '' ;
45- protected consoleSocket : net . Socket = null ;
46- private initResolve : ( result : boolean ) => void ;
47- private initReject : ( error : any ) => void ;
45+ protected consoleSocket : net . Socket | null = null ;
46+ private initResolve : ( ( result : boolean ) => void ) | null = null ;
47+ private initReject : ( ( error : any ) => void ) | null = null ;
4848 public static readonly SERVER_TIMEOUT = 10 * 60 * 1000 ;
4949 public static readonly LOCALHOST = '0.0.0.0' ;
50- public pid : number = - 1 ;
50+ public pid : number | undefined = - 1 ;
5151
5252 constructor (
53- private cwd : string , private application : string , private args : string [ ] ,
54- private initMatch : RegExp , private port : number | undefined , private consolePort : number ) {
53+ private cwd : string | null , private application : string | null , private args : string [ ] ,
54+ private initMatch : RegExp | null , private port : number | undefined , private consolePort : number ) {
5555 super ( ) ;
5656 }
5757
@@ -66,11 +66,13 @@ export class GDBServer extends EventEmitter {
6666 ServerConsoleLog ( 'GDBServer: Could not connect to console: ' + e ) ;
6767 reject ( e ) ;
6868 }
69- this . process = ChildProcess . spawn ( this . application , this . args , { cwd : this . cwd } ) ;
69+ this . process = ChildProcess . spawn ( this . application , this . args , { cwd : this . cwd || undefined } ) ;
7070 currentServers . push ( this ) ;
7171 this . pid = this . process . pid ;
72- this . process . stdout . on ( 'data' , this . onStdout . bind ( this ) ) ;
73- this . process . stderr . on ( 'data' , this . onStderr . bind ( this ) ) ;
72+ if ( this . process . stdout && this . process . stderr ) {
73+ this . process . stdout . on ( 'data' , this . onStdout . bind ( this ) ) ;
74+ this . process . stderr . on ( 'data' , this . onStderr . bind ( this ) ) ;
75+ }
7476 this . process . on ( 'exit' , this . onExit . bind ( this ) ) ;
7577 this . process . on ( 'error' , this . onError . bind ( this ) ) ;
7678
@@ -109,7 +111,7 @@ export class GDBServer extends EventEmitter {
109111 return ! ! this . process ;
110112 }
111113
112- private exitTimeout : NodeJS . Timeout = null ;
114+ private exitTimeout : NodeJS . Timeout | null = null ;
113115 private killInProgress = false ;
114116 public exit ( ) : void {
115117 if ( this . process && ! this . killInProgress ) {
@@ -123,7 +125,7 @@ export class GDBServer extends EventEmitter {
123125 }
124126 }
125127
126- private onExit ( code , signal ) {
128+ private onExit ( code : any , signal : any ) {
127129 if ( this . exitTimeout ) {
128130 clearTimeout ( this . exitTimeout ) ;
129131 this . exitTimeout = null ;
@@ -138,7 +140,7 @@ export class GDBServer extends EventEmitter {
138140 } , 10 ) ;
139141 }
140142
141- private onError ( err ) {
143+ private onError ( err : any ) {
142144 if ( this . initReject ) {
143145 this . initReject ( err ) ;
144146 this . initReject = null ;
@@ -148,7 +150,7 @@ export class GDBServer extends EventEmitter {
148150 this . emit ( 'launcherror' , err ) ;
149151 }
150152
151- private onStdout ( data ) {
153+ private onStdout ( data : any ) {
152154 this . sendToConsole ( data ) ; // Send it without any processing or buffering
153155 if ( this . initResolve ) {
154156 if ( typeof data === 'string' ) {
@@ -172,7 +174,7 @@ export class GDBServer extends EventEmitter {
172174 }
173175 }
174176
175- private onStderr ( data ) {
177+ private onStderr ( data : any ) {
176178 this . sendToConsole ( data ) ; // Send it without any processing or buffering
177179 if ( this . initResolve ) {
178180 if ( typeof data === 'string' ) {
@@ -201,7 +203,9 @@ export class GDBServer extends EventEmitter {
201203 const socket = new net . Socket ( ) ;
202204 socket . on ( 'data' , ( data ) => {
203205 try {
204- this . process . stdin . write ( data , 'utf8' ) ;
206+ if ( this . process && this . process . stdin ) {
207+ this . process . stdin . write ( data , 'utf8' ) ;
208+ }
205209 } catch ( e ) {
206210 console . error ( `stdin write failed ${ e } ` ) ;
207211 }
@@ -227,7 +231,8 @@ export class GDBServer extends EventEmitter {
227231
228232 // It is possible that the server is not ready
229233 socket . connect ( this . consolePort , '127.0.0.1' , ( ) => {
230- socket . write ( greenFormat ( quoteShellCmdLine ( [ this . application , ...this . args ] ) + '\n' ) ) ;
234+ const app = this . application || '' ;
235+ socket . write ( greenFormat ( quoteShellCmdLine ( [ app , ...this . args ] ) + '\n' ) ) ;
231236 this . consoleSocket = socket ;
232237 resolve ( ) ;
233238 } ) ;
@@ -260,7 +265,7 @@ export class GDBServer extends EventEmitter {
260265// are in server mode (as in when in debug) it does not do that because we are always running.
261266//
262267// See GDBDebugSession.disconnectRequest()
263- process . on ( 'exit' , ( code , signal ) => {
268+ process . on ( 'exit' , ( code : any , signal : any ) => {
264269 if ( currentServers . length > 0 ) {
265270 ServerConsoleLog ( `Debug Adapter crashed or killed by VSCode? code=${ code } signal=${ signal } ` ) ;
266271 for ( const p of [ ...currentServers ] ) {
0 commit comments