Browse Source

- bug fix padded/unpadded CommonJS.cpp.

- bug fix instanciate child with parent in another thread.
 - misc changes.
cl-refactor
yann300 10 years ago
committed by yann300
parent
commit
19bb4ebe6f
  1. 10
      libdevcore/CommonJS.cpp
  2. 27
      mix/AssemblyDebuggerCtrl.cpp
  3. 15
      mix/AssemblyDebuggerCtrl.h
  4. 2
      mix/ConstantCompilationCtrl.cpp
  5. 34
      mix/ContractCallDataEncoder.cpp
  6. 9
      mix/DebuggingStateWrapper.cpp
  7. 37
      mix/DebuggingStateWrapper.h
  8. 2
      mix/QBasicNodeDefinition.h
  9. 2
      mix/QVariableDeclaration.h
  10. 16
      mix/QVariableDefinition.cpp
  11. 8
      mix/QVariableDefinition.h
  12. 5
      mix/TransactionListModel.cpp
  13. 6
      mix/qml/Debugger.qml
  14. 3
      mix/qml/js/Debugger.js

10
libdevcore/CommonJS.cpp

@ -49,14 +49,16 @@ bytes padded(bytes _b, unsigned _l)
bytes unpadded(bytes _b)
{
auto p = asString(_b).find_last_not_of((char)0);
auto p = asString(_b).find_first_not_of("0");
_b.resize(p == std::string::npos ? 0 : (p + 1));
return _b;
}
std::string unpadded(std::string _b)
{
auto p = _b.find_last_not_of((char)0);
auto p = _b.find_first_not_of('0');
if (p == std::string::npos)
return "0";
_b = _b.substr(p, _b.length() - 1);
return _b;
}
@ -67,9 +69,9 @@ std::string prettyU256(u256 _n)
std::string raw;
std::ostringstream s;
if (!(_n >> 64))
s << " " << (uint64_t)_n << " (0x" << (uint64_t)_n << ")";
s << " " << (uint64_t)_n << " (0x" << std::hex << (uint64_t)_n << ")";
else if (!~(_n >> 64))
s << " " << (int64_t)_n << " (0x" << (int64_t)_n << ")";
s << " " << (int64_t)_n << " (0x" << std::hex << (int64_t)_n << ")";
else if ((_n >> 160) == 0)
{
Address a = right160(_n);

27
mix/AssemblyDebuggerCtrl.cpp

@ -42,8 +42,8 @@ AssemblyDebuggerCtrl::AssemblyDebuggerCtrl(QTextDocument* _doc): Extension(Exten
qRegisterMetaType<QVariableDefinitionList*>("QVariableDefinitionList*");
qRegisterMetaType<QList<QVariableDefinition*>>("QList<QVariableDefinition*>");
qRegisterMetaType<QVariableDeclaration*>("QVariableDeclaration*");
qRegisterMetaType<AssemblyDebuggerData>();
qRegisterMetaType<DebuggingStatusResult>();
qRegisterMetaType<AssemblyDebuggerData>("AssemblyDebuggerData");
qRegisterMetaType<DebuggingStatusResult>("DebuggingStatusResult");
connect(this, SIGNAL(dataAvailable(bool, DebuggingStatusResult, QList<QVariableDefinition*>, QList<QObject*>, AssemblyDebuggerData)),
this, SLOT(updateGUI(bool, DebuggingStatusResult, QList<QVariableDefinition*>, QList<QObject*>, AssemblyDebuggerData)), Qt::QueuedConnection);
@ -79,7 +79,7 @@ void AssemblyDebuggerCtrl::keyPressed(int _key)
}
}
void AssemblyDebuggerCtrl::callContract(dev::mix::TransactionSettings _tr)
void AssemblyDebuggerCtrl::callContract(dev::mix::TransactionSettings _tr, Address _contract)
{
CompilerResult compilerRes = m_compilation.get()->compile(m_doc->toPlainText());
if (!compilerRes.success)
@ -87,10 +87,8 @@ void AssemblyDebuggerCtrl::callContract(dev::mix::TransactionSettings _tr)
AppContext::getInstance()->displayMessageDialog("debugger","compilation failed");
return;
}
ContractCallDataEncoder c;
std::shared_ptr<QContractDefinition> contractDef = QContractDefinition::Contract(m_doc->toPlainText());
QFunctionDefinition* f = nullptr;
for (int k = 0; k < contractDef.get()->functions().size(); k++)
{
@ -101,21 +99,16 @@ void AssemblyDebuggerCtrl::callContract(dev::mix::TransactionSettings _tr)
}
if (!f)
{
AppContext::getInstance()->displayMessageDialog("debugger","contract code changed. redeploy contract");
AppContext::getInstance()->displayMessageDialog(QApplication::tr("debugger"), QApplication::tr("contract code changed. Please redeploy contract"));
return;
}
c.encode(f->index());
for (int k = 0; k < f->parameters().size(); k++)
{
QVariableDeclaration* var = (QVariableDeclaration*)f->parameters().at(k);
c.encode(var, _tr.parameterValues[var->name()]);
}
DebuggingContent debuggingContent = m_modelDebugger->getContractCallDebugStates(m_previousDebugResult.contractAddress,
c.encodedData(),
_tr);
DebuggingContent debuggingContent = m_modelDebugger->getContractCallDebugStates(_contract, c.encodedData(), _tr);
debuggingContent.returnParameters = c.decode(f->returnParameters(), debuggingContent.returnValue);
finalizeExecution(debuggingContent);
}
@ -128,7 +121,6 @@ void AssemblyDebuggerCtrl::deployContract(QString _source)
emit dataAvailable(false, DebuggingStatusResult::Compilationfailed);
return;
}
m_previousDebugResult = m_modelDebugger->getContractInitiationDebugStates(compilerRes.bytes);
finalizeExecution(m_previousDebugResult);
}
@ -139,11 +131,11 @@ void AssemblyDebuggerCtrl::finalizeExecution(DebuggingContent _debuggingContent)
QList<QObject*> wStates;
for(int i = 0; i < _debuggingContent.machineStates.size(); i++)
{
DebuggingStateWrapper* s = new DebuggingStateWrapper(_debuggingContent.executionCode, _debuggingContent.executionData.toBytes(), this);
QPointer<DebuggingStateWrapper> s(new DebuggingStateWrapper(_debuggingContent.executionCode, _debuggingContent.executionData.toBytes()));
s->setState(_debuggingContent.machineStates.at(i));
wStates.append(s);
}
AssemblyDebuggerData code = DebuggingStateWrapper::getHumanReadableCode(_debuggingContent.executionCode, this);
AssemblyDebuggerData code = DebuggingStateWrapper::getHumanReadableCode(_debuggingContent.executionCode);
emit dataAvailable(true, DebuggingStatusResult::Ok, _debuggingContent.returnParameters, wStates, code);
}
@ -155,8 +147,7 @@ void AssemblyDebuggerCtrl::updateGUI(bool _success, DebuggingStatusResult _reaso
m_appEngine->rootContext()->setContextProperty("debugStates", QVariant::fromValue(_wStates));
m_appEngine->rootContext()->setContextProperty("humanReadableExecutionCode", QVariant::fromValue(std::get<0>(_code)));
m_appEngine->rootContext()->setContextProperty("bytesCodeMapping", QVariant::fromValue(std::get<1>(_code)));
m_appEngine->rootContext()->setContextProperty("contractCallReturnParameters",
QVariant::fromValue(new QVariableDefinitionList(_returnParam)));
m_appEngine->rootContext()->setContextProperty("contractCallReturnParameters", QVariant::fromValue(new QVariableDefinitionList(_returnParam)));
this->addContentOn(this);
}
else
@ -167,6 +158,6 @@ void AssemblyDebuggerCtrl::runTransaction(TransactionSettings _tr)
{
QtConcurrent::run([this, _tr]()
{
callContract(_tr);
callContract(_tr, m_previousDebugResult.contractAddress);
});
}

