Browse Source

- Move memDumpToList into mix project (and list replace by vector).

- Add comments.
 - Coding Standards.
cl-refactor
yann300 10 years ago
committed by yann300
parent
commit
06ac786317
  1. 57
      libdevcore/CommonIO.cpp
  2. 5
      libdevcore/CommonIO.h
  3. 1
      mix/CodeEditorExtensionManager.h
  4. 46
      mix/DebuggingStateWrapper.cpp
  5. 6
      mix/DebuggingStateWrapper.h
  6. 1
      mix/qml.qrc
  7. 12
      mix/qml/Debugger.qml
  8. 28
      mix/qml/js/Debugger.js
  9. 0
      mix/qml/js/main.js

57
libdevcore/CommonIO.cpp

@ -26,67 +26,30 @@
using namespace std;
using namespace dev;
std::list<std::list<std::string>> dev::memDumpToList(bytes const& _b, unsigned _w)
{
std::list<std::list<std::string>> dump;
for (unsigned i = 0; i < _b.size(); i += _w)
{
stringstream ret;
std::list<std::string> dumpLine;
ret << hex << setw(4) << setfill('0') << i << " ";
dumpLine.push_back(ret.str());
ret.str(std::string());
ret.clear();
for (unsigned j = i; j < i + _w; ++j)
if (j < _b.size())
if (_b[j] >= 32 && _b[j] < 127)
if ((char)_b[j] == '<')
ret << "&lt;";
else if ((char)_b[j] == '&')
ret << "&amp;";
else
ret << (char)_b[j];
else
ret << '?';
else
ret << ' ';
dumpLine.push_back(ret.str());
ret.str(std::string());
ret.clear();
for (unsigned j = i; j < i + _w && j < _b.size(); ++j)
ret << setfill('0') << setw(2) << hex << (unsigned)_b[j] << " ";
dumpLine.push_back(ret.str());
dump.push_back(dumpLine);
}
return dump;
}
string dev::memDump(bytes const& _b, unsigned _w, bool _html)
string dev::memDump(bytes const& _bytes, unsigned _width, bool _html)
{
stringstream ret;
if (_html)
ret << "<pre style=\"font-family: Monospace,Lucida Console,Courier,Courier New,sans-serif; font-size: small\">";
for (unsigned i = 0; i < _b.size(); i += _w)
for (unsigned i = 0; i < _bytes.size(); i += _width)
{
ret << hex << setw(4) << setfill('0') << i << " ";
for (unsigned j = i; j < i + _w; ++j)
if (j < _b.size())
if (_b[j] >= 32 && _b[j] < 127)
if ((char)_b[j] == '<' && _html)
for (unsigned j = i; j < i + _width; ++j)
if (j < _bytes.size())
if (_bytes[j] >= 32 && _bytes[j] < 127)
if ((char)_bytes[j] == '<' && _html)
ret << "&lt;";
else if ((char)_b[j] == '&' && _html)
else if ((char)_bytes[j] == '&' && _html)
ret << "&amp;";
else
ret << (char)_b[j];
ret << (char)_bytes[j];
else
ret << '?';
else
ret << ' ';
ret << " ";
for (unsigned j = i; j < i + _w && j < _b.size(); ++j)
ret << setfill('0') << setw(2) << hex << (unsigned)_b[j] << " ";
for (unsigned j = i; j < i + _width && j < _bytes.size(); ++j)
ret << setfill('0') << setw(2) << hex << (unsigned)_bytes[j] << " ";
ret << "\n";
}
if (_html)

5
libdevcore/CommonIO.h

@ -47,9 +47,8 @@ bytes contents(std::string const& _file);
void writeFile(std::string const& _file, bytes const& _data);
/// Nicely renders the given bytes to a string, optionally as HTML.
std::string memDump(bytes const& _b, unsigned _w = 8, bool _html = false);
/// Nicely renders the given bytes to a string, store the content in an array.
std::list<std::list<std::string>> memDumpToList(bytes const& _b, unsigned _w);
/// @a _bytes: bytes array to be rendered as string. @a _width of a bytes line.
std::string memDump(bytes const& _bytes, unsigned _width = 8, bool _html = false);
// Stream I/O functions.
// Provides templated stream I/O for all STL collections so they can be shifted on to any iostream-like interface.

1
mix/CodeEditorExtensionManager.h

@ -65,7 +65,6 @@ private:
QVector<std::shared_ptr<Extension>> m_features;
QQuickItem* m_headerView;
QQuickItem* m_rightView;
QTextDocument* m_doc;
AppContext* m_appContext;
void loadEditor(QQuickItem* _editor);
};

