From a4e1eb08f0e982e2d0313833edbff87f1238edf5 Mon Sep 17 00:00:00 2001 From: oltolm Date: Thu, 7 Mar 2024 20:59:02 +0100 Subject: [PATCH 1/4] fixes: set "default" to "prettyPrinters", read thread names, fix variable creation --- package.json | 2 +- src/backend/mi2/mi2.ts | 14 ++++++++------ src/mibase.ts | 8 ++++++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 23728b7f..70e6f0b4 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/backend/mi2/mi2.ts b/src/backend/mi2/mi2.ts index e6411609..7f2b81e7 100644 --- a/src/backend/mi2/mi2.ts +++ b/src/backend/mi2/mi2.ts @@ -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; }); } @@ -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 { + async varCreate(threadId: number, frameLevel: number, expression: string, name: string = "-", frame: string = "@"): Promise { 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("")); } diff --git a/src/mibase.ts b/src/mibase.ts index 152e7875..9a273e8a 100644 --- a/src/mibase.ts +++ b/src/mibase.ts @@ -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.') { + console.error(error); + return; + } this.sendErrorResponse(response, 17, `Could not get threads: ${error}`); }); } @@ -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; From ec2a93a0997f589516eb960968ec7ca23d6bc293 Mon Sep 17 00:00:00 2001 From: oltolm Date: Thu, 7 Mar 2024 20:59:37 +0100 Subject: [PATCH 2/4] 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 From 5e9abd8c21966ddede380f45205c712b410efe3b Mon Sep 17 00:00:00 2001 From: oltolm Date: Thu, 7 Mar 2024 23:37:01 +0100 Subject: [PATCH 3/4] fix problems found in review --- src/backend/mi2/mi2.ts | 6 +++--- src/mibase.ts | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/backend/mi2/mi2.ts b/src/backend/mi2/mi2.ts index fe55b09a..9980557a 100644 --- a/src/backend/mi2/mi2.ts +++ b/src/backend/mi2/mi2.ts @@ -315,7 +315,7 @@ export class MI2 extends EventEmitter implements IBackend { } onOutputStderr(str: string) { - let lines = str.split('\n'); + const lines = str.split('\n'); lines.forEach(line => { this.log("stderr", line); }); @@ -330,7 +330,7 @@ export class MI2 extends EventEmitter implements IBackend { } onOutput(str: string) { - let lines = str.split('\n'); + const lines = str.split('\n'); lines.forEach(line => { if (couldBeOutput(line)) { if (!gdbMatch.exec(line)) @@ -835,7 +835,7 @@ export class MI2 extends EventEmitter implements IBackend { this.log("stderr", "varCreate"); let miCommand = "var-create "; if (threadId != 0) { - miCommand += `--thread ${threadId} --frame ${frameLevel}` + miCommand += `--thread ${threadId} --frame ${frameLevel}`; } const res = await this.sendCommand(`${miCommand} ${this.quote(name)} ${frame} "${expression}"`); return new VariableObject(res.result("")); diff --git a/src/mibase.ts b/src/mibase.ts index 9a273e8a..159574bf 100644 --- a/src/mibase.ts +++ b/src/mibase.ts @@ -285,7 +285,8 @@ export class MI2DebugSession extends DebugSession { this.sendResponse(response); }).catch((error: MIError) => { if (error.message === 'Selected thread is running.') { - console.error(error); + console.error(error.message); + this.sendResponse(response); return; } this.sendErrorResponse(response, 17, `Could not get threads: ${error}`); From aee5f71652386ba98d03df9c7cdd2de389aad72a Mon Sep 17 00:00:00 2001 From: oltolm Date: Mon, 11 Mar 2024 20:10:19 +0100 Subject: [PATCH 4/4] fix linting problems --- package-lock.json | 18 +++++++++--------- package.json | 2 +- src/backend/mi2/mi2.ts | 8 ++++---- src/mibase.ts | 1 - 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 68d7bce7..b0b94fcd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "debug", - "version": "0.27.0", + "version": "0.27.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "debug", - "version": "0.27.0", + "version": "0.27.1", "license": "public domain", "dependencies": { "ssh2": "^1.6.0", @@ -30,7 +30,7 @@ "nyc": "^15.1.0", "prettier": "^2.6.2", "ts-node": "^10.8.0", - "typescript": "^3.9.3" + "typescript": "^4.3.2" }, "engines": { "vscode": "^1.55.0" @@ -5343,9 +5343,9 @@ } }, "node_modules/typescript": { - "version": "3.9.10", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz", - "integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==", + "version": "4.3.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.2.tgz", + "integrity": "sha512-zZ4hShnmnoVnAHpVHWpTcxdv7dWP60S2FsydQLV8V5PbS3FifjWFFRiHSWpDJahly88PRyV5teTSLoq4eG7mKw==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -9643,9 +9643,9 @@ } }, "typescript": { - "version": "3.9.10", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz", - "integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==", + "version": "4.3.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.2.tgz", + "integrity": "sha512-zZ4hShnmnoVnAHpVHWpTcxdv7dWP60S2FsydQLV8V5PbS3FifjWFFRiHSWpDJahly88PRyV5teTSLoq4eG7mKw==", "dev": true }, "uc.micro": { diff --git a/package.json b/package.json index 70e6f0b4..a57ce891 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/backend/mi2/mi2.ts b/src/backend/mi2/mi2.ts index 9980557a..3d9a4459 100644 --- a/src/backend/mi2/mi2.ts +++ b/src/backend/mi2/mi2.ts @@ -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); diff --git a/src/mibase.ts b/src/mibase.ts index 159574bf..278acce5 100644 --- a/src/mibase.ts +++ b/src/mibase.ts @@ -285,7 +285,6 @@ export class MI2DebugSession extends DebugSession { this.sendResponse(response); }).catch((error: MIError) => { if (error.message === 'Selected thread is running.') { - console.error(error.message); this.sendResponse(response); return; }