Skip to content

Dynamic debug config + Telemetry #8876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
49d36b1
temp
elahehrashedi Feb 9, 2022
4ca70c6
Merge branch 'main' into elrashed/dynamicLaunch
elahehrashedi Feb 10, 2022
52f79bc
Create no launch.json
elahehrashedi Feb 14, 2022
9239b00
Merge branch 'main' into elrashed/dynamicLaunch
elahehrashedi Feb 14, 2022
6e8aa11
lint error
elahehrashedi Feb 14, 2022
e143275
Merge branch 'elrashed/dynamicLaunch' of https://github.com/microsoft…
elahehrashedi Feb 14, 2022
fbb57ac
Merge branch 'main' into elrashed/dynamicLaunch
elahehrashedi Feb 14, 2022
67345c6
save temp
elahehrashedi Feb 17, 2022
58af664
working version
elahehrashedi Feb 17, 2022
fdd32d6
after testing debug panel
elahehrashedi Feb 17, 2022
561e09c
add recently used tasks to debug panel too.
elahehrashedi Feb 17, 2022
239c0ba
resolve variables in play button
elahehrashedi Feb 17, 2022
6bc21f2
lint errors
elahehrashedi Feb 17, 2022
19de8a8
fix nodebug mode
elahehrashedi Feb 17, 2022
a97d832
lint
elahehrashedi Feb 17, 2022
200d69b
comments
elahehrashedi Feb 17, 2022
513df2b
Merge branch 'main' into elrashed/dynamicLaunchNew
elahehrashedi Feb 17, 2022
e799210
reply to reviewers
elahehrashedi Feb 17, 2022
c573461
sort tasks
elahehrashedi Feb 17, 2022
a1fe6ff
linter
elahehrashedi Feb 17, 2022
1b5dd98
Merge branch 'main' into elrashed/dynamicLaunchNew
sean-mcmanus Feb 18, 2022
63dfa63
fix resolve an insider task
elahehrashedi Feb 22, 2022
01fc822
fix problem matcher issue in Single File Mode
elahehrashedi Feb 22, 2022
094a9d0
fix lint errors
elahehrashedi Feb 22, 2022
5355244
Merge branch 'elrashed/dynamicLaunchNew' of https://github.com/micros…
elahehrashedi Feb 22, 2022
d12c832
change button description
elahehrashedi Feb 22, 2022
b3e9786
change autodetect to absolute
elahehrashedi Feb 22, 2022
a526231
cwd
elahehrashedi Feb 23, 2022
70d8399
Merge branch 'main' into elrashed/dynamicLaunchNew
elahehrashedi Feb 23, 2022
44292a1
add comment
elahehrashedi Feb 23, 2022
d73f87a
Merge branch 'elrashed/dynamicLaunchNew' of https://github.com/micros…
elahehrashedi Feb 23, 2022
65d6381
add autoDetect to problrmmatcher
elahehrashedi Feb 23, 2022
fd1cc8d
revert
elahehrashedi Feb 23, 2022
b1f6508
Merge remote-tracking branch 'origin/main' into elrashed/dynamicLaunc…
bobbrow Feb 23, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
"onCommand:C_Cpp.RunCodeAnalysisOnOpenFiles",
"onCommand:C_Cpp.RunCodeAnalysisOnAllFiles",
"onCommand:C_Cpp.ClearCodeAnalysisSquiggles",
"onDebugInitialConfigurations",
"onDebugResolve:cppdbg",
"onDebugResolve:cppvsdbg",
"workspaceContains:/.vscode/c_cpp_properties.json",
Expand Down Expand Up @@ -258,8 +257,7 @@
"source": "gcc",
"owner": "cpptools",
"fileLocation": [
"autoDetect",
"${workspaceFolder}"
"autoDetect"
],
"pattern": {
"regexp": "^(.*?):(\\d+):(\\d*):?\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$",
Expand Down Expand Up @@ -2763,7 +2761,6 @@
"configurationAttributes": {
"launch": {
"type": "object",
"default": {},
"required": [
"program"
],
Expand Down Expand Up @@ -3438,7 +3435,6 @@
"configurationAttributes": {
"launch": {
"type": "object",
"default": {},
"required": [
"program",
"cwd"
Expand Down
2 changes: 1 addition & 1 deletion Extension/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
"c_cpp.configuration.debugger.useBacktickCommandSubstitution.markdownDescription": { "message": "If `true`, debugger shell command substitution will use obsolete backtick ``(`)``.", "comment": [ "Markdown text between `` should not be translated or localized (they represent literal text) and the capitalization, spacing, and punctuation (including the ``) should not be altered." ] },
"c_cpp.contributes.views.cppReferencesView.title": "C/C++: Other references results.",
"c_cpp.contributes.viewsWelcome.contents": { "message": "To learn more about launch.json, see [Configuring C/C++ debugging](https://code.visualstudio.com/docs/cpp/launch-json-reference).", "comment": [ "Markdown text between () should not be altered: https://en.wikipedia.org/wiki/Markdown" ] },
"c_cpp.configuration.debugShortcut.description": "Show icon for 'Debug and Run' in shortcut menu bar",
"c_cpp.configuration.debugShortcut.description": "Show the Run and Debug play button in the editor title bar for C++ files",
"c_cpp.debuggers.pipeTransport.description": "When present, this tells the debugger to connect to a remote computer using another executable as a pipe that will relay standard input/output between VS Code and the MI-enabled debugger backend executable (such as gdb).",
"c_cpp.debuggers.pipeTransport.default.pipeProgram": "enter the fully qualified path for the pipe program name, for example '/usr/bin/ssh'.",
"c_cpp.debuggers.pipeTransport.default.debuggerPath": "The full path to the debugger on the target machine, for example /usr/bin/gdb.",
Expand Down
589 changes: 306 additions & 283 deletions Extension/src/Debugger/configurationProvider.ts

Large diffs are not rendered by default.

32 changes: 19 additions & 13 deletions Extension/src/Debugger/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,26 @@

import * as os from 'os';
import * as nls from 'vscode-nls';
import { CppSourceStrPrefix } from '../LanguageServer/extension';

nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();

export enum DebuggerType {
cppvsdbg,
cppdbg
cppvsdbg = "cppvsdbg",
cppdbg = "cppdbg",
all = "all"
}

export enum DebuggerEvent {
debugPanel = "debugPanel",
launchPlayButton = "launchPlayButton"
}

export enum TaskConfigStatus {
recentlyUsed = "Recently Used Task",
configured = "Configured Task",
detected = "Detected Task"
configured = "Configured Task", // The tasks that are configured in tasks.json file.
detected = "Detected Task" // The tasks that are available based on detected compilers.
}

export interface IConfigurationSnippet {
Expand Down Expand Up @@ -89,7 +96,6 @@ export interface IConfiguration {
}

abstract class Configuration implements IConfiguration {
public snippetPrefix = "C/C++: ";

public executable: string;
public pipeProgram: string;
Expand Down Expand Up @@ -122,7 +128,7 @@ export class MIConfigurations extends Configuration {
this.additionalProperties ? `,${os.EOL}\t${indentJsonString(this.additionalProperties)}` : ""]);

return {
"label": this.snippetPrefix + name,
"label": CppSourceStrPrefix + name,
"description": localize("launch.with", "Launch with {0}.", this.MIMode).replace(/\"/g, "\\\""),
"bodyText": body.trim(),
"isInitialConfiguration": true,
Expand All @@ -140,7 +146,7 @@ export class MIConfigurations extends Configuration {
this.additionalProperties ? `,${os.EOL}\t${indentJsonString(this.additionalProperties)}` : ""]);

return {
"label": this.snippetPrefix + name,
"label": CppSourceStrPrefix + name,
"description": localize("attach.with", "Attach with {0}.", this.MIMode).replace(/\"/g, "\\\""),
"bodyText": body.trim(),
"debuggerType": DebuggerType.cppdbg
Expand All @@ -162,7 +168,7 @@ export class PipeTransportConfigurations extends Configuration {
}`, [this.additionalProperties ? `,${os.EOL}\t${indentJsonString(this.additionalProperties)}` : ""]);

return {
"label": this.snippetPrefix + name,
"label": CppSourceStrPrefix + name,
"description": localize("pipe.launch.with", "Pipe Launch with {0}.", this.MIMode).replace(/\"/g, "\\\""),
"bodyText": body.trim(),
"debuggerType": DebuggerType.cppdbg
Expand All @@ -180,7 +186,7 @@ export class PipeTransportConfigurations extends Configuration {
\t"MIMode": "${this.MIMode}"{0}
}`, [this.additionalProperties ? `,${os.EOL}\t${indentJsonString(this.additionalProperties)}` : ""]);
return {
"label": this.snippetPrefix + name,
"label": CppSourceStrPrefix + name,
"description": localize("pipe.attach.with", "Pipe Attach with {0}.", this.MIMode).replace(/\"/g, "\\\""),
"bodyText": body.trim(),
"debuggerType": DebuggerType.cppdbg
Expand All @@ -200,7 +206,7 @@ export class WindowsConfigurations extends Configuration {
}`;

return {
"label": this.snippetPrefix + name,
"label": CppSourceStrPrefix + name,
"description": localize("launch.with.vs.debugger", "Launch with the Visual Studio C/C++ debugger.").replace(/\"/g, "\\\""),
"bodyText": body.trim(),
"isInitialConfiguration": true,
Expand All @@ -218,7 +224,7 @@ export class WindowsConfigurations extends Configuration {
}`;

return {
"label": this.snippetPrefix + name,
"label": CppSourceStrPrefix + name,
"description": localize("attach.with.vs.debugger", "Attach to a process with the Visual Studio C/C++ debugger.").replace(/\"/g, "\\\""),
"bodyText": body.trim(),
"debuggerType": DebuggerType.cppvsdbg
Expand All @@ -241,7 +247,7 @@ export class WSLConfigurations extends Configuration {
}`, [this.additionalProperties ? `,${os.EOL}\t${indentJsonString(this.additionalProperties)}` : ""]);

return {
"label": this.snippetPrefix + name,
"label": CppSourceStrPrefix + name,
"description": localize("launch.bash.windows", "Launch in Bash on Windows using {0}.", this.MIMode).replace(/\"/g, "\\\""),
"bodyText": body.trim(),
"debuggerType": DebuggerType.cppdbg
Expand All @@ -258,7 +264,7 @@ export class WSLConfigurations extends Configuration {
}`, [this.additionalProperties ? `,${os.EOL}\t${indentJsonString(this.additionalProperties)}` : ""]);

return {
"label": this.snippetPrefix + name,
"label": CppSourceStrPrefix + name,
"description": localize("remote.attach.bash.windows", "Attach to a remote process running in Bash on Windows using {0}.", this.MIMode).replace(/\"/g, "\\\""),
"bodyText": body.trim(),
"debuggerType": DebuggerType.cppdbg
Expand Down
4 changes: 0 additions & 4 deletions Extension/src/Debugger/debugAdapterDescriptorFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ abstract class AbstractDebugAdapterDescriptorFactory implements vscode.DebugAdap
}

export class CppdbgDebugAdapterDescriptorFactory extends AbstractDebugAdapterDescriptorFactory {
public static DEBUG_TYPE: string = "cppdbg";

constructor(context: vscode.ExtensionContext) {
super(context);
}
Expand All @@ -42,8 +40,6 @@ export class CppdbgDebugAdapterDescriptorFactory extends AbstractDebugAdapterDes
}

export class CppvsdbgDebugAdapterDescriptorFactory extends AbstractDebugAdapterDescriptorFactory {
public static DEBUG_TYPE: string = "cppvsdbg";

constructor(context: vscode.ExtensionContext) {
super(context);
}
Expand Down
35 changes: 19 additions & 16 deletions Extension/src/Debugger/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import * as vscode from 'vscode';
import * as os from 'os';
import { AttachPicker, RemoteAttachPicker, AttachItemsProvider } from './attachToProcess';
import { NativeAttachItemsProviderFactory } from './nativeAttach';
import { QuickPickConfigurationProvider, ConfigurationAssetProviderFactory, CppVsDbgConfigurationProvider, CppDbgConfigurationProvider, ConfigurationSnippetProvider, IConfigurationAssetProvider, buildAndDebug } from './configurationProvider';
import { DebugConfigurationProvider, ConfigurationAssetProviderFactory, ConfigurationSnippetProvider, IConfigurationAssetProvider } from './configurationProvider';
import { CppdbgDebugAdapterDescriptorFactory, CppvsdbgDebugAdapterDescriptorFactory } from './debugAdapterDescriptorFactory';
import { DebuggerType } from './configurations';

// The extension deactivate method is asynchronous, so we handle the disposables ourselves instead of using extensonContext.subscriptions.
const disposables: vscode.Disposable[] = [];
Expand All @@ -22,22 +23,24 @@ export async function initialize(context: vscode.ExtensionContext): Promise<void
disposables.push(vscode.commands.registerCommand('extension.pickRemoteNativeProcess', (any) => remoteAttacher.ShowAttachEntries(any)));

// Activate ConfigurationProvider
const configurationProvider: IConfigurationAssetProvider = ConfigurationAssetProviderFactory.getConfigurationProvider();
// On non-windows platforms, the cppvsdbg debugger will not be registered for initial configurations.
// This will cause it to not show up on the dropdown list.
let cppVsDbgProvider: CppVsDbgConfigurationProvider | null = null;
const assetProvider: IConfigurationAssetProvider = ConfigurationAssetProviderFactory.getConfigurationProvider();

// Register DebugConfigurationProviders for "Run and Debug" in Debug Panel.
// On windows platforms, the cppvsdbg debugger will also be registered for initial configurations.
let cppVsDebugProvider: DebugConfigurationProvider | null = null;
if (os.platform() === 'win32') {
cppVsDbgProvider = new CppVsDbgConfigurationProvider(configurationProvider);
disposables.push(vscode.debug.registerDebugConfigurationProvider('cppvsdbg', new QuickPickConfigurationProvider(cppVsDbgProvider)));
cppVsDebugProvider = new DebugConfigurationProvider(assetProvider, DebuggerType.cppvsdbg);
disposables.push(vscode.debug.registerDebugConfigurationProvider(DebuggerType.cppvsdbg, cppVsDebugProvider, vscode.DebugConfigurationProviderTriggerKind.Dynamic));
}
const cppDbgProvider: CppDbgConfigurationProvider = new CppDbgConfigurationProvider(configurationProvider);
disposables.push(vscode.debug.registerDebugConfigurationProvider('cppdbg', new QuickPickConfigurationProvider(cppDbgProvider)));

disposables.push(vscode.commands.registerTextEditorCommand("C_Cpp.BuildAndDebugFile", async (textEditor: vscode.TextEditor, edit: vscode.TextEditorEdit, ...args: any[]) => { await buildAndDebug(textEditor, cppVsDbgProvider, cppDbgProvider); }));
const cppDebugProvider: DebugConfigurationProvider = new DebugConfigurationProvider(assetProvider, DebuggerType.cppdbg);
disposables.push(vscode.debug.registerDebugConfigurationProvider(DebuggerType.cppdbg, cppDebugProvider, vscode.DebugConfigurationProviderTriggerKind.Dynamic));

disposables.push(vscode.commands.registerTextEditorCommand("C_Cpp.BuildAndRunFile", async (textEditor: vscode.TextEditor, edit: vscode.TextEditorEdit, ...args: any[]) => { await buildAndDebug(textEditor, cppVsDbgProvider, cppDbgProvider, false); }));
// Register DebugConfigurationProviders for "Run and Debug" play button.
const debugProvider: DebugConfigurationProvider = new DebugConfigurationProvider(assetProvider, DebuggerType.all);
disposables.push(vscode.commands.registerTextEditorCommand("C_Cpp.BuildAndDebugFile", async (textEditor: vscode.TextEditor, edit: vscode.TextEditorEdit, ...args: any[]) => { await debugProvider.buildAndDebug(textEditor); }));
disposables.push(vscode.commands.registerTextEditorCommand("C_Cpp.BuildAndRunFile", async (textEditor: vscode.TextEditor, edit: vscode.TextEditorEdit, ...args: any[]) => { await debugProvider.buildAndRun(textEditor); }));

configurationProvider.getConfigurationSnippets();
assetProvider.getConfigurationSnippets();

const launchJsonDocumentSelector: vscode.DocumentSelector = [{
scheme: 'file',
Expand All @@ -46,11 +49,11 @@ export async function initialize(context: vscode.ExtensionContext): Promise<void
}];

// ConfigurationSnippetProvider needs to be initiallized after configurationProvider calls getConfigurationSnippets.
disposables.push(vscode.languages.registerCompletionItemProvider(launchJsonDocumentSelector, new ConfigurationSnippetProvider(configurationProvider)));
disposables.push(vscode.languages.registerCompletionItemProvider(launchJsonDocumentSelector, new ConfigurationSnippetProvider(assetProvider)));

// Register Debug Adapters
disposables.push(vscode.debug.registerDebugAdapterDescriptorFactory(CppvsdbgDebugAdapterDescriptorFactory.DEBUG_TYPE, new CppvsdbgDebugAdapterDescriptorFactory(context)));
disposables.push(vscode.debug.registerDebugAdapterDescriptorFactory(CppdbgDebugAdapterDescriptorFactory.DEBUG_TYPE, new CppdbgDebugAdapterDescriptorFactory(context)));
disposables.push(vscode.debug.registerDebugAdapterDescriptorFactory(DebuggerType.cppvsdbg , new CppvsdbgDebugAdapterDescriptorFactory(context)));
disposables.push(vscode.debug.registerDebugAdapterDescriptorFactory(DebuggerType.cppdbg, new CppdbgDebugAdapterDescriptorFactory(context)));

vscode.Disposable.from(...disposables);
}
Expand Down
7 changes: 4 additions & 3 deletions Extension/src/LanguageServer/cppBuildTaskProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ export class CppBuildTaskProvider implements TaskProvider {

public resolveInsiderTask(_task: CppBuildTask): CppBuildTask | undefined {
const definition: CppBuildTaskDefinition = <any>_task.definition;
definition.label = definition.label.replace(ext.CppSourceStrPrefix, "");
_task = this.getTask(definition.command, false, definition.args ? definition.args : [], definition, _task.detail);
return _task;
}

// Generate tasks to build the current file based on the user's detected compilers, the user's compilerPath setting, and the current file's extension.
public async getTasks(appendSourceToName: boolean): Promise<CppBuildTask[]> {
public async getTasks(appendSourceToName: boolean = false): Promise<CppBuildTask[]> {
const editor: TextEditor | undefined = window.activeTextEditor;
const emptyTasks: CppBuildTask[] = [];
if (!editor) {
Expand Down Expand Up @@ -170,8 +171,8 @@ export class CppBuildTaskProvider implements TaskProvider {
if (!definition) {
const isWindows: boolean = os.platform() === 'win32';
const isMacARM64: boolean = (os.platform() === 'darwin' && os.arch() === 'arm64');
const taskLabel: string = ((appendSourceToName && !compilerPathBase.startsWith(ext.CppSourceStr)) ?
ext.CppSourceStr + ": " : "") + compilerPathBase + " " + localize("build_active_file", "build active file");
const taskLabel: string = ((appendSourceToName && !compilerPathBase.startsWith(ext.CppSourceStrPrefix)) ?
ext.CppSourceStrPrefix : "") + compilerPathBase + " " + localize("build_active_file", "build active file");
const filePath: string = path.join('${fileDirname}', '${fileBasenameNoExtension}');
const programName: string = isWindows ? filePath + '.exe' : filePath;
let args: string[] = isCl ? ['/Zi', '/EHsc', '/nologo', '/Fe:', programName, '${file}'] : ['-fdiagnostics-color=always', '-g', '${file}', '-o', programName];
Expand Down
5 changes: 3 additions & 2 deletions Extension/src/LanguageServer/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFo
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
export const cppBuildTaskProvider: CppBuildTaskProvider = new CppBuildTaskProvider();
export const CppSourceStr: string = "C/C++";
export const CppSourceStrPrefix: string = "C/C++: ";

let prevCrashFile: string;
let clients: ClientCollection;
Expand Down Expand Up @@ -174,15 +175,15 @@ export async function activate(): Promise<void> {
vscode.tasks.onDidStartTask(event => {
getActiveClient().PauseCodeAnalysis();
if (event.execution.task.definition.type === CppBuildTaskProvider.CppBuildScriptType
|| event.execution.task.name.startsWith(CppSourceStr)) {
|| event.execution.task.name.startsWith(CppSourceStrPrefix)) {
telemetry.logLanguageServerEvent('buildTaskStarted');
}
});

vscode.tasks.onDidEndTask(event => {
getActiveClient().ResumeCodeAnalysis();
if (event.execution.task.definition.type === CppBuildTaskProvider.CppBuildScriptType
|| event.execution.task.name.startsWith(CppSourceStr)) {
|| event.execution.task.name.startsWith(CppSourceStrPrefix)) {
telemetry.logLanguageServerEvent('buildTaskFinished');
if (event.execution.task.scope !== vscode.TaskScope.Global && event.execution.task.scope !== vscode.TaskScope.Workspace) {
const folder: vscode.WorkspaceFolder | undefined = event.execution.task.scope;
Expand Down
2 changes: 0 additions & 2 deletions Extension/tools/OptionsSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@
},
"CppdbgLaunchOptions": {
"type": "object",
"default": {},
"required": [
"program"
],
Expand Down Expand Up @@ -519,7 +518,6 @@
},
"CppvsdbgLaunchOptions": {
"type": "object",
"default": {},
"required": [
"program",
"cwd"
Expand Down