@ -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) -> !;
|
||||
}
|
||||
|
Reference in New Issue
Block a user