Skip to content
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

Fixes #415

Merged
merged 4 commits into from
Mar 11, 2024
Merged

Fixes #415

Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
"valuesFormatting": {
"type": "string",
"description": "Set the way of showing variable values. 'disabled' - show value as is, 'parseText' - parse debuggers output text into structure, 'prettyPrinters' - enable debuggers custom pretty-printers if there are any",
"default": "parseText",
"default": "prettyPrinters",
"enum": [
"disabled",
"parseText",
Expand Down
26 changes: 11 additions & 15 deletions src/backend/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,29 +141,25 @@ export interface MIError extends Error {
readonly source: string;
}
export interface MIErrorConstructor {
new (message: string, source: string): MIError;
new(message: string, source: string): MIError;
readonly prototype: MIError;
}

export const MIError: MIErrorConstructor = <any> class MIError {
readonly name: string;
readonly message: string;
readonly source: string;
export const MIError: MIErrorConstructor = class MIError {
private readonly _message: string;
private readonly _source: string;
public constructor(message: string, source: string) {
Object.defineProperty(this, 'name', {
get: () => (this.constructor as any).name,
});
Object.defineProperty(this, 'message', {
get: () => message,
});
Object.defineProperty(this, 'source', {
get: () => source,
});
this._message = message;
this._source = source;
Error.captureStackTrace(this, this.constructor);
}

get name() { return this.constructor.name; }
get message() { return this._message; }
get source() { return this._source; }

public toString() {
return `${this.message} (from ${this.source})`;
return `${this.message} (from ${this._source})`;
}
};
Object.setPrototypeOf(MIError as any, Object.create(Error.prototype));
Expand Down
40 changes: 21 additions & 19 deletions src/backend/mi2/mi2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,23 +314,23 @@
}
}

onOutputStderr(lines) {
lines = <string[]> lines.split('\n');
onOutputStderr(str: string) {
const lines = str.split('\n');
lines.forEach(line => {
this.log("stderr", line);
});
}

onOutputPartial(line) {
onOutputPartial(line: string) {
if (couldBeOutput(line)) {
this.logNoNewLine("stdout", line);
return true;
}
return false;
}

onOutput(lines) {
lines = <string[]> lines.split('\n');
onOutput(str: string) {
const lines = str.split('\n');
lines.forEach(line => {
if (couldBeOutput(line)) {
if (!gdbMatch.exec(line))
Expand Down Expand Up @@ -391,13 +391,13 @@
case "solib-event":
case "syscall-entry":
case "syscall-return":
// TODO: inform the user
// TODO: inform the user
this.emit("step-end", parsed);
break;
case "fork":
case "vfork":
case "exec":
// TODO: inform the user, possibly add second inferior
// TODO: inform the user, possibly add second inferior
this.emit("step-end", parsed);
break;
case "signal-received":
Expand All @@ -410,10 +410,10 @@
this.log("stderr", "Program exited with code " + parsed.record("exit-code"));
this.emit("exited-normally", parsed);
break;
// case "exited-signalled": // consider handling that explicit possible
// this.log("stderr", "Program exited because of signal " + parsed.record("signal"));
// this.emit("stopped", parsed);
// break;
// case "exited-signalled": // consider handling that explicit possible

Check failure on line 413 in src/backend/mi2/mi2.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 12 tabs but found 11.
// this.log("stderr", "Program exited because of signal " + parsed.record("signal"));

Check failure on line 414 in src/backend/mi2/mi2.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 12 tabs but found 11.
// this.emit("stopped", parsed);

Check failure on line 415 in src/backend/mi2/mi2.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 12 tabs but found 11.
// break;

Check failure on line 416 in src/backend/mi2/mi2.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 12 tabs but found 11.

default:
this.log("console", "Not implemented stop reason (assuming exception): " + reason);
Expand Down Expand Up @@ -570,7 +570,7 @@
return Promise.all(promisses);
}

setBreakPointCondition(bkptNum, condition): Thenable<any> {
setBreakPointCondition(bkptNum: number, condition: string): Thenable<any> {
if (trace)
this.log("stderr", "setBreakPointCondition");
return this.sendCommand("break-condition " + bkptNum + " " + condition);
Expand Down Expand Up @@ -678,12 +678,10 @@
return threads.map(element => {
const ret: Thread = {
id: parseInt(MINode.valueOf(element, "id")),
targetId: MINode.valueOf(element, "target-id")
targetId: MINode.valueOf(element, "target-id"),
name: MINode.valueOf(element, "name") || MINode.valueOf(element, "details")
};

ret.name = MINode.valueOf(element, "details")
|| undefined;

return ret;
});
}
Expand Down Expand Up @@ -804,7 +802,7 @@
const ret: RegisterValue[] = nodes.map(node => {
const index = parseInt(MINode.valueOf(node, "number"));
const value = MINode.valueOf(node, "value");
return {index: index, value: value};
return { index: index, value: value };
});
return ret;
}
Expand Down Expand Up @@ -832,10 +830,14 @@
return await this.sendCommand(command);
}

async varCreate(expression: string, name: string = "-", frame: string = "@"): Promise<VariableObject> {
async varCreate(threadId: number, frameLevel: number, expression: string, name: string = "-", frame: string = "@"): Promise<VariableObject> {
if (trace)
this.log("stderr", "varCreate");
const res = await this.sendCommand(`var-create ${this.quote(name)} ${frame} "${expression}"`);
let miCommand = "var-create ";
if (threadId != 0) {
miCommand += `--thread ${threadId} --frame ${frameLevel}`;
}
const res = await this.sendCommand(`${miCommand} ${this.quote(name)} ${frame} "${expression}"`);
return new VariableObject(res.result(""));
}

Expand Down
8 changes: 4 additions & 4 deletions src/backend/mi2/mi2lldb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as ChildProcess from "child_process";
import * as path from "path";

export class MI2_LLDB extends MI2 {
protected initCommands(target: string, cwd: string, attach: boolean = false) {
protected override initCommands(target: string, cwd: string, attach: boolean = false) {
// We need to account for the possibility of the path type used by the debugger being different
// than the path type where the extension is running (e.g., SSH from Linux to Windows machine).
// Since the CWD is expected to be an absolute path in the debugger's environment, we can test
Expand Down Expand Up @@ -35,7 +35,7 @@ export class MI2_LLDB extends MI2 {
return cmds;
}

attach(cwd: string, executable: string, target: string, autorun: string[]): Thenable<any> {
override attach(cwd: string, executable: string, target: string, autorun: string[]): Thenable<any> {
return new Promise((resolve, reject) => {
const args = this.preargs.concat(this.extraargs || []);
this.process = ChildProcess.spawn(this.application, args, { cwd: cwd, env: this.procEnv });
Expand All @@ -54,11 +54,11 @@ export class MI2_LLDB extends MI2 {
});
}

setBreakPointCondition(bkptNum, condition): Thenable<any> {
override setBreakPointCondition(bkptNum: number, condition: string): Thenable<any> {
return this.sendCommand("break-condition " + bkptNum + " \"" + escape(condition) + "\" 1");
}

goto(filename: string, line: number): Thenable<Boolean> {
override goto(filename: string, line: number): Thenable<Boolean> {
return new Promise((resolve, reject) => {
// LLDB parses the file differently than GDB...
// GDB doesn't allow quoting only the file but only the whole argument
Expand Down
9 changes: 7 additions & 2 deletions src/mibase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,12 @@
response.body.threads.push(new Thread(thread.id, thread.id + ":" + threadName));
}
this.sendResponse(response);
}).catch(error => {
}).catch((error: MIError) => {
if (error.message === 'Selected thread is running.') {
console.error(error.message);

Check failure on line 288 in src/mibase.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement.
this.sendResponse(response);
return;
WebFreak001 marked this conversation as resolved.
Show resolved Hide resolved
}
this.sendErrorResponse(response, 17, `Could not get threads: ${error}`);
});
}
Expand Down Expand Up @@ -479,7 +484,7 @@
varObj = this.variableHandles.get(varId) as any;
} catch (err) {
if (err instanceof MIError && err.message == "Variable object not found") {
varObj = await this.miDebugger.varCreate(variable.name, varObjName);
varObj = await this.miDebugger.varCreate(id.threadId, id.level, variable.name, varObjName);
const varId = findOrCreateVariable(varObj);
varObj.exp = variable.name;
varObj.id = varId;
Expand Down
Loading