@@ -47,6 +47,7 @@ export class DebugSession implements IDebugSession {
4747
4848 private sources = new Map < string , Source > ( ) ;
4949 private threads = new Map < number , Thread > ( ) ;
50+ private threadIds : number [ ] = [ ] ;
5051 private cancellationMap = new Map < number , CancellationTokenSource [ ] > ( ) ;
5152 private rawListeners : IDisposable [ ] = [ ] ;
5253 private fetchThreadsScheduler : RunOnceScheduler | undefined ;
@@ -738,7 +739,12 @@ export class DebugSession implements IDebugSession {
738739
739740 getAllThreads ( ) : IThread [ ] {
740741 const result : IThread [ ] = [ ] ;
741- this . threads . forEach ( t => result . push ( t ) ) ;
742+ this . threadIds . forEach ( ( threadId ) => {
743+ const thread = this . threads . get ( threadId ) ;
744+ if ( thread ) {
745+ result . push ( thread ) ;
746+ }
747+ } ) ;
742748 return result ;
743749 }
744750
@@ -763,6 +769,7 @@ export class DebugSession implements IDebugSession {
763769
764770 if ( removeThreads ) {
765771 this . threads . clear ( ) ;
772+ this . threadIds = [ ] ;
766773 ExpressionContainer . allValues . clear ( ) ;
767774 }
768775 }
@@ -773,9 +780,9 @@ export class DebugSession implements IDebugSession {
773780 }
774781
775782 rawUpdate ( data : IRawModelUpdate ) : void {
776- const threadIds : number [ ] = [ ] ;
783+ this . threadIds = [ ] ;
777784 data . threads . forEach ( thread => {
778- threadIds . push ( thread . id ) ;
785+ this . threadIds . push ( thread . id ) ;
779786 if ( ! this . threads . has ( thread . id ) ) {
780787 // A new thread came in, initialize it.
781788 this . threads . set ( thread . id , new Thread ( this , thread . name , thread . id ) ) ;
@@ -789,7 +796,7 @@ export class DebugSession implements IDebugSession {
789796 } ) ;
790797 this . threads . forEach ( t => {
791798 // Remove all old threads which are no longer part of the update #75980
792- if ( threadIds . indexOf ( t . threadId ) === - 1 ) {
799+ if ( this . threadIds . indexOf ( t . threadId ) === - 1 ) {
793800 this . threads . delete ( t . threadId ) ;
794801 }
795802 } ) ;
0 commit comments