46
mix/DebuggingStateWrapper.cpp

@ -110,7 +110,7 @@ QStringList DebuggingStateWrapper::debugStorage()
QVariantList DebuggingStateWrapper::debugMemory()
{
std::list<std::list<std::string>> dump = memDumpToList(m_state.memory, 16);
std::vector<std::vector<std::string>> dump = memDumpToList(m_state.memory, 16);
QStringList filled;
filled.append(" ");
filled.append(" ");
@ -120,7 +120,7 @@ QVariantList DebuggingStateWrapper::debugMemory()
QVariantList DebuggingStateWrapper::debugCallData()
{
std::list<std::list<std::string>> dump = memDumpToList(m_data, 16);
std::vector<std::vector<std::string>> dump = memDumpToList(m_data, 16);
QStringList filled;
filled.append(" ");
filled.append(" ");
@ -128,13 +128,45 @@ QVariantList DebuggingStateWrapper::debugCallData()
return fillList(qVariantDump(dump), QVariant(filled));
}
QVariantList DebuggingStateWrapper::qVariantDump(std::list<std::list<std::string>> const& _dump)
std::vector<std::vector<std::string>> DebuggingStateWrapper::memDumpToList(bytes const& _bytes, unsigned _width)
{
std::vector<std::vector<std::string>> dump;
for (unsigned i = 0; i < _bytes.size(); i += _width)
{
std::stringstream ret;
std::vector<std::string> dumpLine;
ret << std::hex << std::setw(4) << std::setfill('0') << i << " ";
dumpLine.push_back(ret.str());
ret.str(std::string());
ret.clear();
for (unsigned j = i; j < i + _width; ++j)
if (j < _bytes.size())
if (_bytes[j] >= 32 && _bytes[j] < 127)
ret << (char)_bytes[j];
else
ret << '?';
else
ret << ' ';
dumpLine.push_back(ret.str());
ret.str(std::string());
ret.clear();
for (unsigned j = i; j < i + _width && j < _bytes.size(); ++j)
ret << std::setfill('0') << std::setw(2) << std::hex << (unsigned)_bytes[j] << " ";
dumpLine.push_back(ret.str());
dump.push_back(dumpLine);
}
return dump;
}
QVariantList DebuggingStateWrapper::qVariantDump(std::vector<std::vector<std::string>> const& _dump)
{
QVariantList ret;
for (std::list<std::string> line: _dump)
for (std::vector<std::string> const& line: _dump)
{
QStringList qLine;
for (std::string cell: line)
for (std::string const& cell: line)
qLine.push_back(QString::fromStdString(cell));
ret.append(QVariant(qLine));
}
@ -185,9 +217,7 @@ QString DebuggingStateWrapper::headerInfo()
QString DebuggingStateWrapper::instruction()
{
std::ostringstream ss;
ss << dev::eth::instructionInfo(m_state.inst).name;
return QString::fromStdString(ss.str());
return QString::fromStdString(dev::eth::instructionInfo(m_state.inst).name);
}
QString DebuggingStateWrapper::endOfDebug()

6
mix/DebuggingStateWrapper.h

@ -136,7 +136,11 @@ private:
bytes m_data;
QStringList fillList(QStringList& _list, QString const& _emptyValue);
QVariantList fillList(QVariantList _list, QVariant const& _emptyValue);
QVariantList qVariantDump(std::list<std::list<std::string>> const& _dump);
QVariantList qVariantDump(std::vector<std::vector<std::string>> const& _dump);
/// Nicely renders the given bytes to a string, store the content in an array.
/// @a _bytes: bytes array to be rendered as string. @a _width of a bytes line.
std::vector<std::vector<std::string>> memDumpToList(bytes const& _bytes, unsigned _width);
};
}

1
mix/qml.qrc

@ -10,7 +10,6 @@
<file>qml/ProjectList.qml</file>
<file>qml/StateDialog.qml</file>
<file>qml/StateList.qml</file>
<file>qml/js/main.js</file>
<file>qml/img/jumpintoback.png</file>
<file>qml/img/jumpintoforward.png</file>
<file>qml/img/jumpoutback.png</file>

