Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit b9628a7

Browse files
committed
Log EVMC trace messages to vmtrace channel
1 parent 86801a9 commit b9628a7

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

libevm/EVMC.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,17 @@ EVMC::EVMC(evmc_instance* _instance) : EVM(_instance)
3535
// TODO: It might be easier to just pass instruction from VM.
3636
char const* name = evmc->m_instructionNames[evmc->m_code[_codeOffset]];
3737

38-
std::cerr << "EVMC "
39-
<< " " << evmc->m_step++ << " " << _codeOffset << " " << name << " "
40-
<< _statusCode << " " << _gasLeft << " " << _stackNumItems;
38+
std::ostringstream logMessage;
39+
logMessage << "EVMC "
40+
<< " " << evmc->m_step++ << " " << _codeOffset << " " << name << " "
41+
<< _statusCode << " " << _gasLeft << " " << _stackNumItems;
4142

4243
if (_pushedStackItem)
43-
std::cerr << " +[" << fromEvmC(*_pushedStackItem) << "]";
44+
logMessage << " +[" << fromEvmC(*_pushedStackItem) << "]";
4445

45-
std::cerr << " " << _memorySize << "\n";
46+
logMessage << " " << _memorySize;
47+
48+
LOG(evmc->m_vmTraceLogger) << logMessage.str();
4649
};
4750

4851
_instance->set_tracer(_instance, tracer, reinterpret_cast<evmc_tracer_context*>(this));
@@ -70,11 +73,11 @@ owning_bytes_ref EVMC::exec(u256& io_gas, ExtVMFace& _ext, const OnOpFunc& _onOp
7073

7174

7275
auto gas = static_cast<int64_t>(io_gas);
73-
std::cerr << "EVMC message START " << _ext.depth << " " << _ext.caller << " -> "
74-
<< _ext.myAddress << " gas: " << gas << "\n";
76+
LOG(m_vmTraceLogger) << "EVMC message START " << _ext.depth << " " << _ext.caller << " -> "
77+
<< _ext.myAddress << " gas: " << gas << "\n";
7578
EVM::Result r = execute(_ext, gas);
76-
std::cerr << "EVMC message END " << _ext.depth << " status: " << r.status()
77-
<< " gas left: " << r.gasLeft() << "\n";
79+
LOG(m_vmTraceLogger) << "EVMC message END " << _ext.depth << " status: " << r.status()
80+
<< " gas left: " << r.gasLeft() << "\n";
7881

7982
switch (r.status())
8083
{

libevm/EVMC.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class EVMC : public EVM, public VMFace
9999
bytesConstRef m_code;
100100
int m_step = 0;
101101
char const* const* m_instructionNames = nullptr;
102+
103+
Logger m_vmTraceLogger{createLogger(VerbosityTrace, "vmtrace")};
102104
};
103105
}
104106
}

0 commit comments

Comments
 (0)