@@ -15,7 +15,8 @@ import { extractBits, hexFormat } from './frontend/utils';
15
15
import { Variable , VariableObject , MIError , OurDataBreakpoint , OurInstructionBreakpoint , OurSourceBreakpoint } from './backend/backend' ;
16
16
import {
17
17
TelemetryEvent , ConfigurationArguments , StoppedEvent , GDBServerController , SymbolFile ,
18
- createPortName , GenericCustomEvent , quoteShellCmdLine , toStringDecHexOctBin , ADAPTER_DEBUG_MODE , defSymbolFile , CTIAction , getPathRelative
18
+ createPortName , GenericCustomEvent , quoteShellCmdLine , toStringDecHexOctBin , ADAPTER_DEBUG_MODE , defSymbolFile , CTIAction , getPathRelative ,
19
+ SWOConfigureEvent
19
20
} from './common' ;
20
21
import { GDBServer , ServerConsoleLog } from './backend/server' ;
21
22
import { MINode } from './backend/mi_parse' ;
@@ -267,6 +268,9 @@ export class GDBDebugSession extends LoggingDebugSession {
267
268
268
269
protected tcpPortAllocatedListner = this . tcpPortsAllocated . bind ( this ) ;
269
270
271
+ private swoLaunchPromise = Promise . resolve ( ) ;
272
+ private swoLaunched ?: ( ) => void ;
273
+
270
274
public constructor ( debuggerLinesStartAt1 : boolean , public readonly isServer : boolean = false , threadID : number = 1 ) {
271
275
super ( undefined , debuggerLinesStartAt1 , isServer ) ; // Use if deriving from LogDebugSession
272
276
// super(debuggerLinesStartAt1, isServer); // Use if deriving from DebugSession
@@ -660,6 +664,9 @@ export class GDBDebugSession extends LoggingDebugSession {
660
664
if ( showTimes ) { this . handleMsg ( 'log' , 'Debug Time: objdump and nm done...\n' ) ; }
661
665
if ( showTimes ) { this . handleMsg ( 'log' , 'Debug Time: All pending items done, proceed to gdb connect...\n' ) ; }
662
666
667
+ // if SWO launch was requested by the server controller, we wait for it to connect before starting actual debug
668
+ await this . swoLaunchPromise ;
669
+
663
670
// This is the last of the place where ports are allocated
664
671
this . sendEvent ( new GenericCustomEvent ( 'post-start-server' , this . args ) ) ;
665
672
commands . push ( ...this . serverController . initCommands ( ) ) ;
@@ -1211,6 +1218,11 @@ export class GDBDebugSession extends LoggingDebugSession {
1211
1218
}
1212
1219
break ;
1213
1220
}
1221
+ case 'swo-connected' : {
1222
+ this . swoLaunched ?.( ) ;
1223
+ this . swoLaunched = undefined ;
1224
+ break ;
1225
+ }
1214
1226
default :
1215
1227
response . body = { error : 'Invalid command.' } ;
1216
1228
this . sendResponse ( response ) ;
@@ -1674,6 +1686,16 @@ export class GDBDebugSession extends LoggingDebugSession {
1674
1686
}
1675
1687
1676
1688
private serverControllerEvent ( event : DebugProtocol . Event ) {
1689
+ if ( event instanceof SWOConfigureEvent ) {
1690
+ this . swoLaunchPromise = new Promise ( ( resolve , reject ) => {
1691
+ const timeout = setTimeout ( ( ) => reject ( new Error ( 'Timeout waiting for SWV connection' ) ) , 1000 ) ;
1692
+ this . swoLaunched = ( ) => {
1693
+ clearTimeout ( timeout ) ;
1694
+ resolve ( ) ;
1695
+ } ;
1696
+ } ) ;
1697
+ }
1698
+
1677
1699
this . sendEvent ( event ) ;
1678
1700
}
1679
1701
0 commit comments