Fix up the VM trace.

This commit is contained in:
Gav Wood 2016-08-03 20:07:30 +02:00
parent 40a304b177
commit 52355855fc
3 changed files with 18 additions and 5 deletions

View File

@ -99,11 +99,11 @@ impl<'a> Executive<'a> {
let check = options.check_nonce; let check = options.check_nonce;
match options.tracing { match options.tracing {
true => match options.vm_tracing { true => match options.vm_tracing {
true => self.transact_with_tracer(t, check, ExecutiveTracer::default(), ExecutiveVMTracer::default()), true => self.transact_with_tracer(t, check, ExecutiveTracer::default(), ExecutiveVMTracer::toplevel()),
false => self.transact_with_tracer(t, check, ExecutiveTracer::default(), NoopVMTracer), false => self.transact_with_tracer(t, check, ExecutiveTracer::default(), NoopVMTracer),
}, },
false => match options.vm_tracing { false => match options.vm_tracing {
true => self.transact_with_tracer(t, check, NoopTracer, ExecutiveVMTracer::default()), true => self.transact_with_tracer(t, check, NoopTracer, ExecutiveVMTracer::toplevel()),
false => self.transact_with_tracer(t, check, NoopTracer, NoopVMTracer), false => self.transact_with_tracer(t, check, NoopTracer, NoopVMTracer),
}, },
} }

View File

@ -160,11 +160,24 @@ impl Tracer for ExecutiveTracer {
} }
/// Simple VM tracer. Traces all operations. /// Simple VM tracer. Traces all operations.
#[derive(Default)]
pub struct ExecutiveVMTracer { pub struct ExecutiveVMTracer {
data: VMTrace, data: VMTrace,
} }
impl ExecutiveVMTracer {
/// Create a new top-level instance.
pub fn toplevel() -> Self {
ExecutiveVMTracer {
data: VMTrace {
parent_step: 0,
code: vec![],
operations: vec![Default::default()], // prefill with a single entry so that prepare_subtrace can get the parent_step
subs: vec![],
}
}
}
}
impl VMTracer for ExecutiveVMTracer { impl VMTracer for ExecutiveVMTracer {
fn trace_prepare_execute(&mut self, pc: usize, instruction: u8, gas_cost: &U256) -> bool { fn trace_prepare_execute(&mut self, pc: usize, instruction: u8, gas_cost: &U256) -> bool {
self.data.operations.push(VMOperation { self.data.operations.push(VMOperation {
@ -188,7 +201,7 @@ impl VMTracer for ExecutiveVMTracer {
fn prepare_subtrace(&self, code: &[u8]) -> Self { fn prepare_subtrace(&self, code: &[u8]) -> Self {
ExecutiveVMTracer { data: VMTrace { ExecutiveVMTracer { data: VMTrace {
parent_step: self.data.operations.len(), parent_step: self.data.operations.len() - 1, // won't overflow since we must already have pushed an operation in trace_prepare_execute.
code: code.to_vec(), code: code.to_vec(),
operations: vec![], operations: vec![],
subs: vec![], subs: vec![],

View File

@ -473,7 +473,7 @@ impl Decodable for VMExecutedOperation {
} }
} }
#[derive(Debug, Clone, PartialEq, Binary)] #[derive(Debug, Clone, PartialEq, Binary, Default)]
/// A record of the execution of a single VM operation. /// A record of the execution of a single VM operation.
pub struct VMOperation { pub struct VMOperation {
/// The program counter. /// The program counter.