Skip to content

Commit d97c325

Browse files
Add device reset (#152)
* Add Custom Reset (for MCU device reset) In launch.json: "customResetCommands": [] Signed-off-by: Thorsten de Buhr <[email protected]> --------- Signed-off-by: Thorsten de Buhr <[email protected]>
1 parent 663320f commit d97c325

File tree

7 files changed

+94
-0
lines changed

7 files changed

+94
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## Unreleased
4+
- Implements:
5+
- [Optional device reset during debug session](https://github.com/eclipse-cdt-cloud/cdt-gdb-adapter/issues/359)
6+
37
## 2.0.3
48
- Fixes [#144](https://github.com/eclipse-cdt-cloud/cdt-gdb-vscode/issues/144): Error with the openGdbConsole option
59

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Launch and attach configuration settings that can be used with the `gdbtarget` d
5757
| `preRunCommands` | x | x | `string[]` | List of GDB commands sent after loading image on target before resuming target. |
5858
| `imageAndSymbols` | x | x | `object` | Additional settings for loading images to the target and symbols into the debugger. See section "`imageAndSymbols` object" for details.
5959
| `target` | x | x | `object` | Additional settings to configure the remote GDB target. See section "`target` object" for details. |
60+
| `customResetCommands` | x | x | `string[]` | List of GDB commands to perform a RESET of the connected target, for example through `monitor ...` commands of the connected GDB server. |
6061

6162
#### `imageAndSymbols` Object
6263

images/CustomReset_Dark.svg

Lines changed: 1 addition & 0 deletions
Loading

images/CustomReset_Light.svg

Lines changed: 1 addition & 0 deletions
Loading

package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@
5454
"light": "images/SuspendAll_Light.png",
5555
"dark": "images/SuspendAll_Dark.png"
5656
}
57+
},
58+
{
59+
"command": "cdt.debug.customReset",
60+
"title": "Custom Reset",
61+
"icon": {
62+
"light": "images/CustomReset_Light.svg",
63+
"dark": "images/CustomReset_Dark.svg"
64+
}
5765
}
5866
],
5967
"breakpoints": [
@@ -300,6 +308,14 @@
300308
},
301309
"default": []
302310
},
311+
"customResetCommands": {
312+
"type": "array",
313+
"description": "List of debugger commands required to execute a reset through connected debugger.",
314+
"items": {
315+
"type": "string"
316+
},
317+
"default": []
318+
},
303319
"preRunCommands": {
304320
"type": "array",
305321
"description": "List of GDB commands sent after loading image on target before resuming target.",
@@ -541,6 +557,14 @@
541557
},
542558
"default": []
543559
},
560+
"customResetCommands": {
561+
"type": "array",
562+
"description": "List of debugger commands required to execute a reset through connected debugger.",
563+
"items": {
564+
"type": "string"
565+
},
566+
"default": []
567+
},
544568
"preRunCommands": {
545569
"type": "array",
546570
"description": "List of GDB commands sent after loading image on target before resuming target.",
@@ -725,6 +749,11 @@
725749
"command": "cdt.debug.suspendAllSession",
726750
"group": "navigation",
727751
"when": "debugType == amalgamator"
752+
},
753+
{
754+
"command": "cdt.debug.customReset",
755+
"group": "custom",
756+
"when": "cdt.debug.hasCustomReset && (debugType == amalgamator || debugType == gdbtarget)"
728757
}
729758
]
730759
}

src/CustomReset.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*********************************************************************
2+
* Copyright (c) 2025 Arm Ltd. and others
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*********************************************************************/
10+
import { ExtensionContext } from 'vscode';
11+
import * as vscode from 'vscode';
12+
13+
export class CustomReset {
14+
constructor(context: ExtensionContext) {
15+
this.registerCommands(context);
16+
this.registerCallbacks();
17+
}
18+
19+
private readonly registerCallbacks = () => {
20+
vscode.debug.onDidStartDebugSession((session) => {
21+
const hasCustomReset =
22+
Array.isArray(session.configuration?.customResetCommands) &&
23+
session.configuration.customResetCommands.length > 0;
24+
vscode.commands.executeCommand(
25+
'setContext',
26+
'cdt.debug.hasCustomReset',
27+
hasCustomReset
28+
);
29+
});
30+
31+
vscode.debug.onDidTerminateDebugSession(() => {
32+
vscode.commands.executeCommand(
33+
'setContext',
34+
'cdt.debug.hasCustomReset',
35+
false
36+
);
37+
});
38+
};
39+
40+
private readonly registerCommands = (context: ExtensionContext) => {
41+
context.subscriptions.push(
42+
vscode.commands.registerCommand(
43+
'cdt.debug.customReset',
44+
async () => {
45+
const session = vscode.debug.activeDebugSession;
46+
if (session) {
47+
await session.customRequest(
48+
'cdt-gdb-adapter/customReset'
49+
);
50+
}
51+
}
52+
)
53+
);
54+
};
55+
}

src/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ import { ResumeAllSession } from './ResumeAllSession';
1414
export { ResumeAllSession } from './ResumeAllSession';
1515
import { SuspendAllSession } from './SuspendAllSession';
1616
export { SuspendAllSession } from './SuspendAllSession';
17+
import { CustomReset } from './CustomReset';
18+
export { CustomReset } from './CustomReset';
1719

1820
export function activate(context: ExtensionContext) {
1921
new MemoryServer(context);
2022
new ResumeAllSession(context);
2123
new SuspendAllSession(context);
24+
new CustomReset(context);
2225

2326
context.subscriptions.push(
2427
commands.registerCommand('cdt.debug.askProgramPath', (_config) => {

0 commit comments

Comments
 (0)