Commit 2161e0f6 authored by hjk's avatar hjk

debugger: refactoring of the plugin interface

There's  some 'external' and some 'internal' part now. Other plugins
are only supposed the external interface.
parent 60bafeb8
......@@ -31,7 +31,7 @@
#include "breakpointmarker.h"
#include "debuggeractions.h"
#include "debuggerplugin.h"
#include "debuggercore.h"
#include "debuggerstringutils.h"
#include <utils/qtcassert.h>
......@@ -40,17 +40,15 @@
#include <QtCore/QFileInfo>
namespace Debugger {
namespace Internal {
static DebuggerPlugin *plugin() { return DebuggerPlugin::instance(); }
//////////////////////////////////////////////////////////////////
//
// BreakHandler
//
//////////////////////////////////////////////////////////////////
namespace Debugger {
namespace Internal {
BreakHandler::BreakHandler()
: m_breakpointIcon(_(":/debugger/images/breakpoint_16.png")),
m_disabledBreakpointIcon(_(":/debugger/images/breakpoint_disabled_16.png")),
......@@ -148,7 +146,7 @@ bool BreakHandler::watchPointAt(quint64 address) const
void BreakHandler::saveBreakpoints()
{
//qDebug() << "SAVING BREAKPOINTS...";
QTC_ASSERT(plugin(), return);
QTC_ASSERT(debuggerCore(), return);
QList<QVariant> list;
for (int index = 0; index != size(); ++index) {
const BreakpointData *data = at(index);
......@@ -178,15 +176,15 @@ void BreakHandler::saveBreakpoints()
map.insert(_("usefullpath"), _("1"));
list.append(map);
}
plugin()->setSessionValue("Breakpoints", list);
debuggerCore()->setSessionValue("Breakpoints", list);
//qDebug() << "SAVED BREAKPOINTS" << this << list.size();
}
void BreakHandler::loadBreakpoints()
{
QTC_ASSERT(plugin(), return);
QTC_ASSERT(debuggerCore(), return);
//qDebug() << "LOADING BREAKPOINTS...";
QVariant value = plugin()->sessionValue("Breakpoints");
QVariant value = debuggerCore()->sessionValue("Breakpoints");
QList<QVariant> list = value.toList();
clear();
foreach (const QVariant &var, list) {
......
......@@ -31,8 +31,7 @@
#include "breakhandler.h"
#include "debuggeractions.h"
#include "debuggerplugin.h"
#include "debuggerconstants.h"
#include "debuggercore.h"
#include "ui_breakpoint.h"
#include "ui_breakcondition.h"
......@@ -44,26 +43,21 @@
#include <QtGui/QAction>
#include <QtGui/QHeaderView>
#include <QtGui/QIntValidator>
#include <QtGui/QItemSelectionModel>
#include <QtGui/QKeyEvent>
#include <QtGui/QMenu>
#include <QtGui/QResizeEvent>
#include <QtGui/QItemSelectionModel>
#include <QtGui/QToolButton>
#include <QtGui/QTreeView>
#include <QtGui/QIntValidator>
namespace Debugger {
namespace Internal {
static DebuggerPlugin *plugin()
{
return DebuggerPlugin::instance();
}
static BreakHandler *breakHandler()
{
return plugin()->breakHandler();
return debuggerCore()->breakHandler();
}
static BreakpointData *breakpointAt(int index)
......@@ -323,7 +317,7 @@ void BreakWindow::contextMenuEvent(QContextMenuEvent *ev)
QAction *synchronizeAction =
new QAction(tr("Synchronize Breakpoints"), &menu);
synchronizeAction->setEnabled(plugin()->hasSnapshots());
synchronizeAction->setEnabled(debuggerCore()->hasSnapshots());
QModelIndex idx0 = (si.size() ? si.front() : QModelIndex());
QModelIndex idx2 = idx0.sibling(idx0.row(), 2);
......@@ -556,7 +550,7 @@ void BreakWindow::rowActivated(const QModelIndex &index)
{
BreakpointData *data = breakpointAt(index.row());
QTC_ASSERT(data, return);
plugin()->gotoLocation(data->markerFileName(),
debuggerCore()->gotoLocation(data->markerFileName(),
data->markerLineNumber(), false);
}
......
......@@ -33,7 +33,7 @@
#include "cdbdumperhelper.h"
#include "cdbengine_p.h"
#include "debuggeractions.h"
#include "debuggerplugin.h"
#include "debuggercore.h"
#include "watchutils.h"
#include "threadshandler.h"
......@@ -74,7 +74,8 @@ CdbStackTraceContext::createSymbolGroup(const CdbCore::ComInterfaces & /* cif */
QStringList uninitializedVariables;
const CdbCore::StackFrame &frame = stackFrameAt(index);
if (theDebuggerAction(UseCodeModel)->isChecked())
getUninitializedVariables(DebuggerPlugin::instance()->cppCodeModelSnapshot(), frame.function, frame.fileName, frame.line, &uninitializedVariables);
getUninitializedVariables(debuggerCore()->cppCodeModelSnapshot(),
frame.function, frame.fileName, frame.line, &uninitializedVariables);
if (debug)
qDebug() << frame << uninitializedVariables;
CdbSymbolGroupContext *sc = CdbSymbolGroupContext::create(prefix,
......
......@@ -24,6 +24,7 @@ HEADERS += breakhandler.h \
debugger_global.h \
debuggeractions.h \
debuggeragents.h \
debuggercore.h \
debuggerconstants.h \
debuggerdialogs.h \
debuggerengine.h \
......
......@@ -30,10 +30,9 @@
#include "debuggeragents.h"
#include "debuggerengine.h"
#include "debuggerplugin.h"
#include "debuggercore.h"
#include "debuggerstringutils.h"
#include "stackframe.h"
#include "debuggerconstants.h"
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/editormanager.h>
......@@ -196,7 +195,7 @@ class LocationMark2 : public TextEditor::ITextMark
public:
LocationMark2() {}
QIcon icon() const { return DebuggerPlugin::instance()->locationMarkIcon(); }
QIcon icon() const { return debuggerCore()->locationMarkIcon(); }
void updateLineNumber(int /*lineNumber*/) {}
void updateBlock(const QTextBlock & /*block*/) {}
void removedFromEditor() {}
......
......@@ -31,8 +31,9 @@
#include "debuggeractions.h"
#include "debuggeragents.h"
#include "debuggerrunner.h"
#include "debuggercore.h"
#include "debuggerplugin.h"
#include "debuggerrunner.h"
#include "debuggerstringutils.h"
#include "debuggertooltip.h"
......@@ -87,6 +88,8 @@ using namespace TextEditor;
//
///////////////////////////////////////////////////////////////////////
namespace Debugger {
DebuggerStartParameters::DebuggerStartParameters() :
isSnapshot(false),
attachPID(-1),
......@@ -106,9 +109,6 @@ void DebuggerStartParameters::clear()
*this = DebuggerStartParameters();
}
namespace Debugger {
QDebug operator<<(QDebug d, DebuggerState state)
{
//return d << DebuggerEngine::stateName(state) << '(' << int(state) << ')';
......@@ -321,7 +321,7 @@ void DebuggerEngine::showModuleSymbols
it->setData(2, Qt::DisplayRole, s.state);
w->addTopLevelItem(it);
}
plugin()->createNewDock(w);
debuggerCore()->createNewDock(w);
}
void DebuggerEngine::frameUp()
......@@ -452,7 +452,7 @@ void DebuggerEngine::showMessage(const QString &msg, int channel, int timeout) c
{
//if (msg.size() && msg.at(0).isUpper() && msg.at(1).isUpper())
// qDebug() << qPrintable(msg) << "IN STATE" << state();
plugin()->showMessage(msg, channel, timeout);
debuggerCore()->showMessage(msg, channel, timeout);
if (d->m_runControl) {
d->m_runControl->showMessage(msg, channel);
} else {
......@@ -516,7 +516,7 @@ void DebuggerEngine::resetLocation()
{
d->m_disassemblerViewAgent.resetLocation();
d->m_stackHandler.setCurrentIndex(-1);
plugin()->resetLocation();
debuggerCore()->resetLocation();
}
void DebuggerEngine::gotoLocation(const QString &fileName, int lineNumber, bool setMarker)
......@@ -531,10 +531,10 @@ void DebuggerEngine::gotoLocation(const StackFrame &frame, bool setMarker)
{
if (theDebuggerBoolSetting(OperateByInstruction) || !frame.isUsable()) {
if (setMarker)
plugin()->resetLocation();
debuggerCore()->resetLocation();
d->m_disassemblerViewAgent.setFrame(frame);
} else {
plugin()->gotoLocation(frame.file, frame.line, setMarker);
debuggerCore()->gotoLocation(frame.file, frame.line, setMarker);
}
}
......@@ -600,7 +600,7 @@ QStringList DebuggerEngine::qtDumperLibraryLocations() const
void DebuggerEngine::showQtDumperLibraryWarning(const QString &details)
{
plugin()->showQtDumperLibraryWarning(details);
debuggerCore()->showQtDumperLibraryWarning(details);
}
QString DebuggerEngine::qtDumperLibraryName() const
......@@ -1011,7 +1011,7 @@ void DebuggerEngine::updateViews()
// should be coordinated by their master engine.
if (isSlaveEngine())
return;
plugin()->updateState(this);
debuggerCore()->updateState(this);
}
bool DebuggerEngine::isSlaveEngine() const
......@@ -1074,14 +1074,9 @@ qint64 DebuggerEngine::inferiorPid() const
return d->m_inferiorPid;
}
DebuggerPlugin *DebuggerEngine::plugin()
{
return DebuggerPlugin::instance();
}
bool DebuggerEngine::isReverseDebugging() const
{
return plugin()->isReverseDebugging();
return debuggerCore()->isReverseDebugging();
}
bool DebuggerEngine::isActive() const
......@@ -1130,7 +1125,7 @@ void DebuggerEngine::progressPing()
QMessageBox *DebuggerEngine::showMessageBox(int icon, const QString &title,
const QString &text, int buttons)
{
return plugin()->showMessageBox(icon, title, text, buttons);
return debuggerCore()->showMessageBox(icon, title, text, buttons);
}
DebuggerRunControl *DebuggerEngine::runControl() const
......@@ -1394,7 +1389,7 @@ void DebuggerEngine::executeDebuggerCommand(const QString &)
Internal::BreakHandler *DebuggerEngine::breakHandler() const
{
return plugin()->breakHandler();
return debuggerCore()->breakHandler();
}
bool DebuggerEngine::isDying() const
......
......@@ -56,8 +56,6 @@ class IOptionsPage;
namespace Debugger {
class DebuggerEnginePrivate;
class DebuggerPlugin;
class DebuggerPluginPrivate;
class DebuggerRunControl;
class QmlCppEngine;
......@@ -118,6 +116,8 @@ DEBUGGER_EXPORT QDebug operator<<(QDebug str, DebuggerState state);
namespace Internal {
class DebuggerCore;
class DebuggerPluginPrivate;
class DisassemblerViewAgent;
class MemoryViewAgent;
class Symbol;
......@@ -209,7 +209,7 @@ public:
(int icon, const QString &title, const QString &text, int buttons = 0);
protected:
friend class DebuggerPluginPrivate;
friend class Internal::DebuggerPluginPrivate;
virtual void detachDebugger();
virtual void exitDebugger();
virtual void executeStep();
......@@ -232,7 +232,6 @@ protected:
virtual void frameDown();
public:
static DebuggerPlugin *plugin();
const DebuggerStartParameters &startParameters() const;
DebuggerStartParameters &startParameters();
......
This diff is collapsed.
......@@ -31,18 +31,10 @@
#define DEBUGGERPLUGIN_H
#include "debugger_global.h"
#include "debuggerconstants.h"
#include <extensionsystem/iplugin.h>
QT_BEGIN_NAMESPACE
class QIcon;
class QMessageBox;
QT_END_NAMESPACE
namespace CPlusPlus {
class Snapshot;
}
#include <QtCore/QObject>
namespace ProjectExplorer {
class RunConfiguration;
......@@ -50,15 +42,15 @@ class RunControl;
}
namespace Debugger {
class DebuggerEngine;
class DebuggerPluginPrivate;
class DebuggerRunControl;
class DebuggerStartParameters;
class DebuggerUISwitcher;
namespace Internal {
class BreakHandler;
class SnapshotHandler;
}
// This is the "external" interface of the debugger plugin that's
// visible from Creator core. The internal interfact to global
// functionality to be used by debugger views and debugger engines
// is DebuggerCore, implemented in DebuggerPluginPrivate.
class DEBUGGER_EXPORT DebuggerPlugin : public ExtensionSystem::IPlugin
{
......@@ -68,68 +60,23 @@ public:
DebuggerPlugin();
~DebuggerPlugin();
static DebuggerPlugin *instance();
static DebuggerRunControl *createDebugger(const DebuggerStartParameters &sp,
ProjectExplorer::RunConfiguration *rc = 0);
static void startDebugger(ProjectExplorer::RunControl *runControl);
static void displayDebugger(ProjectExplorer::RunControl *runControl);
static void displayDebugger(DebuggerEngine *engine, bool updateEngine = true);
QVariant sessionValue(const QString &name);
void setSessionValue(const QString &name, const QVariant &value);
QVariant configValue(const QString &name) const;
void setConfigValue(const QString &name, const QVariant &value);
void updateState(DebuggerEngine *engine);
virtual void remoteCommand(const QStringList &options, const QStringList &arguments);
void showQtDumperLibraryWarning(const QString &details);
QIcon locationMarkIcon() const;
void activateDebugMode();
const CPlusPlus::Snapshot &cppCodeModelSnapshot() const;
bool isRegisterViewVisible() const;
bool hasSnapshots() const;
void openTextEditor(const QString &titlePattern, const QString &contents);
Internal::BreakHandler *breakHandler() const;
Internal::SnapshotHandler *snapshotHandler() const;
DebuggerEngine *currentEngine() const;
public slots:
void clearCppCodeModelSnapshot();
void ensureLogVisible();
// void runTest(const QString &fileName);
void showMessage(const QString &msg, int channel, int timeout = -1);
void gotoLocation(const QString &fileName, int lineNumber = -1,
bool setMarker = false);
static bool isActiveDebugLanguage(int language);
static DebuggerUISwitcher *uiSwitcher();
private:
friend class DebuggerEngine;
friend class DebuggerPluginPrivate;
friend class DebuggerRunControl;
void resetLocation();
// IPlugin implementation.
bool initialize(const QStringList &arguments, QString *errorMessage);
void remoteCommand(const QStringList &options, const QStringList &arguments);
ShutdownFlag aboutToShutdown();
void extensionsInitialized();
void readSettings();
void writeSettings() const;
bool isReverseDebugging() const;
void createNewDock(QWidget *widget);
void runControlStarted(DebuggerRunControl *runControl);
void runControlFinished(DebuggerRunControl *runControl);
DebuggerLanguages activeLanguages() const;
QMessageBox *showMessageBox(int icon, const QString &title,
const QString &text, int buttons = 0);
bool initialize(const QStringList &arguments, QString *errorMessage);
ShutdownFlag aboutToShutdown();
void extensionsInitialized();
QWidget *mainWindow() const;
DebuggerPluginPrivate *d;
};
} // namespace Debugger
......
......@@ -30,6 +30,7 @@
#include "debuggerrunner.h"
#include "debuggeractions.h"
#include "debuggercore.h"
#include "debuggerengine.h"
#include "debuggerplugin.h"
#include "debuggerstringutils.h"
......@@ -112,8 +113,6 @@ static QString msgEngineNotAvailable(const char *engine)
"which is disabled.").arg(QLatin1String(engine));
}
static DebuggerPlugin *plugin() { return DebuggerPlugin::instance(); }
// A factory to create DebuggerRunControls
DebuggerRunControlFactory::DebuggerRunControlFactory(QObject *parent,
unsigned enabledEngines)
......@@ -180,16 +179,17 @@ static DebuggerStartParameters localStartParameters(RunConfiguration *runConfigu
sp.dumperLibrary = rc->dumperLibrary();
sp.dumperLibraryLocations = rc->dumperLibraryLocations();
DebuggerLanguages activeLangs = DebuggerUISwitcher::instance()->activeDebugLanguages();
if (activeLangs & QmlLanguage) {
if (debuggerCore()->isActiveDebugLanguage(QmlLanguage)) {
sp.qmlServerAddress = QLatin1String("127.0.0.1");
sp.qmlServerPort = runConfiguration->qmlDebugServerPort();
sp.projectDir = runConfiguration->target()->project()->projectDirectory();
if (runConfiguration->target()->activeBuildConfiguration())
sp.projectBuildDir = runConfiguration->target()->activeBuildConfiguration()->buildDirectory();
sp.projectBuildDir = runConfiguration->target()
->activeBuildConfiguration()->buildDirectory();
sp.processArgs.append(QLatin1String("-qmljsdebugger=port:") + QString::number(sp.qmlServerPort));
sp.processArgs.append(QLatin1String("-qmljsdebugger=port:")
+ QString::number(sp.qmlServerPort));
}
// FIXME: If it's not yet build this will be empty and not filled
......@@ -413,7 +413,7 @@ void DebuggerRunControl::createEngine(const DebuggerStartParameters &startParams
// Figure out engine according to toolchain, executable, attach or default.
DebuggerEngineType engineType = NoEngineType;
DebuggerLanguages activeLangs = DebuggerPlugin::instance()->activeLanguages();
DebuggerLanguages activeLangs = debuggerCore()->activeLanguages();
const unsigned enabledEngineTypes = d->enabledEngines();
if (sp.executable.endsWith(_(".js")))
engineType = ScriptEngineType;
......@@ -540,7 +540,7 @@ bool DebuggerRunControl::checkDebugConfiguration(int toolChain,
bool success = true;
if (!(DebuggerPlugin::instance()->activeLanguages() & CppLanguage))
if (!(debuggerCore()->activeLanguages() & CppLanguage))
return success;
switch(toolChain) {
......@@ -589,14 +589,7 @@ void DebuggerRunControl::start()
return;
}
plugin()->activateDebugMode();
DebuggerUISwitcher::instance()->aboutToStartDebugger();
const QString message = tr("Starting debugger '%1' for tool chain '%2'...").
arg(d->m_engine->objectName(), toolChainName(sp.toolChainType));
plugin()->showMessage(message, StatusBar);
plugin()->showMessage(DebuggerSettings::instance()->dump(), LogDebug);
plugin()->runControlStarted(this);
debuggerCore()->runControlStarted(this);
// We might get a synchronous startFailed() notification on Windows,
// when launching the process fails. Emit a proper finished() sequence.
......@@ -611,6 +604,13 @@ void DebuggerRunControl::start()
}
}
QString DebuggerRunControl::idString() const
{
return tr("Starting debugger '%1' for tool chain '%2'...")
.arg(d->m_engine->objectName())
.arg(toolChainName(d->m_engine->startParameters().toolChainType));
}
void DebuggerRunControl::startFailed()
{
emit addToOutputWindowInline(this, tr("Debugging has failed"), false);
......@@ -624,7 +624,7 @@ void DebuggerRunControl::handleFinished()
emit addToOutputWindowInline(this, tr("Debugging has finished"), false);
if (engine())
engine()->handleFinished();
plugin()->runControlFinished(this);
debuggerCore()->runControlFinished(this);
}
void DebuggerRunControl::showMessage(const QString &msg, int channel)
......@@ -652,7 +652,7 @@ bool DebuggerRunControl::aboutToStop() const
" Would you still like to terminate it?");
const QMessageBox::StandardButton answer =
QMessageBox::question(DebuggerUISwitcher::instance()->mainWindow(),
QMessageBox::question(debuggerCore()->mainWindow(),
tr("Close Debugging Session"), question,
QMessageBox::Yes|QMessageBox::No);
return answer == QMessageBox::Yes;
......@@ -754,4 +754,5 @@ RunConfiguration *DebuggerRunControl::runConfiguration() const
{
return d->m_myRunConfiguration.data();
}
} // namespace Debugger
......@@ -120,6 +120,7 @@ public:
QString *errorMessage,
QString *settingsCategory = 0,
QString *settingsPage = 0);
QString idString() const;
signals:
void engineRequestSetup();
......
......@@ -140,8 +140,6 @@ struct DebuggerUISwitcherPrivate
QWeakPointer<ProjectExplorer::RunConfiguration> m_previousRunConfiguration;
bool m_initialized;
static DebuggerUISwitcher *m_instance;
};
DebuggerUISwitcherPrivate::DebuggerUISwitcherPrivate(DebuggerUISwitcher *q)
......@@ -160,8 +158,6 @@ DebuggerUISwitcherPrivate::DebuggerUISwitcherPrivate(DebuggerUISwitcher *q)
{
}
DebuggerUISwitcher *DebuggerUISwitcherPrivate::m_instance = 0;
DebuggerUISwitcher::DebuggerUISwitcher(BaseMode *mode, QObject* parent)
: QObject(parent), d(new DebuggerUISwitcherPrivate(this))
{
......@@ -180,13 +176,10 @@ DebuggerUISwitcher::DebuggerUISwitcher(BaseMode *mode, QObject* parent)
d->m_debugMenu = am->actionContainer(ProjectExplorer::Constants::M_DEBUG);
d->m_viewsMenu = am->actionContainer(Core::Id(Core::Constants::M_WINDOW_VIEWS));
QTC_ASSERT(d->m_viewsMenu, return)
DebuggerUISwitcherPrivate::m_instance = this;
}
DebuggerUISwitcher::~DebuggerUISwitcher()
{
DebuggerUISwitcherPrivate::m_instance = 0;
delete d;
}
......@@ -345,11 +338,6 @@ void DebuggerUISwitcher::createViewsMenuItems()
d->m_viewsMenu->addAction(cmd);
}
DebuggerUISwitcher *DebuggerUISwitcher::instance()
{
return DebuggerUISwitcherPrivate::m_instance;
}
void DebuggerUISwitcher::addLanguage(const DebuggerLanguage &languageId, const Context &context)
{
bool activate = (d->m_supportedLanguages == AnyLanguage);
......@@ -595,20 +583,8 @@ QWidget *DebuggerUISwitcher::createContents(BaseMode *mode)
return splitter;
}
void DebuggerUISwitcher::aboutToStartDebugger()
{
if (!DebuggerPlugin::instance()->hasSnapshots())
updateActiveLanguages();
}
void DebuggerUISwitcher::aboutToShutdown()
{
writeSettings();
}
void DebuggerUISwitcher::writeSettings() const
void DebuggerUISwitcher::writeSettings(QSettings *settings) const
{
QSettings *settings = ICore::instance()->settings();
{
settings->beginGroup(QLatin1String("DebugMode.CppMode"));
QHashIterator<QString, QVariant> it(d->m_dockWidgetActiveStateCpp);
......@@ -629,9 +605,8 @@ void DebuggerUISwitcher::writeSettings() const
}
}
void DebuggerUISwitcher::readSettings()
void DebuggerUISwitcher::readSettings(QSettings *settings)
{
QSettings *settings = ICore::instance()->settings();
d->m_dockWidgetActiveStateCpp.clear();
d->m_dockWidgetActiveStateQmlCpp.clear();
......@@ -660,12 +635,12 @@ void DebuggerUISwitcher::readSettings()
d->m_activeDebugLanguages = langs;
}
void DebuggerUISwitcher::initialize()
void DebuggerUISwitcher::initialize(QSettings *settings)
{
createViewsMenuItems();
emit dockResetRequested(AnyLanguage);
readSettings();
readSettings(settings);