@@ -181,6 +181,8 @@ interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArguments {
181181 client : string ;
182182 /// Arguments for GDB client.
183183 clientArgs : string [ ] ;
184+ /// Commands for GDB MI.
185+ gdbCommands : string [ ] ;
184186
185187 /// Path to GDB server.
186188 server : string ;
@@ -216,7 +218,9 @@ export class GnuDebugSession extends DebugSession {
216218 /// Server promise reject
217219 private serverReject : ( error : string ) => void ;
218220 /// Test for server success
219- private serverSuccess : RegExp ;
221+ private serverSuccess0 : RegExp ;
222+ /// Test for server success
223+ private serverSuccess1 : RegExp ;
220224 /// Test for server failure
221225 private serverFailure : RegExp ;
222226
@@ -332,7 +336,21 @@ export class GnuDebugSession extends DebugSession {
332336 args . clientArgs . push ( args . program ) ;
333337 args . clientArgs . push ( '-q' ) ;
334338 args . clientArgs . push ( '--interpreter=mi' ) ;
339+ if ( ! args . gdbCommands ) {
340+ args . gdbCommands =
341+ [
342+ // `-gdb-version`,
343+ `-gdb-set target-async on` ,
344+ `-enable-pretty-printing` ,
345+ `-target-select extended-remote ${ args . serverHost } :${ args . serverPort } ` ,
346+ `-file-exec-and-symbols "${ args . program } "` ,
347+ `-interpreter-exec console "monitor halt"` ,
348+ `-interpreter-exec console "monitor reset"` ,
349+ `-target-download` ,
350+ ] ;
351+ }
335352
353+
336354 if ( ! args . server ) {
337355 args . server = 'JLinkGDBServer' ;
338356 }
@@ -353,21 +371,18 @@ export class GnuDebugSession extends DebugSession {
353371 this . debugOutput = args . debugOutput ;
354372 }
355373
356- this . stdout ( 'program = ' + args . program + '\n' ) ;
357- this . stdout ( 'Toolchain = ' + args . toolchain + '\n' ) ;
358- this . stdout ( 'Client = ' + args . client + '\n' ) ;
359- this . stdout ( 'Server = ' + args . server + '\n' ) ;
360- this . stdout ( 'Server host = ' + args . serverHost + '\n' ) ;
361- this . stdout ( 'Server port = ' + args . serverPort + '\n' ) ;
374+ this . stdout ( 'program = ' + args . program + '\n' ) ;
375+ this . stdout ( 'Toolchain = ' + args . toolchain + '\n' ) ;
376+ this . stdout ( 'Client = ' + args . client + '\n' ) ;
377+ this . stdout ( 'Server = ' + args . server + '\n' ) ;
378+ this . stdout ( 'Server host = ' + args . serverHost + '\n' ) ;
379+ this . stdout ( 'Server port = ' + args . serverPort + '\n' ) ;
362380
363- this . serverSuccess = / C o n n e c t e d t o t a r g e t / ;
381+ this . serverSuccess0 = / C o n n e c t e d t o t a r g e t / ;
382+ this . serverSuccess1 = / I n f o : L i s t e n i n g / ;
364383 this . serverFailure = / E r r o r : | E R R O R : / ;
365384 this . clientSuccess = / \( g d b \) / ;
366385 this . clientFailure = / E r r o r : | E R R O R : / ;
367- if ( args . server == "openocd" )
368- {
369- this . serverSuccess = / I n f o : L i s t e n i n g / ;
370- }
371386
372387 this . halt = false ;
373388 this . starting = true ;
@@ -398,8 +413,7 @@ export class GnuDebugSession extends DebugSession {
398413 ( ) => {
399414 this . stdout ( 'Client success\n' ) ;
400415 this . starting = false ;
401- this . launchCommands
402- ( args . serverHost , args . serverPort , args . program ) ;
416+ this . launchCommands ( args . gdbCommands ) ;
403417 this . sendResponse ( response ) ;
404418 } ,
405419 // Client failure
@@ -445,22 +459,33 @@ export class GnuDebugSession extends DebugSession {
445459
446460 let end = this . serverBuffer . lastIndexOf ( '\n' ) ;
447461 if ( end !== - 1 ) {
448- let lines = this . serverBuffer . substr ( 0 , end ) . split ( '\n' ) as string [ ] ;
462+ let lines = this . serverBuffer . substr ( 0 , end ) . split ( / \r \n | \r | \n / ) as string [ ] ;
449463 this . serverBuffer = this . serverBuffer . substring ( end + 1 ) ;
450464
451465 for ( let line of lines ) {
452466 // Display in vscode debug console
453467 this . debugServer ( line + '\n' ) ;
454468 if ( this . starting ) {
455- if ( ( line . match ( this . serverSuccess ) ) ) {
469+ if
470+ (
471+ line . match ( this . serverSuccess0 ) ||
472+ line . match ( this . serverSuccess1 )
473+ ) {
456474 this . serverResolve ( ) ;
457475 }
458476 if ( ( line . match ( this . serverFailure ) ) ) {
459477 this . serverReject ( line ) ;
460478 }
461479 }
462480 }
463- if ( this . starting && this . serverBuffer . match ( this . serverSuccess ) ) {
481+ if
482+ (
483+ this . starting &&
484+ (
485+ this . serverBuffer . match ( this . serverSuccess0 ) ||
486+ this . serverBuffer . match ( this . serverSuccess1 )
487+ )
488+ ) {
464489 // Display in vscode debug console
465490 this . debugServer ( this . serverBuffer + '\n' ) ;
466491 this . serverBuffer = '' ;
@@ -1418,18 +1443,7 @@ export class GnuDebugSession extends DebugSession {
14181443 this . debugServer ( 'customRequest\n' ) ;
14191444 }
14201445
1421- private launchCommands ( host : string , port : number , program : string ) {
1422- const commands = [
1423- // `-gdb-version`,
1424- `-gdb-set target-async on` ,
1425- `-enable-pretty-printing` ,
1426- `-target-select extended-remote ${ host } :${ port } ` ,
1427- `-file-exec-and-symbols "${ program } "` ,
1428- `-interpreter-exec console "monitor halt"` ,
1429- `-interpreter-exec console "monitor reset"` ,
1430- `-target-download` ,
1431- ] ;
1432-
1446+ private launchCommands ( commands : string [ ] ) {
14331447 const promises = commands . map ( ( c ) => this . sendCommand ( c ) ) ;
14341448
14351449 Promise . all ( promises ) . then ( ( ) => {
0 commit comments