Commit f125b571 authored by hjk's avatar hjk
Browse files

debugger: work on writable memory view

parent 14d59059
......@@ -204,7 +204,7 @@ bool BinEditor::requestOldDataAt(int pos) const
char BinEditor::dataAt(int pos, bool old) const
{
int block = pos / m_blockSize;
return blockData(block, old).at(pos - (block*m_blockSize));
return blockData(block, old).at(pos - block*m_blockSize);
}
void BinEditor::changeDataAt(int pos, char c)
......@@ -221,6 +221,8 @@ void BinEditor::changeDataAt(int pos, char c)
m_modifiedData.insert(block, data);
}
}
emit dataChanged(editor(), m_baseAddr + pos, QByteArray(1, c));
}
QByteArray BinEditor::dataMid(int from, int length, bool old) const
......
......@@ -136,6 +136,7 @@ Q_SIGNALS:
void newRangeRequested(Core::IEditor *, quint64 address);
void startOfFileRequested(Core::IEditor *);
void endOfFileRequested(Core::IEditor *);
void dataChanged(Core::IEditor *, quint64 address, const QByteArray &data);
protected:
void scrollContentsBy(int dx, int dy);
......
......@@ -179,8 +179,7 @@ class BinEditorFile : public Core::IFile
Q_OBJECT
public:
BinEditorFile(BinEditor *parent) :
Core::IFile(parent),
m_mimeType(QLatin1String(BINEditor::Constants::C_BINEDITOR_MIMETYPE))
Core::IFile(parent)
{
m_editor = parent;
connect(m_editor, SIGNAL(dataRequested(Core::IEditor *, quint64, bool)),
......@@ -194,7 +193,9 @@ public:
}
~BinEditorFile() {}
virtual QString mimeType() const { return m_mimeType; }
QString mimeType() const {
return QLatin1String(Constants::C_BINEDITOR_MIMETYPE);
}
bool save(const QString &fileName = QString()) {
const QString fileNameToUse
......@@ -261,19 +262,17 @@ public:
m_fileName = filename;
}
QString fileName() const {
return m_fileName;
}
QString fileName() const { return m_fileName; }
QString defaultPath() const { return QString(); }
QString suggestedFileName() const { return QString(); }
QString fileFilter() const { return QString(); }
QString fileExtension() const { return QString(); }
bool isModified() const {
return m_editor->isModified();
}
bool isModified() const { return m_editor->isModified(); }
bool isReadOnly() const {
if (m_editor->editor()->property("MemoryView").toBool())
return false;
const QFileInfo fi(m_fileName);
return !fi.isWritable();
}
......@@ -304,7 +303,6 @@ public:
}
private:
const QString m_mimeType;
BinEditor *m_editor;
QString m_fileName;
};
......@@ -396,11 +394,10 @@ private:
///////////////////////////////// BinEditorFactory //////////////////////////////////
BinEditorFactory::BinEditorFactory(BinEditorPlugin *owner) :
m_mimeTypes(QLatin1String(BINEditor::Constants::C_BINEDITOR_MIMETYPE)),
m_mimeTypes(QLatin1String(Constants::C_BINEDITOR_MIMETYPE)),
m_owner(owner)
{
}
......
......@@ -487,6 +487,13 @@ void DebuggerEngine::fetchMemory(MemoryAgent *, QObject *,
Q_UNUSED(length);
}
void DebuggerEngine::changeMemory(MemoryAgent *, QObject *,
quint64 addr, const QByteArray &data)
{
Q_UNUSED(addr);
Q_UNUSED(data);
}
void DebuggerEngine::setRegisterValue(int regnr, const QString &value)
{
Q_UNUSED(regnr);
......
......@@ -159,6 +159,8 @@ public:
virtual void openMemoryView(quint64 addr);
virtual void fetchMemory(Internal::MemoryAgent *, QObject *,
quint64 addr, quint64 length);
virtual void changeMemory(Internal::MemoryAgent *, QObject *,
quint64 addr, const QByteArray &data);
virtual void updateMemoryViews();
virtual void openDisassemblerView(const Internal::Location &location);
virtual void fetchDisassembler(Internal::DisassemblerAgent *);
......
......@@ -3860,10 +3860,26 @@ struct MemoryAgentCookie
quint64 address;
};
void GdbEngine::changeMemory(MemoryAgent *agent, QObject *token,
quint64 addr, const QByteArray &data)
{
QByteArray cmd = "-data-write-memory " + QByteArray::number(addr) + " d 1";
foreach (char c, data) {
cmd.append(' ');
cmd.append(QByteArray::number(uint(c)));
}
postCommand(cmd, NeedsStop, CB(handleChangeMemory),
QVariant::fromValue(MemoryAgentCookie(agent, token, addr)));
}
void GdbEngine::handleChangeMemory(const GdbResponse &response)
{
Q_UNUSED(response);
}
void GdbEngine::fetchMemory(MemoryAgent *agent, QObject *token, quint64 addr,
quint64 length)
{
//qDebug() << "GDB MEMORY FETCH" << agent << addr << length;
postCommand("-data-read-memory " + QByteArray::number(addr) + " x 1 1 "
+ QByteArray::number(length),
NeedsStop, CB(handleFetchMemory),
......
......@@ -482,6 +482,9 @@ private: ////////// View & Data Stuff //////////
virtual void fetchMemory(MemoryAgent *agent, QObject *token,
quint64 addr, quint64 length);
void handleChangeMemory(const GdbResponse &response);
virtual void changeMemory(MemoryAgent *agent, QObject *token,
quint64 addr, const QByteArray &data);
void handleFetchMemory(const GdbResponse &response);
virtual void watchPoint(const QPoint &);
......
......@@ -88,25 +88,27 @@ void MemoryAgent::createBinEditor(quint64 addr)
IEditor *editor = editorManager->openEditorWithContents(
Core::Constants::K_DEFAULT_BINARY_EDITOR_ID,
&titlePattern);
editorManager->activateEditor(editor);
if (editor) {
editor->setProperty(Debugger::Constants::OPENED_BY_DEBUGGER, true);
editor->setProperty(Debugger::Constants::OPENED_WITH_MEMORY, true);
editor->setProperty(Constants::OPENED_BY_DEBUGGER, true);
editor->setProperty(Constants::OPENED_WITH_MEMORY, true);
connect(editor->widget(),
SIGNAL(dataRequested(Core::IEditor *, quint64,bool)),
SLOT(fetchLazyData(Core::IEditor *, quint64,bool)));
SIGNAL(dataRequested(Core::IEditor*,quint64,bool)),
SLOT(fetchLazyData(Core::IEditor*,quint64,bool)));
connect(editor->widget(),
SIGNAL(newWindowRequested(quint64)),
SLOT(createBinEditor(quint64)));
connect(editor->widget(),
SIGNAL(newRangeRequested(Core::IEditor *, quint64)),
SIGNAL(newRangeRequested(Core::IEditor*,quint64)),
SLOT(provideNewRange(Core::IEditor*,quint64)));
connect(editor->widget(),
SIGNAL(startOfFileRequested(Core::IEditor *)),
SIGNAL(startOfFileRequested(Core::IEditor*)),
SLOT(handleStartOfFileRequested(Core::IEditor*)));
connect(editor->widget(),
SIGNAL(endOfFileRequested(Core::IEditor *)),
SLOT(handleEndOfFileRequested(Core::IEditor*)));
connect(editor->widget(),
SIGNAL(dataChanged(Core::IEditor*,quint64,QByteArray)),
SLOT(handleDataChanged(Core::IEditor*,quint64,QByteArray)));
m_editors << editor;
QMetaObject::invokeMethod(editor->widget(), "setNewWindowRequestAllowed");
QMetaObject::invokeMethod(editor->widget(), "setSizes",
......@@ -114,6 +116,7 @@ void MemoryAgent::createBinEditor(quint64 addr)
Q_ARG(int, DataRange),
Q_ARG(bool, false),
Q_ARG(int, BinBlockSize));
editorManager->activateEditor(editor);
} else {
showMessageBox(QMessageBox::Warning,
tr("No memory viewer available"),
......@@ -163,6 +166,12 @@ void MemoryAgent::handleEndOfFileRequested(IEditor *editor)
"setCursorPosition", Q_ARG(int, DataRange - 1));
}
void MemoryAgent::handleDataChanged(IEditor *editor,
quint64 addr, const QByteArray &data)
{
m_engine->changeMemory(this, editor, addr, data);
}
void MemoryAgent::updateContents()
{
foreach (QPointer<IEditor> editor, m_editors)
......
......@@ -71,6 +71,7 @@ private:
Q_SLOT void provideNewRange(Core::IEditor *editor, quint64 address);
Q_SLOT void handleStartOfFileRequested(Core::IEditor *editor);
Q_SLOT void handleEndOfFileRequested(Core::IEditor *editor);
Q_SLOT void handleDataChanged(Core::IEditor *editor, quint64 address, const QByteArray &data);
QList<QPointer<Core::IEditor> > m_editors;
QPointer<DebuggerEngine> m_engine;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment