mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
using json_spirit
This commit is contained in:
parent
ab5953b555
commit
35aa48567f
73
vm.cpp
73
vm.cpp
@ -265,42 +265,57 @@ eth::OnOpFunc FakeExtVM::simpleTrace()
|
|||||||
/*creates json stack trace*/
|
/*creates json stack trace*/
|
||||||
if (eth::VMTraceChannel::verbosity <= g_logVerbosity)
|
if (eth::VMTraceChannel::verbosity <= g_logVerbosity)
|
||||||
{
|
{
|
||||||
std::ostringstream ofile;
|
Object o_step;
|
||||||
|
|
||||||
u256s stack = vm.stack();
|
/*add the stack*/
|
||||||
ofile << endl << "{" << endl << " \"stack\":[" << endl;
|
Array a_stack;
|
||||||
for (vector<u256>::iterator i = stack.begin(); i != stack.end(); ++i){
|
for (auto i: vm.stack())
|
||||||
ofile << " \"" << (h256)*i << "\"";
|
a_stack.push_back((string)i);
|
||||||
if(next(i) != stack.end()){
|
|
||||||
ofile << ",";
|
|
||||||
}
|
|
||||||
|
|
||||||
ofile << endl;
|
o_step.push_back(Pair( "stack", a_stack ));
|
||||||
}
|
|
||||||
|
|
||||||
ofile << " ]," << endl;
|
/*add the memory*/
|
||||||
ofile << " \"memory\": \"";
|
Array a_mem;
|
||||||
for(auto i: vm.memory())
|
for(auto i: vm.memory())
|
||||||
ofile << setfill('0') << setw(2) << hex << (unsigned)i;
|
a_mem.push_back(i);
|
||||||
ofile << "\"," << endl;
|
|
||||||
|
|
||||||
ofile << " \"storage\": [" << endl;
|
o_step.push_back(Pair("memory", a_mem));
|
||||||
for (auto const& i: std::get<2>(ext.addresses.find(ext.myAddress)->second)){
|
|
||||||
ofile << " [" << endl;
|
/*add the storage*/
|
||||||
ofile << " \"" << std::showbase << std::hex << i.first << "\": \"" << i.second << "\"" << std::endl;
|
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(...){}
|
||||||
|
|
||||||
ofile << " ]," << endl;
|
/*add this step to the array of steps*/
|
||||||
ofile << " \"depth\": " << dec << ext.depth << "," << endl;
|
a_trace.push_back(o_step);
|
||||||
ofile << " \"gas\":" << dec <<vm.gas() << "," << endl;
|
|
||||||
ofile << " \"address\": \"" << ext.myAddress << "\"," << endl;
|
ofstream os( "./stackTrace.json");
|
||||||
ofile << " \"step\":" << steps << "," << endl;
|
|
||||||
ofile << " \"pc\": " << vm.curPC() << "," << endl;
|
Value v(a_trace);
|
||||||
ofile << " \"opcode\": \"" << instructionInfo(inst).name << "\""<< endl;
|
os << write_string(v, true);
|
||||||
ofile << "},";
|
os.close();
|
||||||
std::ofstream f;
|
|
||||||
f.open("./vmtrace.json", std::ofstream::app);
|
|
||||||
f << ofile.str();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
2
vm.h
2
vm.h
@ -26,7 +26,7 @@ along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
#include "JsonSpiritHeaders.h"
|
#include <json_spirit/json_spirit.h>
|
||||||
#include <libdevcore/Log.h>
|
#include <libdevcore/Log.h>
|
||||||
#include <libdevcore/CommonIO.h>
|
#include <libdevcore/CommonIO.h>
|
||||||
#include <libevmcore/Instruction.h>
|
#include <libevmcore/Instruction.h>
|
||||||
|
Loading…
Reference in New Issue
Block a user