15
mix/AssemblyDebuggerCtrl.h

@ -14,7 +14,7 @@
/** @file AssemblyDebuggerCtrl.h
* @author Yann yann@ethdev.com
* @date 2014
* Ethereum IDE client.
* Display debugging steps in assembly code.s
*/
#pragma once
@ -55,24 +55,23 @@ public:
QString contentUrl() const override;
private:
void deployContract(QString _source);
void callContract(TransactionSettings _tr, Address _contract);
void finalizeExecution(DebuggingContent _content);
std::unique_ptr<AssemblyDebuggerModel> m_modelDebugger;
std::unique_ptr<ConstantCompilationModel> m_compilation;
DebuggingContent m_previousDebugResult; //TODO: to be replaced by more consistent struct. Used for now to keep the contract address in case of future transaction call.
QTextDocument* m_doc;
void deployContract(QString _source);
void callContract(dev::mix::TransactionSettings _contractAddress);
void finalizeExecution(DebuggingContent _content);
DebuggingContent m_previousDebugResult; //used for now to keep the contract address in case of transaction call.
public slots:
void keyPressed(int);
void updateGUI(bool _success, DebuggingStatusResult _reason, QList<QVariableDefinition*> _returnParams = QList<QVariableDefinition*>(), QList<QObject*> _wStates = QList<QObject*>(), AssemblyDebuggerData _code = AssemblyDebuggerData());
void runTransaction(dev::mix::TransactionSettings _tr);
void runTransaction(TransactionSettings _tr);
signals:
void dataAvailable(bool _success, DebuggingStatusResult _reason, QList<QVariableDefinition*> _returnParams = QList<QVariableDefinition*>(), QList<QObject*> _wStates = QList<QObject*>(), AssemblyDebuggerData _code = AssemblyDebuggerData());
};
}
}

