Files
qt-creator/src/plugins/debugger/gdb/gdbengine.h

456 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_GDBENGINE_H
#define DEBUGGER_GDBENGINE_H
#include "idebuggerengine.h"
2009-09-10 13:09:42 +02:00
#include "debuggermanager.h" // only for StartParameters
#include "gdbmi.h"
#include "watchutils.h"
2009-09-21 11:09:38 +02:00
#include "outputcollector.h"
2008-12-02 12:01:29 +01:00
#include <QtCore/QByteArray>
#include <QtCore/QHash>
#include <QtCore/QMap>
#include <QtCore/QObject>
#include <QtCore/QProcess>
#include <QtCore/QPoint>
2009-09-21 11:09:38 +02:00
#include <QtCore/QSet>
#include <QtCore/QTextCodec>
#include <QtCore/QTime>
2008-12-02 12:01:29 +01:00
#include <QtCore/QVariant>
QT_BEGIN_NAMESPACE
class QAction;
class QAbstractItemModel;
class QWidget;
QT_END_NAMESPACE
namespace Debugger {
namespace Internal {
2009-09-21 11:09:38 +02:00
class AbstractGdbAdapter;
2008-12-02 12:01:29 +01:00
class DebuggerManager;
class IDebuggerManagerAccessForEngines;
class GdbResponse;
2008-12-02 12:01:29 +01:00
class GdbMi;
class BreakpointData;
class WatchData;
2008-12-02 12:01:29 +01:00
class AttachGdbAdapter;
class CoreGdbAdapter;
class PlainGdbAdapter;
class RemoteGdbAdapter;
class TrkGdbAdapter;
enum DebuggingHelperState
2008-12-02 12:01:29 +01:00
{
DebuggingHelperUninitialized,
DebuggingHelperLoadTried,
DebuggingHelperAvailable,
DebuggingHelperUnavailable,
2008-12-02 12:01:29 +01:00
};
class GdbEngine : public IDebuggerEngine
{
Q_OBJECT
public:
2009-09-21 11:09:38 +02:00
explicit GdbEngine(DebuggerManager *parent);
2008-12-02 12:01:29 +01:00
~GdbEngine();
signals:
void gdbInputAvailable(int channel, const QString &msg);
void gdbOutputAvailable(int channel, const QString &msg);
void applicationOutputAvailable(const QString &output);
2008-12-02 12:01:29 +01:00
private:
friend class AttachGdbAdapter;
friend class CoreGdbAdapter;
friend class PlainGdbAdapter;
friend class RemoteGdbAdapter;
friend class TrkGdbAdapter;
2009-09-11 12:30:53 +02:00
2008-12-02 12:01:29 +01:00
//
// IDebuggerEngine implementation
//
void stepExec();
void stepOutExec();
void nextExec();
void stepIExec();
void nextIExec();
void shutdown();
void setToolTipExpression(const QPoint &mousePos, TextEditor::ITextEditor *editor, int cursorPos);
2009-09-17 14:38:15 +02:00
void startDebugger(const DebuggerStartParametersPtr &sp);
2008-12-02 12:01:29 +01:00
void exitDebugger();
void detachDebugger();
2008-12-02 12:01:29 +01:00
void continueInferior();
void interruptInferior();
void runToLineExec(const QString &fileName, int lineNumber);
void runToFunctionExec(const QString &functionName);
void jumpToLineExec(const QString &fileName, int lineNumber);
void activateFrame(int index);
void selectThread(int index);
Q_SLOT void attemptBreakpointSynchronization();
void assignValueInDebugger(const QString &expr, const QString &value);
void executeDebuggerCommand(const QString & command);
void watchPoint(const QPoint &);
2008-12-02 12:01:29 +01:00
void loadSymbols(const QString &moduleName);
void loadAllSymbols();
virtual QList<Symbol> moduleSymbols(const QString &moduleName);
2008-12-02 12:01:29 +01:00
void fetchMemory(MemoryViewAgent *agent, quint64 addr, quint64 length);
void handleFetchMemory(const GdbResponse &response);
void fetchDisassembler(DisassemblerViewAgent *agent,
const StackFrame &frame);
void fetchDisassemblerByAddress(DisassemblerViewAgent *agent,
bool useMixedMode);
void handleFetchDisassemblerByLine(const GdbResponse &response);
void handleFetchDisassemblerByAddress1(const GdbResponse &response);
void handleFetchDisassemblerByAddress0(const GdbResponse &response);
Q_SLOT void setDebugDebuggingHelpers(const QVariant &on);
Q_SLOT void setUseDebuggingHelpers(const QVariant &on);
2008-12-02 12:01:29 +01:00
//
// Own stuff
//
2008-12-02 12:01:29 +01:00
int currentFrame() const;
bool supportsThreads() const;
2009-09-17 16:51:27 +02:00
void gotoLocation(const StackFrame &frame, bool setLocationMarker);
2008-12-02 12:01:29 +01:00
void connectAdapter();
void disconnectAdapter();
void initializeVariables();
2008-12-02 12:01:29 +01:00
QString fullName(const QString &fileName);
// get one usable name out of these, try full names first
QString fullName(const QStringList &candidates);
void handleResult(const GdbResponse &response);
2008-12-02 12:01:29 +01:00
public: // otherwise the Qt flag macros are unhappy
enum GdbCommandFlag {
NoFlags = 0,
NeedsStop = 1,
Discardable = 2,
RebuildModel = 4,
WatchUpdate = Discardable | RebuildModel,
EmbedToken = 8
};
Q_DECLARE_FLAGS(GdbCommandFlags, GdbCommandFlag)
2009-09-11 12:30:53 +02:00
private:
2009-09-21 11:09:38 +02:00
typedef void (GdbEngine::*GdbCommandCallback)
(const GdbResponse &response);
2009-09-21 11:09:38 +02:00
typedef void (AbstractGdbAdapter::*AdapterCallback)
(const GdbResponse &response);
struct GdbCommand
{
2009-09-21 11:09:38 +02:00
GdbCommand()
: flags(0), callback(0), adapterCallback(0), callbackName(0)
{}
int flags;
GdbCommandCallback callback;
2009-09-21 11:09:38 +02:00
AdapterCallback adapterCallback;
const char *callbackName;
QString command;
QVariant cookie;
QTime postTime;
};
2008-12-02 12:01:29 +01:00
// type and cookie are sender-internal data, opaque for the "event
// queue". resultNeeded == true increments m_pendingResults on
// send and decrements on receipt, effectively preventing
// watch model updates before everything is finished.
2009-09-21 11:09:38 +02:00
void flushCommand(const GdbCommand &cmd);
void postCommand(const QString &command,
GdbCommandFlags flags,
GdbCommandCallback callback = 0,
const char *callbackName = 0,
const QVariant &cookie = QVariant());
void postCommand(const QString &command,
GdbCommandCallback callback = 0,
const char *callbackName = 0,
const QVariant &cookie = QVariant());
2009-09-21 11:09:38 +02:00
void postCommand(const QString &command,
AdapterCallback callback,
const char *callbackName,
const QVariant &cookie = QVariant());
void postCommand(const QString &command,
GdbCommandFlags flags,
AdapterCallback callback,
const char *callbackName,
const QVariant &cookie = QVariant());
2009-09-21 11:09:38 +02:00
void postCommandHelper(const GdbCommand &cmd);
2008-12-02 12:01:29 +01:00
void setTokenBarrier();
void updateAll();
2008-12-02 12:01:29 +01:00
void updateLocals();
private slots:
void gdbProcError(QProcess::ProcessError error);
void readGdbStandardOutput();
void readGdbStandardError();
void readDebugeeOutput(const QByteArray &data);
2008-12-02 12:01:29 +01:00
2009-09-21 11:09:38 +02:00
void handleAdapterStarted();
void handleAdapterStartFailed(const QString &msg);
void handleInferiorPrepared();
void handleInferiorPreparationFailed(const QString &msg);
void handleInferiorStarted();
void handleInferiorStartFailed(const QString &msg);
void handleInferiorShutDown();
void handleInferiorShutdownFailed(const QString &msg);
void handleAdapterCrashed();
2009-09-21 11:09:38 +02:00
void handleAdapterShutDown();
void handleAdapterShutdownFailed(const QString &msg);
2008-12-02 12:01:29 +01:00
private:
int terminationIndex(const QByteArray &buffer, int &length);
void handleResponse(const QByteArray &buff);
void handleStart(const GdbResponse &response);
2009-02-18 15:27:56 +01:00
void handleAqcuiredInferior();
2008-12-02 12:01:29 +01:00
void handleAsyncOutput(const GdbMi &data);
void handleStop1(const GdbResponse &response);
void handleStop2(const GdbResponse &response);
2009-09-21 11:09:38 +02:00
void handleStop2(const GdbMi &data);
void handleResultRecord(const GdbResponse &response);
void handleFileExecAndSymbols(const GdbResponse &response);
void handleExecContinue(const GdbResponse &response);
void handleExecJumpToLine(const GdbResponse &response);
void handleExecRunToFunction(const GdbResponse &response);
void handleInfoShared(const GdbResponse &response);
void handleInfoProc(const GdbResponse &response);
void handleInfoThreads(const GdbResponse &response);
void handleShowVersion(const GdbResponse &response);
void handleQueryPwd(const GdbResponse &response);
void handleQuerySources(const GdbResponse &response);
void handleWatchPoint(const GdbResponse &response);
bool showToolTip();
2008-12-02 12:01:29 +01:00
// Convenience
DebuggerManager *manager() { return m_manager; }
void showStatusMessage(const QString &msg, int timeout = -1)
{ m_manager->showStatusMessage(msg, timeout); }
int status() const { return m_manager->status(); }
QMainWindow *mainWindow() const { return m_manager->mainWindow(); }
DebuggerStartMode startMode() const;
qint64 inferiorPid() const { return m_manager->inferiorPid(); }
void handleChildren(const WatchData &parent, const GdbMi &child,
QList<WatchData> *insertions);
const bool m_dumperInjectionLoad;
QTextCodec *m_outputCodec;
QTextCodec::ConverterState m_outputCodecState;
2008-12-02 12:01:29 +01:00
QByteArray m_inbuffer;
QHash<int, GdbCommand> m_cookieForToken;
2008-12-02 12:01:29 +01:00
QHash<int, QByteArray> m_customOutputForToken;
QByteArray m_pendingConsoleStreamOutput;
QByteArray m_pendingTargetStreamOutput;
QByteArray m_pendingLogStreamOutput;
// contains the first token number for the current round
// of evaluation. Responses with older tokens are considers
// out of date and discarded.
int m_oldestAcceptableToken;
int m_gdbVersion; // 6.8.0 is 680
2009-02-23 16:06:23 +01:00
int m_gdbBuildVersion; // MAC only?
2008-12-02 12:01:29 +01:00
// awful hack to keep track of used files
QMap<QString, QString> m_shortToFullName;
QMap<QString, QString> m_fullToShortName;
2008-12-02 12:01:29 +01:00
//
// Breakpoint specific stuff
//
void handleBreakList(const GdbResponse &response);
2008-12-02 12:01:29 +01:00
void handleBreakList(const GdbMi &table);
void handleBreakIgnore(const GdbResponse &response);
void handleBreakInsert(const GdbResponse &response);
void handleBreakInsert1(const GdbResponse &response);
void handleBreakCondition(const GdbResponse &response);
void handleBreakInfo(const GdbResponse &response);
2008-12-02 12:01:29 +01:00
void extractDataFromInfoBreak(const QString &output, BreakpointData *data);
void breakpointDataFromOutput(BreakpointData *data, const GdbMi &bkpt);
void sendInsertBreakpoint(int index);
//
// Modules specific stuff
//
void reloadModules();
void handleModulesList(const GdbResponse &response);
2008-12-02 12:01:29 +01:00
//
// Register specific stuff
//
Q_SLOT void reloadRegisters();
void setRegisterValue(int nr, const QString &value);
void handleRegisterListNames(const GdbResponse &response);
void handleRegisterListValues(const GdbResponse &response);
2008-12-02 12:01:29 +01:00
//
// Source file specific stuff
//
void reloadSourceFiles();
2008-12-02 12:01:29 +01:00
//
// Stack specific stuff
//
void handleStackListFrames(const GdbResponse &response);
void handleStackSelectThread(const GdbResponse &response);
void handleStackListThreads(const GdbResponse &response);
Q_SLOT void reloadStack();
Q_SLOT void reloadFullStack();
2008-12-02 12:01:29 +01:00
//
// Tooltip specific stuff
//
void sendToolTipCommand(const QString &command, const QString &cookie);
//
// Watch specific stuff
//
// FIXME: BaseClass. called to improve situation for a watch item
void updateSubItem(const WatchData &data);
void updateWatchData(const WatchData &data);
Q_SLOT void updateWatchDataHelper(const WatchData &data);
void rebuildModel();
2008-12-02 12:01:29 +01:00
void insertData(const WatchData &data);
void sendWatchParameters(const QByteArray &params0);
void createGdbVariable(const WatchData &data);
void maybeHandleInferiorPidChanged(const QString &pid);
void tryLoadDebuggingHelpers();
void tryQueryDebuggingHelpers();
Q_SLOT void recheckDebuggingHelperAvailability();
void runDebuggingHelper(const WatchData &data, bool dumpChildren);
void runDirectDebuggingHelper(const WatchData &data, bool dumpChildren);
bool hasDebuggingHelperForType(const QString &type) const;
2008-12-02 12:01:29 +01:00
void handleVarListChildren(const GdbResponse &response);
void handleVarCreate(const GdbResponse &response);
void handleVarAssign(const GdbResponse &response);
void handleEvaluateExpression(const GdbResponse &response);
//void handleToolTip(const GdbResponse &response);
void handleQueryDebuggingHelper(const GdbResponse &response);
void handleDebuggingHelperValue1(const GdbResponse &response);
void handleDebuggingHelperValue2(const GdbResponse &response);
void handleDebuggingHelperValue3(const GdbResponse &response);
void handleDebuggingHelperEditValue(const GdbResponse &response);
void handleDebuggingHelperSetup(const GdbResponse &response);
void handleStackListLocals(const GdbResponse &response);
void handleStackListArguments(const GdbResponse &response);
2008-12-02 12:01:29 +01:00
void handleVarListChildrenHelper(const GdbMi &child,
const WatchData &parent);
void setWatchDataType(WatchData &data, const GdbMi &mi);
void setWatchDataDisplayedType(WatchData &data, const GdbMi &mi);
2008-12-03 16:51:56 +01:00
void setLocals(const QList<GdbMi> &locals);
void connectDebuggingHelperActions();
void disconnectDebuggingHelperActions();
bool startModeAllowsDumpers() const;
QString parseDisassembler(const GdbMi &lines);
2008-12-02 12:01:29 +01:00
int m_pendingRequests;
QSet<QString> m_processedNames;
2008-12-02 12:01:29 +01:00
QtDumperHelper m_dumperHelper;
2008-12-02 12:01:29 +01:00
DebuggingHelperState m_debuggingHelperState;
2008-12-02 12:01:29 +01:00
QList<GdbMi> m_currentFunctionArgs;
QString m_currentFrame;
QMap<QString, QString> m_varToType;
2009-09-21 11:09:38 +02:00
typedef void (GdbEngine::*Continuation)();
// function called after all previous responses have been received
Continuation m_continuationAfterDone;
void handleInitialBreakpointsSet();
bool m_modulesListOutdated;
QList<GdbCommand> m_commandsToRunOnTemporaryBreak;
2009-02-16 18:28:15 +01:00
DebuggerManager * const m_manager;
IDebuggerManagerAccessForEngines * const qq;
2009-09-17 14:17:43 +02:00
DebuggerStartParametersPtr m_startParameters;
// make sure to re-initialize new members in initializeVariables();
// only one of those is active at a given time, available in m_gdbAdapter
AbstractGdbAdapter *m_gdbAdapter; // pointer to one listed below
AttachGdbAdapter *m_attachAdapter; // owned
CoreGdbAdapter *m_coreAdapter; // owned
PlainGdbAdapter *m_plainAdapter; // owned
RemoteGdbAdapter *m_remoteAdapter; // owned
TrkGdbAdapter *m_trkAdapter; // owned
2009-09-21 11:09:38 +02:00
public:
void showMessageBox(int icon, const QString &title, const QString &text);
void debugMessage(const QString &msg);
void addOptionPages(QList<Core::IOptionsPage*> *opts) const;
const DebuggerStartParameters &startParameters() const
{ return *m_startParameters; }
2009-09-21 11:09:38 +02:00
OutputCollector m_outputCollector;
2008-12-02 12:01:29 +01:00
};
} // namespace Internal
} // namespace Debugger
Q_DECLARE_OPERATORS_FOR_FLAGS(Debugger::Internal::GdbEngine::GdbCommandFlags)
2008-12-02 12:01:29 +01:00
#endif // DEBUGGER_GDBENGINE_H