Skip to content

Commit

Permalink
Add selector to allow windbg preview to be used as C++ debugger (#551)
Browse files Browse the repository at this point in the history
* Add selector to allow windbg preview to be used as C++ debugger

* Fix lint

* 1 more lint
  • Loading branch information
ThadHouse authored Nov 2, 2022
1 parent c281c3c commit d458743
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 7 deletions.
1 change: 1 addition & 0 deletions vscode-wpilib/locale/zh-cn/package.i18n.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ wpilibcore.setSkipTests.title: 设置是否跳过测试API
wpilibcore.setSkipSelectSimulateExtension.title: Change Skip Selection of Simulation Extensions Setting
wpilibcore.setSelectDefaultSimulateExtension.title: Change Default Selection of Simulation Extensions Setting
wpilibcore.setStopSimulationOnEntry.title: 设置是否在进入时停止模拟运行
wpilibcore.setUseWinDbgX.title: Change Use WinDbg Preview (From Store) as Windows Debugger Setting
wpilibcore.setStartRioLog.title: 设置是否在部署时启动 RioLog
wpilibcore.createCommand.title: 创建一个新的类/命令
wpilibcore.cancelTasks.title: 取消正在运行的任务
Expand Down
15 changes: 14 additions & 1 deletion vscode-wpilib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"onCommand:wpilibcore.setSelectDefaultSimulateExtension",
"onCommand:wpilibcore.setOffline",
"onCommand:wpilibcore.setStopSimulationOnEntry",
"onCommand:wpilibcore.setUseWinDbgX",
"onCommand:wpilibcore.setStartRioLog",
"onCommand:wpilibcore.setDeployOffline",
"onCommand:wpilibcore.createCommand",
Expand Down Expand Up @@ -153,9 +154,15 @@
},
"wpilib.stopSimulationOnEntry": {
"type": "boolean",
"default": "false",
"default": false,
"description": "Set to make simulation code stop automatically on entry",
"scope": "resource"
},
"wpilib.useWindbgX": {
"type": "boolean",
"default": false,
"description": "Use WinDbg Preview (from store) as C++ debugger (Windows only)",
"scope": "resource"
}
}
},
Expand Down Expand Up @@ -252,6 +259,12 @@
"category": "WPILib",
"enablement": "isWorkspaceTrusted"
},
{
"command": "wpilibcore.setUseWinDbgX",
"title": "%wpilibcore.setUseWinDbgX.title%",
"category": "WPILib",
"enablement": "isWorkspaceTrusted"
},
{
"command": "wpilibcore.setStartRioLog",
"title": "%wpilibcore.setStartRioLog.title%",
Expand Down
1 change: 1 addition & 0 deletions vscode-wpilib/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"wpilibcore.setOffline.title": "Change Run Commands Except Deploy/Debug in Offline Mode Setting",
"wpilibcore.setDeployOffline.title": "Change Run Deploy/Debug Command in Offline Mode Setting",
"wpilibcore.setStopSimulationOnEntry.title": "Change Stop Simulation on Entry Setting",
"wpilibcore.setUseWinDbgX.title": "Change Use WinDbg Preview (From Store) as Windows Debugger Setting",
"wpilibcore.setStartRioLog.title": "Change Auto Start RioLog on Deploy Setting",
"wpilibcore.createCommand.title": "Create a new class/command",
"wpilibcore.cancelTasks.title": "Cancel currently running tasks",
Expand Down
2 changes: 1 addition & 1 deletion vscode-wpilib/src/cpp/deploydebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class SimulateCodeDeployer implements ICodeDeployer {
workspace,
};

await startWindowsSimulation(config);
await startWindowsSimulation(config, this.executeApi);
}
return true;
}
Expand Down
23 changes: 22 additions & 1 deletion vscode-wpilib/src/cpp/simulatewindows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import * as path from 'path';
import * as vscode from 'vscode';
import { IExecuteAPI } from 'vscode-wpilibapi';
import { logger } from '../logger';

