Browse Source

call stack

cl-refactor
arkpar 10 years ago
parent
commit
2b7c7b187d
  1. 21
      mix/DebuggingStateWrapper.cpp
  2. 9
      mix/DebuggingStateWrapper.h
  3. 4
      mix/MixClient.cpp
  4. 2
      mix/MixClient.h
  5. 31
      mix/qml/CallStack.qml
  6. 18
      mix/qml/Debugger.qml
  7. 2
      mix/qml/TransactionLog.qml
  8. 50
      mix/qml/js/Debugger.js
  9. 3
      mix/res.qrc

21
mix/DebuggingStateWrapper.cpp

@ -144,18 +144,17 @@ QCallData* QMachineState::getDebugCallData(QObject* _owner, bytes const& _data)
return new QCallData(_owner, memDumpToList(_data, 16));
}
QStringList QMachineState::levels()
QVariantList QMachineState::levels()
{
QStringList levelsStr;
for (unsigned i = 0; i <= m_state.levels.size(); ++i)
{
std::ostringstream out;
out << m_state.address.abridged();
if (i)
out << " " << instructionInfo(m_state.inst).name << " @0x" << std::hex << m_state.curPC;
levelsStr.append(QString::fromStdString(out.str()));
}
return levelsStr;
QVariantList levelList;
for (unsigned l: m_state.levels)
levelList.push_back(l);
return levelList;
}
QString QMachineState::address()
{
return QString::fromStdString(toString(m_state.address));
}
QString QMachineState::instruction()

9
mix/DebuggingStateWrapper.h

@ -110,6 +110,7 @@ class QMachineState: public QObject
Q_PROPERTY(QBigInt* gasCost READ gasCost CONSTANT)
Q_PROPERTY(QBigInt* gas READ gas CONSTANT)
Q_PROPERTY(QString instruction READ instruction CONSTANT)
Q_PROPERTY(QString address READ address CONSTANT)
Q_PROPERTY(QStringList debugStack READ debugStack CONSTANT)
Q_PROPERTY(QStringList debugStorage READ debugStorage CONSTANT)
Q_PROPERTY(QVariantList debugMemory READ debugMemory CONSTANT)
@ -117,7 +118,7 @@ class QMachineState: public QObject
Q_PROPERTY(QObject* callData MEMBER m_callData CONSTANT)
Q_PROPERTY(QString endOfDebug READ endOfDebug CONSTANT)
Q_PROPERTY(QBigInt* newMemSize READ newMemSize CONSTANT)
Q_PROPERTY(QStringList levels READ levels CONSTANT)
Q_PROPERTY(QVariantList levels READ levels CONSTANT)
Q_PROPERTY(unsigned codeIndex READ codeIndex CONSTANT)
Q_PROPERTY(unsigned dataIndex READ dataIndex CONSTANT)
@ -132,6 +133,8 @@ public:
unsigned codeIndex() { return m_state.codeIndex; }
/// Get the call data id
unsigned dataIndex() { return m_state.dataIndex; }
/// Get address for call stack
QString address();
/// Get gas cost.
QBigInt* gasCost();
/// Get gas used.
@ -142,8 +145,6 @@ public:
QStringList debugStorage();
/// Get memory.
QVariantList debugMemory();
/// Get call data.
QString headerInfo();
/// get end of debug information.
QString endOfDebug();
/// Get the new memory size.
@ -151,7 +152,7 @@ public:
/// Get current instruction
QString instruction();
/// Get all previous steps.
QStringList levels();
QVariantList levels();
/// Get the current processed machine state.
MachineState state() { return m_state; }
/// Set the current processed machine state.

4
mix/MixClient.cpp

@ -64,7 +64,7 @@ void MixClient::executeTransaction(Transaction const& _t, State& _state)
Executive execution(_state, LastHashes(), 0);
execution.setup(&rlp);
std::vector<MachineState> machineStates;
std::vector<MachineState const*> levels;
std::vector<unsigned> levels;
std::vector<bytes> codes;
std::map<bytes const*, unsigned> codeIndexes;
std::vector<bytes> data;
@ -106,7 +106,7 @@ void MixClient::executeTransaction(Transaction const& _t, State& _state)
}
if (levels.size() < ext.depth)
levels.push_back(&machineStates.back());
levels.push_back(machineStates.size() - 1);
else
levels.resize(ext.depth);

2
mix/MixClient.h

@ -47,7 +47,7 @@ struct MachineState
dev::bytes memory;
dev::bigint gasCost;
std::map<dev::u256, dev::u256> storage;
std::vector<MachineState const*> levels;
std::vector<unsigned> levels;
unsigned codeIndex;
unsigned dataIndex;
};

31
mix/qml/CallStack.qml

