forked from carver/mix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DebuggingStateWrapper.h
204 lines (178 loc) · 5.93 KB
/
DebuggingStateWrapper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file DebuggingStateWrapper.h
* @author Yann [email protected]
* @date 2014
* Ethereum IDE client.
*/
#pragma once
// Make sure boost/asio.hpp is included before windows.h.
#include <boost/asio.hpp>
#include <QStringList>
#include <QHash>
#include <libdevcore/Common.h>
#include <libethereum/State.h>
#include <libethereum/Executive.h>
#include "MachineStates.h"
#include "QVariableDefinition.h"
#include "QBigInt.h"
namespace dev
{
namespace mix
{
/**
* @brief Contains the line nb of the assembly code and the corresponding index in the code bytes array.
*/
class QInstruction: public QObject
{
Q_OBJECT
Q_PROPERTY(QString line MEMBER m_line CONSTANT)
public:
QInstruction(QObject* _owner, QString _line): QObject(_owner), m_line(_line) {}
private:
QString m_line;
};
/**
* @brief Solidity state
*/
class QSolState: public QObject
{
Q_OBJECT
Q_PROPERTY(QVariantMap storage MEMBER m_storage CONSTANT)
Q_PROPERTY(QVariantList callStack MEMBER m_callStack CONSTANT)
Q_PROPERTY(QVariantMap locals MEMBER m_locals CONSTANT)
Q_PROPERTY(int start MEMBER m_start CONSTANT)
Q_PROPERTY(int end MEMBER m_end CONSTANT)
Q_PROPERTY(QString sourceName MEMBER m_sourceName CONSTANT)
public:
QSolState(QObject* _parent, QVariantMap&& _storage, QVariantList&& _callStack, QVariantMap&& _locals, int _start, int _end, QString _sourceName):
QObject(_parent), m_storage(_storage), m_callStack(_callStack), m_locals(_locals), m_start(_start), m_end(_end), m_sourceName(_sourceName)
{ }
private:
QVariantMap m_storage;
QVariantList m_callStack;
QVariantMap m_locals;
int m_start;
int m_end;
QString m_sourceName;
};
/**
* @brief Shared container for lines
*/
class QCode: public QObject
{
Q_OBJECT
Q_PROPERTY(QVariantList instructions MEMBER m_instructions CONSTANT)
Q_PROPERTY(QString address MEMBER m_address CONSTANT)
Q_PROPERTY(QString documentId MEMBER m_document CONSTANT)
public:
QCode(QObject* _owner, QString const& _address, QVariantList&& _instrunctions): QObject(_owner), m_instructions(_instrunctions), m_address(_address) {}
void setDocument(QString const& _documentId) { m_document = _documentId; }
private:
QVariantList m_instructions;
QString m_address;
QString m_document;
};
/**
* @brief Shared container for call data
*/
class QCallData: public QObject
{
Q_OBJECT
Q_PROPERTY(QVariantList items MEMBER m_items CONSTANT)
public:
QCallData(QObject* _owner, QVariantList&& _items): QObject(_owner), m_items(_items) {}
private:
QVariantList m_items;
};
/**
* @brief Shared container for machine states
*/
class QDebugData: public QObject
{
Q_OBJECT
Q_PROPERTY(QVariantList states MEMBER m_states CONSTANT)
public:
QDebugData() { }
void setStates(QVariantList&& _states) { m_states = _states; }
private:
QVariantList m_states;
};
/**
* @brief Wrap MachineState in QObject
*/
class QMachineState: public QObject
{
Q_OBJECT
Q_PROPERTY(int step READ step CONSTANT)
Q_PROPERTY(int curPC READ curPC CONSTANT)
Q_PROPERTY(int instructionIndex MEMBER m_instructionIndex CONSTANT)
Q_PROPERTY(QBigInt* gasCost READ gasCost CONSTANT)
Q_PROPERTY(QBigInt* gas READ gas CONSTANT)
Q_PROPERTY(QString instruction READ instruction CONSTANT)
Q_PROPERTY(QStringList debugStack READ debugStack CONSTANT)
Q_PROPERTY(QStringList debugStorage READ debugStorage CONSTANT)
Q_PROPERTY(QVariantList debugMemory READ debugMemory CONSTANT)
Q_PROPERTY(QObject* code MEMBER m_code CONSTANT)
Q_PROPERTY(QObject* callData MEMBER m_callData CONSTANT)
Q_PROPERTY(QString endOfDebug READ endOfDebug CONSTANT)
Q_PROPERTY(QBigInt* newMemSize READ newMemSize CONSTANT)
Q_PROPERTY(QVariantList levels READ levels CONSTANT)
Q_PROPERTY(unsigned codeIndex READ codeIndex CONSTANT)
Q_PROPERTY(unsigned dataIndex READ dataIndex CONSTANT)
Q_PROPERTY(QObject* solidity MEMBER m_solState CONSTANT)
public:
QMachineState(QObject* _owner, int _instructionIndex, MachineState const& _state, QCode* _code, QCallData* _callData, QSolState* _solState):
QObject(_owner), m_instructionIndex(_instructionIndex), m_state(_state), m_code(_code), m_callData(_callData), m_solState(_solState) { }
/// Get the step of this machine states.
int step() { return (int)m_state.steps; }
/// Get the proccessed code index.
int curPC() { return (int)m_state.curPC; }
/// Get the code id
unsigned codeIndex() { return m_state.codeIndex; }
/// Get the call data id
unsigned dataIndex() { return m_state.dataIndex; }
/// Get gas cost.
QBigInt* gasCost();
/// Get gas used.
QBigInt* gas();
/// Get stack.
QStringList debugStack();
/// Get storage.
QStringList debugStorage();
/// Get memory.
QVariantList debugMemory();
/// Get end of debug information.
QString endOfDebug();
/// Get the new memory size.
QBigInt* newMemSize();
/// Get current instruction
QString instruction();
/// Get all previous steps.
QVariantList levels();
/// Get the current processed machine state.
MachineState const& state() const { return m_state; }
/// Convert all machine states in human readable code.
static QCode* getHumanReadableCode(QObject* _owner, const Address& _address, const bytes& _code, QHash<int, int>& o_codeMap);
/// Convert call data into human readable form
static QCallData* getDebugCallData(QObject* _owner, bytes const& _data);
private:
int m_instructionIndex;
MachineState m_state;
QCode* m_code;
QCallData* m_callData;
QSolState* m_solState;
};
}
}