export interface IWindowsSimulateCommands {
Expand All @@ -19,7 +20,27 @@ interface IEnvMap {
[key: string]: any;
}

export async function startWindowsSimulation(commands: IWindowsSimulateCommands): Promise<void> {
export async function simulateWindowsWindbgX(commands: IWindowsSimulateCommands, executor: IExecuteAPI): Promise<void> {
const env: { [key: string]: string } = {
HALSIM_EXTENSIONS: commands.extensions,
};
if (commands.environment !== undefined) {
for (const envVar of Object.keys(commands.environment)) {
const value = commands.environment[envVar];
// tslint:disable-next-line: no-unsafe-any
env[envVar] = value;
}
}
logger.log('C++ WinDbg Simulation', commands.launchfile, commands.workspace.uri.fsPath, env);
await executor.executeCommand('WinDbgX ' + commands.launchfile, 'windbgx', commands.workspace.uri.fsPath, commands.workspace, env);
}

export async function startWindowsSimulation(commands: IWindowsSimulateCommands, executor: IExecuteAPI): Promise<void> {
const wpConfiguration = vscode.workspace.getConfiguration('wpilib', commands.workspace.uri);
const res = wpConfiguration.get<boolean>('useWindbgX');
if (res === true) {
return simulateWindowsWindbgX(commands, executor);
}

let symbolSearchPath = '';

Expand Down
36 changes: 32 additions & 4 deletions vscode-wpilib/src/vscommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export function createVsCommands(context: vscode.ExtensionContext, externalApi:

const result = await globalProjectSettingUpdate(i18n('message', 'Skip tests on deploy? Currently {0}', preferences.getSkipTests()));
if (result === undefined) {
logger.log('Invalid selection for settting skip tests');
logger.log('Invalid selection for setting skip tests');
return;
}

Expand Down Expand Up @@ -257,7 +257,7 @@ export function createVsCommands(context: vscode.ExtensionContext, externalApi:
const result = await globalProjectSettingUpdate(i18n('message',
'Run commands other then deploy in offline mode? Currently {0}', preferences.getOffline()));
if (result === undefined) {
logger.log('Invalid selection for settting offline');
logger.log('Invalid selection for setting offline');
return;
}

Expand All @@ -277,7 +277,7 @@ export function createVsCommands(context: vscode.ExtensionContext, externalApi:
const result = await globalProjectSettingUpdate(i18n('message',
'Run deploy command in offline mode? Currently {0}', preferences.getDeployOffline()));
if (result === undefined) {
logger.log('Invalid selection for settting deploy offline');
logger.log('Invalid selection for setting deploy offline');
return;
}

Expand All @@ -297,13 +297,41 @@ export function createVsCommands(context: vscode.ExtensionContext, externalApi:
const result = await globalProjectSettingUpdate(i18n('message',
'Stop simulation debugging on entry? Currently {0}', preferences.getStopSimulationOnEntry()));
if (result === undefined) {
logger.log('Invalid selection for settting stop simulation on entry');
logger.log('Invalid selection for setting stop simulation on entry');
return;
}

await preferences.setStopSimulationOnEntry(result.yes, result.global);
}));

context.subscriptions.push(vscode.commands.registerCommand('wpilibcore.setUseWinDbgX', async () => {
const preferencesApi = externalApi.getPreferencesAPI();
const workspace = await preferencesApi.getFirstOrSelectedWorkspace();
if (workspace === undefined) {
vscode.window.showInformationMessage(i18n('message', 'Cannot set windbgx in an empty workspace'));
return;
}

const wpConfiguration = vscode.workspace.getConfiguration('wpilib', workspace.uri);
let res = wpConfiguration.get<boolean>('useWindbgX');
if (res === undefined) {
res = false;
}

const result = await globalProjectSettingUpdate(i18n('message',
'Use WinDbg Preview (from store) for windows debugging? Currently {0}', res));
if (result === undefined) {
logger.log('Invalid selection for setting Use WinDbg Preview');
return;
}

let target: vscode.ConfigurationTarget = vscode.ConfigurationTarget.Global;
if (!result.global) {
target = vscode.ConfigurationTarget.WorkspaceFolder;
}
return wpConfiguration.update('useWindbgX', result.yes, target);
}));

context.subscriptions.push(vscode.commands.registerCommand('wpilibcore.setAutoSave', async () => {
const preferencesApi = externalApi.getPreferencesAPI();
const workspace = await preferencesApi.getFirstOrSelectedWorkspace();
Expand Down

0 comments on commit d458743

Please sign in to comment.