-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathdebugAdapterDescriptorFactory.ts
More file actions
93 lines (79 loc) · 5.12 KB
/
debugAdapterDescriptorFactory.ts
File metadata and controls
93 lines (79 loc) · 5.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved.
* See 'LICENSE' in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import * as os from 'os';
import * as path from 'path';
import * as vscode from "vscode";
import * as nls from 'vscode-nls';
import { getOutputChannel } from '../logger';
import { RunWithoutDebuggingAdapter } from './runWithoutDebuggingAdapter';
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
// Registers DebugAdapterDescriptorFactory for `cppdbg` and `cppvsdbg`.
// NOTE: This file is not automatically tested.
abstract class AbstractDebugAdapterDescriptorFactory implements vscode.DebugAdapterDescriptorFactory {
protected readonly context: vscode.ExtensionContext;
// This is important for the Mock Debugger since it can not use src/common
constructor(context: vscode.ExtensionContext) {
this.context = context;
}
abstract createDebugAdapterDescriptor(session: vscode.DebugSession, executable?: vscode.DebugAdapterExecutable): vscode.ProviderResult<vscode.DebugAdapterDescriptor>;
}
export class CppdbgDebugAdapterDescriptorFactory extends AbstractDebugAdapterDescriptorFactory {
async createDebugAdapterDescriptor(session: vscode.DebugSession, _executable?: vscode.DebugAdapterExecutable): Promise<vscode.DebugAdapterDescriptor> {
if (session.configuration.noDebug) {
if (noDebugSupported(session.configuration)) {
return new vscode.DebugAdapterInlineImplementation(new RunWithoutDebuggingAdapter());
}
// If the configuration is not supported, gracefully fall back to a regular debug session and log a message to the user.
logReasonForNoDebugNotSupported(session.configuration);
}
const adapter: string = "./debugAdapters/bin/OpenDebugAD7" + (os.platform() === 'win32' ? ".exe" : "");
const command: string = path.join(this.context.extensionPath, adapter);
return new vscode.DebugAdapterExecutable(command, []);
}
}
export class CppvsdbgDebugAdapterDescriptorFactory extends AbstractDebugAdapterDescriptorFactory {
async createDebugAdapterDescriptor(session: vscode.DebugSession, _executable?: vscode.DebugAdapterExecutable): Promise<vscode.DebugAdapterDescriptor | null> {
if (session.configuration.noDebug) {
if (noDebugSupported(session.configuration)) {
return new vscode.DebugAdapterInlineImplementation(new RunWithoutDebuggingAdapter());
}
// If the configuration is not supported, gracefully fall back to a regular debug session and log a message to the user.
logReasonForNoDebugNotSupported(session.configuration);
}
if (os.platform() !== 'win32') {
void vscode.window.showErrorMessage(localize("debugger.not.available", "Debugger type '{0}' is not available for non-Windows machines.", "cppvsdbg"));
return null;
} else {
return new vscode.DebugAdapterExecutable(
path.join(this.context.extensionPath, './debugAdapters/vsdbg/bin/vsdbg.exe'),
['--interpreter=vscode', '--extConfigDir=%USERPROFILE%\\.cppvsdbg\\extensions']
);
}
}
}
function noDebugSupported(configuration: vscode.DebugConfiguration): boolean {
// Don't attempt to start a noDebug session if the configuration has any of these properties, which require a debug adapter to function.
return configuration.request === 'launch' && !configuration.pipeTransport && !configuration.debugServerPath && !configuration.miDebuggerServerAddress && !configuration.coreDumpPath;
}
function logReasonForNoDebugNotSupported(configuration: vscode.DebugConfiguration): void {
const outputChannel = getOutputChannel();
if (configuration.request !== 'launch') {
outputChannel.appendLine(localize("debugger.noDebug.requestType.not.supported", "Run Without Debugging is only supported for launch configurations."));
}
if (configuration.pipeTransport) {
outputChannel.appendLine(localize("debugger.noDebug.pipeTransport.not.supported", "Run Without Debugging is not supported for configurations with 'pipeTransport' set."));
}
if (configuration.debugServerPath) {
outputChannel.appendLine(localize("debugger.noDebug.debugServerPath.not.supported", "Run Without Debugging is not supported for configurations with 'debugServerPath' set."));
}
if (configuration.miDebuggerServerAddress) {
outputChannel.appendLine(localize("debugger.noDebug.miDebuggerServerAddress.not.supported", "Run Without Debugging is not supported for configurations with 'miDebuggerServerAddress' set."));
}
if (configuration.coreDumpPath) {
outputChannel.appendLine(localize("debugger.noDebug.coreDumpPath.not.supported", "Run Without Debugging is not supported for configurations with 'coreDumpPath' set."));
}
outputChannel.show(true);
}