@@ -18,6 +18,7 @@ import * as vscode from 'vscode';
1818import { ExtendedGDBTargetConfiguration , GDBTargetConfiguration } from '../gdbtarget-configuration' ;
1919import { CbuildRunReader } from '../../cbuild-run' ;
2020import { logger } from '../../logger' ;
21+ import { extractPname } from '../../utils' ;
2122
2223export abstract class BaseConfigurationProvider implements vscode . DebugConfigurationProvider {
2324 protected _cbuildRunReader ?: CbuildRunReader ;
@@ -51,18 +52,38 @@ export abstract class BaseConfigurationProvider implements vscode.DebugConfigura
5152 return ! this . parameterExists ( paramName , params ) && ( ! commandName || await this . commandExists ( commandName ) ) ;
5253 }
5354
54- protected resolveSvdFile ( debugConfiguration : GDBTargetConfiguration ) {
55+ protected resolveSvdFile ( debugConfiguration : GDBTargetConfiguration , pname ?: string ) {
5556 const extDebugConfig = debugConfiguration as ExtendedGDBTargetConfiguration ;
5657 const cbuildRunFilePath = debugConfiguration . cmsis ?. cbuildRunFile ;
5758 // 'definitionPath' is current default name for SVD file settings in Eclipse CDT Cloud Peripheral Inspector.
5859 if ( extDebugConfig . definitionPath !== undefined || ! cbuildRunFilePath ?. length ) {
5960 return ;
6061 }
61- const svdFilePaths = this . cbuildRunReader . getSvdFilePaths ( debugConfiguration ?. target ?. environment ?. CMSIS_PACK_ROOT ) ;
62- // Needs update when we better support multiple `debugger:` YAML nodes
62+ const svdFilePaths = this . cbuildRunReader . getSvdFilePaths ( debugConfiguration ?. target ?. environment ?. CMSIS_PACK_ROOT , pname ) ;
63+ if ( ! svdFilePaths . length ) {
64+ // No SVD file found for config
65+ return ;
66+ }
67+ // Only one SVD file per pname should be left, log a warning if more
68+ if ( svdFilePaths . length > 1 ) {
69+ let message = 'Found more than one SVD file' ;
70+ if ( pname ) {
71+ message += ` for Pname '${ pname } '` ;
72+ }
73+ message += ', using first' ;
74+ logger . warn ( message ) ;
75+ }
6376 extDebugConfig . definitionPath = svdFilePaths [ 0 ] ;
6477 }
6578
79+ protected extractPnameFromDebugConfig ( debugConfiguration : GDBTargetConfiguration ) : string | undefined {
80+ const pnames = this . cbuildRunReader . getPnames ( ) ;
81+ if ( ! pnames . length ) {
82+ return undefined ;
83+ }
84+ return extractPname ( debugConfiguration . name , pnames ) ;
85+ }
86+
6687 protected abstract resolveServerParameters ( debugConfiguration : GDBTargetConfiguration ) : Promise < GDBTargetConfiguration > ;
6788
6889 public async resolveDebugConfigurationWithSubstitutedVariables (
@@ -71,7 +92,7 @@ export abstract class BaseConfigurationProvider implements vscode.DebugConfigura
7192 _token ?: vscode . CancellationToken
7293 ) : Promise < vscode . DebugConfiguration | null | undefined > {
7394 await this . parseCbuildRunFile ( debugConfiguration ) ;
74- this . resolveSvdFile ( debugConfiguration ) ;
95+ this . resolveSvdFile ( debugConfiguration , this . extractPnameFromDebugConfig ( debugConfiguration ) ) ;
7596 return this . resolveServerParameters ( debugConfiguration ) ;
7697 }
7798
0 commit comments