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 all 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
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions 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 Expand Up @@ -1125,7 +1125,7 @@
"nyc": "^15.1.0",
"prettier": "^2.6.2",
"ts-node": "^10.8.0",
"typescript": "^3.9.3"
"typescript": "^4.3.2"
},
"__metadata": {
"id": "2fd22b8e-b3b8-4e7f-9a28-a5e2d1bdd0d4",
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
32 changes: 17 additions & 15 deletions src/backend/mi2/mi2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,23 +314,23 @@ export class MI2 extends EventEmitter implements IBackend {
}
}

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 @@ export class MI2 extends EventEmitter implements IBackend {
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 Down Expand Up @@ -570,7 +570,7 @@ export class MI2 extends EventEmitter implements IBackend {
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 @@ export class MI2 extends EventEmitter implements IBackend {
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 @@ export class MI2 extends EventEmitter implements IBackend {
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 @@ export class MI2 extends EventEmitter implements IBackend {
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
8 changes: 6 additions & 2 deletions src/mibase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ export class MI2DebugSession extends DebugSession {
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.') {
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 +483,7 @@ export class MI2DebugSession extends DebugSession {
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