Skip to content

Commit

Permalink
debug: fix DebugConfigurationProvider registration
Browse files Browse the repository at this point in the history
We are incorrectly registering a single debug provider that provides
`cppdbg` and `cppvsdbg` configurations using the `cppdbg` type.

Split the cppdb and cppvsdbg debug providers into 2 different providers
and register them based on the current operating system following the
same approach as the `ms-vscode.cpptools` extension.

Also simplify the debug providers into a single MesonDebugProvider
class.
  • Loading branch information
ylatuya committed Aug 8, 2024
1 parent 2aea915 commit 65bfd5b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 80 deletions.
50 changes: 0 additions & 50 deletions src/debug/cppdbg.ts

This file was deleted.

68 changes: 53 additions & 15 deletions src/debug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@ import { getMesonTargets } from "../introspection";
import { Target } from "../types";
import { extensionConfiguration, getTargetName } from "../utils";

export abstract class MesonDebugConfigurationProvider implements vscode.DebugConfigurationProvider {
private readonly path: string;
export enum DebuggerType {
cppvsdbg = "cppvsdbg",
cppdbg = "cppdbg",
lldb = "lldb",
}

abstract type: string;
enum MIMode {
gdb = "gdb",
lldb = "lldb",
}

constructor(path: string) {
export class MesonDebugConfigurationProvider implements vscode.DebugConfigurationProvider {
readonly type: DebuggerType;
private readonly path: string;

constructor(type: DebuggerType, path: string) {
this.type = type;
this.path = path;
}

async createDebugConfiguration(target: Target): Promise<vscode.DebugConfiguration> {
const targetName = await getTargetName(target);
const name = this.type;
return {
type: name,
name: `Debug ${target.name} (${name})`,
request: "launch",
cwd: path.dirname(this.path),
program: target.filename[0],
args: [],
preLaunchTask: `Meson: Build ${targetName}`,
};
return await this.createDebugConfigurationForType(target, this.type);
}

async provideDebugConfigurations(
Expand Down Expand Up @@ -61,4 +62,41 @@ export abstract class MesonDebugConfigurationProvider implements vscode.DebugCon
): vscode.ProviderResult<vscode.DebugConfiguration> {
return debugConfiguration;
}

async createDebugConfigurationForType(target: Target, type: DebuggerType): Promise<vscode.DebugConfiguration> {
const targetName = await getTargetName(target);
const name = type.toString();
let debugConfig: vscode.DebugConfiguration = {
type: name,
name: `Debug ${target.name} (${name})`,
request: "launch",
cwd: path.dirname(this.path),
program: target.filename[0],
args: [],
preLaunchTask: `Meson: Build ${targetName}`,
};

if (type === DebuggerType.cppdbg) {
let miMode;
if (
target.target_sources?.some((source) => source.compiler != null && ["cc", "clang"].includes(source.compiler[0]))
) {
miMode = MIMode.lldb;
} else {
miMode = MIMode.gdb;
}
debugConfig["MIMode"] = miMode.toString();

if (miMode === MIMode.gdb) {
debugConfig["setupCommands"] = [
{
description: "Enable pretty-printing for gdb",
text: "-enable-pretty-printing",
ignoreFailures: true,
},
];
}
}
return debugConfig;
}
}
9 changes: 0 additions & 9 deletions src/debug/lldb.ts

This file was deleted.

21 changes: 15 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as os from "os";
import * as vscode from "vscode";
import { getMesonTasks, getTasks, runTask, runFirstTask } from "./tasks";
import { MesonProjectExplorer } from "./treeview";
Expand All @@ -13,8 +14,7 @@ import {
mesonRootDirs,
shouldModifySetting,
} from "./utils";
import { DebugConfigurationProviderCppdbg } from "./debug/cppdbg";
import { DebugConfigurationProviderLldb } from "./debug/lldb";
import { MesonDebugConfigurationProvider, DebuggerType } from "./debug/index";
import { CpptoolsProvider, registerCppToolsProvider } from "./cpptoolsconfigprovider";
import { testDebugHandler, testRunHandler, rebuildTests } from "./tests";
import { activateLinters } from "./linters";
Expand Down Expand Up @@ -77,11 +77,20 @@ export async function activate(ctx: vscode.ExtensionContext) {

explorer = new MesonProjectExplorer(ctx, sourceDir, buildDir);

const providers = [DebugConfigurationProviderCppdbg, DebugConfigurationProviderLldb];
providers.forEach((provider) => {
const p = new provider(buildDir);
let providers = [];
if (os.platform() === "win32") {
providers.push(new MesonDebugConfigurationProvider(DebuggerType.cppvsdbg, buildDir));
} else {
providers.push(new MesonDebugConfigurationProvider(DebuggerType.cppdbg, buildDir));
}
providers.push(new MesonDebugConfigurationProvider(DebuggerType.lldb, buildDir));
providers.forEach((p) => {
ctx.subscriptions.push(
vscode.debug.registerDebugConfigurationProvider(p.type, p, vscode.DebugConfigurationProviderTriggerKind.Dynamic),
vscode.debug.registerDebugConfigurationProvider(
p.type.toString(),
p,
vscode.DebugConfigurationProviderTriggerKind.Dynamic,
),
);
});

Expand Down

0 comments on commit 65bfd5b

Please sign in to comment.