2
mix/ConstantCompilationCtrl.cpp

@ -82,13 +82,11 @@ void ConstantCompilationCtrl::writeOutPut(CompilerResult const& _res)
status->setProperty("text", "succeeded");
status->setProperty("color", "green");
content->setProperty("text", _res.hexCode);
qDebug() << QString(QApplication::tr("compile succeeded") + " " + _res.hexCode);
}
else
{
status->setProperty("text", "failure");
status->setProperty("color", "red");
content->setProperty("text", _res.comment);
qDebug() << QString(QApplication::tr("compile failed") + " " + _res.comment);
}
}

34
mix/ContractCallDataEncoder.cpp

@ -20,6 +20,7 @@
* Ethereum IDE client.
*/
#include <QDebug>
#include <QMap>
#include <QStringList>
#include <libdevcore/CommonJS.h>
@ -37,6 +38,10 @@ ContractCallDataEncoder::ContractCallDataEncoder()
bytes ContractCallDataEncoder::encodedData()
{
std::ostringstream si;
si << std::hex << toJS(m_encodedData);
qDebug() << "encoded data";
qDebug() << si;
return m_encodedData;
}
@ -53,6 +58,9 @@ void ContractCallDataEncoder::encode(QVariableDeclaration* _dec, bool _value)
void ContractCallDataEncoder::encode(QVariableDeclaration* _dec, QString _value)
{
qDebug() << _dec->type();
qDebug() << _value;
qDebug() << "(())";
int padding = this->padding(_dec->type());
bytes data = padded(jsToBytes(_value.toStdString()), padding);
m_encodedData.insert(m_encodedData.end(), data.begin(), data.end());
@ -61,24 +69,36 @@ void ContractCallDataEncoder::encode(QVariableDeclaration* _dec, QString _value)
void ContractCallDataEncoder::encode(QVariableDeclaration* _dec, u256 _value)
{
int padding = this->padding(_dec->type());
qDebug() << _dec->type();
std::ostringstream s;
s << _value;
s << std::hex << "0x" << _value;
qDebug() << QString::fromStdString(s.str());
bytes data = padded(jsToBytes(s.str()), padding);
std::ostringstream si;
si << std::hex << toJS(data);
qDebug() << si;
m_encodedData.insert(m_encodedData.end(), data.begin(), data.end());
encodedData();
}
QList<QVariableDefinition*> ContractCallDataEncoder::decode(QList<QObject*> _returnParameters, bytes _value)
{
QList<QVariableDefinition*> r;
std::string returnValue = toJS(_value);
qDebug() << QString::fromStdString(returnValue);
returnValue = returnValue.substr(2, returnValue.length() - 1);
for (int k = 0; k <_returnParameters.length(); k++)
{
QVariableDeclaration* dec = (QVariableDeclaration*)_returnParameters.at(k);
int padding = this->padding(dec->type());
std::string rawParam = returnValue.substr(0, padding * 2);
qDebug() << QString::fromStdString(rawParam);
r.append(new QVariableDefinition(dec, convertToReadable(unpadded(rawParam), dec)));
returnValue = returnValue.substr(padding, returnValue.length() - 1);
returnValue = returnValue.substr(rawParam.length(), returnValue.length() - 1);
}
return r;
}
@ -86,7 +106,7 @@ QList<QVariableDefinition*> ContractCallDataEncoder::decode(QList<QObject*> _ret
int ContractCallDataEncoder::padding(QString type)
{
// TODO : to be improved (load types automatically from solidity library).
if (type.indexOf("uint") != 1)
if (type.indexOf("uint") != -1)
{
return integerPadding(type.remove("uint").toInt());
}
@ -139,6 +159,12 @@ QString ContractCallDataEncoder::convertToBool(std::string _v)
QString ContractCallDataEncoder::convertToInt(std::string _v)
{
return QString::fromStdString(_v);
qDebug() << "QString::fromStdString(_v);";
qDebug() << QString::fromStdString(_v);
//TO DO to be improve to manage all int, uint size (128, 256, ...)
int x = std::stol(_v, nullptr, 16);
std::stringstream ss;
ss << std::dec << x;
return QString::fromStdString(ss.str());
}

9
mix/DebuggingStateWrapper.cpp

@ -22,6 +22,7 @@
#include <QApplication>
#include <QDebug>
#include <QPointer>
#include "libevmcore/Instruction.h"
#include "libdevcore/CommonJS.h"
#include "libdevcrypto/Common.h"
@ -32,7 +33,7 @@ using namespace dev;
using namespace dev::eth;
using namespace dev::mix;
std::tuple<QList<QObject*>, QQMLMap*> DebuggingStateWrapper::getHumanReadableCode(const bytes& _code, QObject* _objUsedAsParent)
std::tuple<QList<QObject*>, QQMLMap*> DebuggingStateWrapper::getHumanReadableCode(const bytes& _code)
{
QList<QObject*> codeStr;
QMap<int, int> codeMapping;
@ -52,7 +53,7 @@ std::tuple<QList<QObject*>, QQMLMap*> DebuggingStateWrapper::getHumanReadableCod
s = "PUSH 0x" + QString::fromStdString(toHex(bytesConstRef(&_code[i + 1], bc)));
i += bc;
}
HumanReadableCode* humanCode = new HumanReadableCode(QString::fromStdString(out.str()) + " " + s, line, _objUsedAsParent);
QPointer<HumanReadableCode> humanCode(new HumanReadableCode(QString::fromStdString(out.str()) + " " + s, line));
codeStr.append(humanCode);
}
catch (...)
@ -62,7 +63,7 @@ std::tuple<QList<QObject*>, QQMLMap*> DebuggingStateWrapper::getHumanReadableCod
break; // probably hit data segment
}
}
return std::make_tuple(codeStr, new QQMLMap(codeMapping, _objUsedAsParent));
return std::make_tuple(codeStr, QPointer<QQMLMap>(new QQMLMap(codeMapping)));
}
QString DebuggingStateWrapper::gasLeft()
@ -99,7 +100,7 @@ QString DebuggingStateWrapper::debugStorage()
{
std::stringstream s;
for (auto const& i: m_state.storage)
s << "@" << prettyU256(i.first) << "&nbsp;&nbsp;&nbsp;&nbsp;" << prettyU256(i.second);
s << "@" << prettyU256(i.first) << " " << prettyU256(i.second);
return QString::fromStdString(s.str());
}

