diff --git a/CHANGELOG.md b/CHANGELOG.md index 899fef0..913af5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## Unreleased +- Implements: + - [Optional device reset during debug session](https://github.com/eclipse-cdt-cloud/cdt-gdb-adapter/issues/359) + ## 2.0.3 - Fixes [#144](https://github.com/eclipse-cdt-cloud/cdt-gdb-vscode/issues/144): Error with the openGdbConsole option diff --git a/README.md b/README.md index 10a8169..b0f564a 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ Launch and attach configuration settings that can be used with the `gdbtarget` d | `preRunCommands` | x | x | `string[]` | List of GDB commands sent after loading image on target before resuming target. | | `imageAndSymbols` | x | x | `object` | Additional settings for loading images to the target and symbols into the debugger. See section "`imageAndSymbols` object" for details. | `target` | x | x | `object` | Additional settings to configure the remote GDB target. See section "`target` object" for details. | +| `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. | #### `imageAndSymbols` Object diff --git a/images/CustomReset_Dark.svg b/images/CustomReset_Dark.svg new file mode 100644 index 0000000..99595d5 --- /dev/null +++ b/images/CustomReset_Dark.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/images/CustomReset_Light.svg b/images/CustomReset_Light.svg new file mode 100644 index 0000000..a8b3bba --- /dev/null +++ b/images/CustomReset_Light.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/package.json b/package.json index 825bb00..0ee8cfd 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,14 @@ "light": "images/SuspendAll_Light.png", "dark": "images/SuspendAll_Dark.png" } + }, + { + "command": "cdt.debug.customReset", + "title": "Custom Reset", + "icon": { + "light": "images/CustomReset_Light.svg", + "dark": "images/CustomReset_Dark.svg" + } } ], "breakpoints": [ @@ -300,6 +308,14 @@ }, "default": [] }, + "customResetCommands": { + "type": "array", + "description": "List of debugger commands required to execute a reset through connected debugger.", + "items": { + "type": "string" + }, + "default": [] + }, "preRunCommands": { "type": "array", "description": "List of GDB commands sent after loading image on target before resuming target.", @@ -541,6 +557,14 @@ }, "default": [] }, + "customResetCommands": { + "type": "array", + "description": "List of debugger commands required to execute a reset through connected debugger.", + "items": { + "type": "string" + }, + "default": [] + }, "preRunCommands": { "type": "array", "description": "List of GDB commands sent after loading image on target before resuming target.", @@ -725,6 +749,11 @@ "command": "cdt.debug.suspendAllSession", "group": "navigation", "when": "debugType == amalgamator" + }, + { + "command": "cdt.debug.customReset", + "group": "custom", + "when": "cdt.debug.hasCustomReset && (debugType == amalgamator || debugType == gdbtarget)" } ] } diff --git a/src/CustomReset.ts b/src/CustomReset.ts new file mode 100644 index 0000000..dc34733 --- /dev/null +++ b/src/CustomReset.ts @@ -0,0 +1,55 @@ +/********************************************************************* + * Copyright (c) 2025 Arm Ltd. and others + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *********************************************************************/ +import { ExtensionContext } from 'vscode'; +import * as vscode from 'vscode'; + +export class CustomReset { + constructor(context: ExtensionContext) { + this.registerCommands(context); + this.registerCallbacks(); + } + + private readonly registerCallbacks = () => { + vscode.debug.onDidStartDebugSession((session) => { + const hasCustomReset = + Array.isArray(session.configuration?.customResetCommands) && + session.configuration.customResetCommands.length > 0; + vscode.commands.executeCommand( + 'setContext', + 'cdt.debug.hasCustomReset', + hasCustomReset + ); + }); + + vscode.debug.onDidTerminateDebugSession(() => { + vscode.commands.executeCommand( + 'setContext', + 'cdt.debug.hasCustomReset', + false + ); + }); + }; + + private readonly registerCommands = (context: ExtensionContext) => { + context.subscriptions.push( + vscode.commands.registerCommand( + 'cdt.debug.customReset', + async () => { + const session = vscode.debug.activeDebugSession; + if (session) { + await session.customRequest( + 'cdt-gdb-adapter/customReset' + ); + } + } + ) + ); + }; +} diff --git a/src/extension.ts b/src/extension.ts index 9c7e72c..4c9c74d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -14,11 +14,14 @@ import { ResumeAllSession } from './ResumeAllSession'; export { ResumeAllSession } from './ResumeAllSession'; import { SuspendAllSession } from './SuspendAllSession'; export { SuspendAllSession } from './SuspendAllSession'; +import { CustomReset } from './CustomReset'; +export { CustomReset } from './CustomReset'; export function activate(context: ExtensionContext) { new MemoryServer(context); new ResumeAllSession(context); new SuspendAllSession(context); + new CustomReset(context); context.subscriptions.push( commands.registerCommand('cdt.debug.askProgramPath', (_config) => {