From 67adccf16adda2b8a6d644ef087356f566bf2b2e Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Thu, 29 Oct 2020 19:38:27 +0800 Subject: [PATCH] xous: hosted: attach to debugger on panic When a `panic!()` is hit and we're running in a hosted environment, attach a debugger using `debug-here`. Signed-off-by: Sean Cross --- xous-rs/Cargo.toml | 1 + xous-rs/src/lib.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/xous-rs/Cargo.toml b/xous-rs/Cargo.toml index e5caa1589..93c6bfa37 100644 --- a/xous-rs/Cargo.toml +++ b/xous-rs/Cargo.toml @@ -24,3 +24,4 @@ default = [] [target.'cfg(any(windows,unix))'.dependencies] lazy_static = "1.4" hex = "0.4" +debug-here = "*" diff --git a/xous-rs/src/lib.rs b/xous-rs/src/lib.rs index 795e62f3d..b13d0ad34 100644 --- a/xous-rs/src/lib.rs +++ b/xous-rs/src/lib.rs @@ -22,6 +22,19 @@ pub use syscall::*; #[cfg(not(target_os = "none"))] pub use arch::ProcessArgsAsThread; +#[cfg(target_os = "none")] +pub fn init() {} + +#[cfg(not(target_os = "none"))] +pub fn init() { + use std::panic; + panic::set_hook(Box::new(|arg| { + println!("PANIC!"); + println!("Details: {:?}", arg); + debug_here::debug_here!(); + })); +} + /// Convert a four-letter string into a 32-bit int. #[macro_export] macro_rules! make_name { @@ -39,6 +52,7 @@ macro_rules! maybe_main { extern "Rust" { fn xous_entry() -> !; } + fn main() { xous::arch::ensure_connection().unwrap(); unsafe { xous_entry() };