Enable BPF program instruction traces (#15613)

This commit is contained in:
Jack May 2021-03-01 23:11:58 -08:00 committed by GitHub
parent 4f63afce32
commit 3cd00965a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 4 deletions

1
Cargo.lock generated
View File

@ -4128,6 +4128,7 @@ dependencies = [
"bincode", "bincode",
"byteorder", "byteorder",
"curve25519-dalek 3.0.0", "curve25519-dalek 3.0.0",
"log 0.4.11",
"num-derive", "num-derive",
"num-traits", "num-traits",
"rand 0.7.3", "rand 0.7.3",

View File

@ -430,8 +430,7 @@ impl Default for ProgramTest {
/// ///
fn default() -> Self { fn default() -> Self {
solana_logger::setup_with_default( solana_logger::setup_with_default(
"solana_bpf_loader=debug,\ "solana_rbpf::vm=debug,\
solana_rbpf::vm=debug,\
solana_runtime::message_processor=debug,\ solana_runtime::message_processor=debug,\
solana_runtime::system_instruction_processor=trace,\ solana_runtime::system_instruction_processor=trace,\
solana_program_test=info", solana_program_test=info",
@ -523,7 +522,7 @@ impl ProgramTest {
/// directory. /// directory.
/// ///
/// If `process_instruction` is provided, the natively built-program may be used instead of the /// If `process_instruction` is provided, the natively built-program may be used instead of the
/// BPF shared object depending on the `bpf` environment variable. /// BPF shared object depending on the `BPF_OUT_DIR` environment variable.
pub fn add_program( pub fn add_program(
&mut self, &mut self,
program_name: &str, program_name: &str,

View File

@ -12,6 +12,7 @@ edition = "2018"
bincode = "1.3.1" bincode = "1.3.1"
byteorder = "1.3.4" byteorder = "1.3.4"
curve25519-dalek = "3" curve25519-dalek = "3"
log = "0.4.11"
num-derive = "0.3" num-derive = "0.3"
num-traits = "0.2" num-traits = "0.2"
rand_core = "0.6.2" rand_core = "0.6.2"

View File

@ -14,6 +14,7 @@ use crate::{
serialization::{deserialize_parameters, serialize_parameters}, serialization::{deserialize_parameters, serialize_parameters},
syscalls::SyscallError, syscalls::SyscallError,
}; };
use log::{log_enabled, trace, Level::Trace};
use solana_rbpf::{ use solana_rbpf::{
ebpf::MM_HEAP_START, ebpf::MM_HEAP_START,
error::{EbpfError, UserDefinedError}, error::{EbpfError, UserDefinedError},
@ -80,7 +81,7 @@ pub fn create_and_cache_executor(
max_call_depth: bpf_compute_budget.max_call_depth, max_call_depth: bpf_compute_budget.max_call_depth,
stack_frame_size: bpf_compute_budget.stack_frame_size, stack_frame_size: bpf_compute_budget.stack_frame_size,
enable_instruction_meter: true, enable_instruction_meter: true,
enable_instruction_tracing: false, enable_instruction_tracing: log_enabled!(Trace),
}, },
) )
.map_err(|e| map_ebpf_error(invoke_context, e))?; .map_err(|e| map_ebpf_error(invoke_context, e))?;
@ -804,6 +805,13 @@ impl Executor for BpfExecutor {
before - after, before - after,
before before
); );
if log_enabled!(Trace) {
let mut trace_buffer = String::new();
vm.get_tracer()
.write(&mut trace_buffer, vm.get_program())
.unwrap();
trace!("BPF Program Instruction Trace:\n{}", trace_buffer);
}
match result { match result {
Ok(status) => { Ok(status) => {
if status != SUCCESS { if status != SUCCESS {