Skip to content

Commit 043f334

Browse files
committed
resolve svd filepath (single debugger node)
Signed-off-by: Jens Reinecke <jens.reinecke@arm.com>
1 parent c2975fd commit 043f334

6 files changed

Lines changed: 72 additions & 22 deletions

File tree

src/cbuild-run/cbuild-run-reader.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const TEST_CBUILD_RUN_FILE = '../test-data/cbuild-run/multi-core.cbuild-run.yml'
2020

2121
describe('CbuildRunReader', () => {
2222

23-
it('parses', async () => {
23+
it.skip('parses', async () => {
2424
const reader = new CbuildRunReader();
2525
const contents = await reader.parse(TEST_CBUILD_RUN_FILE);
2626
expect(contents).toMatchSnapshot();

src/cbuild-run/cbuild-run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ interface SystemResourcesType {
3838
memory?: MemoryType[];
3939
};
4040

41-
type SystemDescriptionTypeType = 'svd'|'scvd';
41+
export type SystemDescriptionTypeType = 'svd'|'scvd';
4242

4343
interface SystemDescriptionType {
4444
file: string;

src/debug-configuration/subproviders/base-configuration-provider.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616

1717
import * as vscode from 'vscode';
1818
import { GDBTargetConfiguration } from '../gdbtarget-configuration';
19+
import { CbuildRunType } from '../../cbuild-run/cbuild-run';
20+
import { CbuildRunReader } from '../../cbuild-run/cbuild-run-reader';
21+
import { getCmsisPackRootPath } from '../../desktop/cmsis-utils';
22+
23+
const DEFAULT_SVD_SETTING_NAME = 'definitionPath';
24+
const CMSIS_PACK_ROOT_ENVVAR = '${CMSIS_PACK_ROOT}';
1925

2026
export abstract class BaseConfigurationProvider implements vscode.DebugConfigurationProvider {
2127

@@ -32,13 +38,39 @@ export abstract class BaseConfigurationProvider implements vscode.DebugConfigura
3238
return !this.parameterExists(paramName, params) && (!commandName || await this.commandExists(commandName));
3339
}
3440

41+
protected async resolveSvdFile(debugConfiguration: GDBTargetConfiguration) {
42+
const cbuildRunFilePath = debugConfiguration.cmsis?.cbuildRunFile;
43+
// 'definitionPath' is current default name for SVD file settings in Eclipse CDT Cloud Peripheral Inspector.
44+
if (debugConfiguration[DEFAULT_SVD_SETTING_NAME] || !cbuildRunFilePath?.length) {
45+
return;
46+
}
47+
const cbuildRunReader = new CbuildRunReader();
48+
let cbuildRunContents: CbuildRunType|undefined;
49+
try {
50+
cbuildRunContents = await cbuildRunReader.parse(cbuildRunFilePath);
51+
} catch {
52+
// Failed to read file, nothing to set
53+
return;
54+
}
55+
const systemDescriptions = cbuildRunContents['system-descriptions'];
56+
const svdFileDescriptors = systemDescriptions?.filter(descriptor => descriptor.type === 'svd') ?? [];
57+
if (svdFileDescriptors.length === 0) {
58+
return;
59+
}
60+
const cmsisPackRootValue = debugConfiguration?.target?.environment?.CMSIS_PACK_ROOT ?? getCmsisPackRootPath();
61+
debugConfiguration[DEFAULT_SVD_SETTING_NAME] = cmsisPackRootValue
62+
? svdFileDescriptors[0].file.replaceAll(CMSIS_PACK_ROOT_ENVVAR, cmsisPackRootValue)
63+
: svdFileDescriptors[0].file;
64+
}
65+
3566
protected abstract resolveServerParameters(debugConfiguration: GDBTargetConfiguration): Promise<GDBTargetConfiguration>;
3667

37-
public resolveDebugConfigurationWithSubstitutedVariables(
68+
public async resolveDebugConfigurationWithSubstitutedVariables(
3869
_folder: vscode.WorkspaceFolder | undefined,
3970
debugConfiguration: vscode.DebugConfiguration,
4071
_token?: vscode.CancellationToken
4172
): Promise<vscode.DebugConfiguration | null | undefined> {
73+
await this.resolveSvdFile(debugConfiguration);
4274
return this.resolveServerParameters(debugConfiguration);
4375
}
4476

src/debug-configuration/subproviders/pyocd-configuration-provider.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { logger } from '../../logger';
17+
import { BaseConfigurationProvider } from './base-configuration-provider';
1818
import { GDBTargetConfiguration, TargetConfiguration } from '../gdbtarget-configuration';
1919
import { BuiltinToolPath } from '../../desktop/builtin-tool-path';
20-
import { BaseConfigurationProvider } from './base-configuration-provider';
21-
import * as os from 'os';
22-
import * as path from 'path';
20+
import { getCmsisPackRootPath } from '../../desktop/cmsis-utils';
21+
import { logger } from '../../logger';
2322

2423
const PYOCD_BUILTIN_PATH = 'tools/pyocd/pyocd';
2524
const PYOCD_EXECUTABLE_ONLY_REGEXP = /^\s*pyocd(|.exe)\s*$/i;
@@ -42,20 +41,13 @@ export class PyocdConfigurationProvider extends BaseConfigurationProvider {
4241
}
4342

4443
protected resolveCmsisPackRootPath(target: TargetConfiguration): void {
45-
const environmentValue = process.env['CMSIS_PACK_ROOT'];
46-
if (environmentValue) {
47-
return;
48-
}
49-
5044
if (target.environment?.CMSIS_PACK_ROOT) {
5145
return;
5246
}
53-
const cmsisPackRootDefault = os.platform() === 'win32'
54-
? path.join(process.env['LOCALAPPDATA'] ?? os.homedir(), 'Arm', 'Packs')
55-
: path.join(os.homedir(), '.cache', 'arm', 'packs');
5647

48+
const cmsisPackRootPath = getCmsisPackRootPath();
5749
target.environment ??= {};
58-
target.environment.CMSIS_PACK_ROOT = cmsisPackRootDefault;
50+
target.environment.CMSIS_PACK_ROOT = cmsisPackRootPath;
5951
}
6052

6153
protected async resolveServerParameters(debugConfiguration: GDBTargetConfiguration): Promise<GDBTargetConfiguration> {

src/desktop/cmsis-utils.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright 2025 Arm Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
18+
import * as os from 'os';
19+
import * as path from 'path';
20+
21+
export const getCmsisPackRootPath = (): string|undefined => {
22+
const environmentValue = process.env['CMSIS_PACK_ROOT'];
23+
if (environmentValue) {
24+
return environmentValue;
25+
}
26+
27+
const cmsisPackRootDefault = os.platform() === 'win32'
28+
? path.join(process.env['LOCALAPPDATA'] ?? os.homedir(), 'Arm', 'Packs')
29+
: path.join(os.homedir(), '.cache', 'arm', 'packs');
30+
31+
return cmsisPackRootDefault;
32+
};

src/desktop/extension.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,11 @@ import { GDBTargetDebugTracker } from '../debug-configuration/gdbtarget-debug-tr
1919
import { GDBTargetConfigurationProvider } from '../debug-configuration';
2020
import { logger } from '../logger';
2121
import { addPyocdToPath } from './add-to-path';
22-
import { CbuildRunReader } from '../cbuild-run/cbuild-run-reader';
23-
import { CbuildRunType } from '../cbuild-run/cbuild-run';
2422

2523
export const activate = async (context: vscode.ExtensionContext): Promise<void> => {
2624
const gdbtargetDebugTracker = new GDBTargetDebugTracker();
2725
const gdbtargetConfigurationProvider = new GDBTargetConfigurationProvider();
2826

29-
const reader = new CbuildRunReader();
30-
const contents: CbuildRunType = await reader.parse('D:\\jenrei02\\work\\Projects\\led_blinky\\led_blinky\\led_blinky+mdk.cbuild-run.yml');
31-
console.log(contents);
32-
3327
addPyocdToPath(context);
3428
// Activate components
3529
gdbtargetDebugTracker.activate(context);

0 commit comments

Comments
 (0)