Commit 6321e4eb authored by hjk's avatar hjk
Browse files

debugger: closer dependency plugin<->manager, less signal/slot connections

parent 944b6dad
......@@ -29,6 +29,7 @@
#include "debuggermanager.h"
#include "debuggerplugin.h"
#include "debuggeractions.h"
#include "debuggeragents.h"
#include "debuggerrunner.h"
......@@ -305,6 +306,7 @@ struct DebuggerManagerPrivate
DebuggerState m_state;
CPlusPlus::Snapshot m_codeModelSnapshot;
DebuggerPlugin *m_plugin;
};
DebuggerManager *DebuggerManagerPrivate::instance = 0;
......@@ -322,10 +324,11 @@ DebuggerManagerPrivate::DebuggerManagerPrivate(DebuggerManager *manager) :
m_stopIcon.addFile(":/debugger/images/debugger_stop.png");
}
DebuggerManager::DebuggerManager()
DebuggerManager::DebuggerManager(DebuggerPlugin *plugin)
: d(new DebuggerManagerPrivate(this))
{
DebuggerManagerPrivate::instance = this;
d->m_plugin = plugin;
init();
}
......@@ -564,17 +567,17 @@ void DebuggerManager::init()
this, SLOT(reloadModules()), Qt::QueuedConnection);
d->m_registerDock = uiSwitcher->createDockWidget(LANG_CPP, d->m_registerWindow,
Qt::TopDockWidgetArea, false);
Qt::TopDockWidgetArea, false);
connect(d->m_registerDock->toggleViewAction(), SIGNAL(toggled(bool)),
this, SLOT(reloadRegisters()), Qt::QueuedConnection);
d->m_outputDock = uiSwitcher->createDockWidget(LANG_CPP, d->m_outputWindow,
Qt::TopDockWidgetArea, false);
Qt::TopDockWidgetArea, false);
d->m_snapshotDock = uiSwitcher->createDockWidget(LANG_CPP, d->m_snapshotWindow);
d->m_stackDock = uiSwitcher->createDockWidget(LANG_CPP, d->m_stackWindow);
d->m_sourceFilesDock = uiSwitcher->createDockWidget(LANG_CPP, d->m_sourceFilesWindow,
Qt::TopDockWidgetArea, false);
d->m_sourceFilesDock = uiSwitcher->createDockWidget(LANG_CPP,
d->m_sourceFilesWindow, Qt::TopDockWidgetArea, false);
connect(d->m_sourceFilesDock->toggleViewAction(), SIGNAL(toggled(bool)),
this, SLOT(reloadSourceFiles()), Qt::QueuedConnection);
......@@ -588,7 +591,8 @@ void DebuggerManager::init()
localsAndWatchers->setStretchFactor(0, 3);
localsAndWatchers->setStretchFactor(1, 1);
localsAndWatchers->setStretchFactor(2, 1);
d->m_watchDock = DebuggerUISwitcher::instance()->createDockWidget(LANG_CPP, localsAndWatchers);
d->m_watchDock = DebuggerUISwitcher::instance()->createDockWidget(LANG_CPP,
localsAndWatchers);
d->m_dockWidgets << d->m_breakDock << d->m_modulesDock << d->m_registerDock
<< d->m_outputDock << d->m_stackDock << d->m_sourceFilesDock
<< d->m_threadsDock << d->m_watchDock;
......@@ -691,7 +695,8 @@ QWidget *DebuggerManager::threadsWindow() const
void DebuggerManager::createNewDock(QWidget *widget)
{
QDockWidget *dockWidget = DebuggerUISwitcher::instance()->createDockWidget(LANG_CPP, widget);
QDockWidget *dockWidget =
DebuggerUISwitcher::instance()->createDockWidget(LANG_CPP, widget);
dockWidget->setWindowTitle(widget->windowTitle());
dockWidget->setObjectName(widget->windowTitle());
dockWidget->setFeatures(QDockWidget::DockWidgetClosable);
......@@ -860,7 +865,7 @@ void DebuggerManager::toggleBreakpoint()
{
QString fileName;
int lineNumber = -1;
queryCurrentTextEditor(&fileName, &lineNumber, 0);
d->m_plugin->currentTextEditor(&fileName, &lineNumber);
if (lineNumber == -1)
return;
toggleBreakpoint(fileName, lineNumber);
......@@ -1047,9 +1052,10 @@ void DebuggerManager::startNewDebugger(const DebuggerStartParametersPtr &sp)
d->m_startParameters = sp;
d->m_inferiorPid = d->m_startParameters->attachPID > 0
? d->m_startParameters->attachPID : 0;
const QString toolChainName = ProjectExplorer::ToolChain::toolChainName(static_cast<ProjectExplorer::ToolChain::ToolChainType>(d->m_startParameters->toolChainType));
const QString toolChainName = ProjectExplorer::ToolChain::toolChainName(
ProjectExplorer::ToolChain::ToolChainType(d->m_startParameters->toolChainType));
emit debugModeRequested();
d->m_plugin->activateDebugMode();
showDebuggerOutput(LogStatus,
tr("Starting debugger for tool chain '%1'...").arg(toolChainName));
showDebuggerOutput(LogDebug, DebuggerSettings::instance()->dump());
......@@ -1347,12 +1353,6 @@ void DebuggerManager::setBusyCursor(bool busy)
d->m_watchersWindow->setCursor(cursor);
}
void DebuggerManager::queryCurrentTextEditor(QString *fileName, int *lineNumber,
QObject **object)
{
emit currentTextEditorRequested(fileName, lineNumber, object);
}
void DebuggerManager::continueExec()
{
if (d->m_engine)
......@@ -1382,7 +1382,7 @@ void DebuggerManager::runToLineExec()
{
QString fileName;
int lineNumber = -1;
emit currentTextEditorRequested(&fileName, &lineNumber, 0);
d->m_plugin->currentTextEditor(&fileName, &lineNumber);
if (d->m_engine && !fileName.isEmpty()) {
STATE_DEBUG(fileName << lineNumber);
d->m_engine->runToLineExec(fileName, lineNumber);
......@@ -1393,8 +1393,7 @@ void DebuggerManager::runToFunctionExec()
{
QString fileName;
int lineNumber = -1;
QObject *object = 0;
emit currentTextEditorRequested(&fileName, &lineNumber, &object);
QObject *object = d->m_plugin->currentTextEditor(&fileName, &lineNumber);
QPlainTextEdit *ed = qobject_cast<QPlainTextEdit*>(object);
if (!ed)
return;
......@@ -1426,7 +1425,7 @@ void DebuggerManager::jumpToLineExec()
{
QString fileName;
int lineNumber = -1;
emit currentTextEditorRequested(&fileName, &lineNumber, 0);
d->m_plugin->currentTextEditor(&fileName, &lineNumber);
if (d->m_engine && !fileName.isEmpty()) {
STATE_DEBUG(fileName << lineNumber);
d->m_engine->jumpToLineExec(fileName, lineNumber);
......@@ -1438,18 +1437,18 @@ void DebuggerManager::resetLocation()
d->m_disassemblerViewAgent.resetLocation();
d->m_stackHandler->setCurrentIndex(-1);
// Connected to the plugin.
emit resetLocationRequested();
d->m_plugin->resetLocation();
}
void DebuggerManager::gotoLocation(const Debugger::Internal::StackFrame &frame, bool setMarker)
void DebuggerManager::gotoLocation(const StackFrame &frame, bool setMarker)
{
if (theDebuggerBoolSetting(OperateByInstruction) || !frame.isUsable()) {
if (setMarker)
emit resetLocationRequested();
d->m_plugin->resetLocation();
d->m_disassemblerViewAgent.setFrame(frame);
} else {
// Connected to the plugin.
emit gotoLocationRequested(frame.file, frame.line, setMarker);
d->m_plugin->gotoLocation(frame.file, frame.line, setMarker);
}
}
......@@ -1633,15 +1632,12 @@ bool DebuggerManager::isReverseDebugging() const
QVariant DebuggerManager::sessionValue(const QString &name)
{
// this is answered by the plugin
QVariant value;
emit sessionValueRequested(name, &value);
return value;
return d->m_plugin->sessionValue(name);
}
void DebuggerManager::setSessionValue(const QString &name, const QVariant &value)
{
emit setSessionValueRequested(name, value);
d->m_plugin->setSessionValue(name, value);
}
QMessageBox *DebuggerManager::showMessageBox(int icon, const QString &title,
......@@ -1803,7 +1799,7 @@ void DebuggerManager::setState(DebuggerState state, bool forced)
theDebuggerAction(ExpandStack)->setEnabled(actionsEnabled);
theDebuggerAction(ExecuteCommand)->setEnabled(d->m_state != DebuggerNotReady);
emit stateChanged(d->m_state);
d->m_plugin->handleStateChanged(d->m_state);
const bool notbusy = state == InferiorStopped
|| state == DebuggerNotReady
|| state == InferiorUnrunnable;
......
......@@ -87,7 +87,6 @@ class ScriptEngine;
class CdbDebugEngine;
class CdbDebugEnginePrivate;
struct DebuggerManagerActions;
class DebuggerPlugin;
class CdbDebugEventCallback;
class CdbDumperHelper;
class CdbDumperInitThread;
......@@ -158,7 +157,7 @@ class DEBUGGER_EXPORT DebuggerManager : public QObject
Q_OBJECT
public:
DebuggerManager();
explicit DebuggerManager(Internal::DebuggerPlugin *plugin);
~DebuggerManager();
friend class Internal::IDebuggerEngine;
......@@ -207,7 +206,6 @@ public slots:
void setSimpleDockWidgetArrangement(const QString &activeLanguage);
void setBusyCursor(bool on);
void queryCurrentTextEditor(QString *fileName, int *lineNumber, QObject **ed);
void gotoLocation(const Debugger::Internal::StackFrame &frame, bool setLocationMarker);
void fileOpen(const QString &file);
......@@ -330,16 +328,7 @@ signals:
void debuggingFinished();
void inferiorPidChanged(qint64 pid);
void stateChanged(int newstatus);
void debugModeRequested();
void previousModeRequested();
void statusMessageRequested(const QString &msg, int timeout); // -1 for 'forever'
void gotoLocationRequested(const QString &file, int line, bool setLocationMarker);
void resetLocationRequested();
void currentTextEditorRequested(QString *fileName, int *lineNumber, QObject **ob);
void sessionValueRequested(const QString &name, QVariant *value);
void setSessionValueRequested(const QString &name, const QVariant &value);
void configValueRequested(const QString &name, QVariant *value);
void setConfigValueRequested(const QString &name, const QVariant &value);
void applicationOutputAvailable(const QString &output);
void emitShowOutput(int channel, const QString &output);
void emitShowInput(int channel, const QString &input);
......
......@@ -86,6 +86,7 @@
#include <QtCore/QtPlugin>
#include <QtCore/QCoreApplication>
#include <QtCore/QTimer>
#include <QtCore/QVariant>
#include <QtGui/QLineEdit>
#include <QtGui/QDockWidget>
......@@ -674,11 +675,6 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
ExtensionSystem::PluginManager::instance()->addObject(m_uiSwitcher);
m_uiSwitcher->addLanguage(LANG_CPP);
m_manager = new DebuggerManager;
ExtensionSystem::PluginManager::instance()->addObject(m_manager);
const QList<Core::IOptionsPage *> engineOptionPages =
m_manager->initializeEngines(m_cmdLineEnabledEngines);
ICore *core = ICore::instance();
QTC_ASSERT(core, return false);
......@@ -705,8 +701,13 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
m_gdbRunningContext = uidm->uniqueIdentifier(Constants::GDBRUNNING);
DebuggerManager *manager = new DebuggerManager(this);
ExtensionSystem::PluginManager::instance()->addObject(manager);
const QList<Core::IOptionsPage *> engineOptionPages =
manager->initializeEngines(m_cmdLineEnabledEngines);
// register factory of DebuggerRunControl
m_debuggerRunControlFactory = new DebuggerRunControlFactory(m_manager);
m_debuggerRunControlFactory = new DebuggerRunControlFactory(manager);
addAutoReleasedObject(m_debuggerRunControlFactory);
QList<int> context;
......@@ -741,13 +742,13 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
m_detachAction = new QAction(this);
m_detachAction->setText(tr("Detach Debugger"));
connect(m_detachAction, SIGNAL(triggered()),
m_manager, SLOT(detachDebugger()));
manager, SLOT(detachDebugger()));
// Core::ActionContainer *mdebug =
// am->actionContainer(ProjectExplorer::Constants::M_DEBUG);
Core::Command *cmd = 0;
const DebuggerManagerActions actions = m_manager->debuggerManagerActions();
const DebuggerManagerActions actions = manager->debuggerManagerActions();
Core::ActionContainer *mstart =
......@@ -902,34 +903,33 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
addAutoReleasedObject(new DebuggerListener);
m_locationMark = 0;
m_manager->setSimpleDockWidgetArrangement(LANG_CPP);
manager->setSimpleDockWidgetArrangement(LANG_CPP);
readSettings();
m_uiSwitcher->setToolbar(LANG_CPP, createToolbar());
connect(m_uiSwitcher, SIGNAL(dockArranged(QString)), m_manager,
SLOT(setSimpleDockWidgetArrangement(QString)));
connect(ModeManager::instance(), SIGNAL(currentModeChanged(Core::IMode*)),
this, SLOT(onModeChanged(Core::IMode*)));
m_debugMode->widget()->setFocusProxy(EditorManager::instance());
addObject(m_debugMode);
m_manager = manager;
//
// Connections
//
// TextEditor
connect(TextEditor::TextEditorPlugin::instance(),
connect(TextEditorPlugin::instance(),
SIGNAL(fontSettingsChanged(TextEditor::FontSettings)),
m_manager, SLOT(fontSettingsChanged(TextEditor::FontSettings)));
manager, SLOT(fontSettingsChanged(TextEditor::FontSettings)));
// ProjectExplorer
connect(sessionManager(), SIGNAL(sessionLoaded()),
m_manager, SLOT(sessionLoaded()));
manager, SLOT(sessionLoaded()));
connect(sessionManager(), SIGNAL(aboutToSaveSession()),
m_manager, SLOT(aboutToSaveSession()));
manager, SLOT(aboutToSaveSession()));
connect(sessionManager(), SIGNAL(aboutToUnloadSession()),
m_manager, SLOT(aboutToUnloadSession()));
manager, SLOT(aboutToUnloadSession()));
// EditorManager
QObject *editorManager = core->editorManager();
......@@ -939,60 +939,46 @@ bool DebuggerPlugin::initialize(const QStringList &arguments, QString *errorMess
this, SLOT(editorOpened(Core::IEditor*)));
// Application interaction
connect(m_manager, SIGNAL(currentTextEditorRequested(QString*,int*,QObject**)),
this, SLOT(queryCurrentTextEditor(QString*,int*,QObject**)));
connect(m_manager, SIGNAL(setSessionValueRequested(QString,QVariant)),
this, SLOT(setSessionValue(QString,QVariant)));
connect(m_manager, SIGNAL(sessionValueRequested(QString,QVariant*)),
this, SLOT(querySessionValue(QString,QVariant*)));
connect(m_manager, SIGNAL(resetLocationRequested()),
this, SLOT(resetLocation()));
connect(m_manager, SIGNAL(gotoLocationRequested(QString,int,bool)),
this, SLOT(gotoLocation(QString,int,bool)));
connect(m_manager, SIGNAL(stateChanged(int)),
this, SLOT(handleStateChanged(int)));
connect(m_manager, SIGNAL(previousModeRequested()),
this, SLOT(activatePreviousMode()));
connect(m_manager, SIGNAL(debugModeRequested()),
this, SLOT(activateDebugMode()));
connect(theDebuggerAction(SettingsDialog), SIGNAL(triggered()),
this, SLOT(showSettingsDialog()));
handleStateChanged(DebuggerNotReady);
m_uiSwitcher->setToolbar(LANG_CPP, createToolbar());
connect(m_uiSwitcher, SIGNAL(dockArranged(QString)), manager,
SLOT(setSimpleDockWidgetArrangement(QString)));
return true;
}
QWidget *DebuggerPlugin::createToolbar() const
{
Core::ActionManager *am = ICore::instance()->actionManager();
QWidget *toolbarContainer = new QWidget;
QHBoxLayout *debugToolBarLayout = new QHBoxLayout(toolbarContainer);
debugToolBarLayout->setMargin(0);
debugToolBarLayout->setSpacing(0);
debugToolBarLayout->addWidget(toolButton(am->command(ProjectExplorer::Constants::DEBUG)->action()));
debugToolBarLayout->addWidget(toolButton(am->command(Constants::INTERRUPT)->action()));
debugToolBarLayout->addWidget(toolButton(am->command(Constants::NEXT)->action()));
debugToolBarLayout->addWidget(toolButton(am->command(Constants::STEP)->action()));
debugToolBarLayout->addWidget(toolButton(am->command(Constants::STEPOUT)->action()));
debugToolBarLayout->addWidget(toolButton(am->command(Constants::OPERATE_BY_INSTRUCTION)->action()));
QHBoxLayout *hbox = new QHBoxLayout(toolbarContainer);
hbox->setMargin(0);
hbox->setSpacing(0);
hbox->addWidget(toolButton(am->command(ProjectExplorer::Constants::DEBUG)->action()));
hbox->addWidget(toolButton(am->command(Constants::INTERRUPT)->action()));
hbox->addWidget(toolButton(am->command(Constants::NEXT)->action()));
hbox->addWidget(toolButton(am->command(Constants::STEP)->action()));
hbox->addWidget(toolButton(am->command(Constants::STEPOUT)->action()));
hbox->addWidget(toolButton(am->command(Constants::OPERATE_BY_INSTRUCTION)->action()));
#ifdef USE_REVERSE_DEBUGGING
debugToolBarLayout->addWidget(new Utils::StyledSeparator);
debugToolBarLayout->addWidget(toolButton(am->command(Constants::REVERSE)->action()));
hbox->addWidget(new Utils::StyledSeparator);
hbox->addWidget(toolButton(am->command(Constants::REVERSE)->action()));
#endif
debugToolBarLayout->addWidget(new Utils::StyledSeparator);
debugToolBarLayout->addWidget(new QLabel(tr("Threads:")));
hbox->addWidget(new Utils::StyledSeparator);
hbox->addWidget(new QLabel(tr("Threads:")));
QComboBox *threadBox = new QComboBox;
threadBox->setModel(m_manager->threadsModel());
connect(threadBox, SIGNAL(activated(int)),
m_manager->threadsWindow(), SIGNAL(threadSelected(int)));
debugToolBarLayout->addWidget(threadBox);
debugToolBarLayout->addWidget(m_manager->statusLabel(), 10);
hbox->addWidget(threadBox);
hbox->addWidget(m_manager->statusLabel(), 10);
return toolbarContainer;
}
......@@ -1047,21 +1033,20 @@ void DebuggerPlugin::activateDebugMode()
modeManager->activateMode(QLatin1String(MODE_DEBUG));
}
void DebuggerPlugin::queryCurrentTextEditor(QString *fileName, int *lineNumber, QObject **object)
QWidget *DebuggerPlugin::currentTextEditor(QString *fileName, int *lineNumber)
{
EditorManager *editorManager = EditorManager::instance();
if (!editorManager)
return;
return 0;
Core::IEditor *editor = editorManager->currentEditor();
ITextEditor *textEditor = qobject_cast<ITextEditor*>(editor);
if (!textEditor)
return;
return 0;
if (fileName)
*fileName = textEditor->file()->fileName();
if (lineNumber)
*lineNumber = textEditor->currentLine();
if (object)
*object = textEditor->widget();
return textEditor->widget();
}
void DebuggerPlugin::editorOpened(Core::IEditor *editor)
......@@ -1140,13 +1125,12 @@ void DebuggerPlugin::breakpointEnableDisableMarginActionTriggered()
}
}
void DebuggerPlugin::requestMark(TextEditor::ITextEditor *editor, int lineNumber)
void DebuggerPlugin::requestMark(ITextEditor *editor, int lineNumber)
{
m_manager->toggleBreakpoint(editor->file()->fileName(), lineNumber);
}
void DebuggerPlugin::showToolTip(TextEditor::ITextEditor *editor,
const QPoint &point, int pos)
void DebuggerPlugin::showToolTip(ITextEditor *editor, const QPoint &point, int pos)
{
if (!theDebuggerBoolSetting(UseToolTipsInMainEditor)
|| m_manager->state() == DebuggerNotReady)
......@@ -1157,19 +1141,16 @@ void DebuggerPlugin::showToolTip(TextEditor::ITextEditor *editor,
void DebuggerPlugin::setSessionValue(const QString &name, const QVariant &value)
{
//qDebug() << "SET SESSION VALUE" << name << value;
QTC_ASSERT(sessionManager(), return);
sessionManager()->setValue(name, value);
}
void DebuggerPlugin::querySessionValue(const QString &name, QVariant *value)
QVariant DebuggerPlugin::sessionValue(const QString &name)
{
QTC_ASSERT(sessionManager(), return);
*value = sessionManager()->value(name);
//qDebug() << "GET SESSION VALUE: " << name << value;
QTC_ASSERT(sessionManager(), return QVariant());
return sessionManager()->value(name);
}
void DebuggerPlugin::setConfigValue(const QString &name, const QVariant &value)
{
QTC_ASSERT(m_debugMode, return);
......@@ -1182,12 +1163,6 @@ QVariant DebuggerPlugin::configValue(const QString &name) const
return settings()->value(name);
}
void DebuggerPlugin::queryConfigValue(const QString &name, QVariant *value)
{
QTC_ASSERT(m_debugMode, return);
*value = settings()->value(name);
}
void DebuggerPlugin::resetLocation()
{
//qDebug() << "RESET_LOCATION: current:" << currentTextEditor();
......@@ -1200,7 +1175,12 @@ void DebuggerPlugin::resetLocation()
void DebuggerPlugin::gotoLocation(const QString &file, int line, bool setMarker)
{
bool newEditor = false;
TextEditor::BaseTextEditor::openEditorAt(file, line, 0, QString(), &newEditor);
ITextEditor *editor =
BaseTextEditor::openEditorAt(file, line, 0, QString(), &newEditor);
if (!editor)
return;
if (newEditor)
editor->setProperty("OpenedByDebugger", true);
if (setMarker) {
resetLocation();
m_locationMark = new LocationMark(file, line);
......@@ -1209,6 +1189,10 @@ void DebuggerPlugin::gotoLocation(const QString &file, int line, bool setMarker)
void DebuggerPlugin::handleStateChanged(int state)
{
// Prevent it from beeing triggered on setup.
if (!m_manager)
return;
const bool startIsContinue = (state == InferiorStopped);
ICore *core = ICore::instance();
if (startIsContinue) {
......
......@@ -89,20 +89,20 @@ private:
virtual void remoteCommand(const QStringList &options, const QStringList &arguments);
QVariant configValue(const QString &name) const;
QWidget *currentTextEditor(QString *fileName, int *line);
QVariant sessionValue(const QString &name);
void setSessionValue(const QString &name, const QVariant &value);
QVariant configValue(const QString &name);
void setConfigValue(const QString &name, const QVariant &value);
private slots:
void activatePreviousMode();
void activateDebugMode();
void queryCurrentTextEditor(QString *fileName, int *line, QObject **object);
void editorOpened(Core::IEditor *);
void editorAboutToClose(Core::IEditor *);
void handleStateChanged(int state);
void requestMark(TextEditor::ITextEditor *editor, int lineNumber);
void showToolTip(TextEditor::ITextEditor *editor, const QPoint &pnt, int pos);
void querySessionValue(const QString &name, QVariant *value);
void setSessionValue(const QString &name, const QVariant &value);
void queryConfigValue(const QString &name, QVariant *value);
void setConfigValue(const QString &name, const QVariant &value);
void requestContextMenu(TextEditor::ITextEditor *editor,
int lineNumber, QMenu *menu);
......
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