37
mix/DebuggingStateWrapper.h

@ -66,11 +66,11 @@ struct DebuggingContent
class HumanReadableCode: public QObject
{
Q_OBJECT
Q_PROPERTY(QString line READ line)
Q_PROPERTY(int processIndex READ processIndex)
Q_PROPERTY(QString line READ line CONSTANT)
Q_PROPERTY(int processIndex READ processIndex CONSTANT)
public:
HumanReadableCode(QString _line, int _processIndex, QObject* _parent): QObject(_parent), m_line(_line), m_processIndex(_processIndex) {}
HumanReadableCode(QString _line, int _processIndex): QObject(), m_line(_line), m_processIndex(_processIndex) {}
QString line() { return m_line; }
int processIndex() { return m_processIndex; }
@ -88,7 +88,7 @@ class QQMLMap: public QObject
Q_OBJECT
public:
QQMLMap(QMap<int, int> _map, QObject* _parent): QObject(_parent), m_map(_map) { }
QQMLMap(QMap<int, int> _map): QObject(), m_map(_map) { }
Q_INVOKABLE int getValue(int _key) { return m_map.value(_key); }
private:
@ -101,21 +101,21 @@ private:
class DebuggingStateWrapper: public QObject
{
Q_OBJECT
Q_PROPERTY(int step READ step)
Q_PROPERTY(int curPC READ curPC)
Q_PROPERTY(QString gasCost READ gasCost)
Q_PROPERTY(QString gas READ gas)
Q_PROPERTY(QString gasLeft READ gasLeft)
Q_PROPERTY(QString debugStack READ debugStack)
Q_PROPERTY(QString debugStorage READ debugStorage)
Q_PROPERTY(QString debugMemory READ debugMemory)
Q_PROPERTY(QString debugCallData READ debugCallData)
Q_PROPERTY(QString headerInfo READ headerInfo)
Q_PROPERTY(QString endOfDebug READ endOfDebug)
Q_PROPERTY(QStringList levels READ levels)
Q_PROPERTY(int step READ step CONSTANT)
Q_PROPERTY(int curPC READ curPC CONSTANT)
Q_PROPERTY(QString gasCost READ gasCost CONSTANT)
Q_PROPERTY(QString gas READ gas CONSTANT)
Q_PROPERTY(QString gasLeft READ gasLeft CONSTANT)
Q_PROPERTY(QString debugStack READ debugStack CONSTANT)
Q_PROPERTY(QString debugStorage READ debugStorage CONSTANT)
Q_PROPERTY(QString debugMemory READ debugMemory CONSTANT)
Q_PROPERTY(QString debugCallData READ debugCallData CONSTANT)
Q_PROPERTY(QString headerInfo READ headerInfo CONSTANT)
Q_PROPERTY(QString endOfDebug READ endOfDebug CONSTANT)
Q_PROPERTY(QStringList levels READ levels CONSTANT)
public:
DebuggingStateWrapper(bytes _code, bytes _data, QObject* _parent): QObject(_parent), m_code(_code), m_data(_data) {}
DebuggingStateWrapper(bytes _code, bytes _data): QObject(), m_code(_code), m_data(_data) {}
int step() { return (int)m_state.steps; }
int curPC() { return (int)m_state.curPC; }
QString gasLeft();
@ -130,7 +130,7 @@ public:
QStringList levels();
DebuggingState state() { return m_state; }
void setState(DebuggingState _state) { m_state = _state; }
static std::tuple<QList<QObject*>, QQMLMap*> getHumanReadableCode(bytes const& _code, QObject* _objUsedAsParent);
static std::tuple<QList<QObject*>, QQMLMap*> getHumanReadableCode(bytes const& _code);
private:
DebuggingState m_state;
@ -139,5 +139,4 @@ private:
};
}
}

