Browse Source

- Send String value to QML instead of int value (gas, gasCost,

gasLeft).
 - Wrap label with QApplication::tr (localization).
 - Use of std::hex, std::dec instead of QTextStream (to avoid warning).
cl-refactor
yann300 10 years ago
parent
commit
d76b3f472e
  1. 41
      mix/DebuggingStateWrapper.cpp
  2. 10
      mix/DebuggingStateWrapper.h
  3. 5
      mix/qml/js/Debugger.js

41
mix/DebuggingStateWrapper.cpp

@ -20,9 +20,8 @@
* Used to translate c++ type (u256, bytes, ...) into friendly value (to be used by QML).
*/
#include <QApplication>
#include <QDebug>
#include <QString>
#include <QTextStream>
#include "libevmcore/Instruction.h"
#include "libdevcore/CommonJS.h"
#include "libdevcrypto/Common.h"
@ -44,7 +43,7 @@ std::tuple<QList<QObject*>, QQMLMap*> DebuggingStateWrapper::getHumanReadableCod
{
QString s = QString::fromStdString(instructionInfo((Instruction)b).name);
std::ostringstream out;
out << hex << std::setw(4) << std::setfill('0') << i;
out << std::hex << std::setw(4) << std::setfill('0') << i;
codeMapping[i] = codeStr.size();
int line = i;
if (b >= (byte)Instruction::PUSH1 && b <= (byte)Instruction::PUSH32)
@ -66,6 +65,27 @@ std::tuple<QList<QObject*>, QQMLMap*> DebuggingStateWrapper::getHumanReadableCod
return std::make_tuple(codeStr, new QQMLMap(codeMapping, _objUsedAsParent));
}
QString DebuggingStateWrapper::gasLeft()
{
std::ostringstream ss;
ss << std::dec << (m_state.gas - m_state.gasCost);
return QString::fromStdString(ss.str());
}
QString DebuggingStateWrapper::gasCost()
{
std::ostringstream ss;
ss << std::dec << m_state.gasCost;
return QString::fromStdString(ss.str());
}
QString DebuggingStateWrapper::gas()
{
std::ostringstream ss;
ss << std::dec << m_state.gas;
return QString::fromStdString(ss.str());
}
QString DebuggingStateWrapper::debugStack()
{
QString stack;
@ -99,11 +119,10 @@ QStringList DebuggingStateWrapper::levels()
QStringList levelsStr;
for (unsigned i = 0; i <= m_state.levels.size(); ++i)
{
DebuggingState const& s = i ? *m_state.levels[m_state.levels.size() - i] : m_state;
std::ostringstream out;
out << m_state.cur.abridged();
if (i)
out << " " << instructionInfo(m_state.inst).name << " @0x" << hex << m_state.curPC;
out << " " << instructionInfo(m_state.inst).name << " @0x" << std::hex << m_state.curPC;
levelsStr.append(QString::fromStdString(out.str()));
}
return levelsStr;
@ -112,14 +131,14 @@ QStringList DebuggingStateWrapper::levels()
QString DebuggingStateWrapper::headerInfo()
{
std::ostringstream ss;
ss << dec << " STEP: " << m_state.steps << " | PC: 0x" << hex << m_state.curPC << " : " << dev::eth::instructionInfo(m_state.inst).name << " | ADDMEM: " << dec << m_state.newMemSize << " words | COST: " << dec << m_state.gasCost << " | GAS: " << dec << m_state.gas;
ss << std::dec << " " << QApplication::tr("STEP").toStdString() << " : " << m_state.steps << " | PC: 0x" << std::hex << m_state.curPC << " : " << dev::eth::instructionInfo(m_state.inst).name << " | ADDMEM: " << std::dec << m_state.newMemSize << " " << QApplication::tr("words").toStdString() << " | " << QApplication::tr("COST").toStdString() << " : " << std::dec << m_state.gasCost << " | " << QApplication::tr("GAS").toStdString() << " : " << std::dec << m_state.gas;
return QString::fromStdString(ss.str());
}
QString DebuggingStateWrapper::endOfDebug()
{
if (m_state.gasCost > m_state.gas)
return "OUT-OF-GAS";
return QApplication::tr("OUT-OF-GAS");
else if (m_state.inst == Instruction::RETURN && m_state.stack.size() >= 2)
{
unsigned from = (unsigned)m_state.stack.back();
@ -128,12 +147,12 @@ QString DebuggingStateWrapper::endOfDebug()
bytes out(size, 0);
for (; o < size && from + o < m_state.memory.size(); ++o)
out[o] = m_state.memory[from + o];
return "RETURN " + QString::fromStdString(dev::memDump(out, 16, false));
return QApplication::tr("RETURN") + " " + QString::fromStdString(dev::memDump(out, 16, false));
}
else if (m_state.inst == Instruction::STOP)
return "STOP";
return QApplication::tr("STOP");
else if (m_state.inst == Instruction::SUICIDE && m_state.stack.size() >= 1)
return "SUICIDE 0x" + QString::fromStdString(toString(right160(m_state.stack.back())));
return QApplication::tr("SUICIDE") + " 0x" + QString::fromStdString(toString(right160(m_state.stack.back())));
else
return "EXCEPTION";
return QApplication::tr("EXCEPTION");
}

10
mix/DebuggingStateWrapper.h

@ -99,8 +99,9 @@ class DebuggingStateWrapper: public QObject
Q_OBJECT
Q_PROPERTY(int step READ step)
Q_PROPERTY(int curPC READ curPC)
Q_PROPERTY(int gasCost READ gasCost)
Q_PROPERTY(int gas READ gas)
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)
@ -113,8 +114,9 @@ public:
DebuggingStateWrapper(bytes _code, bytes _data, QObject* _parent): QObject(_parent), m_code(_code), m_data(_data) {}
int step() { return (int)m_state.steps; }
int curPC() { return (int)m_state.curPC; }
int gasCost() { return (int)m_state.gasCost; }
int gas() { return (int)m_state.gas; }
QString gasLeft();
QString gasCost();
QString gas();
QString debugStack();
QString debugStorage();
QString debugMemory();

5
mix/qml/js/Debugger.js

@ -57,7 +57,6 @@ function endOfDebug()
debugStorageTxt.text = "";
debugCallDataTxt.text = "";
debugStackTxt.text = "";
debugMemoryTxt.text = state.endOfDebug
var gascost = state.gas - state.gasCost;
headerInfoLabel.text = "EXIT | GAS: " + gascost;
debugMemoryTxt.text = state.endOfDebug;
headerInfoLabel.text = "EXIT | GAS: " + state.gasLeft;
}

Loading…
Cancel
Save