From 24288c14c34d776a6c63c05bcec9909c0ec37019 Mon Sep 17 00:00:00 2001 From: Basit Sheikh Date: Fri, 15 May 2026 11:01:09 -0700 Subject: [PATCH] Re-added support for 'Jump to Cursor' command --- src/backend/mi2/mi2.ts | 12 ++++++++ src/gdb.ts | 69 ++++++++++++++++++++++++++++++++---------- 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/src/backend/mi2/mi2.ts b/src/backend/mi2/mi2.ts index e102ed7c..cc55e278 100644 --- a/src/backend/mi2/mi2.ts +++ b/src/backend/mi2/mi2.ts @@ -565,6 +565,18 @@ export class MI2 extends EventEmitter implements IBackend { }); } + public goto(filename: string, line: number): Thenable { + if (trace) { + this.log('stderr', 'goto'); + } + return new Promise((resolve, reject) => { + const target = `"${filename ? `${escape(filename)}:` : ''}${line.toString()}"`; + this.sendCommand(`exec-jump ${target}`).then((info) => { + resolve(info.resultRecords.resultClass === 'running'); + }, reject); + }); + } + public restart(commands: string[]): Thenable { if (trace) { this.log('stderr', 'restart'); diff --git a/src/gdb.ts b/src/gdb.ts index 69a5ce01..3fef247e 100755 --- a/src/gdb.ts +++ b/src/gdb.ts @@ -256,6 +256,7 @@ export class GDBDebugSession extends LoggingDebugSession { protected variableHandles = new Handles(HandleRegions.VAR_HANDLES_START); protected variableHandlesReverse = new Map(); + protected gotoTargetHandles = new Handles(1); protected quit!: boolean; protected attached!: boolean; protected started!: boolean; @@ -3594,10 +3595,45 @@ export class GDBDebugSession extends LoggingDebugSession { } protected async gotoTargetsRequest(response: DebugProtocol.GotoTargetsResponse, args: DebugProtocol.GotoTargetsArguments): Promise { + const file = args.source?.path; + if (!file) { + this.sendErrorResponse(response, 16, `Could not jump to: ${args.line}`); + return; + } + + const targetId = this.gotoTargetHandles.create({ + file: file, + line: args.line, + column: args.column + }); + + response.body = { + targets: [{ + id: targetId, + label: args.source.name || path.basename(file), + column: args.column, + line: args.line + }] + }; + this.sendResponse(response); + } + + protected async gotoRequest(response: DebugProtocol.GotoResponse, args: DebugProtocol.GotoArguments): Promise { + if (this.isBusy()) { + this.busyError(response, args); + return; + } + + const target = this.gotoTargetHandles.get(args.targetId); + if (!target?.file) { + this.sendErrorResponse(response, 16, `Could not jump to target ${args.targetId}`); + return; + } + try { const brk: OurSourceBreakpoint = { - file: args.source.path, - line: args.line, + file: target.file, + line: target.line, isTemporary: true, hwOpt: this.hwBreakpointMgr.getGdbMiArg('src') }; @@ -3607,22 +3643,23 @@ export class GDBDebugSession extends LoggingDebugSession { }, brk); if (result instanceof MIError) { - this.sendErrorResponse(response, 16, `Could not jump to: ${result.message} ${args.source.path}:${args.line}`); - } else if (!result) { - this.sendErrorResponse(response, 16, `Could not jump to: ${args.source.path}:${args.line}`); - } else { - response.body = { - targets: [{ - id: result.number || 0, - label: args.source.name || '', - column: args.column, - line: args.line - }] - }; - this.sendResponse(response); + this.sendErrorResponse(response, 16, `Could not jump to: ${result.message} ${target.file}:${target.line}`); + return; + } + if (!result) { + this.sendErrorResponse(response, 16, `Could not jump to: ${target.file}:${target.line}`); + return; + } + + const done = await this.miDebugger.goto(target.file, target.line); + if (!done) { + this.sendErrorResponse(response, 16, `Could not jump to: ${target.file}:${target.line}`); + return; } + + this.sendResponse(response); } catch (msg) { - this.sendErrorResponse(response, 16, `Could not jump to: ${msg ? msg : ''} ${args.source.path}:${args.line}`); + this.sendErrorResponse(response, 16, `Could not jump to: ${msg ? msg : ''} ${target.file}:${target.line}`); } } }