Skip to content

Commit

Permalink
Minor adaptations for integration into SuperBOL
Browse files Browse the repository at this point in the history
  • Loading branch information
nberth committed Dec 19, 2023
1 parent 6300127 commit 49c057d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/debugger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {MINode} from "./parser.mi2";
import {DebugProtocol} from "vscode-debugprotocol/lib/debugProtocol";
import {DebugProtocol} from "@vscode/debugprotocol";
import {removeLeadingZeroes} from "./functions";
import {SourceMap} from "./parser.c";

Expand Down
17 changes: 9 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class GdbConfigurationProvider implements vscode.DebugConfigurationProvider {
config.arguments = "";
}
if (config.cwd === undefined) {
config.cwd = "${workspaceRoot}";
config.cwd = "${workspaceFolder}";
}
if (config.group === undefined) {
config.group = [];
Expand Down Expand Up @@ -65,37 +65,38 @@ class GdbConfigurationProvider implements vscode.DebugConfigurationProvider {
_token?: vscode.CancellationToken):
vscode.ProviderResult<vscode.DebugConfiguration[]> {
const launchConfigDefault: vscode.DebugConfiguration = {
name: "SuperBOL: debug launch",
name: "SuperBOL: debug (launch)",
type: "gdb",
request: "launch",
preLaunchTask: "Superbol: build (debug)",
target: "${file}",
arguments: "",
cwd: "${workspaceRoot}",
cwd: "${workspaceFolder}",
group: [],
coverage: true,
verbose: false
};

const attachLocalConfiguration: vscode.DebugConfiguration = {
name: "SuperBOL: debug attach local",
name: "SuperBOL: debug (attach local)",
type: "gdb",
request: "attach",
pid: "${input:pid}",
target: "${file}",
arguments: "",
cwd: "${workspaceRoot}",
cwd: "${workspaceFolder}",
group: [],
verbose: false
};

const attachRemoteConfiguration: vscode.DebugConfiguration = {
name: "SuperBOL: debug attach remote",
name: "SuperBOL: debug (attach remote)",
type: "gdb",
request: "attach",
remoteDebugger: "${input:remoteDebugger}",
remoteDebugger: "${input:remote-debugger}",
target: "${file}",
arguments: "",
cwd: "${workspaceRoot}",
cwd: "${workspaceFolder}",
group: [],
verbose: false
}
Expand Down
21 changes: 12 additions & 9 deletions src/gdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
Thread,
ThreadEvent
} from '@vscode/debugadapter';
import { DebugProtocol } from 'vscode-debugprotocol';
import { DebugProtocol } from '@vscode/debugprotocol';
import { Breakpoint, VariableObject } from './debugger';
import { MINode } from './parser.mi2';
import { MI2 } from './mi2';
Expand Down Expand Up @@ -125,11 +125,13 @@ export class GDBDebugSession extends DebugSession {
this.handlePause(undefined);
},
(err: Error) => {
this.sendErrorResponse(response, 100, `Failed to start MI Debugger: ${err.toString()}`);
this.sendErrorResponse(response, 100,
`Failed to start MI Debugger: ${err.toString()}`);
});
},
/*onrejected:*/ (err: Error) => {
this.sendErrorResponse(response, 103, `Failed to load MI Debugger: ${err.toString()}`);
this.sendErrorResponse(response, 103,
`Failed to load MI Debugger: ${err.toString()}`);
});
}

Expand All @@ -139,10 +141,9 @@ export class GDBDebugSession extends DebugSession {
void
{
if (!args.pid && !args.remoteDebugger) {
this.sendErrorResponse(
response,
100,
`Failed to start MI Debugger: pid or remoteDebugger is mandatory`);
this.sendErrorResponse (response, 100,
`Failed to start MI Debugger: PID or remote-debugger argument
required`);
return;
}

Expand Down Expand Up @@ -186,11 +187,13 @@ export class GDBDebugSession extends DebugSession {
this.handlePause(undefined);
},
(err: Error) => {
this.sendErrorResponse(response, 100, `Failed to start MI Debugger: ${err.toString()}`);
this.sendErrorResponse(response, 100,
`Failed to start MI Debugger: ${err.toString()}`);
});
},
(err: Error) => {
this.sendErrorResponse(response, 103, `Failed to load MI Debugger: ${err.toString()}`);
this.sendErrorResponse(response, 103,
`Failed to load MI Debugger: ${err.toString()}`);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/mi2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class MI2 extends EventEmitter implements IDebugger {
}

const cmds = [
this.sendCommand("gdb-set target-async on", false),
this.sendCommand("gdb-set mi-async on", false),
this.sendCommand("gdb-set print repeats 1000", false),
this.sendCommand("gdb-set args " + targetargs, false),
this.sendCommand("environment-directory \"" + escape(cwd) + "\"", false),
Expand Down
42 changes: 8 additions & 34 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,24 @@
import * as vscode from 'vscode';

type InspectResult<T> = {
key: string;
defaultValue?: T;
globalValue?: T;
workspaceValue?: T;
workspaceFolderValue?: T;
defaultLanguageValue?: T;
globalLanguageValue?: T;
workspaceLanguageValue?: T;
workspaceFolderLanguageValue?: T;
languageIds?: string[];
} | undefined

export class DebuggerSettings {
private readonly extensionSettings: vscode.WorkspaceConfiguration;
private readonly superbolExtensionSettings: vscode.WorkspaceConfiguration;
private readonly debugSettings: vscode.WorkspaceConfiguration;

constructor() {
this.extensionSettings = vscode.workspace.getConfiguration("superbol-vscode-debug");
// Get SuperBOL base extension settings (for instance to get LibCob path)
// Though shouls should be obtained by querying the extension instead ?
this.superbolExtensionSettings = vscode.workspace.getConfiguration("superbol");
}

private getWithFallback<T>(settings: vscode.WorkspaceConfiguration, section: string): T {
const info: InspectResult<T> = settings.inspect<T>(section);
if (info.workspaceFolderValue !== undefined) {
return info.workspaceFolderValue;
} else if (info.workspaceValue !== undefined) {
return info.workspaceValue;
} else if (info.globalValue !== undefined) {
return info.globalValue;
}
return info.defaultValue;
this.debugSettings =
vscode.workspace.getConfiguration("superbol.debugger");
//this.globalSettings =
// vscode.workspace.getConfiguration("superbol");
}

public get displayVariableAttributes(): boolean {
return this.getWithFallback<boolean>(this.extensionSettings, "displayVariableAttributes");
return this.debugSettings.get <boolean> ("display-variable-attributes");
}

public get gdbpath(): string {
return this.getWithFallback<string>(this.extensionSettings, "pathToGDB");
return this.debugSettings.get <string> ("gdb-path");
}

public get libcobpath(): string {
return this.getWithFallback<string>(this.extensionSettings, "pathToLibCob");
return this.debugSettings.get <string> ("libcob-path");
}
}

0 comments on commit 49c057d

Please sign in to comment.