From f5e78171abfa94572f76c65b8af1e712fcc97891 Mon Sep 17 00:00:00 2001 From: Haneef Mohammed Date: Fri, 17 Jan 2025 12:35:10 -0500 Subject: [PATCH 1/3] Fix for #1007 --- CHANGELOG.md | 3 ++- package-lock.json | 4 ++-- package.json | 2 +- src/gdb.ts | 27 ++++++++++++++++++--------- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd3dd97c..c9961b7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # ChangeLog -# V1.13.0-pre1 +# V1.13.0-pre3 * MAJOR Change. The `Restart` button functionality has been completely changed. This was not a stable function and VSCode kept changing its definition over the years multiple times. However they provide a default functionality, so the `Restart` button still works but very differently from our implementation. As of today, VSCode seems to do the following (and this extension is not involved) * It Stops the current session. This means the current GDB and any GDB-server (openocd, stlink, etc. are also terminated) * If then Starts a new session using the same configuration. @@ -14,6 +14,7 @@ so the extension no longer depends on other extensions to provide related functionality. * Black Magic Probe now supports SWO via the dedicated USB endpoint. * ST-LINK GDB server (*not* st-util) now supports SWO functionality, using standard configuration options. +* Bugfix #1007: An issue with how gdb works prevented RTOS detection when `"symbolFiles"` was used. It will now work if you do not use additional options to specify sections or a textaddress. # V1.12.1 * Fix for [#923: Local variables with same name between functions not tracking or updating context](https://github.com/Marus/cortex-debug/issues/923) diff --git a/package-lock.json b/package-lock.json index 9a96b4ef..e44b537b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cortex-debug", - "version": "1.13.0-pre2", + "version": "1.13.0-pre3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cortex-debug", - "version": "1.13.0-pre2", + "version": "1.13.0-pre3", "license": "MIT", "dependencies": { "@vscode/extension-telemetry": "^0.9.8", diff --git a/package.json b/package.json index af6b1eaf..f16973a2 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "1.13.0-pre2", + "version": "1.13.0-pre3", "preview": false, "activationEvents": [ "onDebugResolve:cortex-debug", diff --git a/src/gdb.ts b/src/gdb.ts index 6bf2bbf8..ffd61c2f 100755 --- a/src/gdb.ts +++ b/src/gdb.ts @@ -947,24 +947,33 @@ export class GDBDebugSession extends LoggingDebugSession { `interpreter-exec console "source ${this.args.extensionPath}/support/gdb-swo.init"`, ...this.formatRadixGdbCommand() ]; + + let loadFiles = this.args.loadFiles; + let isLoaded = false; if (this.args.symbolFiles) { + // If you just used 'add-symbol-file' debugging works but RTOS detection fails + // for most debuggers. While many options work for add-symbol-file, symbol-file + // does not allow a textaddress or sections. See issue #1007 for (const symF of this.args.symbolFiles) { - let cmd = `interpreter-exec console "add-symbol-file \\"${symF.file}\\""`; - cmd += symF.offset ? ` -o ${hexFormat(symF.offset)}"` : ''; - cmd += (typeof symF.textaddress === 'number') ? ` ${hexFormat(symF.textaddress)}"` : ''; + const offset = symF.offset ? `-o ${hexFormat(symF.offset)}"` : ''; + let otherArgs = (typeof symF.textaddress === 'number') ? ` ${hexFormat(symF.textaddress)}"` : ''; for (const section of symF.sections) { - cmd += ` -s ${section.name} ${section.address}`; + otherArgs += ` -s ${section.name} ${section.address}`; } - this.gdbInitCommands.push(cmd); + const gdbCmd = (otherArgs === '') ? 'symbol-file' : 'add-symbol-file'; + const cmd = `${gdbCmd} \\"${symF.file}\\" ${offset} ${otherArgs}`.trimEnd(); + this.gdbInitCommands.push(`interpreter-exec console "${cmd}"`); } if (this.gdbInitCommands.length === 0) { this.handleMsg('log', 'Info: GDB may not start since there were no files with symbols in "symbolFiles?\n'); } - if (this.args.executable) { - this.gdbInitCommands.push(`file-exec-file "${this.args.executable}"`); - } - } else { + } else if (!loadFiles && this.args.executable) { this.gdbInitCommands.push(`file-exec-and-symbols "${this.args.executable}"`); + isLoaded = true; + } + + if (!isLoaded && !loadFiles && this.args.executable) { + this.args.loadFiles = [ this.args.executable ]; } const ret = this.miDebugger.start(this.args.cwd, this.gdbInitCommands); return ret; From c36e3da5ef065d878e324b2b7d10b45f7c3c0b39 Mon Sep 17 00:00:00 2001 From: Haneef Mohammed Date: Fri, 17 Jan 2025 14:03:33 -0500 Subject: [PATCH 2/3] fix lint error --- src/gdb.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/gdb.ts b/src/gdb.ts index ffd61c2f..87e4e040 100755 --- a/src/gdb.ts +++ b/src/gdb.ts @@ -915,11 +915,6 @@ export class GDBDebugSession extends LoggingDebugSession { private startGdb(response: DebugProtocol.LaunchResponse): Promise { const gdbExePath = this.args.gdbPath; const gdbargs = ['-q', '--interpreter=mi2'].concat(this.args.debuggerArgs || []); - // if (!this.args.symbolFiles) { - // if (!path.isAbsolute(this.args.executable)) { - // this.args.executable = path.join(this.args.cwd, this.args.executable); - // } - // } const dbgMsg = 'Launching GDB: ' + quoteShellCmdLine([gdbExePath, ...gdbargs]) + '\n'; this.handleMsg('log', dbgMsg); if (!this.args.showDevDebugOutput) { @@ -948,7 +943,7 @@ export class GDBDebugSession extends LoggingDebugSession { ...this.formatRadixGdbCommand() ]; - let loadFiles = this.args.loadFiles; + const loadFiles = this.args.loadFiles; let isLoaded = false; if (this.args.symbolFiles) { // If you just used 'add-symbol-file' debugging works but RTOS detection fails From a2900a4918e368a75eea8d092b7dbbb892de2fc8 Mon Sep 17 00:00:00 2001 From: Haneef Mohammed Date: Fri, 17 Jan 2025 14:06:23 -0500 Subject: [PATCH 3/3] lint error --- src/gdb.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gdb.ts b/src/gdb.ts index 87e4e040..52cf1847 100755 --- a/src/gdb.ts +++ b/src/gdb.ts @@ -968,7 +968,7 @@ export class GDBDebugSession extends LoggingDebugSession { } if (!isLoaded && !loadFiles && this.args.executable) { - this.args.loadFiles = [ this.args.executable ]; + this.args.loadFiles = [this.args.executable]; } const ret = this.miDebugger.start(this.args.cwd, this.gdbInitCommands); return ret;