forked from microsoft/vscode-cpptools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugAdapterDescriptorFactory.ts
More file actions
117 lines (100 loc) · 6.02 KB
/
Copy pathdebugAdapterDescriptorFactory.ts
File metadata and controls
117 lines (100 loc) · 6.02 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* --------------------------------------------------------------------------------------------
* 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 { logDebuggerEvent } from '../telemetry';
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> {
const properties: { [key: string]: string } = { type: 'cppdbg', noDebug: Boolean(session.configuration.noDebug).toString() };
try {
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);
properties.noDebugSkipped = true.toString();
}
const adapter: string = "./debugAdapters/bin/OpenDebugAD7" + (os.platform() === 'win32' ? ".exe" : "");
const command: string = path.join(this.context.extensionPath, adapter);
return new vscode.DebugAdapterExecutable(command, []);
} finally {
logDebuggerEvent('createDebugAdapter', properties);
}
}
}
export class CppvsdbgDebugAdapterDescriptorFactory extends AbstractDebugAdapterDescriptorFactory {
async createDebugAdapterDescriptor(session: vscode.DebugSession, _executable?: vscode.DebugAdapterExecutable): Promise<vscode.DebugAdapterDescriptor | null> {
const properties: { [key: string]: string } = { type: 'cppvsdbg', noDebug: Boolean(session.configuration.noDebug).toString() };
try {
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);
properties.noDebugSkipped = true.toString();
}
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']
);
}
} finally {
logDebuggerEvent('createDebugAdapter', properties);
}
}
}
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 {
if (configuration.ignoreRunWithoutDebuggingWarnings === true) {
return;
}
const disallowedProperties: string[] = [];
const outputChannel = getOutputChannel();
outputChannel.show(true);
if (configuration.request !== 'launch') {
outputChannel.appendLine(localize("debugger.noDebug.requestType.not.supported", "Run Without Debugging is only supported for launch configurations."));
return;
}
if (configuration.pipeTransport) {
disallowedProperties.push('pipeTransport');
}
if (configuration.debugServerPath) {
disallowedProperties.push('debugServerPath');
}
if (configuration.miDebuggerServerAddress) {
disallowedProperties.push('miDebuggerServerAddress');
}
if (configuration.coreDumpPath) {
disallowedProperties.push('coreDumpPath');
}
outputChannel.appendLine(localize("debugger.unsupported.properties", "Launch configurations with the following properties cannot be run directly in the terminal: {0}", disallowedProperties.join(', ')));
outputChannel.appendLine(localize("debugger.fallback.message", "Program output will appear in the Debug Console instead."));
outputChannel.appendLine(localize("debugger.fallback.message2", "To suppress this warning, set the 'ignoreRunWithoutDebuggingWarnings' property to true in your launch configuration."));
}