@@ -44,6 +44,8 @@ export class MI2DebugSession extends DebugSession {
4444 protected miDebugger : MI2 ;
4545 protected commandServer : net . Server ;
4646 protected serverPath : string ;
47+ protected threadGroupPids = new Map < string , string > ( ) ;
48+ protected threadToPid = new Map < number , string > ( ) ;
4749
4850 public constructor ( debuggerLinesStartAt1 : boolean , isServer : boolean = false ) {
4951 super ( debuggerLinesStartAt1 , isServer ) ;
@@ -64,6 +66,9 @@ export class MI2DebugSession extends DebugSession {
6466 this . miDebugger . on ( "thread-created" , this . threadCreatedEvent . bind ( this ) ) ;
6567 this . miDebugger . on ( "thread-exited" , this . threadExitedEvent . bind ( this ) ) ;
6668 this . miDebugger . once ( "debug-ready" , ( ( ) => this . sendEvent ( new InitializedEvent ( ) ) ) ) ;
69+ this . miDebugger . on ( "thread-group-started" , this . threadGroupStartedEvent . bind ( this ) ) ;
70+ this . miDebugger . on ( "thread-group-exited" , this . threadGroupExitedEvent . bind ( this ) ) ;
71+ this . sendEvent ( new InitializedEvent ( ) ) ;
6772 try {
6873 this . commandServer = net . createServer ( c => {
6974 c . on ( "data" , data => {
@@ -164,22 +169,41 @@ export class MI2DebugSession extends DebugSession {
164169 }
165170
166171 protected threadCreatedEvent ( info : MINode ) {
167- this . sendEvent ( new ThreadEvent ( "started" , info . record ( "id" ) ) ) ;
172+ let threadId = parseInt ( info . record ( "id" ) , 10 ) ;
173+
174+ let threadPid = this . threadGroupPids . get ( info . record ( "group-id" ) ) ;
175+ this . threadToPid . set ( threadId , threadPid ) ;
176+
177+ this . sendEvent ( new ThreadEvent ( "started" , threadId ) ) ;
168178 }
169179
170180 protected threadExitedEvent ( info : MINode ) {
171- this . sendEvent ( new ThreadEvent ( "exited" , info . record ( "id" ) ) ) ;
181+ let threadId = parseInt ( info . record ( "id" ) , 10 ) ;
182+
183+ this . threadToPid . delete ( info . record ( "group-id" ) ) ;
184+
185+ this . sendEvent ( new ThreadEvent ( "exited" , threadId ) ) ;
186+ }
187+
188+ protected threadGroupStartedEvent ( info : MINode ) {
189+ this . threadGroupPids . set ( info . record ( "id" ) , info . record ( "pid" ) ) ;
190+ }
191+
192+ protected threadGroupExitedEvent ( info : MINode ) {
193+ this . threadGroupPids . delete ( info . record ( "id" ) ) ;
172194 }
173195
174- protected quitEvent ( ) {
175- this . quit = true ;
176- this . sendEvent ( new TerminatedEvent ( ) ) ;
196+ protected quitEvent ( info ?: MINode ) {
197+ if ( this . threadGroupPids . size == 0 ) {
198+ this . quit = true ;
199+ this . sendEvent ( new TerminatedEvent ( ) ) ;
177200
178- if ( this . serverPath )
179- fs . unlink ( this . serverPath , ( err ) => {
201+ if ( this . serverPath )
202+ fs . unlink ( this . serverPath , ( err ) => {
180203 // eslint-disable-next-line no-console
181204 console . error ( "Failed to unlink debug server" ) ;
182- } ) ;
205+ } ) ;
206+ }
183207 }
184208
185209 protected launchError ( err : any ) {
@@ -286,7 +310,13 @@ export class MI2DebugSession extends DebugSession {
286310 } ;
287311 for ( const thread of threads ) {
288312 const threadName = thread . name || thread . targetId || "<unnamed>" ;
289- response . body . threads . push ( new Thread ( thread . id , thread . id + ":" + threadName ) ) ;
313+
314+ if ( this . threadGroupPids . size > 1 ) {
315+ let pid = this . threadToPid . get ( thread . id ) ;
316+ response . body . threads . push ( new Thread ( thread . id , `(${ pid } ) ${ thread . id } :${ threadName } ` ) ) ;
317+ } else {
318+ response . body . threads . push ( new Thread ( thread . id , `${ thread . id } :${ threadName } ` ) ) ;
319+ }
290320 }
291321 this . sendResponse ( response ) ;
292322 } ) . catch ( ( error : MIError ) => {
@@ -672,6 +702,7 @@ export class MI2DebugSession extends DebugSession {
672702
673703 protected override reverseContinueRequest ( response : DebugProtocol . ReverseContinueResponse , args : DebugProtocol . ReverseContinueArguments ) : void {
674704 this . miDebugger . continue ( true ) . then ( done => {
705+ response . body . allThreadsContinued = true ;
675706 this . sendResponse ( response ) ;
676707 } , msg => {
677708 this . sendErrorResponse ( response , 2 , `Could not continue: ${ msg } ` ) ;
@@ -680,6 +711,7 @@ export class MI2DebugSession extends DebugSession {
680711
681712 protected override continueRequest ( response : DebugProtocol . ContinueResponse , args : DebugProtocol . ContinueArguments ) : void {
682713 this . miDebugger . continue ( ) . then ( done => {
714+ response . body . allThreadsContinued = true ;
683715 this . sendResponse ( response ) ;
684716 } , msg => {
685717 this . sendErrorResponse ( response , 2 , `Could not continue: ${ msg } ` ) ;
0 commit comments