Commit 69a4ed32 authored by hjk's avatar hjk

debugger: move ModulesHandler from DebuggerManager to DebuggerRunControl

parent 83e47982
......@@ -152,6 +152,19 @@ enum LogChannel
StatusBar // LogStatus and also put to the status bar
};
enum ModelRoles
{
DisplaySourceRole = 32, // Qt::UserRole,
EngineCapabilityRole,
EngineActionsEnabledRole,
// Modules
RequestReloadModulesRole,
RequestModuleSymbolsRole,
RequestAllSymbolsRole
};
} // namespace Debugger
#endif // DEBUGGERCONSTANTS_H
......
......@@ -85,6 +85,7 @@
#include <QtCore/QTimer>
#include <QtGui/QApplication>
#include <QtGui/QAbstractItemView>
#include <QtGui/QAction>
#include <QtGui/QComboBox>
#include <QtGui/QDockWidget>
......@@ -269,7 +270,7 @@ struct DebuggerManagerPrivate
const QIcon m_locationMarkIcon;
// FIXME: Remove engine-specific state
const DebuggerRunControl *m_runControl;
DebuggerRunControl *m_runControl;
qint64 m_inferiorPid;
/// Views
......@@ -279,7 +280,6 @@ struct DebuggerManagerPrivate
// FIXME: Move to DebuggerRunControl
BreakHandler *m_breakHandler;
ModulesHandler *m_modulesHandler;
RegisterHandler *m_registerHandler;
SnapshotHandler *m_snapshotHandler;
StackHandler *m_stackHandler;
......@@ -304,7 +304,7 @@ struct DebuggerManagerPrivate
QWidget *m_localsWindow;
QWidget *m_watchersWindow;
QWidget *m_registerWindow;
QWidget *m_modulesWindow;
QAbstractItemView *m_modulesWindow;
QWidget *m_snapshotWindow;
SourceFilesWindow *m_sourceFilesWindow;
QWidget *m_stackWindow;
......@@ -358,7 +358,6 @@ DebuggerManager::~DebuggerManager()
doDelete(d->m_breakHandler);
doDelete(d->m_threadsHandler);
doDelete(d->m_modulesHandler);
doDelete(d->m_registerHandler);
doDelete(d->m_snapshotHandler);
doDelete(d->m_stackHandler);
......@@ -378,7 +377,6 @@ void DebuggerManager::init()
d->m_state = DebuggerState(-1);
d->m_busy = false;
d->m_modulesHandler = 0;
d->m_registerHandler = 0;
d->m_statusLabel = new QLabel;
......@@ -386,7 +384,7 @@ void DebuggerManager::init()
d->m_breakWindow = new BreakWindow(this);
d->m_breakWindow->setObjectName(QLatin1String("CppDebugBreakpoints"));
d->m_modulesWindow = new ModulesWindow(this);
d->m_modulesWindow = new ModulesWindow();
d->m_modulesWindow->setObjectName(QLatin1String("CppDebugModules"));
d->m_outputWindow = new DebuggerOutputWindow;
d->m_outputWindow->setObjectName(QLatin1String("CppDebugOutput"));
......@@ -457,17 +455,7 @@ void DebuggerManager::init()
this, SLOT(breakByFunctionMain()), Qt::QueuedConnection);
// Modules
QAbstractItemView *modulesView =
qobject_cast<QAbstractItemView *>(d->m_modulesWindow);
d->m_modulesHandler = new ModulesHandler;
modulesView->setModel(d->m_modulesHandler->model());
connect(modulesView, SIGNAL(reloadModulesRequested()),
this, SLOT(reloadModules()));
connect(modulesView, SIGNAL(loadSymbolsRequested(QString)),
this, SLOT(loadSymbols(QString)));
connect(modulesView, SIGNAL(loadAllSymbolsRequested()),
this, SLOT(loadAllSymbols()));
connect(modulesView, SIGNAL(fileOpenRequested(QString)),
connect(d->m_modulesWindow, SIGNAL(fileOpenRequested(QString)),
this, SLOT(fileOpen(QString)));
// Source Files
......@@ -724,6 +712,11 @@ void DebuggerManager::clearCppCodeModelSnapshot()
d->m_codeModelSnapshot = CPlusPlus::Snapshot();
}
QAbstractItemView *DebuggerManager::modulesWindow() const
{
return d->m_modulesWindow;
}
SourceFilesWindow *DebuggerManager::sourceFileWindow() const
{
return d->m_sourceFilesWindow;
......@@ -1069,8 +1062,7 @@ void DebuggerManager::startNewDebugger(DebuggerRunControl *runControl)
setBusyCursor(false);
setState(EngineStarting);
connect(d->m_engine, SIGNAL(startFailed()), this, SLOT(startFailed()));
d->m_engine->setRunControl(runControl);
d->m_engine->startDebugger();
runControl->startDebugger(d->m_engine);
const unsigned engineCapabilities = d->m_engine->debuggerCapabilities();
theDebuggerAction(OperateByInstruction)
......@@ -1095,7 +1087,6 @@ void DebuggerManager::cleanupViews()
breakHandler()->setAllPending();
stackHandler()->removeAll();
threadsHandler()->removeAll();
modulesHandler()->removeAll();
watchHandler()->cleanup();
registerHandler()->removeAll();
d->m_sourceFilesWindow->removeAll();
......@@ -1104,6 +1095,10 @@ void DebuggerManager::cleanupViews()
d->m_actions.reverseDirectionAction->setEnabled(false);
hideDebuggerToolTip();
// FIXME: Delete run control?
if (d->m_runControl)
d->m_runControl->cleanup();
// FIXME: Move to plugin?
using namespace Core;
if (EditorManager *editorManager = EditorManager::instance()) {
......@@ -1543,8 +1538,8 @@ void DebuggerManager::showMessage(const QString &msg, int channel)
{
if (runControl())
runControl()->showMessage(msg, channel);
else
qDebug() << "OUTPUT: " << channel << msg;
//else
// qDebug() << "OUTPUT: " << channel << msg;
}
......@@ -1976,11 +1971,6 @@ DebuggerOutputWindow *DebuggerManager::debuggerOutputWindow() const
return d->m_outputWindow;
}
ModulesHandler *DebuggerManager::modulesHandler() const
{
return d->m_modulesHandler;
}
BreakHandler *DebuggerManager::breakHandler() const
{
return d->m_breakHandler;
......@@ -2034,6 +2024,10 @@ void IDebuggerEngine::setState(DebuggerState state, bool forced)
m_manager->setState(state, forced);
}
bool IDebuggerEngine::debuggerActionsEnabled() const
{
return m_manager->debuggerActionsEnabled();
}
//////////////////////////////////////////////////////////////////////
//
......
......@@ -41,6 +41,7 @@
QT_BEGIN_NAMESPACE
class QAbstractItemModel;
class QAbstractItemView;
class QAction;
class QDebug;
class QDockWidget;
......@@ -252,7 +253,6 @@ public slots: // FIXME
void startFailed();
friend class DebuggerRunControl;
Internal::ModulesHandler *modulesHandler() const;
public:
Internal::BreakHandler *breakHandler() const;
Internal::RegisterHandler *registerHandler() const;
......@@ -264,6 +264,7 @@ public:
private:
Internal::SourceFilesWindow *sourceFileWindow() const;
QAbstractItemView *modulesWindow() const;
QWidget *threadsWindow() const;
Internal::DebuggerManagerActions debuggerManagerActions() const;
......
......@@ -31,6 +31,9 @@
#include "debuggermanager.h"
#include "debuggeroutputwindow.h"
#include "idebuggerengine.h"
#include "moduleshandler.h"
#include <projectexplorer/debugginghelper.h>
#include <projectexplorer/environment.h>
#include <projectexplorer/project.h>
......@@ -46,6 +49,7 @@
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtGui/QAbstractItemView>
#include <QtGui/QTextDocument>
using namespace ProjectExplorer;
......@@ -142,19 +146,22 @@ QWidget *DebuggerRunControlFactory::createConfigurationWidget(RunConfiguration *
class DebuggerRunControl::Private
{
public:
Private(DebuggerRunControl *parent);
Private(DebuggerRunControl *parent, DebuggerManager *manager,
const DebuggerStartParameters &startParameters);
~Private();
public:
DebuggerRunControl *q;
DebuggerStartParameters m_startParameters;
DebuggerManager *m_manager;
Internal::IDebuggerEngine *m_engine;
bool m_running;
ModulesHandler *m_modulesHandler;
/*
// FIXME: Move from DebuggerManager
BreakHandler *m_breakHandler;
ModulesHandler *m_modulesHandler;
RegisterHandler *m_registerHandler;
SnapshotHandler *m_snapshotHandler;
StackHandler *m_stackHandler;
......@@ -163,9 +170,23 @@ public:
*/
};
DebuggerRunControl::Private::Private(DebuggerRunControl *parent)
: q(parent)
DebuggerRunControl::Private::Private(DebuggerRunControl *parent,
DebuggerManager *manager,
const DebuggerStartParameters &startParameters)
: q(parent),
m_startParameters(startParameters),
m_manager(manager),
m_engine(0)
{
m_running = false;
m_modulesHandler = new ModulesHandler(q);
}
DebuggerRunControl::Private::~Private()
{
#define doDelete(ptr) delete ptr; ptr = 0
doDelete(m_modulesHandler);
#undef doDelete
}
......@@ -178,11 +199,8 @@ DebuggerRunControl::Private::Private(DebuggerRunControl *parent)
DebuggerRunControl::DebuggerRunControl(DebuggerManager *manager,
const DebuggerStartParameters &startParameters)
: RunControl(0, ProjectExplorer::Constants::DEBUGMODE),
d(new Private(this))
d(new Private(this, manager, startParameters))
{
d->m_startParameters = startParameters;
d->m_manager = manager;
d->m_running = false;
connect(d->m_manager, SIGNAL(debuggingFinished()),
this, SLOT(debuggingFinished()),
Qt::QueuedConnection);
......@@ -298,7 +316,7 @@ const DebuggerStartParameters &DebuggerRunControl::sp() const
ModulesHandler *DebuggerRunControl::modulesHandler() const
{
return d->m_manager->modulesHandler();
return d->m_modulesHandler;
}
BreakHandler *DebuggerRunControl::breakHandler() const
......@@ -331,4 +349,23 @@ SnapshotHandler *DebuggerRunControl::snapshotHandler() const
return d->m_manager->snapshotHandler();
}
void DebuggerRunControl::cleanup()
{
modulesHandler()->removeAll();
}
Internal::IDebuggerEngine *DebuggerRunControl::engine()
{
QTC_ASSERT(d->m_engine, /**/);
return d->m_engine;
}
void DebuggerRunControl::startDebugger(IDebuggerEngine *engine)
{
d->m_engine = engine;
d->m_engine->setRunControl(this);
d->m_manager->modulesWindow()->setModel(d->m_modulesHandler->model());
d->m_engine->startDebugger();
}
} // namespace Debugger
......@@ -48,6 +48,7 @@ namespace Debugger {
class DebuggerManager;
namespace Internal {
class IDebuggerEngine;
class BreakHandler;
class ModulesHandler;
class RegisterHandler;
......@@ -147,6 +148,10 @@ public:
Internal::WatchHandler *watchHandler() const;
Internal::SnapshotHandler *snapshotHandler() const;
void cleanup();
void startDebugger(Internal::IDebuggerEngine *engine);
Internal::IDebuggerEngine *engine();
signals:
void stopRequested();
......
......@@ -2709,7 +2709,7 @@ void GdbEngine::handleModulesList(const GdbResponse &response)
}
}
}
manager()->modulesHandler()->setModules(modules);
runControl()->modulesHandler()->setModules(modules);
}
......
......@@ -138,6 +138,7 @@ public slots:
void showStatusMessage(const QString &msg, int timeout = -1) const
{ showMessage(msg, StatusBar, timeout); }
DebuggerManager *manager() const { return m_manager; }
bool debuggerActionsEnabled() const;
protected:
DebuggerState state() const;
......
......@@ -28,6 +28,8 @@
**************************************************************************/
#include "moduleshandler.h"
#include "idebuggerengine.h"
#include "debuggerrunner.h"
#include <utils/qtcassert.h>
......@@ -41,9 +43,6 @@
#include <QtGui/QStandardItemModel>
#include <QtGui/QSortFilterProxyModel>
using namespace Debugger;
using namespace Debugger::Internal;
//////////////////////////////////////////////////////////////////
//
......@@ -51,12 +50,13 @@ using namespace Debugger::Internal;
//
//////////////////////////////////////////////////////////////////
class Debugger::Internal::ModulesModel : public QAbstractItemModel
{
Q_OBJECT
namespace Debugger {
namespace Internal {
class ModulesModel : public QAbstractItemModel
{
public:
explicit ModulesModel(ModulesHandler *parent);
explicit ModulesModel(ModulesHandler *parent, DebuggerRunControl *runControl);
// QAbstractItemModel
int columnCount(const QModelIndex &parent) const
......@@ -76,20 +76,22 @@ public:
void setModules(const QList<Module> &m);
const QList<Module> &modules() const { return m_modules; }
IDebuggerEngine *engine() { return m_runControl->engine(); }
const IDebuggerEngine *engine() const { return m_runControl->engine(); }
private:
int indexOfModule(const QString &name) const;
DebuggerRunControl *m_runControl;
const QVariant m_yes;
const QVariant m_no;
QList<Module> m_modules;
};
ModulesModel::ModulesModel(ModulesHandler *parent) :
QAbstractItemModel(parent),
m_yes(tr("yes")), m_no(tr("no"))
{
}
ModulesModel::ModulesModel(ModulesHandler *parent, DebuggerRunControl *runControl)
: QAbstractItemModel(parent),
m_runControl(runControl), m_yes(tr("yes")), m_no(tr("no"))
{}
QVariant ModulesModel::headerData(int section,
Qt::Orientation orientation, int role) const
......@@ -109,6 +111,12 @@ QVariant ModulesModel::headerData(int section,
QVariant ModulesModel::data(const QModelIndex &index, int role) const
{
if (role == EngineCapabilityRole)
return engine()->debuggerCapabilities();
if (role == EngineActionsEnabledRole)
return engine()->debuggerActionsEnabled();
int row = index.row();
if (row < 0 || row >= m_modules.size())
return QVariant();
......@@ -145,6 +153,18 @@ QVariant ModulesModel::data(const QModelIndex &index, int role) const
bool ModulesModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (role == RequestReloadModulesRole) {
engine()->reloadModules();
return true;
}
if (role == RequestModuleSymbolsRole) {
engine()->loadSymbols(value.toString());
return true;
}
if (role == RequestAllSymbolsRole) {
engine()->loadAllSymbols();
return true;
}
return QAbstractItemModel::setData(index, value, role);
}
......@@ -194,9 +214,9 @@ void ModulesModel::removeModule(const QString &moduleName)
//
//////////////////////////////////////////////////////////////////
ModulesHandler::ModulesHandler()
ModulesHandler::ModulesHandler(DebuggerRunControl *runControl)
{
m_model = new ModulesModel(this);
m_model = new ModulesModel(this, runControl);
m_proxyModel = new QSortFilterProxyModel(this);
m_proxyModel->setSourceModel(m_model);
}
......@@ -231,4 +251,7 @@ QList<Module> ModulesHandler::modules() const
return m_model->modules();
}
} // namespace Internal
} // namespace Debugger
#include "moduleshandler.moc"
......@@ -40,17 +40,13 @@ QT_END_NAMESPACE
namespace Debugger {
class DebuggerRunControl;
namespace Internal {
class ModulesModel;
enum ModulesModelRoles
{
DisplaySourceRole = Qt::UserRole,
LoadSymbolsRole,
LoadAllSymbolsRole
};
//////////////////////////////////////////////////////////////////
//
// Symbol
......@@ -93,10 +89,8 @@ public:
class ModulesHandler : public QObject
{
Q_OBJECT
public:
ModulesHandler();
explicit ModulesHandler(DebuggerRunControl *runControl);
QAbstractItemModel *model() const;
......
......@@ -29,23 +29,19 @@
#include "moduleswindow.h"
#include "moduleshandler.h" // for model roles
#include "debuggerconstants.h"
#include "debuggeractions.h"
#include "debuggermanager.h"
#include <utils/qtcassert.h>
#include <utils/savedaction.h>
#include <QtCore/QDebug>
#include <QtCore/QProcess>
#include <QtCore/QRegExp>
#include <QtGui/QAction>
#include <QtGui/QHeaderView>
#include <QtGui/QMenu>
#include <QtGui/QResizeEvent>
#include <QtGui/QToolButton>
#include <QtGui/QTreeWidget>
#include <QtGui/QApplication>
///////////////////////////////////////////////////////////////////////////
//
......@@ -56,11 +52,8 @@
namespace Debugger {
namespace Internal {
ModulesWindow::ModulesWindow(DebuggerManager *debuggerManager,
QWidget *parent) :
QTreeView(parent),
m_alwaysResizeColumnsToContents(false),
m_debuggerManager(debuggerManager)
ModulesWindow::ModulesWindow(QWidget *parent)
: QTreeView(parent), m_alwaysResizeColumnsToContents(false)
{
QAction *act = theDebuggerAction(UseAlternatingRowColors);
setWindowTitle(tr("Modules"));
......@@ -106,12 +99,14 @@ void ModulesWindow::contextMenuEvent(QContextMenuEvent *ev)
if (index.isValid())
index = index.sibling(index.row(), 0);
if (index.isValid())
name = model()->data(index).toString();
name = index.data().toString();
const bool enabled =
model() && model()->data(index, EngineActionsEnabledRole).toBool();
const unsigned capabilities =
model()->data(index, EngineCapabilityRole).toInt();
QMenu menu;
const bool enabled = Debugger::DebuggerManager::instance()->debuggerActionsEnabled();
const unsigned capabilities = Debugger::DebuggerManager::instance()->debuggerCapabilities();
QAction *act0 = new QAction(tr("Update Module List"), &menu);
act0->setEnabled(enabled && (capabilities & ReloadModuleCapability));
QAction *act3 = new QAction(tr("Show Source Files for Module \"%1\"").arg(name), &menu);
......@@ -136,10 +131,11 @@ void ModulesWindow::contextMenuEvent(QContextMenuEvent *ev)
}
menu.addAction(act0);
//menu.addAction(act3); // FIXME
menu.addAction(act4);
menu.addAction(act5);
menu.addAction(act6);
menu.addAction(act7);
//menu.addAction(act7); // FIXME
menu.addSeparator();
QAction *actAdjustColumnWidths =
menu.addAction(tr("Adjust Column Widths to Contents"));
......@@ -152,22 +148,27 @@ void ModulesWindow::contextMenuEvent(QContextMenuEvent *ev)
QAction *act = menu.exec(ev->globalPos());
if (act == act0)
emit reloadModulesRequested();
else if (act == actAdjustColumnWidths)
if (act == act0) {
QTC_ASSERT(model(), return);
model()->setData(QModelIndex(), QVariant(), RequestReloadModulesRole);
} else if (act == actAdjustColumnWidths) {
resizeColumnsToContents();
else if (act == actAlwaysAdjustColumnWidth)
} else if (act == actAlwaysAdjustColumnWidth) {
setAlwaysResizeColumnsToContents(!m_alwaysResizeColumnsToContents);
else if (act == act3)
emit displaySourceRequested(name);
else if (act == act4)
emit loadAllSymbolsRequested();
else if (act == act5)
emit loadSymbolsRequested(name);
else if (act == act6)
//} else if (act == act3) {
// emit displaySourceRequested(name);
} else if (act == act4) {
QTC_ASSERT(model(), return);
model()->setData(QModelIndex(), QVariant(), RequestAllSymbolsRole);
} else if (act == act5) {
QTC_ASSERT(model(), return);
model()->setData(QModelIndex(), name, RequestModuleSymbolsRole);
} else if (act == act6) {
emit fileOpenRequested(name);
else if (act == act7)
showSymbols(name);
} else if (act == act7) {
QTC_ASSERT(model(), return);
model()->setData(QModelIndex(), name, RequestModuleSymbolsRole);
}
}
void ModulesWindow::resizeColumnsToContents()
......@@ -197,11 +198,5 @@ void ModulesWindow::setModel(QAbstractItemModel *model)
setAlwaysResizeColumnsToContents(true);
}
void ModulesWindow::showSymbols(const QString &name)
{
if (!name.isEmpty())
m_debuggerManager->requestModuleSymbols(name);
}
} // namespace Internal
} // namespace Debugger
......@@ -33,8 +33,6 @@
#include <QTreeView>
namespace Debugger {
class DebuggerManager;
namespace Internal {