gdb_breakpoint/
lib.rs

1#![feature(core_intrinsics)]
2extern crate nix;
3
4use nix::sys::signal::{kill, Signal};
5use nix::unistd::getpid;
6use std::process::Command;
7
8use std::sync::Once;
9
10static INIT: Once = Once::new();
11
12pub fn breakpoint() {
13    let mut init = false;
14    INIT.call_once(|| {
15        let gdb = format!("ugdb --layout=\"(1s-1c)\" --gdb=rust-gdb --pid {}", getpid());
16        println!("Launching {}", gdb);
17        let argv = vec!["neww", &gdb];
18        let argv_c = argv.iter().map(|s| s.to_string()).collect::<Vec<_>>();
19        Command::new("tmux").args(&argv_c[..]).spawn().unwrap();
20        init = true;
21    });
22    if init{
23        kill(getpid(), Signal::SIGSTOP).unwrap();
24    }
25    unsafe{
26        std::intrinsics::breakpoint();
27    }
28}
29
30#[cfg(test)]
31mod tests {
32    use crate::breakpoint;
33    #[test]
34    fn it_works() {
35        let x = 3 + 4;
36        breakpoint();
37        assert!(true);
38        breakpoint();
39        assert!(true);
40    }
41}