From 3f6c41cfb2d33e6914074339d00f1092360727fe Mon Sep 17 00:00:00 2001 From: Haneef Mohammed Date: Mon, 3 Jan 2022 09:18:30 -0800 Subject: [PATCH] toggle hex display setting --- CHANGELOG.md | 3 ++- package-lock.json | 4 ++-- package.json | 24 ++++++++++++++++---- src/frontend/extension.ts | 47 ++++++++++++++++++++++++++++++--------- src/gdb.ts | 4 ++-- 5 files changed, 62 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a71818e2..cb70de25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ ChangeLog # V1.1.5 -* Fixed issue with with SWO (or RTT) not working the first time. It was a race condition where we were trying to connect too fast. Now we re-try +* Feature: There now a command (default key-binding Ctrl+Shift+X) to toggle Hex display in the Variables window. Does not affect the Registers window (which may be going away) as it has its own command and button. You can find this command in the "Command Palette" as "Cortex-Debug: Toggle hex display in Variables window" +* Fixed issue with with SWO (or RTT) not working the first time. It was a race condition where we were trying to connect too fast. Now we re-try. The max timeout is 5 mins. * Fixed SWO and RTT are now session aware. As in, you can have multiple RTT/SWO windows from different debug sessions. # V1.1.4 * BugFix: Reset was broken in previous release diff --git a/package-lock.json b/package-lock.json index 6a412470..4954b571 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "cortex-debug", - "version": "1.1.2", + "version": "1.1.5", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "1.1.2", + "version": "1.1.5", "license": "MIT", "dependencies": { "binary-parser": "^1.7.0", diff --git a/package.json b/package.json index dd0fcacf..f081a5b4 100644 --- a/package.json +++ b/package.json @@ -382,7 +382,7 @@ } }, { - "command": "cortex-debug.registers.varHexModeTurnOff", + "command": "cortex-debug.varHexModeTurnOff", "title": "Enable Natural mode", "icon": { "light": "images/hex-on-light.svg", @@ -390,7 +390,7 @@ } }, { - "command": "cortex-debug.registers.varHexModeTurnOn", + "command": "cortex-debug.varHexModeTurnOn", "title": "Enable Hex mode", "icon": { "light": "images/hex-off-light.svg", @@ -430,8 +430,20 @@ "category": "Cortex-Debug", "command": "cortex-debug.setForceDisassembly", "title": "Set Force Disassembly" + }, + { + "category": "Cortex-Debug", + "command": "cortex-debug.toggleVariableHexFormat", + "title": "Toggle hex display in Variables window" } ], + "keybindings": [ + { + "command": "cortex-debug.toggleVariableHexFormat", + "key": "ctrl+shift+x", + "when": "debugType == cortex-debug" + } + ], "languages": [ { "id": "cortex-debug.disassembly", @@ -2421,6 +2433,10 @@ { "command": "cortex-debug.resetDevice", "when": "debugType == cortex-debug" + }, + { + "command": "cortex-debug.toggleVariableHexFormat", + "when": "debugType == cortex-debug" } ], "debug/toolBar": [ @@ -2531,12 +2547,12 @@ ], "debug/variables/context": [ { - "command": "cortex-debug.registers.varHexModeTurnOn", + "command": "cortex-debug.varHexModeTurnOn", "when": "inDebugMode && debugType == 'cortex-debug' && debugState == stopped && cortex-debug:variableUseNaturalFormat", "group": "navigation" }, { - "command": "cortex-debug.registers.varHexModeTurnOff", + "command": "cortex-debug.varHexModeTurnOff", "when": "inDebugMode && debugType == 'cortex-debug' && debugState == stopped && !cortex-debug:variableUseNaturalFormat", "group": "navigation" } diff --git a/src/frontend/extension.ts b/src/frontend/extension.ts index 8d196824..1469c493 100644 --- a/src/frontend/extension.ts +++ b/src/frontend/extension.ts @@ -92,8 +92,9 @@ export class CortexDebugExtension { vscode.commands.registerCommand('cortex-debug.registers.refresh', this.registersRefresh.bind(this)), vscode.commands.registerCommand('cortex-debug.registers.regHexModeTurnOn', this.registersNaturalMode.bind(this, false)), vscode.commands.registerCommand('cortex-debug.registers.regHexModeTurnOff', this.registersNaturalMode.bind(this, true)), - vscode.commands.registerCommand('cortex-debug.registers.varHexModeTurnOn', this.variablesNaturalMode.bind(this, false)), - vscode.commands.registerCommand('cortex-debug.registers.varHexModeTurnOff', this.variablesNaturalMode.bind(this, true)), + vscode.commands.registerCommand('cortex-debug.varHexModeTurnOn', this.variablesNaturalMode.bind(this, false)), + vscode.commands.registerCommand('cortex-debug.varHexModeTurnOff', this.variablesNaturalMode.bind(this, true)), + vscode.commands.registerCommand('cortex-debug.toggleVariableHexFormat', this.toggleVariablesHexMode.bind(this)), vscode.commands.registerCommand('cortex-debug.examineMemory', this.examineMemory.bind(this)), vscode.commands.registerCommand('cortex-debug.viewDisassembly', this.showDisassembly.bind(this)), @@ -163,8 +164,8 @@ export class CortexDebugExtension { } private settingsChanged(e: vscode.ConfigurationChangeEvent) { - const msg = 'New format will take effect next time the program pauses'; if (e.affectsConfiguration(`cortex-debug.${CortexDebugKeys.REGISTER_DISPLAY_MODE}`)) { + const msg = 'Cortex-Debug: New format will take effect next time the program pauses'; const session = CortexDebugExtension.getActiveCDSession(); if (session) { const mySession = CDebugSession.FindSession(session); @@ -178,16 +179,25 @@ export class CortexDebugExtension { } } if (e.affectsConfiguration(`cortex-debug.${CortexDebugKeys.VARIABLE_DISPLAY_MODE}`)) { - const session = CortexDebugExtension.getActiveCDSession(); - if (session) { - const mySession = CDebugSession.FindSession(session); - const config = vscode.workspace.getConfiguration('cortex-debug'); - const isHex = config.get(CortexDebugKeys.VARIABLE_DISPLAY_MODE, true) ? false : true; - session.customRequest('set-var-format', { hex: isHex }); - if (mySession.status === 'running') { - vscode.window.showInformationMessage(msg); + const config = vscode.workspace.getConfiguration('cortex-debug'); + const isHex = config.get(CortexDebugKeys.VARIABLE_DISPLAY_MODE, true) ? false : true; + let foundStopped = false; + for (const s of CDebugSession.CurrentSessions) { + try { + // Session may not have actually started according to VSCode but we know of it + s.session.customRequest('set-var-format', { hex: isHex }); + if (s.status === 'stopped') { + foundStopped = true; + } + } + catch (e) { } } + if (!foundStopped) { + const fmt = isHex ? 'hex' : 'dec'; + const msg = `Cortex-Debug: Variables window format "${fmt}" will take effect next time the program pauses`; + vscode.window.showInformationMessage(msg); + } } if (e.affectsConfiguration(`cortex-debug.${CortexDebugKeys.SERVER_LOG_FILE_NAME}`)) { const config = vscode.workspace.getConfiguration('cortex-debug'); @@ -498,6 +508,21 @@ export class CortexDebugExtension { } } + private toggleVariablesHexMode() { + // 'cxt' contains the treeItem on which this menu was invoked. Maybe we can do something + // with it later + const config = vscode.workspace.getConfiguration('cortex-debug'); + const curVal = config.get(CortexDebugKeys.VARIABLE_DISPLAY_MODE, true); + const newVal = !curVal; + vscode.commands.executeCommand('setContext', `cortex-debug:${CortexDebugKeys.VARIABLE_DISPLAY_MODE}`, newVal); + try { + config.update(CortexDebugKeys.VARIABLE_DISPLAY_MODE, newVal); + } + catch (e) { + console.error(e); + } + } + // Debug Events private debugSessionStarted(session: vscode.DebugSession) { if (session.type !== 'cortex-debug') { return; } diff --git a/src/gdb.ts b/src/gdb.ts index dc50ce40..38dc56d0 100755 --- a/src/gdb.ts +++ b/src/gdb.ts @@ -850,7 +850,7 @@ export class GDBDebugSession extends DebugSession { this.miDebugger.sendCommand(cmd); } if (this.stopped) { - // We area already stopped but this fakes a stop again which referhes all debugger windows + // We area already stopped but this fakes a stop again which refreshes all debugger windows // We don't have a way to only referesh portions. It is all or nothing, there is a bit // of screen flashing and causes changes in GUI contexts (stack for instance) this.sendEvent(new StoppedEvent(this.stoppedReason, this.currentThreadId, true)); @@ -2090,7 +2090,7 @@ export class GDBDebugSession extends DebugSession { try { const [threadId, frameId] = GDBDebugSession.decodeReference(args.variablesReference); - const fmt = this.args.registerUseNaturalFormat ? 'N' : 'x'; + const fmt = this.args.variableUseNaturalFormat ? 'N' : 'x'; // --thread --frame does not work properly this.miDebugger.sendCommand(`thread-select ${threadId}`); this.miDebugger.sendCommand(`stack-select-frame ${frameId}`);