Created
March 12, 2020 06:26
-
-
Save epilys/a6caba03cb02cfd2880fd80755cd08b8 to your computer and use it in GitHub Desktop.
easy core dump on panic in rust for debugging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn register_panic_handler() { | |
let default_panic = std::panic::take_hook(); | |
std::panic::set_hook(Box::new(move |panic_info| { | |
default_panic(panic_info); | |
// Don't forget to enable core dumps on your shell with eg `ulimit -c unlimited` | |
let pid = std::process::id(); | |
eprintln!("dumping core for pid {}", std::process::id()); | |
use libc::kill; | |
use libc::SIGQUIT; | |
use std::convert::TryInto; | |
unsafe { kill(pid.try_into().unwrap(), SIGQUIT) }; | |
})); | |
} | |
fn main() { | |
register_panic_handler(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment