const EventEmitter = require("node:events");
const await_notify_1 = require("await-notify");
const net = require("node:net");
+const child_process = require("node:child_process");
class OVMDebugSession extends debugadapter_1.LoggingDebugSession {
constructor() {
super("ovm-debug-log.txt");
}
disconnectRequest(response, args, request) {
console.log(`disconnectRequest suspend: ${args.suspendDebuggee}, terminate: ${args.terminateDebuggee}`);
+ if (args.terminateDebuggee) {
+ console.log("TERMINATE");
+ if (this.running_process) {
+ this.running_process.kill('SIGTERM');
+ }
+ }
+ this.sendResponse(response);
}
cancelRequest(response, args, request) {
this.sendResponse(response);
this.sendResponse(response);
}
launchRequest(response, args, request) {
- console.log("LAUNCH");
- // console.error(`Unable to launch a new Onyx debugging session. Please use { "request": "attach" } instead.`);
+ this.running_process = child_process.spawn("onyx-run", ["--debug", args.wasmFile], {
+ "cwd": args.workingDir,
+ });
+ this.running_process.stdout.setEncoding("utf-8");
+ this.running_process.stdout.on("data", (chunk) => {
+ this.sendEvent(new debugadapter_1.OutputEvent(chunk, "console"));
+ });
this.attachRequest(response, { "socketPath": "/tmp/ovm-debug.0000", "stopOnEntry": true });
}
attachRequest(response, args, request) {
import { Subject } from "await-notify";
import * as net from "node:net";
+import * as child_process from "node:child_process";
+import { ChildProcess } from 'node:child_process';
+import { Message } from '@vscode/debugadapter/lib/messages';
interface IOVMAttachRequestArguments extends DebugProtocol.AttachRequestArguments {
stopOnEntry?: boolean;
}
+interface IOVMLaunchRequestArguments extends DebugProtocol.AttachRequestArguments {
+ wasmFile: string;
+ workingDir: string;
+ stopOnEntry?: boolean;
+}
+
export class OVMDebugSession extends LoggingDebugSession {
private debugger: OVMDebugger;
+ private running_process: ChildProcess;
private _configurationDone: Subject = new Subject();
private _clientConnectedNotifier: Subject = new Subject();
protected disconnectRequest(response: DebugProtocol.DisconnectResponse, args: DebugProtocol.DisconnectArguments, request?: DebugProtocol.Request): void {
console.log(`disconnectRequest suspend: ${args.suspendDebuggee}, terminate: ${args.terminateDebuggee}`);
+
+ if (args.terminateDebuggee) {
+ console.log("TERMINATE");
+
+ if (this.running_process) {
+ this.running_process.kill('SIGTERM');
+ }
+ }
+
+ this.sendResponse(response);
}
protected cancelRequest(response: DebugProtocol.CancelResponse, args: DebugProtocol.CancelArguments, request?: DebugProtocol.Request): void {
this.sendResponse(response);
}
- protected launchRequest(response: DebugProtocol.LaunchResponse, args: DebugProtocol.LaunchRequestArguments, request?: DebugProtocol.Request): void {
- console.log("LAUNCH");
- // console.error(`Unable to launch a new Onyx debugging session. Please use { "request": "attach" } instead.`);
+ protected launchRequest(response: DebugProtocol.LaunchResponse, args: IOVMLaunchRequestArguments, request?: DebugProtocol.Request): void {
+ this.running_process = child_process.spawn("onyx-run", ["--debug", args.wasmFile], {
+ "cwd": args.workingDir,
+ });
+
+ this.running_process.stdout.setEncoding("utf-8");
+ this.running_process.stdout.on("data", (chunk) => {
+ this.sendEvent(new OutputEvent(chunk, "console"));
+ });
+
this.attachRequest(response, {"socketPath": "/tmp/ovm-debug.0000", "stopOnEntry": true});
}
"default": true
}
}
+ },
+ "launch": {
+ "properties": {
+ "wasmFile": {
+ "type": "string",
+ "description": "The WASM file for debugging, compiled with the --debug flag.",
+ "default": "out.wasm"
+ },
+ "workingDir": {
+ "type": "string",
+ "description": "The working directory for the execution",
+ "default": "${workspaceFolder}"
+ },
+ "stopOnEntry": {
+ "type": "boolean",
+ "description": "Automatically stop after launch.",
+ "default": true
+ }
+ }
}
},
"initialConfigurations": [
"type": "onyx",
"request": "attach",
"stopOnEntry": true
+ },
+ {
+ "type": "onyx",
+ "request": "launch",
+ "wasmFile": "out.wasm",
+ "workingDir": "${workspaceFolder}",
+ "stopOnEntry": true
}
]
}