@ -0,0 +1,31 @@
import QtQuick 2.2
import QtQuick.Controls.Styles 1.1
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
Item {
property alias model: callTable.model
signal frameActivated(int index)
ColumnLayout {
anchors.fill: parent
Text {
text: qsTr("Call Stack")
Layout.fillWidth: true
}
TableView {
id: callTable
Layout.fillWidth: true
Layout.fillHeight: true
headerDelegate: null
TableViewColumn {
role: "modelData"
title: qsTr("Address")
width: parent.width
}
onActivated: {
frameActivated(row);
}
}
}
}

18
mix/qml/Debugger.qml

@ -444,6 +444,24 @@ Rectangle {
orientation: Qt.Vertical
width: debugPanel.width - 2 * machineStates.sideMargin
Rectangle
{
id: callStackRect;
color: "transparent"
height: 120
width: parent.width
Layout.minimumHeight: 120
Layout.maximumHeight: 400
CallStack {
anchors.fill: parent
id: callStack
onFrameActivated: Debugger.displayFrame(index);
}
}
Rectangle
{
id: storageRect

2
mix/qml/TransactionLog.qml

@ -55,7 +55,7 @@ Item {
}
onActivated: {
var item = logModel.get(row);
clientModel.debugTransaction(item.block, item.index);
clientModel.debugTransaction(item.block, item.tindex);
}
Keys.onPressed: {
if ((event.modifiers & Qt.ControlModifier) && event.key === Qt.Key_C && currentRow >=0 && currentRow < logModel.count) {

50
mix/qml/js/Debugger.js

@ -2,6 +2,7 @@
//statesList => ListView
var currentSelectedState = null;
var currentDisplayedState = null;
var debugData = null;
var codeMap = null;
@ -19,20 +20,23 @@ function init(data)
statesSlider.maximumValue = 0;
statesSlider.value = 0;
currentSelectedState = null;
currentDisplayedState = null;
debugData = null;
return;
}
debugData = data;
statesSlider.maximumValue = data.states.length - 1;
statesSlider.value = 0;
currentSelectedState = 0;
currentDisplayedState = 0;
setupInstructions(currentSelectedState);
setupCallData(currentSelectedState);
statesSlider.maximumValue = data.states.length - 1;
statesSlider.value = 0;
select(currentSelectedState);
}
function setupInstructions(stateIndex) {
function setupInstructions(stateIndex)
{
var instructions = debugData.states[stateIndex].code.instructions;
codeMap = {};
statesList.model.clear();
@ -43,6 +47,11 @@ function setupInstructions(stateIndex) {
callDataDump.listModel = debugData.states[stateIndex].callData.items;
}
function setupCallData(stateIndex)
{
callDataDump.listModel = debugData.states[stateIndex].callData.items;
}
function moveSelection(incr)
{
var prevState = currentSelectedState;
@ -53,27 +62,52 @@ function moveSelection(incr)
}
}
function select(stateIndex)
function display(stateIndex)
{
if (stateIndex < 0)
stateIndex = 0;
if (stateIndex >= debugData.states.length)
stateIndex = debugData.state.length - 1;
if (debugData.states[stateIndex].codeIndex !== debugData.states[currentSelectedState].codeIndex)
if (debugData.states[stateIndex].codeIndex !== debugData.states[currentDisplayedState].codeIndex)
setupInstructions(stateIndex);
currentSelectedState = stateIndex;
if (debugData.states[stateIndex].dataIndex !== debugData.states[currentDisplayedState].dataIndex)
setupCallData(stateIndex);
var codeLine = codeStr(stateIndex);
var state = debugData.states[stateIndex];
highlightSelection(codeLine);
completeCtxInformation(state);
currentDisplayedState = stateIndex;
}
function displayFrame(frameIndex)
{
var state = debugData.states[currentSelectedState];
if (frameIndex === 0)
display(currentSelectedState);
else
display(state.levels[frameIndex - 1]);
}
statesSlider.value = currentSelectedState;
function select(stateIndex)
{
display(stateIndex);
currentSelectedState = stateIndex;
var state = debugData.states[stateIndex];
statesSlider.value = stateIndex;
jumpIntoForwardAction.enabled(stateIndex < debugData.states.length - 1)
jumpIntoBackAction.enabled(stateIndex > 0);
jumpOverForwardAction.enabled(stateIndex < debugData.states.length - 1);
jumpOverBackAction.enabled(stateIndex > 0);
jumpOutBackAction.enabled(state.levels.length > 1);
jumpOutForwardAction.enabled(state.levels.length > 1);
var callStackData = [];
for (var l = 0; l < state.levels.length; l++) {
var address = debugData.states[state.levels[l] + 1].address;
callStackData.push(address);
}
callStackData.push(debugData.states[0].address);
callStack.model = callStackData;
}
function codeStr(stateIndex)

3
mix/res.qrc

@ -50,6 +50,7 @@
<file>stdc/namereg.sol</file>
<file>stdc/std.sol</file>
<file>qml/TransactionLog.qml</file>
<file>res/mix_256x256x32.png</file>
<file>res/mix_256x256x32.png</file>
<file>qml/CallStack.qml</file>
</qresource>
</RCC>

Loading…
Cancel
Save