@@ -38,6 +38,8 @@ export class MI2DebugSession extends DebugSession {
3838 protected miDebugger : MI2 ;
3939 protected commandServer : net . Server ;
4040 protected serverPath : string ;
41+ protected threadGroupPids = new Map < string , string > ( ) ;
42+ protected threadToPid = new Map < number , string > ( ) ;
4143
4244 public constructor ( debuggerLinesStartAt1 : boolean , isServer : boolean = false ) {
4345 super ( debuggerLinesStartAt1 , isServer ) ;
@@ -56,6 +58,8 @@ export class MI2DebugSession extends DebugSession {
5658 this . miDebugger . on ( "signal-stop" , this . handlePause . bind ( this ) ) ;
5759 this . miDebugger . on ( "thread-created" , this . threadCreatedEvent . bind ( this ) ) ;
5860 this . miDebugger . on ( "thread-exited" , this . threadExitedEvent . bind ( this ) ) ;
61+ this . miDebugger . on ( "thread-group-started" , this . threadGroupStartedEvent . bind ( this ) ) ;
62+ this . miDebugger . on ( "thread-group-exited" , this . threadGroupExitedEvent . bind ( this ) ) ;
5963 this . sendEvent ( new InitializedEvent ( ) ) ;
6064 try {
6165 this . commandServer = net . createServer ( c => {
@@ -140,21 +144,39 @@ export class MI2DebugSession extends DebugSession {
140144 }
141145
142146 protected threadCreatedEvent ( info : MINode ) {
143- this . sendEvent ( new ThreadEvent ( "started" , info . record ( "id" ) ) ) ;
147+ let threadId = parseInt ( info . record ( "id" ) , 10 ) ;
148+
149+ let threadPid = this . threadGroupPids . get ( info . record ( "group-id" ) ) ;
150+ this . threadToPid . set ( threadId , threadPid ) ;
151+
152+ this . sendEvent ( new ThreadEvent ( "started" , threadId ) ) ;
144153 }
145154
146155 protected threadExitedEvent ( info : MINode ) {
147- this . sendEvent ( new ThreadEvent ( "exited" , info . record ( "id" ) ) ) ;
156+ let threadId = parseInt ( info . record ( "id" ) , 10 ) ;
157+
158+ this . threadToPid . delete ( info . record ( "group-id" ) ) ;
159+
160+ this . sendEvent ( new ThreadEvent ( "exited" , threadId ) ) ;
148161 }
149162
150- protected quitEvent ( ) {
151- this . quit = true ;
152- this . sendEvent ( new TerminatedEvent ( ) ) ;
163+ protected threadGroupStartedEvent ( info : MINode ) {
164+ this . threadGroupPids . set ( info . record ( "id" ) , info . record ( "pid" ) ) ;
165+ }
153166
154- if ( this . serverPath )
155- fs . unlink ( this . serverPath , ( err ) => {
156- console . error ( "Failed to unlink debug server" ) ;
157- } ) ;
167+ protected threadGroupExitedEvent ( info : MINode ) {
168+ this . threadGroupPids . delete ( info . record ( "id" ) ) ;
169+ }
170+
171+ protected quitEvent ( info ?: MINode ) {
172+ if ( this . threadGroupPids . size == 0 ) {
173+ this . quit = true ;
174+ this . sendEvent ( new TerminatedEvent ( ) ) ;
175+ if ( this . serverPath )
176+ fs . unlink ( this . serverPath , ( err ) => {
177+ console . error ( "Failed to unlink debug server" ) ;
178+ } ) ;
179+ }
158180 }
159181
160182 protected launchError ( err : any ) {
@@ -274,8 +296,14 @@ export class MI2DebugSession extends DebugSession {
274296 threads : [ ]
275297 } ;
276298 for ( const thread of threads ) {
277- let threadName = thread . name || thread . targetId || "<unnamed>" ;
278- response . body . threads . push ( new Thread ( thread . id , thread . id + ":" + threadName ) ) ;
299+ let threadName = thread . name || thread . targetId || "<unnamed>" ;
300+ if ( this . threadGroupPids . size > 1 ) {
301+ let pid = this . threadToPid . get ( thread . id ) ;
302+ threadName = `(${ pid } ) ${ thread . id } :${ threadName } ` ;
303+ } else {
304+ threadName = `${ thread . id } :${ threadName } ` ;
305+ }
306+ response . body . threads . push ( new Thread ( thread . id , threadName ) ) ;
279307 }
280308 this . sendResponse ( response ) ;
281309 } ) ;
@@ -561,7 +589,7 @@ export class MI2DebugSession extends DebugSession {
561589 }
562590 }
563591
564- protected pauseRequest ( response : DebugProtocol . ContinueResponse , args : DebugProtocol . ContinueArguments ) : void {
592+ protected pauseRequest ( response : DebugProtocol . PauseResponse , args : DebugProtocol . PauseArguments ) : void {
565593 this . miDebugger . interrupt ( ) . then ( done => {
566594 this . sendResponse ( response ) ;
567595 } , msg => {
@@ -571,6 +599,7 @@ export class MI2DebugSession extends DebugSession {
571599
572600 protected reverseContinueRequest ( response : DebugProtocol . ReverseContinueResponse , args : DebugProtocol . ReverseContinueArguments ) : void {
573601 this . miDebugger . continue ( true ) . then ( done => {
602+ response . body . allThreadsContinued = true ;
574603 this . sendResponse ( response ) ;
575604 } , msg => {
576605 this . sendErrorResponse ( response , 2 , `Could not continue: ${ msg } ` ) ;
@@ -579,6 +608,7 @@ export class MI2DebugSession extends DebugSession {
579608
580609 protected continueRequest ( response : DebugProtocol . ContinueResponse , args : DebugProtocol . ContinueArguments ) : void {
581610 this . miDebugger . continue ( ) . then ( done => {
611+ response . body . allThreadsContinued = true ;
582612 this . sendResponse ( response ) ;
583613 } , msg => {
584614 this . sendErrorResponse ( response , 2 , `Could not continue: ${ msg } ` ) ;
0 commit comments