Commit 3e152fc8 authored by hjk's avatar hjk

debugger: add an "Memory View" item to the menu

Task-number: QTCREATORBUG-1600
parent c3b81616
......@@ -58,6 +58,8 @@
#include <limits.h>
using namespace Core;
namespace Debugger {
namespace Internal {
......@@ -95,9 +97,9 @@ MemoryViewAgent::MemoryViewAgent(DebuggerEngine *engine, const QString &addr)
MemoryViewAgent::~MemoryViewAgent()
{
Core::EditorManager *editorManager = Core::EditorManager::instance();
QList<Core::IEditor *> editors;
foreach (QPointer<Core::IEditor> editor, m_editors)
EditorManager *editorManager = EditorManager::instance();
QList<IEditor *> editors;
foreach (QPointer<IEditor> editor, m_editors)
if (editor)
editors.append(editor.data());
editorManager->closeEditors(editors);
......@@ -105,25 +107,29 @@ MemoryViewAgent::~MemoryViewAgent()
void MemoryViewAgent::createBinEditor(quint64 addr)
{
Core::EditorManager *editorManager = Core::EditorManager::instance();
EditorManager *editorManager = EditorManager::instance();
QString titlePattern = tr("Memory $");
Core::IEditor *editor = editorManager->openEditorWithContents(
IEditor *editor = editorManager->openEditorWithContents(
Core::Constants::K_DEFAULT_BINARY_EDITOR_ID,
&titlePattern);
if (editor) {
connect(editor->widget(), SIGNAL(lazyDataRequested(Core::IEditor *, quint64,bool)),
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,
SIGNAL(lazyDataRequested(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)),
SLOT(provideNewRange(Core::IEditor*,quint64)));
connect(editor->widget(), SIGNAL(startOfFileRequested(Core::IEditor *)),
this, SLOT(handleStartOfFileRequested(Core::IEditor*)));
connect(editor->widget(), SIGNAL(endOfFileRequested(Core::IEditor *)),
this, SLOT(handleEndOfFileRequested(Core::IEditor*)));
connect(editor->widget(),
SIGNAL(startOfFileRequested(Core::IEditor *)),
SLOT(handleStartOfFileRequested(Core::IEditor*)));
connect(editor->widget(),
SIGNAL(endOfFileRequested(Core::IEditor *)),
SLOT(handleEndOfFileRequested(Core::IEditor*)));
m_editors << editor;
editorManager->activateEditor(editor, Core::EditorManager::NoModeSwitch);
editorManager->activateEditor(editor, EditorManager::NoModeSwitch);
QMetaObject::invokeMethod(editor->widget(), "setNewWindowRequestAllowed");
QMetaObject::invokeMethod(editor->widget(), "setLazyData",
Q_ARG(quint64, addr), Q_ARG(int, DataRange), Q_ARG(int, BinBlockSize));
......@@ -136,7 +142,7 @@ void MemoryViewAgent::createBinEditor(quint64 addr)
}
}
void MemoryViewAgent::fetchLazyData(Core::IEditor *editor, quint64 block, bool sync)
void MemoryViewAgent::fetchLazyData(IEditor *editor, quint64 block, bool sync)
{
Q_UNUSED(sync); // FIXME: needed support for incremental searching
m_engine->fetchMemory(this, editor, BinBlockSize * block, BinBlockSize);
......@@ -145,15 +151,15 @@ void MemoryViewAgent::fetchLazyData(Core::IEditor *editor, quint64 block, bool s
void MemoryViewAgent::addLazyData(QObject *editorToken, quint64 addr,
const QByteArray &ba)
{
Core::IEditor *editor = qobject_cast<Core::IEditor *>(editorToken);
IEditor *editor = qobject_cast<IEditor *>(editorToken);
if (editor && editor->widget()) {
Core::EditorManager::instance()->activateEditor(editor, Core::EditorManager::NoModeSwitch);
EditorManager::instance()->activateEditor(editor, EditorManager::NoModeSwitch);
QMetaObject::invokeMethod(editor->widget(), "addLazyData",
Q_ARG(quint64, addr / BinBlockSize), Q_ARG(QByteArray, ba));
}
}
void MemoryViewAgent::provideNewRange(Core::IEditor *editor, quint64 address)
void MemoryViewAgent::provideNewRange(IEditor *editor, quint64 address)
{
QMetaObject::invokeMethod(editor->widget(), "setLazyData",
Q_ARG(quint64, address), Q_ARG(int, DataRange),
......@@ -163,13 +169,13 @@ void MemoryViewAgent::provideNewRange(Core::IEditor *editor, quint64 address)
// Since we are not dealing with files, we take these signals to mean
// "move to start/end of range". This seems to make more sense than
// jumping to the start or end of the address space, respectively.
void MemoryViewAgent::handleStartOfFileRequested(Core::IEditor *editor)
void MemoryViewAgent::handleStartOfFileRequested(IEditor *editor)
{
QMetaObject::invokeMethod(editor->widget(),
"setCursorPosition", Q_ARG(int, 0));
}
void MemoryViewAgent::handleEndOfFileRequested(Core::IEditor *editor)
void MemoryViewAgent::handleEndOfFileRequested(IEditor *editor)
{
QMetaObject::invokeMethod(editor->widget(),
"setCursorPosition", Q_ARG(int, DataRange - 1));
......@@ -234,9 +240,9 @@ DisassemblerViewAgent::DisassemblerViewAgent(DebuggerEngine *engine)
DisassemblerViewAgent::~DisassemblerViewAgent()
{
Core::EditorManager *editorManager = Core::EditorManager::instance();
EditorManager *editorManager = EditorManager::instance();
if (d->editor)
editorManager->closeEditors(QList<Core::IEditor *>() << d->editor);
editorManager->closeEditors(QList<IEditor *>() << d->editor);
d->editor = 0;
delete d->locationMark;
d->locationMark = 0;
......@@ -301,7 +307,7 @@ void DisassemblerViewAgentPrivate::configureMimeType()
TextEditor::PlainTextEditor *pe = qobject_cast<TextEditor::PlainTextEditor *>(editor->widget());
QTC_ASSERT(pe, return);
if (const Core::MimeType mtype = Core::ICore::instance()->mimeDatabase()->findByType(mimeType)) {
if (const MimeType mtype = ICore::instance()->mimeDatabase()->findByType(mimeType)) {
pe->configure(mtype);
} else {
qWarning("Assembler mimetype '%s' not found.", qPrintable(mimeType));
......@@ -343,7 +349,7 @@ void DisassemblerViewAgent::setContents(const QString &contents)
d->configureMimeType();
}
editorManager->activateEditor(d->editor, Core::EditorManager::NoModeSwitch);
editorManager->activateEditor(d->editor, EditorManager::NoModeSwitch);
plainTextEdit = qobject_cast<QPlainTextEdit *>(d->editor->widget());
if (plainTextEdit) {
......
......@@ -543,6 +543,12 @@ void DebuggerEngine::handleCommand(int role, const QVariant &value)
d->handleContextMenuRequest(list);
break;
}
case RequestShowMemoryRole: {
qDebug() << "CREATING MEMORY VIEW";
(void) MemoryViewAgent(this, "0x0");
break;
}
}
}
......
......@@ -923,6 +923,7 @@ public slots:
void enableReverseDebuggingTriggered(const QVariant &value);
void languagesChanged(const Debugger::DebuggerLanguages &languages);
void showStatusMessage(const QString &msg, int timeout = -1);
void openMemoryEditor();
DebuggerMainWindow *mainWindow()
{ return qobject_cast<DebuggerMainWindow*>
......@@ -2346,8 +2347,7 @@ void DebuggerPluginPrivate::gotoLocation(const QString &file, int line, bool set
bool newEditor = false;
ITextEditor *editor =
BaseTextEditor::openEditorAt(file, line, 0, QString(),
Core::EditorManager::IgnoreNavigationHistory,
&newEditor);
EditorManager::IgnoreNavigationHistory, &newEditor);
if (!editor)
return;
if (newEditor)
......@@ -2488,6 +2488,15 @@ void DebuggerPluginPrivate::scriptExpressionEntered(const QString &expression)
notifyCurrentEngine(RequestExecuteCommandRole, expression);
}
void DebuggerPluginPrivate::openMemoryEditor()
{
AddressDialog dialog;
if (dialog.exec() != QDialog::Accepted)
return;
QTC_ASSERT(m_watchersWindow, return);
m_watchersWindow->model()->setData(
QModelIndex(), dialog.address(), RequestShowMemoryRole);
}
///////////////////////////////////////////////////////////////////////
......@@ -2704,6 +2713,8 @@ void DebuggerPlugin::extensionsInitialized()
d->m_uiSwitcher->initialize();
d->m_watchersWindow->setVisible(false);
d->m_returnWindow->setVisible(false);
connect(d->m_uiSwitcher, SIGNAL(memoryEditorRequested()),
d, SLOT(openMemoryEditor()));
// time gdb -i mi -ex 'debuggerplugin.cpp:800' -ex r -ex q bin/qtcreator.bin
const QByteArray env = qgetenv("QTC_DEBUGGER_TEST");
......
......@@ -73,15 +73,11 @@
#include <QtCore/QSettings>
namespace Debugger {
using namespace Debugger::Internal;
namespace Internal {
DockWidgetEventFilter::DockWidgetEventFilter(QObject *parent)
: QObject(parent)
{
}
{}
bool DockWidgetEventFilter::eventFilter(QObject *obj, QEvent *event)
{
......@@ -125,6 +121,7 @@ struct DebuggerUISwitcherPrivate
DebuggerLanguages m_activeDebugLanguages;
QAction *m_activateCppAction;
QAction *m_activateQmlAction;
QAction *m_openMemoryEditorAction;
bool m_qmlEnabled;
Core::ActionContainer *m_viewsMenu;
......@@ -154,6 +151,7 @@ DebuggerUISwitcherPrivate::DebuggerUISwitcherPrivate(DebuggerUISwitcher *q)
, m_activeDebugLanguages(AnyLanguage)
, m_activateCppAction(0)
, m_activateQmlAction(0)
, m_openMemoryEditorAction(0)
, m_qmlEnabled(false)
, m_viewsMenu(0)
, m_debugMenu(0)
......@@ -164,8 +162,12 @@ DebuggerUISwitcherPrivate::DebuggerUISwitcherPrivate(DebuggerUISwitcher *q)
DebuggerUISwitcher *DebuggerUISwitcherPrivate::m_instance = 0;
DebuggerUISwitcher::DebuggerUISwitcher(Core::BaseMode *mode, QObject* parent) :
QObject(parent), d(new DebuggerUISwitcherPrivate(this))
} // namespace Internal
using namespace Internal;
DebuggerUISwitcher::DebuggerUISwitcher(Core::BaseMode *mode, QObject* parent)
: QObject(parent), d(new DebuggerUISwitcherPrivate(this))
{
mode->setWidget(createContents(mode));
......@@ -325,13 +327,13 @@ void DebuggerUISwitcher::onModeChanged(Core::IMode *mode)
void DebuggerUISwitcher::hideInactiveWidgets()
{
// Hide all the debugger windows if mode is different.
if (d->m_inDebugMode)
return;
// Hide dock widgets manually in case they are floating.
if (!d->m_inDebugMode) {
// hide all the debugger windows if mode is different
foreach(QDockWidget *dockWidget, d->m_dockWidgets) {
if (dockWidget->isFloating())
dockWidget->hide();
}
foreach (QDockWidget *dockWidget, d->m_dockWidgets) {
if (dockWidget->isFloating())
dockWidget->hide();
}
}
......@@ -344,8 +346,17 @@ void DebuggerUISwitcher::createViewsMenuItems()
d->m_debugMenu->addMenu(d->m_debuggerLanguageMenu, Core::Constants::G_DEFAULT_THREE);
d->m_debuggerLanguageMenu->menu()->setTitle(tr("&Debug Languages"));
d->m_openMemoryEditorAction = new QAction(this);
d->m_openMemoryEditorAction->setText(tr("Memory..."));
connect(d->m_openMemoryEditorAction, SIGNAL(triggered()),
SIGNAL(memoryEditorRequested()));
// Add menu items
Core::Command *cmd = am->registerAction(d->m_mainWindow->menuSeparator1(),
Core::Command *cmd = 0;
cmd = am->registerAction(d->m_openMemoryEditorAction,
QLatin1String("Debugger.Views.OpenMemoryEditor"), globalcontext);
d->m_viewsMenu->addAction(cmd);
cmd = am->registerAction(d->m_mainWindow->menuSeparator1(),
QLatin1String("Debugger.Views.Separator1"), globalcontext);
d->m_viewsMenu->addAction(cmd);
cmd = am->registerAction(d->m_mainWindow->toggleLockedAction(),
......@@ -742,7 +753,8 @@ void DebuggerUISwitcher::updateDockWidgetSettings()
bool DebuggerUISwitcher::isQmlCppActive() const
{
return (d->m_activeDebugLanguages & CppLanguage) && (d->m_activeDebugLanguages & QmlLanguage);
return (d->m_activeDebugLanguages & CppLanguage)
&& (d->m_activeDebugLanguages & QmlLanguage);
}
bool DebuggerUISwitcher::isQmlActive() const
......
......@@ -61,10 +61,10 @@ namespace ProjectExplorer {
}
namespace Debugger {
struct DebuggerUISwitcherPrivate;
namespace Internal {
class DebuggerMainWindow;
class DebuggerUISwitcherPrivate;
class DebuggerMainWindow;
};
class DEBUGGER_EXPORT DebuggerUISwitcher : public QObject
......@@ -122,8 +122,8 @@ signals:
// emit when user changes active languages from the menu.
// Both UI and debugger startup are affected.
void activeLanguagesChanged(Debugger::DebuggerLanguages activeLanguages);
void dockResetRequested(const Debugger::DebuggerLanguages &activeLanguages);
void memoryEditorRequested();
private slots:
void updateUi();
......@@ -156,7 +156,7 @@ private:
QWidget *createContents(Core::BaseMode *mode);
QWidget *createMainWindow(Core::BaseMode *mode);
DebuggerUISwitcherPrivate *d;
Internal::DebuggerUISwitcherPrivate *d;
};
namespace Internal {
......
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