Panic filename (#4625)

automerge
This commit is contained in:
Jack May
2019-06-10 11:00:15 -07:00
committed by Grimes
parent 1fa31c9410
commit 9f6496d38a
13 changed files with 129 additions and 75 deletions

View File

@ -1,36 +1,32 @@
//! @brief Solana Rust-based BPF program panic handling
use crate::log::*;
use core::fmt::{self, Write};
use core::panic::PanicInfo;
#[cfg(not(test))]
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
sol_log("Panic!");
// TODO crashes! sol_log(_info.payload().downcast_ref::<&str>().unwrap());
if let Some(location) = info.location() {
if !location.file().is_empty() {
// TODO location.file() returns empty str, if we get here its been fixed
sol_log(location.file());
sol_log("location.file() is fixed!!");
match info.location() {
Some(location) => {
let mut file: [u8; 128] = [0; 128];
for (i, c) in location.file().as_bytes().iter().enumerate() {
if i >= 126 {
break;
}
file[i] = *c;
}
unsafe {
sol_panic_();
sol_panic_(
file.as_ptr(),
u64::from(location.line()),
u64::from(location.column()),
);
}
}
sol_log_64(
0,
0,
0,
u64::from(location.line()),
u64::from(location.column()),
);
} else {
sol_log("Panic!, but could not get location information");
}
unsafe {
sol_panic_();
None => unsafe { sol_panic_(0 as *const u8, 0, 0) },
}
}
extern "C" {
pub fn sol_panic_() -> !;
pub fn sol_panic_(message: *const u8, line: u64, column: u64) -> !;
}