Skip to content

Instantly share code, notes, and snippets.

@Mart-Bogdan
Created November 19, 2022 01:29
Show Gist options
  • Save Mart-Bogdan/7d19218837b419d53cc0c415879ea847 to your computer and use it in GitHub Desktop.
Save Mart-Bogdan/7d19218837b419d53cc0c415879ea847 to your computer and use it in GitHub Desktop.
Rust snippet to attach VS Code debugger to current running process
// can be used to attach to existing running app.
// If you need to run app from shell, for example, passing in stdin or command line args, or whatever else.
#[allow(unused)]
fn attch_vs_code() {
use std::time::Duration;
let url = format!(
"vscode://vadimcn.vscode-lldb/launch/config?{{'request':'attach','pid':{}}}",
std::process::id()
);
_ = std::process::Command::new("code.cmd")
.arg("--open-url")
.arg(url)
.output()
.unwrap();
std::thread::sleep(Duration::from_millis(1000)); // Wait for debugger to attach
}
//attch_vs_code();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment