Skip to content

Commit 18ddb8c

Browse files
authored
Add Architecture check in AdapterExectuableCommand (#2094)
* Add Architecture check in AdapterExectuableCommand x86 messages only show during the first installation. But it still registeres the vsdbg-ui.exe command. This adds a check so it will error instead of returning the command. * Moving arch check into completeDebuggerInstall
1 parent 4da1337 commit 18ddb8c

File tree

1 file changed

+40
-30
lines changed

1 file changed

+40
-30
lines changed

src/coreclr-debug/activate.ts

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*--------------------------------------------------------------------------------------------*/
55
'use strict';
66

7-
import * as os from 'os';
87
import * as path from 'path';
98
import * as vscode from 'vscode';
109
import * as common from './../common';
@@ -23,42 +22,55 @@ export async function activate(thisExtension : vscode.Extension<any>, context: v
2322
_logger = logger;
2423

2524
if (!CoreClrDebugUtil.existsSync(_debugUtil.debugAdapterDir())) {
26-
let platformInformation: PlatformInformation;
27-
28-
try {
29-
platformInformation = await PlatformInformation.GetCurrent();
30-
}
31-
catch (err) {
32-
// Somehow we couldn't figure out the platform we are on
33-
logger.appendLine("[ERROR]: C# Extension failed to install the debugger package");
25+
let isInvalidArchitecture: boolean = await checkForInvalidArchitecture(logger);
26+
if (!isInvalidArchitecture) {
27+
logger.appendLine("[ERROR]: C# Extension failed to install the debugger package.");
3428
showInstallErrorMessage(channel);
3529
}
30+
} else if (!CoreClrDebugUtil.existsSync(_debugUtil.installCompleteFilePath())) {
31+
completeDebuggerInstall(logger, channel);
32+
}
33+
}
34+
35+
async function checkForInvalidArchitecture(logger: Logger): Promise<boolean> {
36+
let platformInformation: PlatformInformation;
3637

37-
if (platformInformation) {
38-
if (platformInformation.architecture !== "x86_64") {
39-
if (platformInformation.isWindows() && platformInformation.architecture === "x86") {
40-
logger.appendLine(`[WARNING]: x86 Windows is not currently supported by the .NET Core debugger. Debugging will not be available.`);
41-
} else {
42-
logger.appendLine(`[WARNING]: Processor architecture '${platformInformation.architecture}' is not currently supported by the .NET Core debugger. Debugging will not be available.`);
43-
}
38+
try {
39+
platformInformation = await PlatformInformation.GetCurrent();
40+
}
41+
catch (err) {
42+
// Somehow we couldn't figure out the platform we are on
43+
logger.appendLine("[ERROR] The debugger cannot be installed. Could not determine current platform.");
44+
return true;
45+
}
46+
47+
if (platformInformation) {
48+
if (platformInformation.isMacOS() && !CoreClrDebugUtil.isMacOSSupported()) {
49+
logger.appendLine("[ERROR] The debugger cannot be installed. The debugger requires macOS 10.12 (Sierra) or newer.");
50+
return true;
51+
}
52+
else if (platformInformation.architecture !== "x86_64") {
53+
if (platformInformation.isWindows() && platformInformation.architecture === "x86") {
54+
logger.appendLine(`[WARNING]: x86 Windows is not currently supported by the .NET Core debugger. Debugging will not be available.`);
4455
} else {
45-
logger.appendLine("[ERROR]: C# Extension failed to install the debugger package");
46-
showInstallErrorMessage(channel);
56+
logger.appendLine(`[WARNING]: Processor architecture '${platformInformation.architecture}' is not currently supported by the .NET Core debugger. Debugging will not be available.`);
4757
}
58+
return true;
4859
}
49-
} else if (!CoreClrDebugUtil.existsSync(_debugUtil.installCompleteFilePath())) {
50-
completeDebuggerInstall(logger, channel);
5160
}
61+
62+
return false;
5263
}
5364

5465
async function completeDebuggerInstall(logger: Logger, channel: vscode.OutputChannel) : Promise<boolean> {
5566
return _debugUtil.checkDotNetCli()
56-
.then((dotnetInfo: DotnetInfo) => {
67+
.then(async (dotnetInfo: DotnetInfo) => {
68+
69+
let isInvalidArchitecture: boolean = await checkForInvalidArchitecture(logger);
5770

58-
if (os.platform() === "darwin" && !CoreClrDebugUtil.isMacOSSupported()) {
59-
logger.appendLine("[ERROR] The debugger cannot be installed. The debugger requires macOS 10.12 (Sierra) or newer.");
71+
if (isInvalidArchitecture) {
6072
channel.show();
61-
73+
vscode.window.showErrorMessage('Failed to complete the installation of the C# extension. Please see the error in the output window below.');
6274
return false;
6375
}
6476

@@ -123,15 +135,14 @@ export async function getAdapterExecutionCommand(channel: vscode.OutputChannel):
123135
let util = new CoreClrDebugUtil(common.getExtensionPath(), logger);
124136

125137
// Check for .debugger folder. Handle if it does not exist.
126-
if (!CoreClrDebugUtil.existsSync(util.debugAdapterDir()))
127-
{
138+
if (!CoreClrDebugUtil.existsSync(util.debugAdapterDir())) {
128139
// our install.complete file does not exist yet, meaning we have not completed the installation. Try to figure out what if anything the package manager is doing
129140
// the order in which files are dealt with is this:
130141
// 1. install.Begin is created
131142
// 2. install.Lock is created
132143
// 3. install.Begin is deleted
133144
// 4. install.complete is created
134-
145+
135146
// install.Lock does not exist, need to wait for packages to finish downloading.
136147
let installLock: boolean = await common.installFileExists(common.InstallFileType.Lock);
137148
if (!installLock) {
@@ -142,15 +153,14 @@ export async function getAdapterExecutionCommand(channel: vscode.OutputChannel):
142153
else if (!CoreClrDebugUtil.existsSync(util.installCompleteFilePath())) {
143154
let success: boolean = await completeDebuggerInstall(logger, channel);
144155

145-
if (!success)
146-
{
156+
if (!success) {
147157
channel.show();
148158
throw new Error('Failed to complete the installation of the C# extension. Please see the error in the output window below.');
149159
}
150160
}
151161
}
152162

153-
// debugger has finished install, kick off our debugger process
163+
// debugger has finished installation, kick off our debugger process
154164
return {
155165
command: path.join(common.getExtensionPath(), ".debugger", "vsdbg-ui" + CoreClrDebugUtil.getPlatformExeExtension())
156166
};

0 commit comments

Comments
 (0)