@@ -48,7 +48,7 @@ export class MI2DebugSession extends DebugSession {
48
48
super ( debuggerLinesStartAt1 , isServer ) ;
49
49
}
50
50
51
- protected initDebugger ( ) {
51
+ protected async initDebugger ( ) {
52
52
this . miDebugger . on ( "launcherror" , this . launchError . bind ( this ) ) ;
53
53
this . miDebugger . on ( "quit" , this . quitEvent . bind ( this ) ) ;
54
54
this . miDebugger . on ( "exited-normally" , this . quitEvent . bind ( this ) ) ;
@@ -64,6 +64,10 @@ export class MI2DebugSession extends DebugSession {
64
64
this . miDebugger . on ( "thread-exited" , this . threadExitedEvent . bind ( this ) ) ;
65
65
this . miDebugger . once ( "debug-ready" , ( ( ) => this . sendEvent ( new InitializedEvent ( ) ) ) ) ;
66
66
try {
67
+ const socketlists = systemPath . join ( os . tmpdir ( ) , "code-debug-sockets" ) ;
68
+ if ( fs . existsSync ( socketlists ) ) {
69
+ await cleanInvalidSocketPath ( socketlists ) ;
70
+ }
67
71
this . commandServer = net . createServer ( c => {
68
72
c . on ( "data" , data => {
69
73
const rawCmd = data . toString ( ) ;
@@ -75,7 +79,7 @@ export class MI2DebugSession extends DebugSession {
75
79
args = JSON . parse ( rawCmd . substring ( spaceIndex + 1 ) ) ;
76
80
}
77
81
Promise . resolve ( this . miDebugger [ func ] . apply ( this . miDebugger , args ) ) . then ( data => {
78
- c . write ( data . toString ( ) ) ;
82
+ c . write ( data instanceof Object ? JSON . stringify ( data ) . toString ( ) : data . toString ( ) ) ;
79
83
} ) ;
80
84
} ) ;
81
85
} ) ;
@@ -516,10 +520,9 @@ export class MI2DebugSession extends DebugSession {
516
520
}
517
521
} else if ( typeof id == "string" ) {
518
522
// Variable members
519
- let variable ;
520
523
try {
521
524
// TODO: this evaluates on an (effectively) unknown thread for multithreaded programs.
522
- variable = await this . miDebugger . evalExpression ( JSON . stringify ( id ) , 0 , 0 ) ;
525
+ const variable = await this . miDebugger . evalExpression ( JSON . stringify ( id ) , 0 , 0 ) ;
523
526
try {
524
527
let expanded = expandValue ( createVariable , variable . result ( "value" ) , id , variable ) ;
525
528
if ( ! expanded ) {
@@ -759,3 +762,38 @@ function prettyStringArray(strings) {
759
762
return JSON . stringify ( strings ) ;
760
763
} else return strings ;
761
764
}
765
+
766
+ async function cleanInvalidSocketPath ( socketlists :string ) {
767
+ return new Promise ( ( resolve , reject ) => {
768
+ fs . readdir ( socketlists , ( err , files ) => {
769
+ if ( ! err ) {
770
+ if ( files . length == 0 ) resolve ( '' ) ;
771
+ files . forEach ( ( file ) => {
772
+ try {
773
+ const conn = net . connect ( systemPath . join ( socketlists , file ) ) ;
774
+ conn . setTimeout ( 200 ) ;
775
+ conn . on ( 'error' , ( ) => {
776
+ fs . unlink ( systemPath . join ( socketlists , file ) , ( err ) => {
777
+ if ( err )
778
+ // eslint-disable-next-line no-console
779
+ console . error ( "Failed to unlink invalid debug server" ) ;
780
+ resolve ( '' ) ;
781
+ } ) ;
782
+ } ) ;
783
+ conn . on ( 'timeout' , ( ) => {
784
+ conn . destroy ( ) ;
785
+ } ) ;
786
+ } catch {
787
+ fs . unlink ( systemPath . join ( socketlists , file ) , ( err ) => {
788
+ if ( err )
789
+ // eslint-disable-next-line no-console
790
+ console . error ( "Failed to unlink invalid debug server" ) ;
791
+ resolve ( '' ) ;
792
+ } ) ;
793
+ }
794
+ } ) ;
795
+ }
796
+ resolve ( '' ) ;
797
+ } ) ;
798
+ } ) ;
799
+ }
0 commit comments