@@ -38,6 +38,8 @@ export class MI2DebugSession extends DebugSession {
38
38
protected miDebugger : MI2 ;
39
39
protected commandServer : net . Server ;
40
40
protected serverPath : string ;
41
+ protected threadGroupPids = new Map < string , string > ( ) ;
42
+ protected threadToPid = new Map < number , string > ( ) ;
41
43
42
44
public constructor ( debuggerLinesStartAt1 : boolean , isServer : boolean = false ) {
43
45
super ( debuggerLinesStartAt1 , isServer ) ;
@@ -56,6 +58,8 @@ export class MI2DebugSession extends DebugSession {
56
58
this . miDebugger . on ( "signal-stop" , this . handlePause . bind ( this ) ) ;
57
59
this . miDebugger . on ( "thread-created" , this . threadCreatedEvent . bind ( this ) ) ;
58
60
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 ) ) ;
59
63
this . sendEvent ( new InitializedEvent ( ) ) ;
60
64
try {
61
65
this . commandServer = net . createServer ( c => {
@@ -140,21 +144,39 @@ export class MI2DebugSession extends DebugSession {
140
144
}
141
145
142
146
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 ) ) ;
144
153
}
145
154
146
155
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 ) ) ;
148
161
}
149
162
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
+ }
153
166
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
+ }
158
180
}
159
181
160
182
protected launchError ( err : any ) {
@@ -274,8 +296,14 @@ export class MI2DebugSession extends DebugSession {
274
296
threads : [ ]
275
297
} ;
276
298
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 ) ) ;
279
307
}
280
308
this . sendResponse ( response ) ;
281
309
} ) ;
@@ -561,7 +589,7 @@ export class MI2DebugSession extends DebugSession {
561
589
}
562
590
}
563
591
564
- protected pauseRequest ( response : DebugProtocol . ContinueResponse , args : DebugProtocol . ContinueArguments ) : void {
592
+ protected pauseRequest ( response : DebugProtocol . PauseResponse , args : DebugProtocol . PauseArguments ) : void {
565
593
this . miDebugger . interrupt ( ) . then ( done => {
566
594
this . sendResponse ( response ) ;
567
595
} , msg => {
@@ -571,6 +599,7 @@ export class MI2DebugSession extends DebugSession {
571
599
572
600
protected reverseContinueRequest ( response : DebugProtocol . ReverseContinueResponse , args : DebugProtocol . ReverseContinueArguments ) : void {
573
601
this . miDebugger . continue ( true ) . then ( done => {
602
+ response . body . allThreadsContinued = true ;
574
603
this . sendResponse ( response ) ;
575
604
} , msg => {
576
605
this . sendErrorResponse ( response , 2 , `Could not continue: ${ msg } ` ) ;
@@ -579,6 +608,7 @@ export class MI2DebugSession extends DebugSession {
579
608
580
609
protected continueRequest ( response : DebugProtocol . ContinueResponse , args : DebugProtocol . ContinueArguments ) : void {
581
610
this . miDebugger . continue ( ) . then ( done => {
611
+ response . body . allThreadsContinued = true ;
582
612
this . sendResponse ( response ) ;
583
613
} , msg => {
584
614
this . sendErrorResponse ( response , 2 , `Could not continue: ${ msg } ` ) ;
0 commit comments