diff options
author | Christoph Jentzsch <jentzsch.software@gmail.com> | 2014-10-28 05:21:30 +0800 |
---|---|---|
committer | Christoph Jentzsch <jentzsch.software@gmail.com> | 2014-10-28 05:21:30 +0800 |
commit | 7a3517ed3af5525de8af979baa229f9fdb94b2b6 (patch) | |
tree | c7e78e98c595c3685141a1d6ebfcba09459dcad8 /vm.h | |
parent | 6d1c06a7194209f5a33643198a3734b3be744e49 (diff) | |
download | dexon-solidity-7a3517ed3af5525de8af979baa229f9fdb94b2b6.tar dexon-solidity-7a3517ed3af5525de8af979baa229f9fdb94b2b6.tar.gz dexon-solidity-7a3517ed3af5525de8af979baa229f9fdb94b2b6.tar.bz2 dexon-solidity-7a3517ed3af5525de8af979baa229f9fdb94b2b6.tar.lz dexon-solidity-7a3517ed3af5525de8af979baa229f9fdb94b2b6.tar.xz dexon-solidity-7a3517ed3af5525de8af979baa229f9fdb94b2b6.tar.zst dexon-solidity-7a3517ed3af5525de8af979baa229f9fdb94b2b6.zip |
log VMTRACE in file for user defined test
Diffstat (limited to 'vm.h')
-rw-r--r-- | vm.h | 36 |
1 files changed, 34 insertions, 2 deletions
@@ -28,6 +28,7 @@ along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. #include <boost/test/unit_test.hpp> #include "JsonSpiritHeaders.h" #include <libdevcore/Log.h> +#include <libdevcore/CommonIO.h> #include <libevmface/Instruction.h> #include <libevm/ExtVMFace.h> #include <libevm/VM.h> @@ -36,6 +37,7 @@ along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. #include <libethereum/ExtVM.h> #include <libethereum/State.h> + namespace dev { namespace test { struct FakeExtVMFailure : virtual Exception {}; @@ -44,7 +46,7 @@ class FakeState: public eth::State { public: /// Execute a contract-creation transaction. - h160 createNewAddress(Address _newAddress, Address _txSender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, Address _originAddress = {}, eth::SubState* o_suicides = nullptr, eth::Manifest* o_ms = nullptr, eth::OnOpFunc const& _onOp = {}, unsigned _level = 0); + h160 createNewAddress(Address _newAddress, Address _txSender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, Address _originAddress = {}, eth::SubState* o_sub = nullptr, eth::Manifest* o_ms = nullptr, eth::OnOpFunc const& _onOp = {}, unsigned _level = 0); }; class FakeExtVM: public eth::ExtVMFace @@ -80,7 +82,9 @@ public: json_spirit::mArray exportCallCreates(); void importCallCreates(json_spirit::mArray& _callcreates); - static eth::OnOpFunc simpleTrace(); + template<typename ExtVMType> + eth::OnOpFunc simpleTrace(); + FakeState state() const { return m_s; } std::map<Address, std::tuple<u256, u256, std::map<u256, u256>, bytes>> addresses; @@ -94,4 +98,32 @@ private: eth::Manifest m_ms; }; +template<typename ExtVMType> +eth::OnOpFunc FakeExtVM::simpleTrace() +{ + return [](uint64_t steps, eth::Instruction inst, bigint newMemSize, bigint gasCost, void* voidVM, void const* voidExt) + { + ExtVMType const& ext = *(ExtVMType const*)voidExt; + eth::VM& vm = *(eth::VM*)voidVM; + + std::ostringstream o; + o << std::endl << " STACK" << std::endl; + for (auto i: vm.stack()) + o << (h256)i << std::endl; + o << " MEMORY" << std::endl << memDump(vm.memory()); + o << " STORAGE" << std::endl; + for (auto const& i: ext.state().storage(ext.myAddress)) + o << std::showbase << std::hex << i.first << ": " << i.second << std::endl; + dev::LogOutputStream<eth::VMTraceChannel, false>(true) << o.str(); + dev::LogOutputStream<eth::VMTraceChannel, false>(false) << " | " << std::dec << ext.depth << " | " << ext.myAddress << " | #" << steps << " | " << std::hex << std::setw(4) << std::setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " | " << std::dec << vm.gas() << " | -" << std::dec << gasCost << " | " << newMemSize << "x32" << " ]"; + + if (eth::VMTraceChannel::verbosity <= g_logVerbosity) + { + std::ofstream f; + f.open("./vmtrace.log", std::ofstream::app); + f << o.str(); + f << " | " << std::dec << ext.depth << " | " << ext.myAddress << " | #" << steps << " | " << std::hex << std::setw(4) << std::setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " | " << std::dec << vm.gas() << " | -" << std::dec << gasCost << " | " << newMemSize << "x32"; + } + }; +} } } // Namespace Close |