From dfd45c6dee69a45cc219eef717a3e9c88d3962bb Mon Sep 17 00:00:00 2001 From: kadenlei <95266101+kadenlei@users.noreply.github.com> Date: Tue, 5 Dec 2023 15:24:23 -0500 Subject: [PATCH] Implemented Single session (#1797) * Still working * Implemented single-session and configurations for session type * Finalizaing single-session * Resolved comments * Got rid of dead code --- .vscode/launch.json | 191 +++++++++++++----------------- cider-dap/README.md | 4 +- cider-dap/calyxDebug/extension.ts | 47 ++++++-- cider-dap/calyxDebug/package.json | 12 ++ cider-dap/src/main.rs | 12 +- 5 files changed, 135 insertions(+), 131 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 4b303a6e4f..f7eb3af4eb 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,108 +1,85 @@ { - "version": "0.2.0", - "configurations": [ - { - "type": "cider-dap", - "request": "launch", - "name": "Launch Program (Multi Session)", - "program": "${file}", - "stopOnEntry": true, - }, - { - "type": "cider-dap", - "request": "launch", - "name": "Launch Program", - "program": "${workspaceFolder}/Program" - }, - { - "name": "Python: Current File", - "type": "python", - "request": "launch", - "program": "${file}", - "console": "integratedTerminal", - "justMyCode": false - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug Compiler", - "args": [ - "${input:target}", - "-l", - "${workspaceFolder}", - "-p", - "${input:pass}", - "-b", - "${input:backend}", - ], - "program": "${workspaceFolder}/target/debug/calyx", - "cwd": "${workspaceFolder}", - "stopOnEntry": false, - "sourceLanguages": [ - "rust" - ], - "preLaunchTask": "Cargo Build", - "console": "integratedTerminal", - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug Interpreter", - "args": [ - "${input:target}", - "-l", - "${workspaceFolder}" - ], - "program": "${workspaceFolder}/target/debug/cider", - "windows": { - "program": "${workspaceFolder}/target/debug/cider.exe" - }, - "cwd": "${workspaceFolder}", - "stopOnEntry": false, - "sourceLanguages": [ - "rust" - ], - }, - { - "type": "lldb", - "request": "launch", - "name": "Debug Interpreter on current file", - "args": [ - "${file}", - "-l", - "${workspaceFolder}" - ], - "program": "${workspaceFolder}/target/debug/cider", - "windows": { - "program": "${workspaceFolder}/target/debug/cider.exe" - }, - "cwd": "${workspaceFolder}", - "stopOnEntry": false, - "sourceLanguages": [ - "rust" - ], - } - ], - "inputs": [ - { - "id": "target", - "type": "promptString", - "description": "Target file" - }, - { - "id": "pass", - "type": "promptString", - "description": "Pass to be executed by the compiler (only one allowed)", - "default": "all" - }, - { - "id": "backend", - "type": "pickString", - "description": "Backend to be used by the compiler", - "options": [ - "verilog", - "calyx", - ], - } - ] -} \ No newline at end of file + "version": "0.2.0", + "configurations": [ + { + "type": "cider-dap", + "request": "launch", + "name": "Debug w/ Cider", + "program": "${file}", + "stopOnEntry": true + }, + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "justMyCode": false + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug Compiler", + "args": [ + "${input:target}", + "-l", + "${workspaceFolder}", + "-p", + "${input:pass}", + "-b", + "${input:backend}" + ], + "program": "${workspaceFolder}/target/debug/calyx", + "cwd": "${workspaceFolder}", + "stopOnEntry": false, + "sourceLanguages": ["rust"], + "preLaunchTask": "Cargo Build", + "console": "integratedTerminal" + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug Interpreter", + "args": ["${input:target}", "-l", "${workspaceFolder}"], + "program": "${workspaceFolder}/target/debug/cider", + "windows": { + "program": "${workspaceFolder}/target/debug/cider.exe" + }, + "cwd": "${workspaceFolder}", + "stopOnEntry": false, + "sourceLanguages": ["rust"] + }, + { + "type": "lldb", + "request": "launch", + "name": "Debug Interpreter on current file", + "args": ["${file}", "-l", "${workspaceFolder}"], + "program": "${workspaceFolder}/target/debug/cider", + "windows": { + "program": "${workspaceFolder}/target/debug/cider.exe" + }, + "cwd": "${workspaceFolder}", + "stopOnEntry": false, + "sourceLanguages": ["rust"] + } + ], + "inputs": [ + { + "id": "target", + "type": "promptString", + "description": "Target file" + }, + { + "id": "pass", + "type": "promptString", + "description": "Pass to be executed by the compiler (only one allowed)", + "default": "all" + }, + { + "id": "backend", + "type": "pickString", + "description": "Backend to be used by the compiler", + "options": ["verilog", "calyx"] + } + ] +} diff --git a/cider-dap/README.md b/cider-dap/README.md index 44b371a7ad..5511e95744 100644 --- a/cider-dap/README.md +++ b/cider-dap/README.md @@ -19,7 +19,7 @@ the cider-dap binary somewhere on your path. From some directory on your PATH: ln -s /target/debug/cider-dap ``` -You will have to configure user settings of cider-dap in VSCode and input your cider binary path and port number. You can then launch the adapter with the Launch Program (Multi Session) action +You will have to configure user settings of cider-dap in VSCode and input your cider binary path, session type, and port number (if debug adapter is started as a server). You can then launch the adapter with the Launch Program (Multi Session) action. ## Known issues @@ -40,7 +40,7 @@ This project primarily leverages the Debug Adapter Protocol (DAP) for its functi         `adapter.rs`: Defines the primary adapter structure for the project and its associated functionalities. Not just any adapter, this file structures the fundamental protocols, handling the translation of high-level debugging commands into actionable, low-level instructions.
        `error.rs`: Contains custom error definitions and types for better error handling.
        `main.rs`: The entry point for the project, it integrates functionalities from the other source files and provides the main execution logic.
4. `calyxDebug` directory:
-        `extension.js`: JavaScript file for VSCode extension integration. It provides functions to interface between the VSCode environment and the Rust backend.
+        `extension.ts`: TypeScript file for VSCode extension integration. It provides functions to interface between the VSCode environment and the Rust backend.
### About main.rs: the Main File diff --git a/cider-dap/calyxDebug/extension.ts b/cider-dap/calyxDebug/extension.ts index 10fb8144ed..94ba4e60f5 100644 --- a/cider-dap/calyxDebug/extension.ts +++ b/cider-dap/calyxDebug/extension.ts @@ -35,7 +35,8 @@ async function getProgramName() { } } -class CiderDebugAdapterDescriptorFactory { +// Factory for multi-session +class CiderDebugAdapterDescriptorFactoryServer { adapter: CiderDebugAdapter; adapterPath: string; workspace: string; @@ -97,7 +98,7 @@ class CiderDebugAdapter { // Include the port as a command line argument this.adapterProcess = cp.spawn( this.adapterPath, - [programName, "--port", port, "--tcp"], + ["--port", port, "--tcp"], { cwd: this.cwd } ); @@ -128,15 +129,42 @@ class CiderDebugAdapter { } } +// Factory for single-session +class CiderDebugAdapterDescriptorFactoryExecutable { + createDebugAdapterDescriptor(_session) { + // Use the DebugAdapterExecutable as the debug adapter descriptor + console.log("inside adapter factory"); + console.log(vscode.workspace.getConfiguration("cider-dap").path); + + return new vscode.DebugAdapterExecutable( + vscode.workspace.getConfiguration("cider-dap").path, + [programName], + { cwd: vscode.workspace.rootPath } + ); + } +} + function activate(context) { logToPanel("Extension activated!"); - // Start the debug server explicitly - const factory = new CiderDebugAdapterDescriptorFactory( - vscode.workspace.getConfiguration("cider-dap").path, - vscode.workspace.rootPath, - outputChannel - ); + let factory: vscode.DebugAdapterDescriptorFactory; + + // Get session type (multi or single) from package.json configuration + switch (vscode.workspace.getConfiguration("cider-dap").sessionType) { + case "Multi-Session": + factory = new CiderDebugAdapterDescriptorFactoryServer( + vscode.workspace.getConfiguration("cider-dap").path, + vscode.workspace.rootPath, + outputChannel + ); + break; + + case "Single-Session": + default: + factory = new CiderDebugAdapterDescriptorFactoryExecutable(); + break; + } + context.subscriptions.push( vscode.debug.registerDebugAdapterDescriptorFactory("cider-dap", factory) ); @@ -144,9 +172,6 @@ function activate(context) { // Update the adapter path with the serverPort and use it for starting the debug adapter logToPanel("before startDebugging"); - /* context.subscriptions.push(vscode.commands.registerCommand('cider.startDebugging', startDebugging)); - context.subscriptions.push(vscode.commands.registerCommand('cider.stopDebugging', stopDebugging)); - */ logToPanel("Hello, your extension is now activated!"); } diff --git a/cider-dap/calyxDebug/package.json b/cider-dap/calyxDebug/package.json index dbc2c936e9..b6bf43bd0b 100644 --- a/cider-dap/calyxDebug/package.json +++ b/cider-dap/calyxDebug/package.json @@ -43,6 +43,18 @@ "scope": "machine", "default": 8888, "description": "Port number" + }, + "cider-dap.sessionType": { + "type": "string", + "default": "Single-Session", + "enum": [ + "Single-Session", + "Multi-Session" + ], + "enumDescriptions": [ + "Runs the debugger in single-session", + "Runs the debugger in multi-session" + ] } } } diff --git a/cider-dap/src/main.rs b/cider-dap/src/main.rs index fc001530ec..2d4b24a23e 100644 --- a/cider-dap/src/main.rs +++ b/cider-dap/src/main.rs @@ -14,14 +14,10 @@ use error::AdapterResult; use std::fs::File; use std::io::{stdin, stdout, BufReader, BufWriter, Read, Write}; use std::net::TcpListener; -use std::path::PathBuf; #[derive(argh::FromArgs)] /// Positional arguments for file path struct Opts { - /// input file - #[argh(positional, from_str_fn(read_path))] - file: Option, #[argh(switch, long = "tcp")] /// runs in tcp mode is_multi_session: bool, @@ -29,13 +25,9 @@ struct Opts { /// port for the TCP server port: u16, } -fn read_path(path: &str) -> Result { - Ok(PathBuf::from(path)) -} fn main() -> Result<(), MyAdapterError> { let opts: Opts = argh::from_env(); - if opts.is_multi_session { eprintln!("running multi-session"); let listener = TcpListener::bind(("127.0.0.1", opts.port))?; @@ -52,13 +44,11 @@ fn main() -> Result<(), MyAdapterError> { // Run the server using the adapter run_server(&mut server, adapter)?; } else { - let path = opts.file.ok_or(MyAdapterError::MissingFile)?; - let file = File::open(path)?; - let adapter = MyAdapter::new(file); eprintln!("running single-session"); let write = BufWriter::new(stdout()); let read = BufReader::new(stdin()); let mut server = Server::new(read, write); + let adapter = multi_session_init(&mut server)?; run_server(&mut server, adapter)?; } eprintln!("exited run_Server");