1616
1717import * as vscode from 'vscode' ;
1818import { GDBTargetConfiguration } from '../gdbtarget-configuration' ;
19- import { CbuildRunReader , CbuildRunType } from '../../cbuild-run' ;
20- import { getCmsisPackRootPath } from '../../utils ' ;
19+ import { CbuildRunReader } from '../../cbuild-run' ;
20+ import { logger } from '../../logger ' ;
2121
2222const DEFAULT_SVD_SETTING_NAME = 'definitionPath' ;
23- const CMSIS_PACK_ROOT_ENVVAR = '${CMSIS_PACK_ROOT}' ;
2423
2524export abstract class BaseConfigurationProvider implements vscode . DebugConfigurationProvider {
25+ protected _cbuildRunReader ?: CbuildRunReader ;
26+
27+ protected get cbuildRunReader ( ) : CbuildRunReader {
28+ this . _cbuildRunReader ??= new CbuildRunReader ( ) ;
29+ return this . _cbuildRunReader ;
30+ } ;
31+
32+ protected async parseCbuildRunFile ( debugConfiguration : GDBTargetConfiguration ) : Promise < void > {
33+ if ( ! debugConfiguration . cmsis ?. cbuildRunFile ?. length ) {
34+ return ;
35+ }
36+ try {
37+ await this . cbuildRunReader . parse ( debugConfiguration . cmsis . cbuildRunFile ) ;
38+ } catch ( error ) {
39+ logger . warn ( ( error as Error ) . message ) ;
40+ }
41+ }
2642
2743 protected async commandExists ( commandName : string ) : Promise < boolean > {
2844 const commands = await vscode . commands . getCommands ( ) ;
@@ -37,29 +53,15 @@ export abstract class BaseConfigurationProvider implements vscode.DebugConfigura
3753 return ! this . parameterExists ( paramName , params ) && ( ! commandName || await this . commandExists ( commandName ) ) ;
3854 }
3955
40- protected async resolveSvdFile ( debugConfiguration : GDBTargetConfiguration ) {
56+ protected resolveSvdFile ( debugConfiguration : GDBTargetConfiguration ) {
4157 const cbuildRunFilePath = debugConfiguration . cmsis ?. cbuildRunFile ;
4258 // 'definitionPath' is current default name for SVD file settings in Eclipse CDT Cloud Peripheral Inspector.
4359 if ( debugConfiguration [ DEFAULT_SVD_SETTING_NAME ] || ! cbuildRunFilePath ?. length ) {
4460 return ;
4561 }
46- const cbuildRunReader = new CbuildRunReader ( ) ;
47- let cbuildRunContents : CbuildRunType | undefined ;
48- try {
49- cbuildRunContents = await cbuildRunReader . parse ( cbuildRunFilePath ) ;
50- } catch {
51- // Failed to read file, nothing to set
52- return ;
53- }
54- const systemDescriptions = cbuildRunContents [ 'system-descriptions' ] ;
55- const svdFileDescriptors = systemDescriptions ?. filter ( descriptor => descriptor . type === 'svd' ) ?? [ ] ;
56- if ( svdFileDescriptors . length === 0 ) {
57- return ;
58- }
59- const cmsisPackRootValue = debugConfiguration ?. target ?. environment ?. CMSIS_PACK_ROOT ?? getCmsisPackRootPath ( ) ;
60- debugConfiguration [ DEFAULT_SVD_SETTING_NAME ] = cmsisPackRootValue
61- ? svdFileDescriptors [ 0 ] . file . replaceAll ( CMSIS_PACK_ROOT_ENVVAR , cmsisPackRootValue )
62- : svdFileDescriptors [ 0 ] . file ;
62+ const svdFilePaths = this . cbuildRunReader . getSvdFilePaths ( debugConfiguration ?. target ?. environment ?. CMSIS_PACK_ROOT ) ;
63+ // Needs update when we better support multiple `debugger:` YAML nodes
64+ debugConfiguration [ DEFAULT_SVD_SETTING_NAME ] = svdFilePaths [ 0 ] ;
6365 }
6466
6567 protected abstract resolveServerParameters ( debugConfiguration : GDBTargetConfiguration ) : Promise < GDBTargetConfiguration > ;
@@ -69,7 +71,8 @@ export abstract class BaseConfigurationProvider implements vscode.DebugConfigura
6971 debugConfiguration : vscode . DebugConfiguration ,
7072 _token ?: vscode . CancellationToken
7173 ) : Promise < vscode . DebugConfiguration | null | undefined > {
72- await this . resolveSvdFile ( debugConfiguration ) ;
74+ await this . parseCbuildRunFile ( debugConfiguration ) ;
75+ this . resolveSvdFile ( debugConfiguration ) ;
7376 return this . resolveServerParameters ( debugConfiguration ) ;
7477 }
7578
0 commit comments