provide full Rust panic messages in BPF and add memory optimizations (#13455)
This commit is contained in:
@ -11,6 +11,10 @@ edition = "2018"
|
||||
[dependencies]
|
||||
solana-program = { path = "../../../../sdk/program", version = "1.5.0" }
|
||||
|
||||
[features]
|
||||
default = ["custom-panic"]
|
||||
custom-panic = []
|
||||
|
||||
[lib]
|
||||
name = "solana_bpf_rust_panic"
|
||||
crate-type = ["cdylib"]
|
||||
|
@ -1,8 +1,24 @@
|
||||
//! @brief Example Rust-based BPF program that panics
|
||||
|
||||
extern crate solana_program;
|
||||
|
||||
#[cfg(all(feature = "custom-panic", target_arch = "bpf"))]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
||||
panic!();
|
||||
fn custom_panic(info: &core::panic::PanicInfo<'_>) {
|
||||
// Note: Full panic reporting is included here for testing purposes
|
||||
solana_program::info!("program custom panic enabled");
|
||||
solana_program::info!(&format!("{}", info));
|
||||
}
|
||||
|
||||
extern crate solana_program;
|
||||
use solana_program::{
|
||||
account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, pubkey::Pubkey,
|
||||
};
|
||||
|
||||
entrypoint!(process_instruction);
|
||||
fn process_instruction(
|
||||
_program_id: &Pubkey,
|
||||
_accounts: &[AccountInfo],
|
||||
_instruction_data: &[u8],
|
||||
) -> ProgramResult {
|
||||
assert_eq!(1, 2);
|
||||
Ok(())
|
||||
}
|
||||
|
@ -533,11 +533,7 @@ fn test_program_bpf_invoke() {
|
||||
&[TEST_SUCCESS, bump_seed1, bump_seed2, bump_seed3],
|
||||
account_metas.clone(),
|
||||
);
|
||||
let noop_instruction = Instruction::new(
|
||||
noop_program_id,
|
||||
&(),
|
||||
vec![]
|
||||
);
|
||||
let noop_instruction = Instruction::new(noop_program_id, &(), vec![]);
|
||||
let message = Message::new(&[instruction, noop_instruction], Some(&mint_pubkey));
|
||||
let tx = Transaction::new(
|
||||
&[
|
||||
@ -763,8 +759,8 @@ fn assert_instruction_count() {
|
||||
("multiple_static", 8),
|
||||
("noop", 57),
|
||||
("relative_call", 10),
|
||||
("sanity", 1140),
|
||||
("sanity++", 1140),
|
||||
("sanity", 176),
|
||||
("sanity++", 176),
|
||||
("struct_pass", 8),
|
||||
("struct_ret", 22),
|
||||
]);
|
||||
@ -772,16 +768,16 @@ fn assert_instruction_count() {
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
{
|
||||
programs.extend_from_slice(&[
|
||||
("solana_bpf_rust_128bit", 543),
|
||||
("solana_bpf_rust_alloc", 19082),
|
||||
("solana_bpf_rust_128bit", 572),
|
||||
("solana_bpf_rust_alloc", 12777),
|
||||
("solana_bpf_rust_dep_crate", 2),
|
||||
("solana_bpf_rust_external_spend", 538),
|
||||
("solana_bpf_rust_iter", 723),
|
||||
("solana_bpf_rust_many_args", 231),
|
||||
("solana_bpf_rust_iter", 724),
|
||||
("solana_bpf_rust_many_args", 237),
|
||||
("solana_bpf_rust_noop", 488),
|
||||
("solana_bpf_rust_param_passing", 46),
|
||||
("solana_bpf_rust_param_passing", 48),
|
||||
("solana_bpf_rust_ristretto", 19399),
|
||||
("solana_bpf_rust_sanity", 1965),
|
||||
("solana_bpf_rust_sanity", 894),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ use thiserror::Error as ThisError;
|
||||
pub enum SyscallError {
|
||||
#[error("{0}: {1:?}")]
|
||||
InvalidString(Utf8Error, Vec<u8>),
|
||||
#[error("BPF program called abort()!")]
|
||||
#[error("BPF program panicked")]
|
||||
Abort,
|
||||
#[error("BPF program Panicked in {0} at {1}:{2}")]
|
||||
Panic(String, u64, u64),
|
||||
|
Reference in New Issue
Block a user