2
mix/QBasicNodeDefinition.h

@ -32,7 +32,7 @@ namespace mix
class QBasicNodeDefinition: public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name)
Q_PROPERTY(QString name READ name CONSTANT)
public:
QBasicNodeDefinition(): QObject() {}

2
mix/QVariableDeclaration.h

@ -32,7 +32,7 @@ namespace mix
class QVariableDeclaration: public QBasicNodeDefinition
{
Q_OBJECT
Q_PROPERTY(QString type READ type)
Q_PROPERTY(QString type READ type CONSTANT)
public:
QVariableDeclaration(dev::solidity::VariableDeclaration* _v): QBasicNodeDefinition(_v){}

16
mix/QVariableDefinition.cpp

@ -22,17 +22,18 @@
#include "QVariableDefinition.h"
using namespace dev::mix;
int QVariableDefinitionList::rowCount(const QModelIndex& parent) const
int QVariableDefinitionList::rowCount(const QModelIndex& _parent) const
{
Q_UNUSED(_parent);
return m_def.size();
}
QVariant QVariableDefinitionList::data(const QModelIndex& index, int role) const
QVariant QVariableDefinitionList::data(const QModelIndex& _index, int _role) const
{
if (role != Qt::DisplayRole)
if (_role != Qt::DisplayRole)
return QVariant();
int i = index.row();
int i = _index.row();
if (i < 0 || i >= m_def.size())
return QVariant(QVariant::Invalid);
@ -46,10 +47,9 @@ QHash<int, QByteArray> QVariableDefinitionList::roleNames() const
return roles;
}
QVariableDefinition* QVariableDefinitionList::val(int idx)
QVariableDefinition* QVariableDefinitionList::val(int _idx)
{
if (idx < 0 || idx >= m_def.size())
if (_idx < 0 || _idx >= m_def.size())
return nullptr;
return m_def.at(idx);
return m_def.at(_idx);
}

8
mix/QVariableDefinition.h

@ -32,18 +32,18 @@ namespace mix
class QVariableDefinition: public QObject
{
Q_OBJECT
Q_PROPERTY(QString value READ value)
Q_PROPERTY(QVariableDeclaration* declaration READ declaration)
Q_PROPERTY(QString value READ value CONSTANT)
Q_PROPERTY(QVariableDeclaration* declaration READ declaration CONSTANT)
public:
QVariableDefinition(QVariableDeclaration* _def, QString _value): QObject(_def->parent()), m_value(_value), m_dec(_def) {}
QVariableDefinition(QVariableDeclaration* _def, QString _value): QObject(), m_value(_value), m_dec(_def) {}
QVariableDeclaration* declaration() const { return m_dec; }
QString value() const { return m_value; }
private:
QVariableDeclaration* m_dec;
QString m_value;
QVariableDeclaration* m_dec;
};
class QVariableDefinitionList: public QAbstractListModel

5
mix/TransactionListModel.cpp

@ -92,8 +92,7 @@ QList<TransactionParameterItem*> buildParameters(QTextDocument* _document, Trans
QList<TransactionParameterItem*> params;
try
{
QString code = _document->toPlainText().replace("\n", ""); //TODO: is this required?
std::shared_ptr<QContractDefinition> contract = QContractDefinition::Contract(code);
std::shared_ptr<QContractDefinition> contract = QContractDefinition::Contract(_document->toPlainText());
auto functions = contract->functions();
for(auto qf : functions)
{
@ -133,7 +132,7 @@ QList<QString> TransactionListModel::getFunctions()
QList<QString> functionNames;
try
{
QString code = m_document->toPlainText().replace("\n", ""); //TODO: is this required?
QString code = m_document->toPlainText();
std::shared_ptr<QContractDefinition> contract(QContractDefinition::Contract(code));
auto functions = contract->functions();
for(auto qf : functions)

6
mix/qml/Debugger.qml

@ -34,10 +34,12 @@ Rectangle {
Rectangle {
color: "transparent"
width: parent.width
anchors.horizontalCenter: parent.horizontalCenter
height: 30
ListView {
orientation: ListView.Horizontal
anchors.centerIn: parent;
width: parent.width
id: headerReturnList
delegate: renderDelegateReturnValues
}
@ -45,10 +47,10 @@ Rectangle {
id: renderDelegateReturnValues
Item {
id: wrapperItem
width: parent.width
width: 80
Text {
anchors.centerIn: parent
text: variable.declaration.name + " : " + variable.value
text: variable.declaration.name + " = " + variable.value
font.pointSize: 9
}
}

3
mix/qml/js/Debugger.js

@ -6,7 +6,6 @@
var currentSelectedState = null;
function init()
{
console.log("init");
currentSelectedState = 0;
select(currentSelectedState);
displayReturnValue();
@ -29,7 +28,6 @@ function moveSelection(incr)
function select(stateIndex)
{
console.log(stateIndex);
var state = debugStates[stateIndex];
var codeStr = bytesCodeMapping.getValue(state.curPC);
highlightSelection(codeStr);
@ -41,7 +39,6 @@ function select(stateIndex)
function highlightSelection(index)
{
console.log(index);
statesList.currentIndex = index;
}

Loading…
Cancel
Save