Browse Source

- store memory dump in list instead of raw string, use the list as QML

model.
 - UI: layout of step button.
cl-refactor
yann300 10 years ago
committed by yann300
parent
commit
6845bb908e
  1. 43
      libdevcore/CommonIO.cpp
  2. 4
      libdevcore/CommonIO.h
  3. 11
      mix/AssemblyDebuggerControl.cpp
  4. 1
      mix/CodeEditorExtensionManager.cpp
  5. 45
      mix/DebuggingStateWrapper.cpp
  6. 10
      mix/DebuggingStateWrapper.h
  7. 1
      mix/qml/CodeEditor.qml
  8. 1
      mix/qml/CodeEditorView.qml
  9. 12
      mix/qml/Debugger.qml
  10. 14
      mix/qml/ItemDelegateDataDump.qml
  11. 7
      mix/qml/StepActionImage.qml

43
libdevcore/CommonIO.cpp

@ -26,14 +26,51 @@
using namespace std;
using namespace dev;
string dev::memDump(bytes const& _b, unsigned _w, bool _html, string _separator)
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)
{
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)
{
ret << hex << setw(4) << setfill('0') << i << _separator;
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)
@ -47,7 +84,7 @@ string dev::memDump(bytes const& _b, unsigned _w, bool _html, string _separator)
ret << '?';
else
ret << ' ';
ret << _separator;
ret << " ";
for (unsigned j = i; j < i + _w && j < _b.size(); ++j)
ret << setfill('0') << setw(2) << hex << (unsigned)_b[j] << " ";
ret << "\n";

4
libdevcore/CommonIO.h

@ -47,7 +47,9 @@ 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, std::string _separator = " ");
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);
// Stream I/O functions.
// Provides templated stream I/O for all STL collections so they can be shifted on to any iostream-like interface.

11
mix/AssemblyDebuggerControl.cpp

@ -29,17 +29,6 @@ using namespace dev::mix;
AssemblyDebuggerControl::AssemblyDebuggerControl(AppContext* _context):
Extension(_context, ExtensionDisplayBehavior::RightView)
{
/*
qRegisterMetaType<QVariableDefinition*>("QVariableDefinition*");
qRegisterMetaType<QVariableDefinitionList*>("QVariableDefinitionList*");
qRegisterMetaType<QList<QVariableDefinition*>>("QList<QVariableDefinition*>");
qRegisterMetaType<QList<QVariableDeclaration*>>("QList<QVariableDeclaration*>");
qRegisterMetaType<QVariableDeclaration*>("QVariableDeclaration*");
qRegisterMetaType<AssemblyDebuggerData>("AssemblyDebuggerData");
connect(this, &AssemblyDebuggerControl::dataAvailable, this, &AssemblyDebuggerControl::showDebugger, Qt::QueuedConnection);
m_modelDebugger = std::unique_ptr<AssemblyDebuggerModel>(new AssemblyDebuggerModel);
_context->appEngine()->rootContext()->setContextProperty("debugModel", this);*/
connect(_context->clientModel(), &ClientModel::showDebuggerWindow, this, &AssemblyDebuggerControl::showDebugger, Qt::QueuedConnection);
}

1
mix/CodeEditorExtensionManager.cpp

@ -59,7 +59,6 @@ void CodeEditorExtensionManager::initExtensions()
std::shared_ptr<StatusPane> output = std::make_shared<StatusPane>(m_appContext);
std::shared_ptr<AssemblyDebuggerControl> debug = std::make_shared<AssemblyDebuggerControl>(m_appContext);
std::shared_ptr<StateListView> stateList = std::make_shared<StateListView>(m_appContext);
//QObject::connect(m_appContext->clientModel(), &ClientModel::runFailed, output.get(), &sta::displayError);
QObject::connect(m_appContext->codeModel(), &CodeModel::compilationComplete, this, &CodeEditorExtensionManager::applyCodeHighlight);
initExtension(output);

45
mix/DebuggingStateWrapper.cpp

@ -108,17 +108,37 @@ QStringList DebuggingStateWrapper::debugStorage()
return fillList(storage, "@ -");
}
QStringList DebuggingStateWrapper::debugMemory()
QVariantList DebuggingStateWrapper::debugMemory()
{
QStringList re = QString::fromStdString(memDump(m_state.memory, 16, false, "_separator_")).split('\n');
return fillList(re, " ");
std::list<std::list<std::string>> dump = memDumpToList(m_state.memory, 16);
QStringList filled;
filled.append(" ");
filled.append(" ");
filled.append(" ");
return fillList(qVariantDump(dump), QVariant(filled));
}
QStringList DebuggingStateWrapper::debugCallData()
QVariantList DebuggingStateWrapper::debugCallData()
{
qDebug() << QString::fromStdString(memDump(m_data, 16, false, "_separator_"));
QStringList re = QString::fromStdString(memDump(m_data, 16, false, "_separator_")).split('\n');
return fillList(re, " ");
std::list<std::list<std::string>> dump = memDumpToList(m_data, 16);
QStringList filled;
filled.append(" ");
filled.append(" ");
filled.append(" ");
return fillList(qVariantDump(dump), QVariant(filled));
}
QVariantList DebuggingStateWrapper::qVariantDump(std::list<std::list<std::string>> const& dump)
{
QVariantList ret;
for (std::list<std::string> line: dump)
{
QStringList qLine;
for (std::string cell: line)
qLine.push_back(QString::fromStdString(cell));
ret.append(QVariant(qLine));
}
return ret;
}
QStringList DebuggingStateWrapper::fillList(QStringList& _list, QString const& _emptyValue)
@ -131,6 +151,17 @@ QStringList DebuggingStateWrapper::fillList(QStringList& _list, QString const& _
return _list;
}
QVariantList DebuggingStateWrapper::fillList(QVariantList _list, QVariant const& _emptyValue)
{
if (_list.size() < 20)
{
for (int k = _list.size(); k < 20 - _list.size(); k++)
_list.append(_emptyValue);
}
return _list;
}
QStringList DebuggingStateWrapper::levels()
{
QStringList levelsStr;

10
mix/DebuggingStateWrapper.h

@ -86,8 +86,8 @@ class DebuggingStateWrapper: public QObject
Q_PROPERTY(QString instruction READ instruction CONSTANT)
Q_PROPERTY(QStringList debugStack READ debugStack CONSTANT)
Q_PROPERTY(QStringList debugStorage READ debugStorage CONSTANT)
Q_PROPERTY(QStringList debugMemory READ debugMemory CONSTANT)
Q_PROPERTY(QStringList debugCallData READ debugCallData CONSTANT)
Q_PROPERTY(QVariantList debugMemory READ debugMemory CONSTANT)
Q_PROPERTY(QVariantList debugCallData READ debugCallData CONSTANT)
Q_PROPERTY(QString headerInfo READ headerInfo CONSTANT)
Q_PROPERTY(QString endOfDebug READ endOfDebug CONSTANT)
Q_PROPERTY(QString newMemSize READ newMemSize CONSTANT)
@ -110,9 +110,9 @@ public:
/// Get storage.
QStringList debugStorage();
/// Get memory.
QStringList debugMemory();
QVariantList debugMemory();
/// Get call data.
QStringList debugCallData();
QVariantList debugCallData();
/// Get info to be displayed in the header.
QString headerInfo();
/// get end of debug information.
@ -135,6 +135,8 @@ private:
bytes m_code;
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);
};
}

