Files
qt-creator/src/plugins/debugger/debuggermanager.h

501 lines
15 KiB
C
Raw Normal View History

/**************************************************************************
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
2008-12-02 12:01:29 +01:00
**
** Contact: Nokia Corporation (qt-info@nokia.com)
2008-12-02 12:01:29 +01:00
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
2009-08-14 09:30:56 +02:00
** contact the sales department at http://qt.nokia.com/contact.
2008-12-02 12:01:29 +01:00
**
**************************************************************************/
2008-12-02 15:08:31 +01:00
2008-12-02 12:01:29 +01:00
#ifndef DEBUGGER_DEBUGGERMANAGER_H
#define DEBUGGER_DEBUGGERMANAGER_H
#include <utils/fancymainwindow.h>
2008-12-02 12:01:29 +01:00
#include <QtCore/QByteArray>
#include <QtCore/QObject>
#include <QtCore/QStringList>
#include <QtCore/QVariant>
#include <QtCore/QSharedPointer>
2008-12-02 12:01:29 +01:00
QT_BEGIN_NAMESPACE
class QAction;
class QAbstractItemModel;
class QDockWidget;
class QLabel;
class QModelIndex;
class QPoint;
class QTimer;
2008-12-02 12:01:29 +01:00
class QWidget;
class QDebug;
2008-12-02 12:01:29 +01:00
QT_END_NAMESPACE
namespace Core {
class IOptionsPage;
} // namespace Core
namespace TextEditor {
class ITextEditor;
}
2008-12-02 12:01:29 +01:00
namespace Debugger {
namespace Internal {
typedef QLatin1Char _c;
typedef QLatin1String __;
inline QString _(const char *s) { return QString::fromLatin1(s); }
inline QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); }
2008-12-02 12:01:29 +01:00
class DebuggerOutputWindow;
class DebuggerRunControl;
2008-12-02 12:01:29 +01:00
class DebuggerPlugin;
class DebugMode;
class BreakHandler;
class BreakpointData;
2008-12-02 12:01:29 +01:00
class ModulesHandler;
class RegisterHandler;
class SourceFilesWindow;
struct StackFrame;
2008-12-02 12:01:29 +01:00
class StackHandler;
class Symbol;
2008-12-02 12:01:29 +01:00
class ThreadsHandler;
class WatchData;
class WatchHandler;
2008-12-02 12:01:29 +01:00
// Note: the Debugger process itself is referred to as 'Debugger',
// whereas the debugged process is referred to as 'Inferior' or 'Debuggee'.
// DebuggerProcessNotReady
// |
// DebuggerProcessStartingUp
// | <-------------------------------------.
// DebuggerInferiorRunningRequested |
// | |
// DebuggerInferiorRunning |
// | |
2008-12-02 12:01:29 +01:00
// DebuggerInferiorStopRequested |
// | |
// DebuggerInferiorStopped |
// | |
// `---------------------------------------'
//
// Allowed actions:
// [R] : Run
// [C] : Continue
// [N] : Step, Next
enum DebuggerStatus
{
DebuggerProcessNotReady, // Debugger not started
DebuggerProcessStartingUp, // Debugger starting up
DebuggerInferiorRunningRequested, // Debuggee requested to run
DebuggerInferiorRunning, // Debuggee running
DebuggerInferiorStopRequested, // Debuggee running, stop requested
DebuggerInferiorStopped, // Debuggee stopped
};
enum DebuggerStartMode
{
NoStartMode,
StartInternal, // Start current start project's binary
StartExternal, // Start binary found in file system
AttachExternal, // Attach to running process by process id
AttachCrashedExternal, // Attach to crashed process by process id
AttachTcf, // Attach to a running Target Communication Framework agent
AttachCore, // Attach to a core file
StartRemote // Start and attach to a remote process
};
enum LogChannel
{
LogInput, // Used for user input
LogOutput,
LogWarning,
LogError,
LogStatus, // Used for status changed messages
LogTime, // Used for time stamp messages
LogDebug,
LogMisc
};
class DebuggerStartParameters
{
public:
DebuggerStartParameters();
void clear();
QString executable;
QString coreFile;
QStringList processArgs;
QStringList environment;
QString workingDir;
QString buildDir;
qint64 attachPID;
bool useTerminal;
QString crashParameter; // for AttachCrashedExternal
// for remote debugging
QString remoteChannel;
QString remoteArchitecture;
QString serverStartScript;
int toolChainType;
};
QDebug operator<<(QDebug str, const DebuggerStartParameters &);
2008-12-02 12:01:29 +01:00
class IDebuggerEngine;
class GdbEngine;
class ScriptEngine;
2009-02-20 14:56:36 +01:00
class CdbDebugEngine;
2009-02-20 17:07:00 +01:00
struct CdbDebugEnginePrivate;
2008-12-02 12:01:29 +01:00
// Flags for initialization
2009-09-10 13:09:42 +02:00
enum DebuggerEngineTypeFlags
{
GdbEngineType = 0x01,
ScriptEngineType = 0x02,
CdbEngineType = 0x04,
TcfEngineType = 0x08,
SymbianEngineType = 0x10,
AllEngineTypes = GdbEngineType
| ScriptEngineType
| CdbEngineType
| TcfEngineType
| SymbianEngineType
};
2008-12-02 12:01:29 +01:00
// The construct below is not nice but enforces a bit of order. The
// DebuggerManager interfaces a lots of thing: The DebuggerPlugin,
// the DebuggerEngines, the RunMode, the handlers and views.
// Instead of making the whole interface public, we split in into
// smaller parts and grant friend access only to the classes that
// need it.
//
// IDebuggerManagerAccessForEngines
//
class IDebuggerManagerAccessForEngines
{
public:
virtual ~IDebuggerManagerAccessForEngines() {}
private:
// This is the part of the interface that's exclusively seen by the
2009-02-20 17:07:00 +01:00
// debugger engines
2009-02-20 14:56:36 +01:00
friend class CdbDebugEngine;
friend class CdbDebugEventCallback;
friend class CdbDumperHelper;
friend class CdbExceptionLoggerEventCallback;
friend class GdbEngine;
friend class ScriptEngine;
friend class TcfEngine;
friend struct CdbDebugEnginePrivate;
2008-12-02 12:01:29 +01:00
// called from the engines after successful startup
2009-02-16 18:28:15 +01:00
virtual void notifyInferiorStopRequested() = 0;
virtual void notifyInferiorStopped() = 0;
2008-12-02 12:01:29 +01:00
virtual void notifyInferiorRunningRequested() = 0;
virtual void notifyInferiorRunning() = 0;
virtual void notifyInferiorExited() = 0;
virtual void notifyInferiorPidChanged(qint64) = 0;
2008-12-02 12:01:29 +01:00
virtual ModulesHandler *modulesHandler() = 0;
virtual BreakHandler *breakHandler() = 0;
virtual RegisterHandler *registerHandler() = 0;
virtual StackHandler *stackHandler() = 0;
virtual ThreadsHandler *threadsHandler() = 0;
virtual WatchHandler *watchHandler() = 0;
virtual SourceFilesWindow *sourceFileWindow() = 0;
2008-12-02 12:01:29 +01:00
virtual void showApplicationOutput(const QString &data) = 0;
virtual void showDebuggerOutput(int channel, const QString &msg) = 0;
virtual void showDebuggerInput(int channel, const QString &msg) = 0;
2008-12-02 12:01:29 +01:00
virtual void reloadModules() = 0;
virtual void reloadSourceFiles() = 0;
2008-12-02 12:01:29 +01:00
virtual void reloadRegisters() = 0;
virtual bool qtDumperLibraryEnabled() const = 0;
virtual QString qtDumperLibraryName() const = 0;
virtual QStringList qtDumperLibraryLocations() const = 0;
virtual void showQtDumperLibraryWarning(const QString &details = QString()) = 0;
virtual bool isReverseDebugging() const = 0;
virtual qint64 inferiorPid() const = 0;
virtual QSharedPointer<DebuggerStartParameters> startParameters() const = 0;
2008-12-02 12:01:29 +01:00
};
//
// DebuggerManager
//
class DebuggerManager : public QObject, public IDebuggerManagerAccessForEngines
2008-12-02 12:01:29 +01:00
{
Q_OBJECT
public:
DebuggerManager();
QList<Core::IOptionsPage*> initializeEngines(unsigned enabledTypeFlags);
2008-12-02 12:01:29 +01:00
~DebuggerManager();
IDebuggerManagerAccessForEngines *engineInterface();
Core::Utils::FancyMainWindow *mainWindow() const { return m_mainWindow; }
QLabel *statusLabel() const { return m_statusLabel; }
IDebuggerEngine *currentEngine() const { return m_engine; }
2008-12-02 12:01:29 +01:00
public slots:
void startNewDebugger(DebuggerRunControl *runControl,
const QSharedPointer<DebuggerStartParameters> &startParameters);
void exitDebugger();
virtual QSharedPointer<DebuggerStartParameters> startParameters() const;
virtual qint64 inferiorPid() const;
void setQtDumperLibraryName(const QString &dl); // Run Control
void setQtDumperLibraryLocations(const QStringList &dl);
2008-12-02 12:01:29 +01:00
void setSimpleDockWidgetArrangement();
void setBusyCursor(bool on);
void queryCurrentTextEditor(QString *fileName, int *lineNumber, QObject **ed);
void gotoLocation(const StackFrame &frame, bool setLocationMarker);
void fileOpen(const QString &file);
2008-12-02 12:01:29 +01:00
void resetLocation();
void interruptDebuggingRequest();
void jumpToLineExec();
void runToLineExec();
void runToFunctionExec();
void toggleBreakpoint();
void breakByFunction(const QString &functionName);
void breakByFunctionMain();
2008-12-02 12:01:29 +01:00
void setBreakpoint(const QString &fileName, int lineNumber);
void activateFrame(int index);
void selectThread(int index);
void stepExec();
void stepOutExec();
void nextExec();
void continueExec();
void detachDebugger();
2008-12-02 12:01:29 +01:00
void addToWatchWindow();
void updateWatchData(const WatchData &data);
2008-12-02 12:01:29 +01:00
void sessionLoaded();
void aboutToUnloadSession();
2008-12-02 12:01:29 +01:00
void aboutToSaveSession();
QVariant sessionValue(const QString &name);
void setSessionValue(const QString &name, const QVariant &value);
2008-12-02 12:01:29 +01:00
void assignValueInDebugger();
2008-12-02 12:01:29 +01:00
void assignValueInDebugger(const QString &expr, const QString &value);
void executeDebuggerCommand();
2008-12-02 12:01:29 +01:00
void executeDebuggerCommand(const QString &command);
void watchPoint();
void setRegisterValue(int nr, const QString &value);
void showStatusMessage(const QString &msg, int timeout = -1); // -1 forever
2008-12-02 12:01:29 +01:00
private slots:
2009-09-10 13:09:42 +02:00
void showDebuggerOutput(const QString &msg)
{ showDebuggerOutput(LogDebug, msg); }
void showDebuggerOutput(int channel, const QString &msg);
void showDebuggerInput(int channel, const QString &msg);
void showApplicationOutput(const QString &data);
2008-12-02 12:01:29 +01:00
void reloadSourceFiles();
void sourceFilesDockToggled(bool on);
2008-12-02 12:01:29 +01:00
void reloadModules();
void modulesDockToggled(bool on);
void loadSymbols(const QString &moduleName);
void loadAllSymbols();
void reloadRegisters();
void registerDockToggled(bool on);
void setStatus(int status);
void clearStatusMessage();
void attemptBreakpointSynchronization();
void reloadFullStack();
void stepByInstructionTriggered();
2009-09-10 13:09:42 +02:00
void startFailed();
2008-12-02 12:01:29 +01:00
private:
//
// Implementation of IDebuggerManagerAccessForEngines
//
2008-12-02 12:01:29 +01:00
ModulesHandler *modulesHandler() { return m_modulesHandler; }
BreakHandler *breakHandler() { return m_breakHandler; }
RegisterHandler *registerHandler() { return m_registerHandler; }
StackHandler *stackHandler() { return m_stackHandler; }
ThreadsHandler *threadsHandler() { return m_threadsHandler; }
WatchHandler *watchHandler() { return m_watchHandler; }
SourceFilesWindow *sourceFileWindow() { return m_sourceFilesWindow; }
2008-12-02 12:01:29 +01:00
void notifyInferiorStopped();
void notifyInferiorRunningRequested();
2009-02-16 18:28:15 +01:00
void notifyInferiorStopRequested();
2008-12-02 12:01:29 +01:00
void notifyInferiorRunning();
void notifyInferiorExited();
void notifyInferiorPidChanged(qint64);
2008-12-02 12:01:29 +01:00
void cleanupViews();
2008-12-02 12:01:29 +01:00
//
// Implementation of IDebuggerManagerAccessForDebugMode
//
QWidget *threadsWindow() const { return m_threadsWindow; }
2008-12-02 12:01:29 +01:00
virtual bool qtDumperLibraryEnabled() const;
virtual QString qtDumperLibraryName() const;
virtual QStringList qtDumperLibraryLocations() const;
virtual void showQtDumperLibraryWarning(const QString &details = QString());
virtual bool isReverseDebugging() const;
//
2008-12-02 12:01:29 +01:00
// internal implementation
//
2008-12-02 12:01:29 +01:00
Q_SLOT void loadSessionData();
Q_SLOT void saveSessionData();
Q_SLOT void dumpLog();
public:
// stuff in this block should be made private by moving it to
2008-12-02 12:01:29 +01:00
// one of the interfaces
QAbstractItemModel *threadsModel();
int status() const { return m_status; }
DebuggerStartMode startMode() const;
DebuggerRunControl *runControl() const { return m_runControl; }
2008-12-02 12:01:29 +01:00
QList<Symbol> moduleSymbols(const QString &moduleName);
2008-12-02 12:01:29 +01:00
signals:
void debuggingFinished();
void inferiorPidChanged(qint64 pid);
void statusChanged(int newstatus);
void debugModeRequested();
void previousModeRequested();
void statusMessageRequested(const QString &msg, int timeout); // -1 for 'forever'
void gotoLocationRequested(const StackFrame &frame, bool setLocationMarker);
2008-12-02 12:01:29 +01:00
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);
2008-12-02 12:01:29 +01:00
private:
void init();
2009-04-06 16:30:11 +02:00
void runTest(const QString &fileName);
Q_SLOT void createNewDock(QWidget *widget);
2008-12-02 12:01:29 +01:00
void shutdown();
void toggleBreakpoint(const QString &fileName, int lineNumber);
void toggleBreakpointEnabled(const QString &fileName, int lineNumber);
BreakpointData *findBreakpoint(const QString &fileName, int lineNumber);
void setToolTipExpression(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos);
2008-12-02 12:01:29 +01:00
2009-09-11 12:30:53 +02:00
// FIXME: Remove engine-specific state
QSharedPointer<DebuggerStartParameters> m_startParameters;
DebuggerRunControl *m_runControl;
QString m_dumperLib;
QStringList m_dumperLibLocations;
qint64 m_inferiorPid;
2008-12-02 12:01:29 +01:00
/// Views
Core::Utils::FancyMainWindow *m_mainWindow;
QLabel *m_statusLabel;
2008-12-02 12:01:29 +01:00
QDockWidget *m_breakDock;
QDockWidget *m_modulesDock;
QDockWidget *m_outputDock;
QDockWidget *m_registerDock;
QDockWidget *m_stackDock;
QDockWidget *m_sourceFilesDock;
2008-12-02 12:01:29 +01:00
QDockWidget *m_threadsDock;
QDockWidget *m_watchDock;
BreakHandler *m_breakHandler;
ModulesHandler *m_modulesHandler;
RegisterHandler *m_registerHandler;
StackHandler *m_stackHandler;
ThreadsHandler *m_threadsHandler;
WatchHandler *m_watchHandler;
SourceFilesWindow *m_sourceFilesWindow;
2008-12-02 12:01:29 +01:00
/// Actions
friend class DebuggerPlugin;
QAction *m_continueAction;
QAction *m_stopAction;
QAction *m_resetAction; // FIXME: Should not be needed in a stable release
QAction *m_stepAction;
QAction *m_stepOutAction;
QAction *m_runToLineAction;
QAction *m_runToFunctionAction;
QAction *m_jumpToLineAction;
QAction *m_nextAction;
QAction *m_watchAction;
QAction *m_breakAction;
QAction *m_sepAction;
//QActio *m_stepByInstructionAction;
QAction *m_reverseDirectionAction;
2008-12-02 12:01:29 +01:00
QWidget *m_breakWindow;
QWidget *m_localsWindow;
2008-12-02 12:01:29 +01:00
QWidget *m_registerWindow;
QWidget *m_modulesWindow;
//QWidget *m_tooltipWindow;
2008-12-02 12:01:29 +01:00
QWidget *m_stackWindow;
QWidget *m_threadsWindow;
QWidget *m_watchersWindow;
2008-12-02 12:01:29 +01:00
DebuggerOutputWindow *m_outputWindow;
int m_status;
bool m_busy;
QTimer *m_statusTimer;
QString m_lastPermanentStatusMessage;
2008-12-02 12:01:29 +01:00
IDebuggerEngine *engine();
IDebuggerEngine *m_engine;
};
} // namespace Internal
} // namespace Debugger
#endif // DEBUGGER_DEBUGGERMANAGER_H