Browse Source

Debug past transactions in debugger.

cl-refactor
Gav Wood 10 years ago
parent
commit
7e3b199b77
  1. 9
      alethzero/Main.ui
  2. 29
      alethzero/MainWin.cpp
  3. 1
      alethzero/MainWin.h
  4. 15
      libethereum/Executive.cpp
  5. 6
      libethereum/Executive.h

9
alethzero/Main.ui

@ -165,6 +165,7 @@
<addaction name="paranoia"/>
<addaction name="killBlockchain"/>
<addaction name="inject"/>
<addaction name="debugStepback"/>
</widget>
<addaction name="menu_File"/>
<addaction name="menu_Network"/>
@ -1430,6 +1431,14 @@ font-family: Monospace, Ubuntu Mono, Lucida Console, Courier New</string>
<string>&amp;Load Javascript...</string>
</property>
</action>
<action name="debugStepback">
<property name="text">
<string>Single Step &amp;Backwards</string>
</property>
<property name="shortcut">
<string>Shift+F10</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>

29
alethzero/MainWin.cpp

@ -868,9 +868,25 @@ void Main::on_blocks_currentItemChanged()
if (tx.data.size())
s << eth::memDump(tx.data, 16, true);
}
s << "<br/><br/>";
auto st = eth::State(m_client->state().db(), m_client->blockChain(), h);
s << renderDiff(st.pendingDiff(txi));
s << renderDiff(eth::State(m_client->state().db(), m_client->blockChain(), h).pendingDiff(txi));
m_executiveState = st.fromPending(txi);
m_currentExecution = unique_ptr<Executive>(new Executive(m_executiveState));
Transaction t = st.pending()[txi];
auto r = t.rlp();
m_pcWarp.clear();
m_history.clear();
bool done = m_currentExecution->setup(&r);
if (!done)
{
for (; !done; done = m_currentExecution->go(1))
m_history.append(WorldState({m_currentExecution->vm().curPC(), m_currentExecution->vm().gas(), m_currentExecution->vm().stack(), m_currentExecution->vm().memory(), m_currentExecution->state().storage(m_currentExecution->ext().myAddress)}));
initDebugger();
updateDebugger();
}
m_currentExecution.reset();
}
@ -1200,8 +1216,8 @@ void Main::on_debug_clicked()
t.receiveAddress = isCreation() ? Address() : fromString(ui->destination->currentText());
t.sign(s);
auto r = t.rlp();
m_currentExecution->setup(&r);
m_currentExecution->setup(&r);
m_pcWarp.clear();
m_history.clear();
bool ok = true;
@ -1234,6 +1250,11 @@ void Main::on_debugStep_triggered()
ui->debugTimeline->setValue(ui->debugTimeline->value() + 1);
}
void Main::on_debugStepback_triggered()
{
ui->debugTimeline->setValue(ui->debugTimeline->value() - 1);
}
void Main::debugFinished()
{
m_pcWarp.clear();
@ -1245,6 +1266,7 @@ void Main::debugFinished()
ui->debugStateInfo->setText("");
// ui->send->setEnabled(true);
ui->debugStep->setEnabled(false);
ui->debugStepback->setEnabled(false);
ui->debugPanel->setEnabled(false);
}
@ -1252,6 +1274,7 @@ void Main::initDebugger()
{
// ui->send->setEnabled(false);
ui->debugStep->setEnabled(true);
ui->debugStepback->setEnabled(true);
ui->debugPanel->setEnabled(true);
ui->debugCode->setEnabled(false);
ui->debugTimeline->setMinimum(0);

1
alethzero/MainWin.h

@ -101,6 +101,7 @@ private slots:
void on_quit_triggered() { close(); }
void on_urlEdit_returnPressed();
void on_debugStep_triggered();
void on_debugStepback_triggered();
void on_debug_clicked();
void on_debugTimeline_valueChanged();
void on_jsInput_returnPressed();

15
libethereum/Executive.cpp

@ -40,7 +40,7 @@ u256 Executive::gasUsed() const
return m_t.gas - m_endGas;
}
void Executive::setup(bytesConstRef _rlp)
bool Executive::setup(bytesConstRef _rlp)
{
// Entry point for a user-executed transaction.
m_t = Transaction(_rlp);
@ -95,12 +95,12 @@ void Executive::setup(bytesConstRef _rlp)
m_s.subBalance(m_sender, cost);
if (m_t.isCreation())
create(m_sender, m_t.value, m_t.gasPrice, m_t.gas - gasCost, &m_t.data, m_sender);
return create(m_sender, m_t.value, m_t.gasPrice, m_t.gas - gasCost, &m_t.data, m_sender);
else
call(m_t.receiveAddress, m_sender, m_t.value, m_t.gasPrice, bytesConstRef(&m_t.data), m_t.gas - gasCost, m_sender);
return call(m_t.receiveAddress, m_sender, m_t.value, m_t.gasPrice, bytesConstRef(&m_t.data), m_t.gas - gasCost, m_sender);
}
void Executive::call(Address _receiveAddress, Address _senderAddress, u256 _value, u256 _gasPrice, bytesConstRef _data, u256 _gas, Address _originAddress)
bool Executive::call(Address _receiveAddress, Address _senderAddress, u256 _value, u256 _gasPrice, bytesConstRef _data, u256 _gas, Address _originAddress)
{
// cnote << "Transferring" << formatBalance(_value) << "to receiver.";
m_s.addBalance(_receiveAddress, _value);
@ -110,12 +110,16 @@ void Executive::call(Address _receiveAddress, Address _senderAddress, u256 _valu
m_vm = new VM(_gas);
bytes const& c = m_s.code(_receiveAddress);
m_ext = new ExtVM(m_s, _receiveAddress, _senderAddress, _originAddress, _value, _gasPrice, _data, &c);
return false;
}
else
{
m_endGas = _gas;
return true;
}
}
void Executive::create(Address _sender, u256 _endowment, u256 _gasPrice, u256 _gas, bytesConstRef _init, Address _origin)
bool Executive::create(Address _sender, u256 _endowment, u256 _gasPrice, u256 _gas, bytesConstRef _init, Address _origin)
{
m_newAddress = right160(sha3(rlpList(_sender, m_s.transactionsFrom(_sender) - 1)));
while (m_s.addressInUse(m_newAddress))
@ -127,6 +131,7 @@ void Executive::create(Address _sender, u256 _endowment, u256 _gasPrice, u256 _g
// Execute _init.
m_vm = new VM(_gas);
m_ext = new ExtVM(m_s, m_newAddress, _sender, _origin, _endowment, _gasPrice, bytesConstRef(), _init);
return _init.empty();
}
bool Executive::go(uint64_t _steps)

6
libethereum/Executive.h

@ -40,9 +40,9 @@ public:
Executive(State& _s): m_s(_s) {}
~Executive();
void setup(bytesConstRef _transaction);
void create(Address _txSender, u256 _endowment, u256 _gasPrice, u256 _gas, bytesConstRef _code, Address _originAddress);
void call(Address _myAddress, Address _txSender, u256 _txValue, u256 _gasPrice, bytesConstRef _txData, u256 _gas, Address _originAddress);
bool setup(bytesConstRef _transaction);
bool create(Address _txSender, u256 _endowment, u256 _gasPrice, u256 _gas, bytesConstRef _code, Address _originAddress);
bool call(Address _myAddress, Address _txSender, u256 _txValue, u256 _gasPrice, bytesConstRef _txData, u256 _gas, Address _originAddress);
bool go(uint64_t _steps = (uint64_t)-1);
void finalize();
u256 gasUsed() const;

Loading…
Cancel
Save