12
mix/qml/Debugger.qml

@ -133,7 +133,7 @@ Rectangle {
spacing: 3
StepActionImage
{
id: jumpoutbackaction;
id: jumpOutBackAction;
enabledStateImg: "qrc:/qml/img/jumpoutback.png"
disableStateImg: "qrc:/qml/img/jumpoutbackdisabled.png"
onClicked: Debugger.stepOutBack()
@ -143,7 +143,7 @@ Rectangle {
StepActionImage
{
id: jumpintobackaction
id: jumpIntoBackAction
enabledStateImg: "qrc:/qml/img/jumpintoback.png"
disableStateImg: "qrc:/qml/img/jumpintobackdisabled.png"
onClicked: Debugger.stepIntoBack()
@ -153,7 +153,7 @@ Rectangle {
StepActionImage
{
id: jumpoverbackaction
id: jumpOverBackAction
enabledStateImg: "qrc:/qml/img/jumpoverback.png"
disableStateImg: "qrc:/qml/img/jumpoverbackdisabled.png"
onClicked: Debugger.stepOverBack()
@ -163,7 +163,7 @@ Rectangle {
StepActionImage
{
id: jumpoverforwardaction
id: jumpOverForwardAction
enabledStateImg: "qrc:/qml/img/jumpoverforward.png"
disableStateImg: "qrc:/qml/img/jumpoverforwarddisabled.png"
onClicked: Debugger.stepOverForward()
@ -173,7 +173,7 @@ Rectangle {
StepActionImage
{
id: jumpintoforwardaction
id: jumpIntoForwardAction
enabledStateImg: "qrc:/qml/img/jumpintoforward.png"
disableStateImg: "qrc:/qml/img/jumpintoforwarddisabled.png"
onClicked: Debugger.stepIntoForward()
@ -183,7 +183,7 @@ Rectangle {
StepActionImage
{
id: jumpoutforwardaction
id: jumpOutForwardAction
enabledStateImg: "qrc:/qml/img/jumpoutforward.png"
disableStateImg: "qrc:/qml/img/jumpoutforwarddisabled.png"
onClicked: Debugger.stepOutForward()

28
mix/qml/js/Debugger.js

@ -16,10 +16,10 @@ function init()
currentSelectedState = 0;
select(currentSelectedState);
jumpoutbackaction.enabled(false);
jumpintobackaction.enabled(false);
jumpintoforwardaction.enabled(false);
jumpoutforwardaction.enabled(false);
jumpOutBackAction.enabled(false);
jumpIntoBackAction.enabled(false);
jumpIntoForwardAction.enabled(false);
jumpOutForwardAction.enabled(false);
}
function moveSelection(incr)
@ -41,14 +41,14 @@ function select(stateIndex)
completeCtxInformation(state);
if (state.instruction === "JUMP")
jumpintoforwardaction.enabled(true);
jumpIntoForwardAction.enabled(true);
else
jumpintoforwardaction.enabled(false);
jumpIntoForwardAction.enabled(false);
if (state.instruction === "JUMPDEST")
jumpintobackaction.enabled(true);
jumpIntoBackAction.enabled(true);
else
jumpintobackaction.enabled(false);
jumpIntoBackAction.enabled(false);
}
function codeStr(stateIndex)
@ -87,8 +87,8 @@ function stepOutBack()
{
select(jumpStartingPoint);
jumpStartingPoint = null;
jumpoutbackaction.enabled(false);
jumpoutforwardaction.enabled(false);
jumpOutBackAction.enabled(false);
jumpOutForwardAction.enabled(false);
}
}
@ -142,8 +142,8 @@ function stepIntoForward()
{
jumpStartingPoint = currentSelectedState;
moveSelection(1);
jumpoutbackaction.enabled(true);
jumpoutforwardaction.enabled(true);
jumpOutBackAction.enabled(true);
jumpOutForwardAction.enabled(true);
}
}
@ -153,8 +153,8 @@ function stepOutForward()
{
stepOutBack();
stepOverForward();
jumpoutbackaction.enabled(false);
jumpoutforwardaction.enabled(false);
jumpOutBackAction.enabled(false);
jumpOutForwardAction.enabled(false);
}
}

0
mix/qml/js/main.js

Loading…
Cancel
Save