From ec2a93a0997f589516eb960968ec7ca23d6bc293 Mon Sep 17 00:00:00 2001 From: oltolm Date: Thu, 7 Mar 2024 20:59:37 +0100 Subject: [PATCH] small cleanup --- src/backend/backend.ts | 26 +++++++++++--------------- src/backend/mi2/mi2.ts | 26 +++++++++++++------------- src/backend/mi2/mi2lldb.ts | 8 ++++---- 3 files changed, 28 insertions(+), 32 deletions(-) diff --git a/src/backend/backend.ts b/src/backend/backend.ts index d47f89b3..747c0188 100644 --- a/src/backend/backend.ts +++ b/src/backend/backend.ts @@ -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 = 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)); diff --git a/src/backend/mi2/mi2.ts b/src/backend/mi2/mi2.ts index 7f2b81e7..fe55b09a 100644 --- a/src/backend/mi2/mi2.ts +++ b/src/backend/mi2/mi2.ts @@ -314,14 +314,14 @@ export class MI2 extends EventEmitter implements IBackend { } } - onOutputStderr(lines) { - lines = lines.split('\n'); + onOutputStderr(str: string) { + let 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; @@ -329,8 +329,8 @@ export class MI2 extends EventEmitter implements IBackend { return false; } - onOutput(lines) { - lines = lines.split('\n'); + onOutput(str: string) { + let lines = str.split('\n'); lines.forEach(line => { if (couldBeOutput(line)) { if (!gdbMatch.exec(line)) @@ -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": @@ -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 + // this.log("stderr", "Program exited because of signal " + parsed.record("signal")); + // this.emit("stopped", parsed); + // break; default: this.log("console", "Not implemented stop reason (assuming exception): " + reason); @@ -570,7 +570,7 @@ export class MI2 extends EventEmitter implements IBackend { return Promise.all(promisses); } - setBreakPointCondition(bkptNum, condition): Thenable { + setBreakPointCondition(bkptNum: number, condition: string): Thenable { if (trace) this.log("stderr", "setBreakPointCondition"); return this.sendCommand("break-condition " + bkptNum + " " + condition); @@ -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; } diff --git a/src/backend/mi2/mi2lldb.ts b/src/backend/mi2/mi2lldb.ts index 44999144..e04f118c 100644 --- a/src/backend/mi2/mi2lldb.ts +++ b/src/backend/mi2/mi2lldb.ts @@ -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 @@ -35,7 +35,7 @@ export class MI2_LLDB extends MI2 { return cmds; } - attach(cwd: string, executable: string, target: string, autorun: string[]): Thenable { + override attach(cwd: string, executable: string, target: string, autorun: string[]): Thenable { return new Promise((resolve, reject) => { const args = this.preargs.concat(this.extraargs || []); this.process = ChildProcess.spawn(this.application, args, { cwd: cwd, env: this.procEnv }); @@ -54,11 +54,11 @@ export class MI2_LLDB extends MI2 { }); } - setBreakPointCondition(bkptNum, condition): Thenable { + override setBreakPointCondition(bkptNum: number, condition: string): Thenable { return this.sendCommand("break-condition " + bkptNum + " \"" + escape(condition) + "\" 1"); } - goto(filename: string, line: number): Thenable { + override goto(filename: string, line: number): Thenable { 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