mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
log VMTRACE in file for user defined test
This commit is contained in:
parent
6d1c06a719
commit
7a3517ed3a
31
vm.cpp
31
vm.cpp
@ -21,7 +21,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <boost/filesystem/path.hpp>
|
#include <boost/filesystem/path.hpp>
|
||||||
#include <libdevcore/CommonIO.h>
|
|
||||||
#include "vm.h"
|
#include "vm.h"
|
||||||
|
|
||||||
//#define FILL_TESTS
|
//#define FILL_TESTS
|
||||||
@ -63,7 +62,6 @@ h160 FakeExtVM::create(u256 _endowment, u256* _gas, bytesConstRef _init, OnOpFun
|
|||||||
|
|
||||||
bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data, u256* _gas, bytesRef _out, OnOpFunc const&, Address _myAddressOverride, Address _codeAddressOverride)
|
bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data, u256* _gas, bytesRef _out, OnOpFunc const&, Address _myAddressOverride, Address _codeAddressOverride)
|
||||||
{
|
{
|
||||||
|
|
||||||
u256 contractgas = 0xffff;
|
u256 contractgas = 0xffff;
|
||||||
|
|
||||||
Transaction t;
|
Transaction t;
|
||||||
@ -132,7 +130,7 @@ bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data,
|
|||||||
|
|
||||||
m_ms.internal.resize(m_ms.internal.size() + 1);
|
m_ms.internal.resize(m_ms.internal.size() + 1);
|
||||||
|
|
||||||
auto ret = m_s.call(_receiveAddress,_codeAddressOverride ? _codeAddressOverride : _receiveAddress, _myAddressOverride ? _myAddressOverride : myAddress, _value, gasPrice, _data, _gas, _out, origin, &sub, &(m_ms.internal.back()), OnOpFunc(), 1);
|
auto ret = m_s.call(_receiveAddress,_codeAddressOverride ? _codeAddressOverride : _receiveAddress, _myAddressOverride ? _myAddressOverride : myAddress, _value, gasPrice, _data, _gas, _out, origin, &sub, &(m_ms.internal.back()), simpleTrace<ExtVM>(), 1);
|
||||||
|
|
||||||
if (!m_ms.internal.back().from)
|
if (!m_ms.internal.back().from)
|
||||||
m_ms.internal.pop_back();
|
m_ms.internal.pop_back();
|
||||||
@ -423,27 +421,8 @@ void FakeExtVM::importCallCreates(mArray& _callcreates)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OnOpFunc FakeExtVM::simpleTrace()
|
// THIS IS BROKEN AND NEEDS TO BE REMOVED.
|
||||||
{
|
h160 FakeState::createNewAddress(Address _newAddress, Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, Address _origin, SubState* o_sub, Manifest* o_ms, OnOpFunc const& _onOp, unsigned _level)
|
||||||
return [](uint64_t steps, Instruction inst, bigint newMemSize, bigint gasCost, void* voidVM, void const* voidExt)
|
|
||||||
{
|
|
||||||
FakeExtVM const& ext = *(FakeExtVM const*)voidExt;
|
|
||||||
VM& vm = *(VM*)voidVM;
|
|
||||||
|
|
||||||
ostringstream o;
|
|
||||||
o << endl << " STACK" << endl;
|
|
||||||
for (auto i: vm.stack())
|
|
||||||
o << (h256)i << endl;
|
|
||||||
o << " MEMORY" << endl << memDump(vm.memory());
|
|
||||||
o << " STORAGE" << endl;
|
|
||||||
for (auto const& i: ext.state().storage(ext.myAddress))
|
|
||||||
o << showbase << hex << i.first << ": " << i.second << endl;
|
|
||||||
dev::LogOutputStream<VMTraceChannel, false>(true) << o.str();
|
|
||||||
dev::LogOutputStream<VMTraceChannel, false>(false) << " | " << dec << ext.depth << " | " << ext.myAddress << " | #" << steps << " | " << hex << setw(4) << setfill('0') << vm.curPC() << " : " << instructionInfo(inst).name << " | " << dec << vm.gas() << " | -" << dec << gasCost << " | " << newMemSize << "x32" << " ]";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
h160 FakeState::createNewAddress(Address _newAddress, Address _sender, u256 _endowment, u256 _gasPrice, u256* _gas, bytesConstRef _code, Address _origin, std::set<Address>* o_suicides, Manifest* o_ms, OnOpFunc const& _onOp, unsigned _level)
|
|
||||||
{
|
{
|
||||||
(void)o_sub;
|
(void)o_sub;
|
||||||
|
|
||||||
@ -541,7 +520,7 @@ void doTests(json_spirit::mValue& v, bool _fillin)
|
|||||||
VM vm(fev.gas);
|
VM vm(fev.gas);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
output = vm.go(fev, fev.simpleTrace()).toVector();
|
output = vm.go(fev, fev.simpleTrace<FakeExtVM>()).toVector();
|
||||||
}
|
}
|
||||||
catch (Exception const& _e)
|
catch (Exception const& _e)
|
||||||
{
|
{
|
||||||
@ -784,6 +763,7 @@ BOOST_AUTO_TEST_CASE(userDefinedFile)
|
|||||||
if (boost::unit_test::framework::master_test_suite().argc == 2)
|
if (boost::unit_test::framework::master_test_suite().argc == 2)
|
||||||
{
|
{
|
||||||
string filename = boost::unit_test::framework::master_test_suite().argv[1];
|
string filename = boost::unit_test::framework::master_test_suite().argv[1];
|
||||||
|
int currentVerbosity = g_logVerbosity;
|
||||||
g_logVerbosity = 12;
|
g_logVerbosity = 12;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -802,5 +782,6 @@ BOOST_AUTO_TEST_CASE(userDefinedFile)
|
|||||||
{
|
{
|
||||||
BOOST_ERROR("Failed VM Test with Exception: " << _e.what());
|
BOOST_ERROR("Failed VM Test with Exception: " << _e.what());
|
||||||
}
|
}
|
||||||
|
g_logVerbosity = currentVerbosity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
36
vm.h
36
vm.h
@ -28,6 +28,7 @@ along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
#include "JsonSpiritHeaders.h"
|
#include "JsonSpiritHeaders.h"
|
||||||
#include <libdevcore/Log.h>
|
#include <libdevcore/Log.h>
|
||||||
|
#include <libdevcore/CommonIO.h>
|
||||||
#include <libevmface/Instruction.h>
|
#include <libevmface/Instruction.h>
|
||||||
#include <libevm/ExtVMFace.h>
|
#include <libevm/ExtVMFace.h>
|
||||||
#include <libevm/VM.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/ExtVM.h>
|
||||||
#include <libethereum/State.h>
|
#include <libethereum/State.h>
|
||||||
|
|
||||||
|
|
||||||
namespace dev { namespace test {
|
namespace dev { namespace test {
|
||||||
|
|
||||||
struct FakeExtVMFailure : virtual Exception {};
|
struct FakeExtVMFailure : virtual Exception {};
|
||||||
@ -44,7 +46,7 @@ class FakeState: public eth::State
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// Execute a contract-creation transaction.
|
/// 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
|
class FakeExtVM: public eth::ExtVMFace
|
||||||
@ -80,7 +82,9 @@ public:
|
|||||||
json_spirit::mArray exportCallCreates();
|
json_spirit::mArray exportCallCreates();
|
||||||
void importCallCreates(json_spirit::mArray& _callcreates);
|
void importCallCreates(json_spirit::mArray& _callcreates);
|
||||||
|
|
||||||
static eth::OnOpFunc simpleTrace();
|
template<typename ExtVMType>
|
||||||
|
eth::OnOpFunc simpleTrace();
|
||||||
|
|
||||||
FakeState state() const { return m_s; }
|
FakeState state() const { return m_s; }
|
||||||
|
|
||||||
std::map<Address, std::tuple<u256, u256, std::map<u256, u256>, bytes>> addresses;
|
std::map<Address, std::tuple<u256, u256, std::map<u256, u256>, bytes>> addresses;
|
||||||
@ -94,4 +98,32 @@ private:
|
|||||||
eth::Manifest m_ms;
|
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
|
} } // Namespace Close
|
||||||
|
Loading…
Reference in New Issue
Block a user