Skip to content

Instantly share code, notes, and snippets.

@fungos
Forked from epilys/dump_core.rs
Created March 12, 2020 13:17
Show Gist options
  • Save fungos/b1d26dfc64b74add2cc7fd32597d97ac to your computer and use it in GitHub Desktop.
Save fungos/b1d26dfc64b74add2cc7fd32597d97ac 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