diff --git a/arduino-debugger-extension/src/node/arduino-debug-adapter-contribution.ts b/arduino-debugger-extension/src/node/arduino-debug-adapter-contribution.ts index 6176a507..9f6ee487 100644 --- a/arduino-debugger-extension/src/node/arduino-debug-adapter-contribution.ts +++ b/arduino-debugger-extension/src/node/arduino-debug-adapter-contribution.ts @@ -23,16 +23,11 @@ export class ArduinoDebugAdapterContribution implements DebugAdapterContribution 'description': 'path to the sketch root ino file', 'default': '${file}', }, - 'runToMain': { - 'description': 'If enabled the debugger will run until the start of the main function.', + 'pauseAtMain': { + 'description': 'If enabled the debugger will pause at the start of the main function.', 'type': 'boolean', 'default': false }, - 'verbose': { - 'type': 'boolean', - 'description': 'Produce verbose log output', - 'default': false - }, 'debugDebugAdapter': { 'type': 'boolean', 'description': 'Start the debug adapter in debug mode (with --inspect-brk)', @@ -68,11 +63,15 @@ export class ArduinoDebugAdapterContribution implements DebugAdapterContribution } async resolveDebugConfiguration(config: DebugConfiguration): Promise { + const startFunction = config.pauseAtMain ? 'main' : 'setup'; const res: ActualDebugConfig = { ...config, arduinoCli: await this.arduinoCli.getExecPath(), fqbn: '${fqbn}', - uploadPort: '${port}' + uploadPort: '${port}', + initCommands: [ + `-break-insert -t --function ${startFunction}` + ] } if (!res.sketch) { res.sketch = '${file}'; diff --git a/arduino-debugger-extension/src/node/debug-adapter/arduino-debug-session.ts b/arduino-debugger-extension/src/node/debug-adapter/arduino-debug-session.ts index c53246fa..7c305bdc 100644 --- a/arduino-debugger-extension/src/node/debug-adapter/arduino-debug-session.ts +++ b/arduino-debugger-extension/src/node/debug-adapter/arduino-debug-session.ts @@ -1,5 +1,6 @@ +import * as mi from 'cdt-gdb-adapter/dist/mi'; import { DebugProtocol } from 'vscode-debugprotocol'; -import { GDBDebugSession } from 'cdt-gdb-adapter/dist/GDBDebugSession'; +import { GDBDebugSession, LaunchRequestArguments } from 'cdt-gdb-adapter/dist/GDBDebugSession'; import { GDBBackend } from 'cdt-gdb-adapter/dist/GDBBackend'; import { ArduinoGDBBackend } from './arduino-gdb-backend'; @@ -16,4 +17,25 @@ export class ArduinoDebugSession extends GDBDebugSession { return new ArduinoGDBBackend(); } + protected launchRequest(response: DebugProtocol.LaunchResponse, args: LaunchRequestArguments): Promise { + const additionalCommands = [ + '-interpreter-exec console "monitor reset halt"' + ]; + if (!args.initCommands) { + args.initCommands = additionalCommands; + } else { + args.initCommands.push(...additionalCommands); + } + return super.launchRequest(response, args); + } + + protected async configurationDoneRequest(response: DebugProtocol.ConfigurationDoneResponse): Promise { + try { + await mi.sendExecContinue(this.gdb); + this.sendResponse(response); + } catch (err) { + this.sendErrorResponse(response, 100, err.message); + } + } + } diff --git a/arduino-debugger-extension/src/node/debug-adapter/arduino-gdb-backend.ts b/arduino-debugger-extension/src/node/debug-adapter/arduino-gdb-backend.ts index 800472ce..7af3c61a 100644 --- a/arduino-debugger-extension/src/node/debug-adapter/arduino-gdb-backend.ts +++ b/arduino-debugger-extension/src/node/debug-adapter/arduino-gdb-backend.ts @@ -1,13 +1,12 @@ import * as path from 'path'; import * as fs from 'arduino-ide-extension/lib/node/fs-extra' -import * as mi from './mi'; import { spawn } from 'child_process'; import { GDBBackend } from 'cdt-gdb-adapter/dist/GDBBackend'; import { ArduinoLaunchRequestArguments } from './arduino-debug-session'; export class ArduinoGDBBackend extends GDBBackend { - public spawn(requestArgs: ArduinoLaunchRequestArguments) { + public spawn(requestArgs: ArduinoLaunchRequestArguments): Promise { if (!requestArgs.sketch) { throw new Error('Missing argument: sketch'); } @@ -29,8 +28,13 @@ export class ArduinoGDBBackend extends GDBBackend { return this.parser.parse(proc.stdout); } - public pause() { - mi.sendExecInterrupt(this); + public sendFileExecAndSymbols(): Promise { + // The program file is already sent by `arduino-cli` + return Promise.resolve(); + } + + public pause(): boolean { + this.sendCommand('-exec-interrupt'); return true; }