@@ -118,24 +118,21 @@ export class CortexDebugConfigurationProvider implements vscode.DebugConfigurati
118118
119119 const configuration = vscode . workspace . getConfiguration ( 'cortex-debug' ) ;
120120
121- // Special case to auto-resolve GCC toolchain for STM32CubeIDE users
122- if ( ! config . armToolchainPath && config . servertype === 'stlink' ) {
123- config . armToolchainPath = STLinkServerController . getArmToolchainPath ( ) ;
124- }
125-
126121 if ( config . armToolchainPath ) { config . toolchainPath = config . armToolchainPath ; }
122+ this . setOsSpecficConfigSetting ( config , 'toolchainPath' , 'armToolchainPath' ) ;
123+
127124 if ( ! config . toolchainPath ) {
128- config . toolchainPath = configuration . armToolchainPath ;
125+ // Special case to auto-resolve GCC toolchain for STM32CubeIDE users
126+ if ( ! config . armToolchainPath && config . servertype === 'stlink' ) {
127+ config . armToolchainPath = STLinkServerController . getArmToolchainPath ( ) ;
128+ }
129129 }
130130
131131 if ( ! config . toolchainPrefix ) {
132132 config . toolchainPrefix = configuration . armToolchainPrefix || 'arm-none-eabi' ;
133133 }
134134
135- if ( ! config . gdbPath ) {
136- config . gdbPath = configuration . gdbPath ;
137- }
138-
135+ this . setOsSpecficConfigSetting ( config , 'gdbPath' ) ;
139136 config . extensionPath = this . context . extensionPath ;
140137 if ( os . platform ( ) === 'win32' ) {
141138 config . extensionPath = config . extensionPath . replace ( / \\ / g, '/' ) ; // GDB doesn't interpret the path correctly with backslashes.
@@ -153,8 +150,18 @@ export class CortexDebugConfigurationProvider implements vscode.DebugConfigurati
153150 return config ;
154151 }
155152
153+ private setOsSpecficConfigSetting ( config : vscode . DebugConfiguration , dstName : string , propName : string = '' ) {
154+ if ( ! config [ dstName ] ) {
155+ const configuration = vscode . workspace . getConfiguration ( 'cortex-debug' ) ;
156+ const osName = os . platform ( ) ;
157+ const osOverride = ( propName || dstName ) + '-' + ( ( osName === 'win32' ) ? 'windows' : ( osName === 'darwin' ) ? 'osx' : 'linux' ) ;
158+ config [ dstName ] = configuration . get ( osOverride , configuration . get ( propName , '' ) ) ;
159+ }
160+ }
161+
156162 private verifyQEMUConfiguration ( folder : vscode . WorkspaceFolder | undefined , config : vscode . DebugConfiguration ) : string {
157- if ( config . qemupath && ! config . serverpath ) { config . serverpath = config . qemupath ; }
163+ this . setOsSpecficConfigSetting ( config , 'serverpath' , 'qemupath' ) ;
164+ // if (config.qemupath && !config.serverpath) { config.serverpath = config.qemupath; }
158165
159166 if ( ! config . cpu ) { config . cpu = 'cortex-m3' ; }
160167 if ( ! config . machine ) { config . machine = 'lm3s6965evb' ; }
@@ -173,14 +180,11 @@ export class CortexDebugConfigurationProvider implements vscode.DebugConfigurati
173180 }
174181
175182 private verifyJLinkConfiguration ( folder : vscode . WorkspaceFolder | undefined , config : vscode . DebugConfiguration ) : string {
176- if ( config . jlinkpath && ! config . serverpath ) { config . serverpath = config . jlinkpath ; }
183+ if ( config . jlinkpath && ! config . serverpath ) { config . serverpath = config . jlinkpath ; } // Obsolete
177184 if ( ! config . interface && config . jlinkInterface ) { config . interface = config . jlinkInterface ; }
178185 if ( ! config . interface ) { config . interface = 'swd' ; }
179186
180- if ( ! config . serverpath ) {
181- const configuration = vscode . workspace . getConfiguration ( 'cortex-debug' ) ;
182- config . serverpath = configuration . JLinkGDBServerPath ;
183- }
187+ this . setOsSpecficConfigSetting ( config , 'serverpath' , 'JLinkGDBServerPath' ) ;
184188 if ( config . rtos ) {
185189 if ( JLINK_VALID_RTOS . indexOf ( config . rtos ) === - 1 ) {
186190 if ( ! fs . existsSync ( config . rtos ) ) {
@@ -212,11 +216,8 @@ export class CortexDebugConfigurationProvider implements vscode.DebugConfigurati
212216 }
213217
214218 private verifyOpenOCDConfiguration ( folder : vscode . WorkspaceFolder | undefined , config : vscode . DebugConfiguration ) : string {
215- if ( config . openOCDPath && ! config . serverpath ) { config . serverpath = config . openOCDPath ; }
216- if ( ! config . serverpath ) {
217- const configuration = vscode . workspace . getConfiguration ( 'cortex-debug' ) ;
218- config . serverpath = configuration . openocdPath ;
219- }
219+ if ( config . openOCDPath && ! config . serverpath ) { config . serverpath = config . openOCDPath ; } // Obsolete
220+ this . setOsSpecficConfigSetting ( config , 'serverpath' , 'openocdPath' ) ;
220221
221222 if ( config . rtos && OPENOCD_VALID_RTOS . indexOf ( config . rtos ) === - 1 ) {
222223 return `The following RTOS values are supported by OpenOCD: ${ OPENOCD_VALID_RTOS . join ( ' ' ) } ` ;
@@ -234,11 +235,8 @@ export class CortexDebugConfigurationProvider implements vscode.DebugConfigurati
234235 }
235236
236237 private verifySTUtilConfiguration ( folder : vscode . WorkspaceFolder | undefined , config : vscode . DebugConfiguration ) : string {
237- if ( config . stutilpath && ! config . serverpath ) { config . serverpath = config . stutilpath ; }
238- if ( ! config . serverpath ) {
239- const configuration = vscode . workspace . getConfiguration ( 'cortex-debug' ) ;
240- config . serverpath = configuration . stutilPath ;
241- }
238+ if ( config . stutilpath && ! config . serverpath ) { config . serverpath = config . stutilpath ; } // obsolete
239+ this . setOsSpecficConfigSetting ( config , 'serverpath' , 'stutilPath' ) ;
242240
243241 if ( config . rtos ) {
244242 return 'The st-util GDB Server does not have support for the rtos option.' ;
@@ -254,16 +252,9 @@ export class CortexDebugConfigurationProvider implements vscode.DebugConfigurati
254252 }
255253
256254 private verifySTLinkConfiguration ( folder : vscode . WorkspaceFolder | undefined , config : vscode . DebugConfiguration ) : string {
257- if ( config . stlinkPath && ! config . serverpath ) { config . serverpath = config . stlinkPath ; }
258- if ( ! config . serverpath ) {
259- const configuration = vscode . workspace . getConfiguration ( 'cortex-debug' ) ;
260- config . serverpath = configuration . stlinkPath ;
261- }
262-
263- if ( ! config . stm32cubeprogrammer ) {
264- const configuration = vscode . workspace . getConfiguration ( 'cortex-debug' ) ;
265- config . stm32cubeprogrammer = configuration . stm32cubeprogrammer ;
266- }
255+ if ( config . stlinkPath && ! config . serverpath ) { config . serverpath = config . stlinkPath ; } // Obsolete
256+ this . setOsSpecficConfigSetting ( config , 'serverpath' , 'stlinkPath' ) ;
257+ this . setOsSpecficConfigSetting ( config , 'stm32cubeprogrammer' ) ;
267258
268259 if ( config . rtos ) {
269260 return 'The ST-Link GDB Server does not have support for the rtos option.' ;
@@ -279,11 +270,8 @@ export class CortexDebugConfigurationProvider implements vscode.DebugConfigurati
279270 }
280271
281272 private verifyPyOCDConfiguration ( folder : vscode . WorkspaceFolder | undefined , config : vscode . DebugConfiguration ) : string {
282- if ( config . pyocdPath && ! config . serverpath ) { config . serverpath = config . pyocdPath ; }
283- if ( ! config . serverpath ) {
284- const configuration = vscode . workspace . getConfiguration ( 'cortex-debug' ) ;
285- config . serverpath = configuration . pyocdPath ;
286- }
273+ if ( config . pyocdPath && ! config . serverpath ) { config . serverpath = config . pyocdPath ; } // Obsolete
274+ this . setOsSpecficConfigSetting ( config , 'serverpath' , 'pyocdPath' ) ;
287275
288276 if ( config . rtos ) {
289277 return 'The PyOCD GDB Server does not have support for the rtos option.' ;
@@ -315,10 +303,7 @@ export class CortexDebugConfigurationProvider implements vscode.DebugConfigurati
315303 }
316304
317305 private verifyPEConfiguration ( folder : vscode . WorkspaceFolder | undefined , config : vscode . DebugConfiguration ) : string {
318- if ( ! config . serverpath ) {
319- const configuration = vscode . workspace . getConfiguration ( 'cortex-debug' ) ;
320- config . serverpath = configuration . PEGDBServerPath ;
321- }
306+ this . setOsSpecficConfigSetting ( config , 'serverpath' , 'PEGDBServerPath' ) ;
322307
323308 if ( config . configFiles && config . configFiles . length > 1 ) {
324309 return 'Only one pegdbserver Configuration File is allowed.' ;
0 commit comments