From 55f56517e40fa0dd607c2408d8d9b59ddc2253f1 Mon Sep 17 00:00:00 2001 From: Fenrir Date: Wed, 26 Jul 2017 03:00:57 -0600 Subject: [PATCH] Print thread name in panic msg --- ctr-std/src/panicking.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/ctr-std/src/panicking.rs b/ctr-std/src/panicking.rs index c7139fd..8d28317 100644 --- a/ctr-std/src/panicking.rs +++ b/ctr-std/src/panicking.rs @@ -19,6 +19,7 @@ use fmt::{self, Display}; use mem; use ptr; use raw; +use sys_common::thread_info; thread_local! { pub static LOCAL_STDERR: RefCell>> = { @@ -74,15 +75,22 @@ pub fn begin_panic(msg: M, file_line_col: &(&'static st let (file, line, col) = *file_line_col; // 3DS-specific code begins here - use libctru::{consoleInit, gfxScreen_t}; + use libctru::{consoleInit, consoleClear, gfxScreen_t, threadGetCurrent}; unsafe { - // set up a new console, overwriting whatever was on the top screen + // Set up a new console, overwriting whatever was on the top screen // before we started panicking let _console = consoleInit(gfxScreen_t::GFX_TOP, ptr::null_mut()); + consoleClear(); + + // Determine thread name + let thread = thread_info::current_thread(); + let name = thread.as_ref() + .and_then(|t| t.name()) + .unwrap_or(if threadGetCurrent() == ptr::null_mut() {"main"} else {""}); println!("thread '{}' panicked at '{}', {}:{}:{}", - "", msg, file, line, col); + name, msg, file, line, col); // Citra seems to ignore calls to svcExitProcess, and libc::abort() // causes it to lock up and fill the console with endless debug statements. @@ -103,14 +111,20 @@ pub fn begin_panic(msg: M, file_line_col: &(&'static st let (file, line, col) = *file_line_col; // 3DS-specific code begins here - use libctru::{errorInit, errorText, errorDisp, svcExitProcess, + use libctru::{errorInit, errorText, errorDisp, svcExitProcess, threadGetCurrent, errorConf, errorType, CFG_Language}; use libc; unsafe { + // Determine thread name + let thread = thread_info::current_thread(); + let name = thread.as_ref() + .and_then(|t| t.name()) + .unwrap_or(if threadGetCurrent() == ptr::null_mut() {"main"} else {""}); + // Setup error payload let error_text = format!("thread '{}' panicked at '{}', {}:{}:{}", - "", msg, file, line, col); + name, msg, file, line, col); let mut error_conf: errorConf = mem::uninitialized(); errorInit(&mut error_conf, errorType::ERROR_TEXT_WORD_WRAP,