From 4461ec2ef57e16a3ba69ec0e9ee919a8b1d6c4f3 Mon Sep 17 00:00:00 2001 From: hjk <qtc-committer@nokia.com> Date: Thu, 19 Nov 2009 09:51:21 +0100 Subject: [PATCH] debugger: prevent crash when trying to view memory if bin editor is unavailable --- src/plugins/debugger/debuggeragents.cpp | 24 +++++++++++++++++------- src/plugins/debugger/debuggeragents.h | 1 + 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/plugins/debugger/debuggeragents.cpp b/src/plugins/debugger/debuggeragents.cpp index d29b5e506fc..102be15cb7f 100644 --- a/src/plugins/debugger/debuggeragents.cpp +++ b/src/plugins/debugger/debuggeragents.cpp @@ -44,6 +44,8 @@ #include <utils/qtcassert.h> #include <QtCore/QDebug> + +#include <QtGui/QMessageBox> #include <QtGui/QPlainTextEdit> #include <QtGui/QTextCursor> #include <QtGui/QSyntaxHighlighter> @@ -68,13 +70,13 @@ namespace Internal { */ MemoryViewAgent::MemoryViewAgent(DebuggerManager *manager, quint64 addr) - : QObject(manager), m_engine(manager->currentEngine()) + : QObject(manager), m_engine(manager->currentEngine()), m_manager(manager) { init(addr); } MemoryViewAgent::MemoryViewAgent(DebuggerManager *manager, const QString &addr) - : QObject(manager), m_engine(manager->currentEngine()) + : QObject(manager), m_engine(manager->currentEngine()), m_manager(manager) { bool ok = true; init(addr.toULongLong(&ok, 0)); @@ -94,11 +96,19 @@ void MemoryViewAgent::init(quint64 addr) m_editor = editorManager->openEditorWithContents( Core::Constants::K_DEFAULT_BINARY_EDITOR, &titlePattern); - connect(m_editor->widget(), SIGNAL(lazyDataRequested(quint64,bool)), - this, SLOT(fetchLazyData(quint64,bool))); - editorManager->activateEditor(m_editor); - QMetaObject::invokeMethod(m_editor->widget(), "setLazyData", - Q_ARG(quint64, addr), Q_ARG(int, 1024 * 1024), Q_ARG(int, BinBlockSize)); + if (m_editor) { + connect(m_editor->widget(), SIGNAL(lazyDataRequested(quint64,bool)), + this, SLOT(fetchLazyData(quint64,bool))); + editorManager->activateEditor(m_editor); + QMetaObject::invokeMethod(m_editor->widget(), "setLazyData", + Q_ARG(quint64, addr), Q_ARG(int, 1024 * 1024), Q_ARG(int, BinBlockSize)); + } else { + m_manager->showMessageBox(QMessageBox::Warning, + tr("No memory viewer available"), + tr("The memory contents cannot be shown as no viewer plugin not " + "the BinEditor plugin could be loaded.")); + deleteLater(); + } } void MemoryViewAgent::fetchLazyData(quint64 block, bool sync) diff --git a/src/plugins/debugger/debuggeragents.h b/src/plugins/debugger/debuggeragents.h index ff7e4879aa6..f0888c6b92f 100644 --- a/src/plugins/debugger/debuggeragents.h +++ b/src/plugins/debugger/debuggeragents.h @@ -70,6 +70,7 @@ private: QPointer<IDebuggerEngine> m_engine; QPointer<Core::IEditor> m_editor; + QPointer<DebuggerManager> m_manager; }; -- GitLab