1
mix/qml/CodeEditor.qml

@ -73,7 +73,6 @@ Component {
}
}
onTextChanged: {
console.log("textchange")
editorTextChanged();
}

1
mix/qml/CodeEditorView.qml

@ -32,7 +32,6 @@ Item {
function doLoadDocument(editor, document) {
var data = fileIo.readFile(document.path);
console.log(document.isContract)
if (document.isContract)
editor.onEditorTextChanged.connect(function() {
codeModel.registerCodeChange(editor.getText());

12
mix/qml/Debugger.qml

@ -141,6 +141,8 @@ Rectangle {
enabledStateImg: "qrc:/qml/img/jumpoutback.png"
disableStateImg: "qrc:/qml/img/jumpoutbackdisabled.png"
onClicked: Debugger.stepOutBack()
width: 25
height: 27
}
StepActionImage
@ -149,6 +151,8 @@ Rectangle {
enabledStateImg: "qrc:/qml/img/jumpintoback.png"
disableStateImg: "qrc:/qml/img/jumpintobackdisabled.png"
onClicked: Debugger.stepIntoBack()
width: 25
height: 27
}
StepActionImage
@ -157,6 +161,8 @@ Rectangle {
enabledStateImg: "qrc:/qml/img/jumpoverback.png"
disableStateImg: "qrc:/qml/img/jumpoverbackdisabled.png"
onClicked: Debugger.stepOverBack()
width: 25
height: 27
}
StepActionImage
@ -165,6 +171,8 @@ Rectangle {
enabledStateImg: "qrc:/qml/img/jumpoverforward.png"
disableStateImg: "qrc:/qml/img/jumpoverforwarddisabled.png"
onClicked: Debugger.stepOverForward()
width: 25
height: 27
}
StepActionImage
@ -173,6 +181,8 @@ Rectangle {
enabledStateImg: "qrc:/qml/img/jumpintoforward.png"
disableStateImg: "qrc:/qml/img/jumpintoforwarddisabled.png"
onClicked: Debugger.stepIntoForward()
width: 25
height: 27
}
StepActionImage
@ -181,6 +191,8 @@ Rectangle {
enabledStateImg: "qrc:/qml/img/jumpoutforward.png"
disableStateImg: "qrc:/qml/img/jumpoutforwarddisabled.png"
onClicked: Debugger.stepOutForward()
width: 25
height: 27
}
}
}

14
mix/qml/ItemDelegateDataDump.qml

@ -8,14 +8,6 @@ Rectangle {
RowLayout
{
id: row;
function formatData(data, index)
{
if (data.indexOf("_separator_") !== -1)
return modelData.split("_separator_")[index];
else
return "";
}
anchors.fill: parent
spacing: 2
Rectangle
@ -31,7 +23,7 @@ Rectangle {
anchors.centerIn: parent
anchors.leftMargin: 5
color: "#8b8b8b"
text: row.formatData(modelData, 0)
text: modelData[0]
font.pointSize: 9;
}
}
@ -49,7 +41,7 @@ Rectangle {
anchors.leftMargin: 7
anchors.verticalCenter: parent.verticalCenter
color: "#8b8b8b"
text: row.formatData(modelData, 1)
text: modelData[1]
font.pointSize: 9
}
}
@ -64,7 +56,7 @@ Rectangle {
anchors.verticalCenter: parent.verticalCenter
color: "#ededed"
font.bold: true
text: row.formatData(modelData, 2)
text: modelData[2]
font.pointSize: 10
}
}

7
mix/qml/StepActionImage.qml

@ -19,8 +19,6 @@ Rectangle {
debugImg.iconSource = disableStateImg;
}
width: debugImg.width + 4
height: debugImg.height
color: "transparent"
Button
{
@ -28,9 +26,10 @@ Rectangle {
id: debugImg
iconSource: enabledStateImg
action: buttonAction
width: 17
height: 27
width: buttonActionContainer.width - 3
height: buttonActionContainer.height
}
Action {
id: buttonAction
onTriggered: {

Loading…
Cancel
Save