diff --git a/libaleth-interpreter/VM.cpp b/libaleth-interpreter/VM.cpp index a3331d2fd2b..29918f1850b 100644 --- a/libaleth-interpreter/VM.cpp +++ b/libaleth-interpreter/VM.cpp @@ -144,7 +144,7 @@ namespace dev { namespace eth { -void VM::trace() noexcept +void VM::trace(uint64_t _pc) noexcept { if (m_traceCallback) { @@ -156,7 +156,7 @@ void VM::trace() noexcept topStackItem = toEvmC(m_SPP[0]); pushedStackItem = &topStackItem; } - m_traceCallback(m_traceContext, m_PC, EVMC_SUCCESS, m_io_gas, m_stackEnd - m_SPP, + m_traceCallback(m_traceContext, _pc, EVMC_SUCCESS, m_io_gas, m_stackEnd - m_SPP, pushedStackItem, m_mem.size(), 0, 0, nullptr); } } @@ -457,7 +457,6 @@ void VM::interpretCases() updateIOGas(); m_SPP[0] = (u256)*(h256 const*)(m_mem.data() + (unsigned)m_SP[0]); - trace(); } NEXT @@ -468,7 +467,6 @@ void VM::interpretCases() updateIOGas(); *(h256*)&m_mem[(unsigned)m_SP[0]] = (h256)m_SP[1]; - trace(); } NEXT @@ -1217,14 +1215,11 @@ void VM::interpretCases() // get val at two-byte offset into const pool and advance pc by one-byte remainder TRACE_OP(2, m_PC, m_OP); unsigned off; - uint64_t pc = m_PC; - ++pc; - off = m_code[pc++] << 8; - off |= m_code[pc++]; - pc += m_code[pc]; + ++m_PC; + off = m_code[m_PC++] << 8; + off |= m_code[m_PC++]; + m_PC += m_code[m_PC]; m_SPP[0] = m_pool[off]; - trace(); - m_PC = pc; TRACE_VAL(2, "Retrieved pooled const", m_SPP[0]); #else throwBadInstruction(); @@ -1237,7 +1232,6 @@ void VM::interpretCases() ON_OP(); updateIOGas(); m_SPP[0] = m_code[m_PC + 1]; - trace(); m_PC += 2; } CONTINUE @@ -1286,7 +1280,6 @@ void VM::interpretCases() for (; numBytes--; ++codeOffset) m_SPP[0] = (m_SPP[0] << 8) | m_code[codeOffset]; - trace(); m_PC = codeOffset; } CONTINUE @@ -1416,7 +1409,6 @@ void VM::interpretCases() updateSSGas(); updateIOGas(); - trace(); evmc_uint256be key = toEvmC(m_SP[0]); evmc_uint256be value = toEvmC(m_SP[1]); diff --git a/libaleth-interpreter/VM.h b/libaleth-interpreter/VM.h index f07a3d3e6f0..697d191d555 100644 --- a/libaleth-interpreter/VM.h +++ b/libaleth-interpreter/VM.h @@ -117,7 +117,7 @@ class VM evmc_trace_callback m_traceCallback = nullptr; evmc_tracer_context* m_traceContext = nullptr; - void trace() noexcept; + void trace(uint64_t _pc) noexcept; // initialize interpreter void initEntry(); diff --git a/libaleth-interpreter/VMConfig.h b/libaleth-interpreter/VMConfig.h index b94ac62316a..13c56b89d14 100644 --- a/libaleth-interpreter/VMConfig.h +++ b/libaleth-interpreter/VMConfig.h @@ -124,18 +124,24 @@ namespace eth #if EVM_SWITCH_DISPATCH #define INIT_CASES -#define DO_CASES \ - for (;;) \ - { \ - fetchInstruction(); \ - switch (m_OP) \ +#define DO_CASES \ + for (;;) \ + { \ + fetchInstruction(); \ + auto startPC = m_PC; \ + switch (m_OP) \ { #define CASE(name) case Instruction::name: -#define NEXT \ - ++m_PC; \ +#define NEXT \ + trace(startPC); \ + ++m_PC; \ break; -#define CONTINUE continue; -#define BREAK return; +#define CONTINUE \ + trace(startPC); \ + continue; +#define BREAK \ + trace(startPC); \ + return; #define DEFAULT default: #define WHILE_CASES \ } \ @@ -410,19 +416,24 @@ namespace eth &&SUICIDE, \ }; -#define DO_CASES \ - fetchInstruction(); \ +#define DO_CASES \ + fetchInstruction(); \ + auto startPC = m_PC; \ goto* jumpTable[(int)m_OP]; #define CASE(name) \ name: #define NEXT \ + trace(startPC); \ ++m_PC; \ fetchInstruction(); \ goto* jumpTable[(int)m_OP]; #define CONTINUE \ + trace(startPC); \ fetchInstruction(); \ goto* jumpTable[(int)m_OP]; -#define BREAK return; +#define BREAK \ + trace(startPC); \ + return; #define DEFAULT #define WHILE_CASES