Skip to content

Instantly share code, notes, and snippets.

@epilys
Created March 12, 2020 06:26
Show Gist options
  • Save epilys/a6caba03cb02cfd2880fd80755cd08b8 to your computer and use it in GitHub Desktop.
Save epilys/a6caba03cb02cfd2880fd80755cd08b8 to your computer and use it in GitHub Desktop.
easy core dump on panic in rust for debugging
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