From 7d276df77c2913aace5bdef622d4725c6eda9a79 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Thu, 22 Aug 2024 14:38:18 +0200 Subject: [PATCH] Support GDB frame filters This adds a new `frameFilters` option for GDB. When enabled, `enable-frame-filters` is passed to GDB which will run frame filters before they are passed to the extension. --- CHANGELOG.md | 3 +++ package.json | 10 ++++++++++ src/backend/mi2/mi2.ts | 10 +++++++++- src/gdb.ts | 4 ++++ src/mibase.ts | 2 +- 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 521f9e90..b41a3c0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ Versioning]. - fix implicitly type error in log message when build vsix ([@henryriley0]) - check for configured debugger before start to provide a nicer error message ([@GitMensch]) +- New `frameFilters` option for GDB that allows using custom frame filters, + enabled by default ([@JacquesLucke]) ## [0.27.0] - 2024-02-07 @@ -245,6 +247,7 @@ Versioning]. [@gitmensch]: https://github.com/GitMensch [@haronk]: https://github.com/HaronK [@henryriley0]: https://github.com/HenryRiley0 +[@jacqueslucke]: https://github.com/JacquesLucke [@jelleroets]: https://github.com/JelleRoets [@karljs]: https://github.com/karljs [@kvinwang]: https://github.com/kvinwang diff --git a/package.json b/package.json index fb20330b..5454bf60 100644 --- a/package.json +++ b/package.json @@ -194,6 +194,11 @@ "prettyPrinters" ] }, + "frameFilters": { + "type": "boolean", + "description": "Use frame filters registered in GDB", + "default": true + }, "printCalls": { "type": "boolean", "description": "Prints all GDB calls to the console", @@ -322,6 +327,11 @@ "prettyPrinters" ] }, + "frameFilters": { + "type": "boolean", + "description": "Use frame filters registered in GDB", + "default": true + }, "printCalls": { "type": "boolean", "description": "Prints all GDB calls to the console", diff --git a/src/backend/mi2/mi2.ts b/src/backend/mi2/mi2.ts index 82e7ae6a..f28c61aa 100644 --- a/src/backend/mi2/mi2.ts +++ b/src/backend/mi2/mi2.ts @@ -54,7 +54,7 @@ class LogMessage { } } - logMsgProcess(parsed:any){ + logMsgProcess(parsed:MINode){ this.logMsgBrkList.forEach((brk)=>{ if(parsed.outOfBandRecord[0].output[0][1] == "breakpoint-hit" && parsed.outOfBandRecord[0].output[2][1] == brk.id){ this.logMsgVar = brk?.logMessage; @@ -264,6 +264,8 @@ export class MI2 extends EventEmitter implements IBackend { cmds.push(this.sendCommand("file-exec-and-symbols \"" + escape(target) + "\"")); if (this.prettyPrint) cmds.push(this.sendCommand("enable-pretty-printing")); + if (this.frameFilters) + cmds.push(this.sendCommand("enable-frame-filters")); for (const cmd of this.extraCommands) { cmds.push(this.sendCommand(cmd)); } @@ -794,6 +796,11 @@ export class MI2 extends EventEmitter implements IBackend { const func = MINode.valueOf(element, "@frame.func"); const filename = MINode.valueOf(element, "@frame.file"); let file: string = MINode.valueOf(element, "@frame.fullname"); + if (!file) { + // Fallback to using `file` if `fullname` is not provided. + // GDB does this for some reason when frame filters are used. + file = MINode.valueOf(element, "@frame.file"); + } if (file) { if (this.isSSH) file = path.posix.normalize(file); @@ -1012,6 +1019,7 @@ export class MI2 extends EventEmitter implements IBackend { } prettyPrint: boolean = true; + frameFilters: boolean = true; printCalls: boolean; debugOutput: boolean; features: string[]; diff --git a/src/gdb.ts b/src/gdb.ts index ecc6c3ce..b8d9d5ac 100644 --- a/src/gdb.ts +++ b/src/gdb.ts @@ -17,6 +17,7 @@ export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArgum stopAtEntry: boolean | string; ssh: SSHArguments; valuesFormatting: ValuesFormattingMode; + frameFilters: boolean; printCalls: boolean; showDevDebugOutput: boolean; } @@ -35,6 +36,7 @@ export interface AttachRequestArguments extends DebugProtocol.AttachRequestArgum stopAtEntry: boolean | string; ssh: SSHArguments; valuesFormatting: ValuesFormattingMode; + frameFilters: boolean; printCalls: boolean; showDevDebugOutput: boolean; } @@ -69,6 +71,7 @@ class GDBDebugSession extends MI2DebugSession { this.started = false; this.crashed = false; this.setValuesFormattingMode(args.valuesFormatting); + this.miDebugger.frameFilters = !!args.frameFilters; this.miDebugger.printCalls = !!args.printCalls; this.miDebugger.debugOutput = !!args.showDevDebugOutput; this.stopAtEntry = args.stopAtEntry; @@ -113,6 +116,7 @@ class GDBDebugSession extends MI2DebugSession { this.initialRunCommand = args.stopAtConnect ? RunCommand.NONE : RunCommand.CONTINUE; this.isSSH = false; this.setValuesFormattingMode(args.valuesFormatting); + this.miDebugger.frameFilters = !!args.frameFilters; this.miDebugger.printCalls = !!args.printCalls; this.miDebugger.debugOutput = !!args.showDevDebugOutput; this.stopAtEntry = args.stopAtEntry; diff --git a/src/mibase.ts b/src/mibase.ts index 4538d565..9bc16127 100644 --- a/src/mibase.ts +++ b/src/mibase.ts @@ -320,7 +320,7 @@ export class MI2DebugSession extends DebugSession { ret.push(new StackFrame( this.threadAndLevelToFrameId(args.threadId, element.level), - element.function + "@" + element.address, + element.function + (element.address ? "@" + element.address : ""), source, element.line, 0));