Commit 161e0322 authored by ck's avatar ck
Browse files

BinEditor: Refactor new range requesting.

Also adds the "new range" ability to the debugger's memory viewer.
parent 2c3dd303
...@@ -453,9 +453,10 @@ void BinEditor::scrollContentsBy(int dx, int dy) ...@@ -453,9 +453,10 @@ void BinEditor::scrollContentsBy(int dx, int dy)
const QScrollBar * const scrollBar = verticalScrollBar(); const QScrollBar * const scrollBar = verticalScrollBar();
const int scrollPos = scrollBar->value(); const int scrollPos = scrollBar->value();
if (dy <= 0 && scrollPos == scrollBar->maximum()) if (dy <= 0 && scrollPos == scrollBar->maximum())
emit endOfRangeReached(editorInterface()); emit newRangeRequested(editorInterface(),
baseAddress() + dataSize());
else if (dy >= 0 && scrollPos == scrollBar->minimum()) else if (dy >= 0 && scrollPos == scrollBar->minimum())
emit startOfRangeReached(editorInterface()); emit newRangeRequested(editorInterface(), baseAddress());
} }
} }
...@@ -1025,7 +1026,8 @@ bool BinEditor::event(QEvent *e) { ...@@ -1025,7 +1026,8 @@ bool BinEditor::event(QEvent *e) {
if (m_inLazyMode) { if (m_inLazyMode) {
const QScrollBar * const scrollBar = verticalScrollBar(); const QScrollBar * const scrollBar = verticalScrollBar();
if (scrollBar->value() >= scrollBar->maximum() - 1) { if (scrollBar->value() >= scrollBar->maximum() - 1) {
emit endOfRangeReached(editorInterface()); emit newRangeRequested(editorInterface(),
baseAddress() + dataSize());
return true; return true;
} }
} }
...@@ -1303,9 +1305,9 @@ void BinEditor::contextMenuEvent(QContextMenuEvent *event) ...@@ -1303,9 +1305,9 @@ void BinEditor::contextMenuEvent(QContextMenuEvent *event)
else if (action == &copyHexAction) else if (action == &copyHexAction)
copy(false); copy(false);
else if (action == &jumpToBeAddressHere) else if (action == &jumpToBeAddressHere)
setCursorPosition(beAddress - m_baseAddr); jumpToAddress(beAddress);
else if (action == &jumpToLeAddressHere) else if (action == &jumpToLeAddressHere)
setCursorPosition(leAddress - m_baseAddr); jumpToAddress(leAddress);
else if (action == &jumpToBeAddressNewWindow) else if (action == &jumpToBeAddressNewWindow)
emit newWindowRequested(beAddress); emit newWindowRequested(beAddress);
else if (action == &jumpToLeAddressNewWindow) else if (action == &jumpToLeAddressNewWindow)
...@@ -1321,12 +1323,18 @@ void BinEditor::setupJumpToMenuAction(QMenu *menu, QAction *actionHere, ...@@ -1321,12 +1323,18 @@ void BinEditor::setupJumpToMenuAction(QMenu *menu, QAction *actionHere,
.arg(QString::number(addr, 16))); .arg(QString::number(addr, 16)));
menu->addAction(actionHere); menu->addAction(actionHere);
menu->addAction(actionNew); menu->addAction(actionNew);
if (addr < m_baseAddr || addr >= m_baseAddr + m_size)
actionHere->setEnabled(false);
if (!m_canRequestNewWindow) if (!m_canRequestNewWindow)
actionNew->setEnabled(false); actionNew->setEnabled(false);
} }
void BinEditor::jumpToAddress(quint64 address)
{
if (address >= m_baseAddr && address < m_baseAddr + m_data.size())
setCursorPosition(address - m_baseAddr);
else
emit newRangeRequested(editorInterface(), address);
}
void BinEditor::setNewWindowRequestAllowed() void BinEditor::setNewWindowRequestAllowed()
{ {
m_canRequestNewWindow = true; m_canRequestNewWindow = true;
......
...@@ -131,8 +131,7 @@ Q_SIGNALS: ...@@ -131,8 +131,7 @@ Q_SIGNALS:
void lazyDataRequested(Core::IEditor *editor, quint64 block, bool synchronous); void lazyDataRequested(Core::IEditor *editor, quint64 block, bool synchronous);
void newWindowRequested(quint64 address); void newWindowRequested(quint64 address);
void startOfRangeReached(Core::IEditor *editor); void newRangeRequested(Core::IEditor *, quint64 address);
void endOfRangeReached(Core::IEditor *editor);
protected: protected:
void scrollContentsBy(int dx, int dy); void scrollContentsBy(int dx, int dy);
...@@ -213,6 +212,7 @@ private: ...@@ -213,6 +212,7 @@ private:
void setupJumpToMenuAction(QMenu *menu, QAction *actionHere, QAction *actionNew, void setupJumpToMenuAction(QMenu *menu, QAction *actionHere, QAction *actionNew,
quint64 addr); quint64 addr);
void jumpToAddress(quint64 address);
struct BinEditorEditCommand { struct BinEditorEditCommand {
int position; int position;
......
...@@ -179,10 +179,8 @@ public: ...@@ -179,10 +179,8 @@ public:
m_editor = parent; m_editor = parent;
connect(m_editor, SIGNAL(lazyDataRequested(Core::IEditor *, quint64, bool)), connect(m_editor, SIGNAL(lazyDataRequested(Core::IEditor *, quint64, bool)),
this, SLOT(provideData(Core::IEditor *, quint64))); this, SLOT(provideData(Core::IEditor *, quint64)));
connect(m_editor, SIGNAL(startOfRangeReached(Core::IEditor*)), connect(m_editor, SIGNAL(newRangeRequested(Core::IEditor*,quint64)),
this, SLOT(handleStartOfRangeReached())); this, SLOT(provideNewRange(Core::IEditor*,quint64)));
connect(m_editor, SIGNAL(endOfRangeReached(Core::IEditor*)),
this, SLOT(handleEndOfRangeReached()));
} }
~BinEditorFile() {} ~BinEditorFile() {}
...@@ -202,7 +200,8 @@ public: ...@@ -202,7 +200,8 @@ public:
bool open(const QString &fileName, quint64 offset = 0) { bool open(const QString &fileName, quint64 offset = 0) {
QFile file(fileName); QFile file(fileName);
if (file.open(QIODevice::ReadOnly)) { if (offset < static_cast<quint64>(file.size())
&& file.open(QIODevice::ReadOnly)) {
m_fileName = fileName; m_fileName = fileName;
qint64 maxRange = 64 * 1024 * 1024; qint64 maxRange = 64 * 1024 * 1024;
if (file.isSequential() && file.size() <= maxRange) { if (file.isSequential() && file.size() <= maxRange) {
...@@ -233,20 +232,8 @@ private slots: ...@@ -233,20 +232,8 @@ private slots:
} }
} }
void handleStartOfRangeReached() void provideNewRange(Core::IEditor *, quint64 offset) {
{ open(m_fileName, offset);
if (m_editor->baseAddress() != 0) {
open(m_fileName, m_editor->baseAddress());
}
}
void handleEndOfRangeReached()
{
const quint64 currentEndAdress
= m_editor->baseAddress() + m_editor->dataSize();
if (currentEndAdress
< static_cast<quint64>(QFileInfo(m_fileName).size()))
open(m_fileName, currentEndAdress);
} }
public: public:
......
...@@ -105,6 +105,9 @@ void MemoryViewAgent::createBinEditor(quint64 addr) ...@@ -105,6 +105,9 @@ void MemoryViewAgent::createBinEditor(quint64 addr)
this, SLOT(fetchLazyData(Core::IEditor *, quint64,bool))); this, SLOT(fetchLazyData(Core::IEditor *, quint64,bool)));
connect(editor->widget(), SIGNAL(newWindowRequested(quint64)), connect(editor->widget(), SIGNAL(newWindowRequested(quint64)),
this, SLOT(createBinEditor(quint64))); this, SLOT(createBinEditor(quint64)));
connect(editor->widget(),
SIGNAL(newRangeRequested(Core::IEditor *, quint64)), this,
SLOT(provideNewRange(Core::IEditor*,quint64)));
m_editors << editor; m_editors << editor;
editorManager->activateEditor(editor); editorManager->activateEditor(editor);
QMetaObject::invokeMethod(editor->widget(), "setNewWindowRequestAllowed"); QMetaObject::invokeMethod(editor->widget(), "setNewWindowRequestAllowed");
...@@ -137,6 +140,13 @@ void MemoryViewAgent::addLazyData(QObject *editorToken, quint64 addr, ...@@ -137,6 +140,13 @@ void MemoryViewAgent::addLazyData(QObject *editorToken, quint64 addr,
} }
} }
void MemoryViewAgent::provideNewRange(Core::IEditor *editor, quint64 address)
{
QMetaObject::invokeMethod(editor->widget(), "setLazyData",
Q_ARG(quint64, address), Q_ARG(int, 1024 * 1024),
Q_ARG(int, BinBlockSize));
}
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
// //
......
...@@ -59,11 +59,11 @@ public: ...@@ -59,11 +59,11 @@ public:
public slots: public slots:
// Called from Engine // Called from Engine
void addLazyData(QObject *editorToken, quint64 addr, const QByteArray &data); void addLazyData(QObject *editorToken, quint64 addr, const QByteArray &data);
// Called from Editor
void fetchLazyData(Core::IEditor *, quint64 block, bool sync);
private: private:
Q_SLOT void createBinEditor(quint64 startAddr); Q_SLOT void createBinEditor(quint64 startAddr);
Q_SLOT void fetchLazyData(Core::IEditor *, quint64 block, bool sync);
Q_SLOT void provideNewRange(Core::IEditor *editor, quint64 address);
QPointer<IDebuggerEngine> m_engine; QPointer<IDebuggerEngine> m_engine;
QList<QPointer<Core::IEditor> > m_editors; QList<QPointer<Core::IEditor> > m_editors;
......
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