Skip to content

Commit 80a006d

Browse files
authored
Fix pyocd launch and other small improvements (#23)
* refactor and logging * prepend 'gdbserver' option for pyocd * removed auto-filled 'target' and 'pack' options * comment in cbuild run file support * resolve args as late as possible * remove reset before load * change pyOCD to pyocd for Unix * pyocd debug setup docs --------- Signed-off-by: Jens Reinecke <[email protected]>
1 parent 2b00c45 commit 80a006d

File tree

4 files changed

+48
-36
lines changed

4 files changed

+48
-36
lines changed

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,22 @@ The following extensions are included in this extension pack:
2020
- [Memory Inspector](https://marketplace.visualstudio.com/items?itemName=eclipse-cdt.memory-inspector), an Eclipse CDT Cloud extension that provides a powerful and configurable memory viewer that works with debug adapters.
2121
- [Peripheral Inspector](https://marketplace.visualstudio.com/items?itemName=eclipse-cdt.peripheral-inspector), an Eclipse CDT Cloud extension that provides a CMSIS SVD viewer and works with debug adapters.
2222

23-
## Additional Functionality
23+
## pyOCD Debug Setup
24+
25+
- Install `GCC compiler for ARM CPUs` with the `Arm Tools Environment Manager` to get access to a GDB (`arm-none-eabi-gdb`).
26+
27+
- (Temporary, should become obsolete with full `*.cbuild-run.yml` support in pyOCD)<br>
28+
Make sure to set up your CMSIS Pack installation root folder by one of the following methods:
29+
- Set your system environment variable `CMSIS_PACK_ROOT`.
30+
- Add the following to your debug launch configuration
31+
```
32+
"environment": {
33+
"CMSIS_PACK_ROOT": "</path/to/your/pack/cache>"
34+
}
35+
36+
```
37+
38+
## Additional Extension Functionality
2439
2540
This extension contributes additional functionality to more seamlessly integrate the included extensions:
2641
- The pseudo debugger types `cmsis-debug-pyocd` and `cmsis-debug-jlink`. These types allow a more seamless integration into the VS Code IDE. However, these are not full debug adapters but generate debug configurations of type `gdbtarget` which comes with the [CDT GDB Debug Adapter Extension](https://marketplace.visualstudio.com/items?itemName=eclipse-cdt.cdt-gdb-vscode).

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,12 @@
5757
"program": "${command:cmsis-csolution.getBinaryFile}",
5858
"gdb": "arm-none-eabi-gdb",
5959
"initCommands": [
60-
"monitor reset halt",
6160
"load",
6261
"break main",
6362
"continue"
6463
],
6564
"target": {
66-
"server": "pyOCD",
65+
"server": "pyocd",
6766
"port": "3333"
6867
},
6968
"cmsis": {
@@ -83,13 +82,12 @@
8382
"program": "^\"\\${command:cmsis-csolution.getBinaryFile}\"",
8483
"gdb": "arm-none-eabi-gdb",
8584
"initCommands": [
86-
"monitor reset halt",
8785
"load",
8886
"break main",
8987
"continue"
9088
],
9189
"target": {
92-
"server": "pyOCD",
90+
"server": "pyocd",
9391
"port": "3333"
9492
},
9593
"cmsis": {

src/debug-configuration/gdbtarget-configuration-provider.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ export class GDBTargetConfigurationProvider implements vscode.DebugConfiguration
5151
);
5252
}
5353

54+
private logDebugConfiguration(resolverType: ResolverType, config: vscode.DebugConfiguration, message = '') {
55+
logger.debug(`${resolverType}: ${message}`);
56+
logger.debug(JSON.stringify(config));
57+
}
58+
59+
private logGdbServerCommandLine(resolverType: ResolverType, config: vscode.DebugConfiguration) {
60+
logger.debug(`${resolverType}: GDB server command line`);
61+
const resolvedGDBConfig = config as GDBTargetConfiguration;
62+
logger.debug(`\t${resolvedGDBConfig.target?.server} ${resolvedGDBConfig.target?.serverParameters?.join(' ')}`);
63+
}
64+
5465
private isRelevantSubprovider(resolverType: ResolverType, serverType: string, subProvider: GDBTargetConfigurationSubProvider): boolean {
5566
const serverTypeMatch = subProvider.serverRegExp.test(serverType);
5667
const hasResolverFunction = !!subProvider.provider[resolverType];
@@ -65,6 +76,7 @@ export class GDBTargetConfigurationProvider implements vscode.DebugConfiguration
6576
}
6677

6778
private getRelevantSubprovider(resolverType: ResolverType, serverType?: string): GDBTargetConfigurationSubProvider | undefined {
79+
logger.debug(`${resolverType}: Check for relevant configuration subproviders`);
6880
const subproviders = this.getRelevantSubproviders(resolverType, serverType);
6981
if (!subproviders.length) {
7082
logger.debug('No relevant configuration subproviders found');
@@ -74,7 +86,12 @@ export class GDBTargetConfigurationProvider implements vscode.DebugConfiguration
7486
logger.warn('Multiple configuration subproviders detected. Using first in list:');
7587
subproviders.forEach((subprovider, index) => logger.warn(`#${index}: '${subprovider.serverRegExp}'`));
7688
}
77-
return subproviders[0];
89+
const relevantProvider = subproviders[0];
90+
if (!relevantProvider.provider[resolverType]) {
91+
logger.debug(`${resolverType}: Subprovider '${relevantProvider.serverRegExp}' does not implement '${resolverType}'.`);
92+
return undefined;
93+
}
94+
return relevantProvider;
7895
}
7996

8097
private async resolveDebugConfigurationByResolverType(
@@ -83,29 +100,22 @@ export class GDBTargetConfigurationProvider implements vscode.DebugConfiguration
83100
debugConfiguration: vscode.DebugConfiguration,
84101
token?: vscode.CancellationToken
85102
): Promise<vscode.DebugConfiguration | null | undefined> {
86-
logger.debug(`${resolverType}: Check for relevant configuration subproviders`);
103+
this.logDebugConfiguration(resolverType, debugConfiguration, 'original config');
87104
const gdbTargetConfig: GDBTargetConfiguration = debugConfiguration;
88105
const gdbServerType = gdbTargetConfig.target?.server;
89106
const subprovider = this.getRelevantSubprovider(resolverType, gdbServerType);
90107
if (!subprovider) {
91-
return debugConfiguration;
92-
}
93-
if (!subprovider.provider[resolverType]) {
94-
logger.debug(`${resolverType}: Subprovider '${subprovider.serverRegExp}' does not implement '${resolverType}'.`);
108+
this.logGdbServerCommandLine(resolverType, debugConfiguration);
95109
return debugConfiguration;
96110
}
97111
logger.debug(`${resolverType}: Resolve config with subprovider '${subprovider.serverRegExp}'`);
98-
logger.debug(`${resolverType}: original config:`);
99-
logger.debug(JSON.stringify(debugConfiguration));
100-
const resolvedConfig = await subprovider.provider[resolverType](folder, debugConfiguration, token);
112+
const resolvedConfig = await subprovider.provider[resolverType]!(folder, debugConfiguration, token);
101113
if (!resolvedConfig) {
102114
logger.error(`${resolverType}: Resolving config failed with subprovider '${subprovider.serverRegExp}'`);
115+
return undefined;
103116
}
104-
logger.debug(`${resolverType}: resolved config:`);
105-
logger.debug(JSON.stringify(resolvedConfig));
106-
logger.debug(`${resolverType}: expected server command line:`);
107-
const resolvedGDBConfig = resolvedConfig as GDBTargetConfiguration;
108-
logger.debug(`${resolvedGDBConfig.target?.server} ${resolvedGDBConfig.target?.serverParameters?.join(' ')}`);
117+
this.logDebugConfiguration(resolverType, resolvedConfig, 'resolved config');
118+
this.logGdbServerCommandLine(resolverType, resolvedConfig);
109119
return resolvedConfig;
110120
}
111121

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

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,25 @@ export class PyocdConfigurationProvider implements vscode.DebugConfigurationProv
4242
const parameters = debugConfiguration.target.serverParameters ??= [];
4343
// gdbserver
4444
if (await this.shouldAppendParam(parameters, 'gdbserver')) {
45-
parameters.push('gdbserver');
46-
}
47-
// target
48-
if (await this.shouldAppendParam(parameters, '--target')) {
49-
parameters.push('--target');
50-
parameters.push('${command:cmsis-csolution.getDeviceName}');
51-
}
52-
// pack
53-
if (await this.shouldAppendParam(parameters, '--pack')) {
54-
parameters.push('--pack');
55-
parameters.push('${command:cmsis-csolution.getDfpPath}');
45+
// Prepend, it must be the first argument
46+
parameters.unshift('gdbserver');
5647
}
5748
// port (use value defined in 'port' outside 'serverParamters')
5849
const port = debugConfiguration.target?.port;
59-
if (await this.shouldAppendParam(parameters, '--port') && port) {
50+
if (port && await this.shouldAppendParam(parameters, '--port')) {
6051
parameters.push('--port');
6152
parameters.push(`${port}`);
6253
}
63-
// cbuild-run (ToDo: comment in the code when pyOCD supports it)
64-
/*
54+
// cbuild-run
6555
const cbuildRunFile = debugConfiguration.cmsis?.cbuildRunFile;
66-
if (await this.shouldAppendParam(parameters, '--cbuild-run') && cbuildRunFile) {
56+
if (cbuildRunFile && await this.shouldAppendParam(parameters, '--cbuild-run')) {
6757
parameters.push('--cbuild-run');
6858
parameters.push(`${cbuildRunFile}`);
6959
}
70-
*/
7160
return debugConfiguration;
7261
}
7362

74-
public async resolveDebugConfiguration(
63+
public async resolveDebugConfigurationWithSubstitutedVariables(
7564
_folder: vscode.WorkspaceFolder | undefined,
7665
debugConfiguration: vscode.DebugConfiguration,
7766
_token?: vscode.CancellationToken

0 commit comments

Comments
 (0)