Skip to content

Commit

Permalink
small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
oltolm committed Mar 7, 2024
1 parent a4e1eb0 commit ec2a93a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 32 deletions.
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
26 changes: 13 additions & 13 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) {
let lines = str.split('\n');

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

View workflow job for this annotation

GitHub Actions / lint

'lines' is never reassigned. Use 'const' instead.
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) {
let lines = str.split('\n');

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

View workflow job for this annotation

GitHub Actions / lint

'lines' is never reassigned. Use 'const' instead.
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 All @@ -410,10 +410,10 @@ export class MI2 extends EventEmitter implements IBackend {
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 @@ 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 @@ -802,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
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

0 comments on commit ec2a93a

Please sign in to comment.