diff options
author | wanderer <mjbecze@gmail.com> | 2014-12-15 02:11:54 +0800 |
---|---|---|
committer | wanderer <mjbecze@gmail.com> | 2014-12-17 03:28:28 +0800 |
commit | 35aa48567ff7461a9fccde1df7d9916d7e7222cc (patch) | |
tree | 5c72ca2e784158563cbd8752a13f3fb5bfdaa356 | |
parent | ab5953b55583c9b4028286860397bf4e9fca801b (diff) | |
download | dexon-solidity-35aa48567ff7461a9fccde1df7d9916d7e7222cc.tar.gz dexon-solidity-35aa48567ff7461a9fccde1df7d9916d7e7222cc.tar.zst dexon-solidity-35aa48567ff7461a9fccde1df7d9916d7e7222cc.zip |
using json_spirit
-rw-r--r-- | vm.cpp | 77 | ||||
-rw-r--r-- | vm.h | 2 |
2 files changed, 47 insertions, 32 deletions
@@ -265,42 +265,57 @@ eth::OnOpFunc FakeExtVM::simpleTrace() /*creates json stack trace*/ if (eth::VMTraceChannel::verbosity <= g_logVerbosity) { - std::ostringstream ofile; - - u256s stack = vm.stack(); - ofile << endl << "{" << endl << " \"stack\":[" << endl; - for (vector<u256>::iterator i = stack.begin(); i != stack.end(); ++i){ - ofile << " \"" << (h256)*i << "\""; - if(next(i) != stack.end()){ - ofile << ","; - } + Object o_step; - ofile << endl; - } + /*add the stack*/ + Array a_stack; + for (auto i: vm.stack()) + a_stack.push_back((string)i); - ofile << " ]," << endl; - ofile << " \"memory\": \""; - for(auto i: vm.memory()) - ofile << setfill('0') << setw(2) << hex << (unsigned)i; - ofile << "\"," << endl; + o_step.push_back(Pair( "stack", a_stack )); - ofile << " \"storage\": [" << endl; - for (auto const& i: std::get<2>(ext.addresses.find(ext.myAddress)->second)){ - ofile << " [" << endl; - ofile << " \"" << std::showbase << std::hex << i.first << "\": \"" << i.second << "\"" << std::endl; + /*add the memory*/ + Array a_mem; + for(auto i: vm.memory()) + a_mem.push_back(i); + + o_step.push_back(Pair("memory", a_mem)); + + /*add the storage*/ + Object storage; + for (auto const& i: std::get<2>(ext.addresses.find(ext.myAddress)->second)) + storage.push_back(Pair( (string)i.first , (string)i.second)); + + /*add all the other details*/ + o_step.push_back(Pair("storage", storage)); + o_step.push_back(Pair("depth", to_string(ext.depth))); + o_step.push_back(Pair("gas", (string)vm.gas())); + o_step.push_back(Pair("address", "0x" + toString(ext.myAddress ))); + o_step.push_back(Pair("step", steps )); + o_step.push_back(Pair("pc", (int)vm.curPC())); + o_step.push_back(Pair("opcode", instructionInfo(inst).name )); + + ifstream is( "./stackTrace.json"); + string istr((std::istreambuf_iterator<char>(is) ), (std::istreambuf_iterator<char>())); + is.close(); + Value iv; + Array a_trace; + + /*try to parse the current trace file*/ + try{ + read_string(istr, iv); + a_trace = iv.get_array(); } + catch(...){} + + /*add this step to the array of steps*/ + a_trace.push_back(o_step); + + ofstream os( "./stackTrace.json"); - ofile << " ]," << endl; - ofile << " \"depth\": " << dec << ext.depth << "," << endl; - ofile << " \"gas\":" << dec <<vm.gas() << "," << endl; - ofile << " \"address\": \"" << ext.myAddress << "\"," << endl; - ofile << " \"step\":" << steps << "," << endl; - ofile << " \"pc\": " << vm.curPC() << "," << endl; - ofile << " \"opcode\": \"" << instructionInfo(inst).name << "\""<< endl; - ofile << "},"; - std::ofstream f; - f.open("./vmtrace.json", std::ofstream::app); - f << ofile.str(); + Value v(a_trace); + os << write_string(v, true); + os.close(); } }; } @@ -26,7 +26,7 @@ along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. #include <fstream> #include <cstdint> #include <boost/test/unit_test.hpp> -#include "JsonSpiritHeaders.h" +#include <json_spirit/json_spirit.h> #include <libdevcore/Log.h> #include <libdevcore/CommonIO.h> #include <libevmcore/Instruction.h> |