Debugger: Move session load/restore handling

... to breakpoint and watchhandler.

More modular this way.

Change-Id: I4a45481fcc2bfde67b164bd7274fb7b2a12cb7ac
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2018-08-23 16:39:23 +02:00
parent 37dbc7ba85
commit a68e8c5b69
7 changed files with 46 additions and 73 deletions

View File

@@ -40,6 +40,8 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/idocument.h> #include <coreplugin/idocument.h>
#include <projectexplorer/session.h>
#include <texteditor/textmark.h> #include <texteditor/textmark.h>
#include <texteditor/texteditor.h> #include <texteditor/texteditor.h>
@@ -69,6 +71,7 @@
#include <QMenu> #include <QMenu>
using namespace Core; using namespace Core;
using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
namespace Debugger { namespace Debugger {
@@ -2391,6 +2394,12 @@ BreakpointManager::BreakpointManager()
theBreakpointManager = this; theBreakpointManager = this;
setHeader({tr("Debuggee"), tr("Function"), tr("File"), tr("Line"), tr("Address"), setHeader({tr("Debuggee"), tr("Function"), tr("File"), tr("Line"), tr("Address"),
tr("Condition"), tr("Ignore"), tr("Threads")}); tr("Condition"), tr("Ignore"), tr("Threads")});
connect(SessionManager::instance(), &SessionManager::sessionLoaded,
this, &BreakpointManager::loadSessionData);
connect(SessionManager::instance(), &SessionManager::aboutToSaveSession,
this, &BreakpointManager::saveSessionData);
connect(SessionManager::instance(), &SessionManager::aboutToUnloadSession,
this, &BreakpointManager::aboutToUnloadSession);
} }
QAbstractItemModel *BreakpointManager::model() QAbstractItemModel *BreakpointManager::model()
@@ -2755,20 +2764,20 @@ void BreakpointManager::saveSessionData()
map.insert("message", params.message); map.insert("message", params.message);
list.append(map); list.append(map);
}); });
setSessionValue("Breakpoints", list); SessionManager::setValue("Breakpoints", list);
} }
void BreakpointManager::aboutToUnloadSession() void BreakpointManager::aboutToUnloadSession()
{ {
saveSessionData(); saveSessionData();
theBreakpointManager->clear(); clear();
} }
void BreakpointManager::loadSessionData() void BreakpointManager::loadSessionData()
{ {
theBreakpointManager->clear(); clear();
const QVariant value = sessionValue("Breakpoints"); const QVariant value = SessionManager::value("Breakpoints");
const QList<QVariant> list = value.toList(); const QList<QVariant> list = value.toList();
for (const QVariant &var : list) { for (const QVariant &var : list) {
const QMap<QString, QVariant> map = var.toMap(); const QMap<QString, QVariant> map = var.toMap();

View File

@@ -234,9 +234,6 @@ public:
QAbstractItemModel *model() { return this; } QAbstractItemModel *model() { return this; }
const Breakpoints breakpoints() const; const Breakpoints breakpoints() const;
void loadSessionData();
void saveSessionData();
bool tryClaimBreakpoint(const GlobalBreakpoint &gbp); bool tryClaimBreakpoint(const GlobalBreakpoint &gbp);
void releaseAllBreakpoints(); void releaseAllBreakpoints();
@@ -297,9 +294,6 @@ public:
static QAbstractItemModel *model(); static QAbstractItemModel *model();
static const GlobalBreakpoints globalBreakpoints(); static const GlobalBreakpoints globalBreakpoints();
static void loadSessionData();
static void saveSessionData();
static void aboutToUnloadSession();
static GlobalBreakpoint createBreakpoint(const BreakpointParameters &data); static GlobalBreakpoint createBreakpoint(const BreakpointParameters &data);
@@ -325,6 +319,10 @@ private:
QVariant data(const QModelIndex &idx, int role) const final; QVariant data(const QModelIndex &idx, int role) const final;
bool setData(const QModelIndex &idx, const QVariant &value, int role) final; bool setData(const QModelIndex &idx, const QVariant &value, int role) final;
void loadSessionData();
void saveSessionData();
void aboutToUnloadSession();
bool contextMenuEvent(const Utils::ItemViewEvent &ev); bool contextMenuEvent(const Utils::ItemViewEvent &ev);
void gotoLocation(const GlobalBreakpoint &gbp) const; void gotoLocation(const GlobalBreakpoint &gbp) const;
void editBreakpoints(const GlobalBreakpoints &gbps, QWidget *parent); void editBreakpoints(const GlobalBreakpoints &gbps, QWidget *parent);

View File

@@ -73,8 +73,6 @@ void showModuleSections(const QString &moduleName, const QVector<Internal::Secti
QSharedPointer<Internal::GlobalDebuggerOptions> globalDebuggerOptions(); QSharedPointer<Internal::GlobalDebuggerOptions> globalDebuggerOptions();
QVariant sessionValue(const QByteArray &name);
void setSessionValue(const QByteArray &name, const QVariant &value);
QVariant configValue(const QString &name); QVariant configValue(const QString &name);
void setConfigValue(const QString &name, const QVariant &value); void setConfigValue(const QString &name, const QVariant &value);

View File

@@ -676,10 +676,6 @@ public:
void onStartupProjectChanged(Project *project); void onStartupProjectChanged(Project *project);
void sessionLoaded();
void aboutToUnloadSession();
void aboutToSaveSession();
void handleOperateByInstructionTriggered(bool operateByInstructionTriggered); void handleOperateByInstructionTriggered(bool operateByInstructionTriggered);
bool parseArgument(QStringList::const_iterator &it, bool parseArgument(QStringList::const_iterator &it,
@@ -1330,12 +1326,6 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments,
// ProjectExplorer // ProjectExplorer
connect(SessionManager::instance(), &SessionManager::sessionLoaded,
this, &DebuggerPluginPrivate::sessionLoaded);
connect(SessionManager::instance(), &SessionManager::aboutToSaveSession,
this, &DebuggerPluginPrivate::aboutToSaveSession);
connect(SessionManager::instance(), &SessionManager::aboutToUnloadSession,
this, &DebuggerPluginPrivate::aboutToUnloadSession);
connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::updateRunActions, connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::updateRunActions,
this, &DebuggerPluginPrivate::updatePresetState); this, &DebuggerPluginPrivate::updatePresetState);
@@ -2073,23 +2063,6 @@ void DebuggerPluginPrivate::dumpLog()
saver.finalize(ICore::mainWindow()); saver.finalize(ICore::mainWindow());
} }
void DebuggerPluginPrivate::sessionLoaded()
{
BreakpointManager::loadSessionData();
WatchHandler::loadSessionData();
}
void DebuggerPluginPrivate::aboutToUnloadSession()
{
BreakpointManager::aboutToUnloadSession();
}
void DebuggerPluginPrivate::aboutToSaveSession()
{
WatchHandler::saveSessionData();
BreakpointManager::saveSessionData();
}
void DebuggerPluginPrivate::aboutToShutdown() void DebuggerPluginPrivate::aboutToShutdown()
{ {
m_shuttingDown = true; m_shuttingDown = true;
@@ -2108,16 +2081,6 @@ void DebuggerPluginPrivate::aboutToShutdown()
m_shutdownTimer.start(); m_shutdownTimer.start();
} }
void setSessionValue(const QByteArray &key, const QVariant &value)
{
SessionManager::setValue(QString::fromUtf8(key), value);
}
QVariant sessionValue(const QByteArray &key)
{
return SessionManager::value(QString::fromUtf8(key));
}
static void createNewDock(QWidget *widget) static void createNewDock(QWidget *widget)
{ {
auto dockWidget = new QDockWidget; auto dockWidget = new QDockWidget;

View File

@@ -1076,7 +1076,7 @@ void DebuggerToolTipManagerPrivate::sessionAboutToChange()
void DebuggerToolTipManagerPrivate::loadSessionData() void DebuggerToolTipManagerPrivate::loadSessionData()
{ {
closeAllToolTips(); closeAllToolTips();
const QString data = sessionValue(sessionSettingsKeyC).toString(); const QString data = SessionManager::value(sessionSettingsKeyC).toString();
QXmlStreamReader r(data); QXmlStreamReader r(data);
if (r.readNextStartElement() && r.name() == QLatin1String(sessionDocumentC)) { if (r.readNextStartElement() && r.name() == QLatin1String(sessionDocumentC)) {
while (!r.atEnd()) { while (!r.atEnd()) {

View File

@@ -45,6 +45,8 @@
#include <coreplugin/helpmanager.h> #include <coreplugin/helpmanager.h>
#include <coreplugin/messagebox.h> #include <coreplugin/messagebox.h>
#include <projectexplorer/session.h>
#include <texteditor/syntaxhighlighter.h> #include <texteditor/syntaxhighlighter.h>
#include <app/app_version.h> #include <app/app_version.h>
@@ -81,6 +83,7 @@
#include <ctype.h> #include <ctype.h>
using namespace Core; using namespace Core;
using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
namespace Debugger { namespace Debugger {
@@ -212,12 +215,12 @@ static QString stripForFormat(const QString &ba)
static void saveWatchers() static void saveWatchers()
{ {
setSessionValue("Watchers", WatchHandler::watchedExpressions()); SessionManager::setValue("Watchers", WatchHandler::watchedExpressions());
} }
static void loadFormats() static void loadFormats()
{ {
QVariant value = sessionValue("DefaultFormats"); QVariant value = SessionManager::value("DefaultFormats");
QMapIterator<QString, QVariant> it(value.toMap()); QMapIterator<QString, QVariant> it(value.toMap());
while (it.hasNext()) { while (it.hasNext()) {
it.next(); it.next();
@@ -225,7 +228,7 @@ static void loadFormats()
theTypeFormats.insert(it.key(), it.value().toInt()); theTypeFormats.insert(it.key(), it.value().toInt());
} }
value = sessionValue("IndividualFormats"); value = SessionManager::value("IndividualFormats");
it = QMapIterator<QString, QVariant>(value.toMap()); it = QMapIterator<QString, QVariant>(value.toMap());
while (it.hasNext()) { while (it.hasNext()) {
it.next(); it.next();
@@ -247,7 +250,7 @@ static void saveFormats()
formats.insert(key, format); formats.insert(key, format);
} }
} }
setSessionValue("DefaultFormats", formats); SessionManager::setValue("DefaultFormats", formats);
formats.clear(); formats.clear();
it = QHashIterator<QString, int>(theIndividualFormats); it = QHashIterator<QString, int>(theIndividualFormats);
@@ -258,7 +261,18 @@ static void saveFormats()
if (!key.isEmpty()) if (!key.isEmpty())
formats.insert(key, format); formats.insert(key, format);
} }
setSessionValue("IndividualFormats", formats); SessionManager::setValue("IndividualFormats", formats);
}
static void saveSessionData()
{
saveWatchers();
saveFormats();
}
static void loadSessionData()
{
// Handled by loadSesseionDataForEngine.
} }
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
@@ -277,7 +291,7 @@ public:
setWindowFlags(windowFlags() | Qt::Window); setWindowFlags(windowFlags() | Qt::Window);
setWindowTitle(WatchHandler::tr("Debugger - %1").arg(Core::Constants::IDE_DISPLAY_NAME)); setWindowTitle(WatchHandler::tr("Debugger - %1").arg(Core::Constants::IDE_DISPLAY_NAME));
QVariant geometry = sessionValue("DebuggerSeparateWidgetGeometry"); QVariant geometry = SessionManager::value("DebuggerSeparateWidgetGeometry");
if (geometry.isValid()) { if (geometry.isValid()) {
QRect rc = geometry.toRect(); QRect rc = geometry.toRect();
if (rc.width() < 400) if (rc.width() < 400)
@@ -290,7 +304,7 @@ public:
void saveGeometry() void saveGeometry()
{ {
setSessionValue("DebuggerSeparateWidgetGeometry", geometry()); SessionManager::setValue("DebuggerSeparateWidgetGeometry", geometry());
} }
~SeparatedView() override ~SeparatedView() override
@@ -506,6 +520,11 @@ WatchModel::WatchModel(WatchHandler *handler, DebuggerEngine *engine)
m_engine, &DebuggerEngine::updateAll); m_engine, &DebuggerEngine::updateAll);
connect(action(ShowQObjectNames), &SavedAction::valueChanged, connect(action(ShowQObjectNames), &SavedAction::valueChanged,
m_engine, &DebuggerEngine::updateAll); m_engine, &DebuggerEngine::updateAll);
connect(SessionManager::instance(), &SessionManager::sessionLoaded,
this, &loadSessionData);
connect(SessionManager::instance(), &SessionManager::aboutToSaveSession,
this, &saveSessionData);
} }
void WatchModel::reinitialize(bool includeInspectData) void WatchModel::reinitialize(bool includeInspectData)
@@ -2077,7 +2096,7 @@ void WatchHandler::resetWatchers()
loadFormats(); loadFormats();
theWatcherNames.clear(); theWatcherNames.clear();
theWatcherCount = 0; theWatcherCount = 0;
const QStringList watchers = sessionValue("Watchers").toStringList(); const QStringList watchers = SessionManager::value("Watchers").toStringList();
m_model->m_watchRoot->removeChildren(); m_model->m_watchRoot->removeChildren();
for (const QString &exp : watchers) for (const QString &exp : watchers)
watchExpression(exp.trimmed()); watchExpression(exp.trimmed());
@@ -2383,23 +2402,12 @@ QStringList WatchHandler::watchedExpressions()
return watcherNames; return watcherNames;
} }
void WatchHandler::saveSessionData()
{
saveWatchers();
saveFormats();
}
void WatchHandler::loadSessionData()
{
// Handled by loadSesseionDataForEngine.
}
void WatchHandler::loadSessionDataForEngine() void WatchHandler::loadSessionDataForEngine()
{ {
loadFormats(); loadFormats();
theWatcherNames.clear(); theWatcherNames.clear();
theWatcherCount = 0; theWatcherCount = 0;
QVariant value = sessionValue("Watchers"); QVariant value = SessionManager::value("Watchers");
m_model->m_watchRoot->removeChildren(); m_model->m_watchRoot->removeChildren();
foreach (const QString &exp, value.toStringList()) foreach (const QString &exp, value.toStringList())
watchExpression(exp.trimmed()); watchExpression(exp.trimmed());

View File

@@ -78,9 +78,6 @@ public:
void loadSessionDataForEngine(); void loadSessionDataForEngine();
static void loadSessionData();
static void saveSessionData();
bool isExpandedIName(const QString &iname) const; bool isExpandedIName(const QString &iname) const;
QSet<QString> expandedINames() const; QSet<QString> expandedINames() const;