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