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

548 lines
19 KiB
C
Raw Normal View History

/**************************************************************************
2008-12-02 12:01:29 +01:00
**
** This file is part of Qt Creator
**
2010-03-05 11:25:49 +01:00
** Copyright (c) 2010 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 "debuggerengine.h"
#include "gdbmi.h"
#include "localgdbprocess.h"
#include "stackframe.h"
#include "watchutils.h"
2008-12-02 12:01:29 +01:00
#include <QtCore/QByteArray>
2010-03-22 16:17:06 +01:00
#include <QtCore/QFutureInterface>
2008-12-02 12:01:29 +01:00
#include <QtCore/QHash>
#include <QtCore/QMap>
#include <QtCore/QMultiMap>
2008-12-02 12:01:29 +01:00
#include <QtCore/QObject>
#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>
#include <QtCore/QSharedPointer>
2008-12-02 12:01:29 +01:00
QT_BEGIN_NAMESPACE
class QMainWindow;
class QMessageBox;
class QTimer;
2008-12-02 12:01:29 +01:00
QT_END_NAMESPACE
namespace Debugger {
namespace Internal {
2009-09-21 11:09:38 +02:00
class AbstractGdbAdapter;
class AbstractGdbProcess;
class GdbResponse;
2008-12-02 12:01:29 +01:00
class GdbMi;
class BreakpointData;
class WatchData;
class DisassemblerAgentCookie;
2008-12-02 12:01:29 +01:00
class AttachGdbAdapter;
class CoreGdbAdapter;
class LocalPlainGdbAdapter;
class RemoteGdbServerAdapter;
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 DebuggerEngine
2008-12-02 12:01:29 +01:00
{
Q_OBJECT
public:
explicit GdbEngine(const DebuggerStartParameters &startParameters);
2008-12-02 12:01:29 +01:00
~GdbEngine();
private:
2009-10-07 17:36:44 +02:00
friend class AbstractGdbAdapter;
friend class AbstractPlainGdbAdapter;
friend class AttachGdbAdapter;
friend class CoreGdbAdapter;
friend class LocalPlainGdbAdapter;
friend class TermGdbAdapter;
friend class RemoteGdbServerAdapter;
friend class RemotePlainGdbAdapter;
friend class TrkGdbAdapter;
friend class TcfTrkGdbAdapter;
2009-09-11 12:30:53 +02:00
2009-10-15 12:32:49 +02:00
private: ////////// General Interface //////////
2008-12-02 12:01:29 +01:00
2010-07-08 18:10:50 +02:00
virtual void setupEngine();
virtual void setupInferior();
virtual void runEngine();
virtual unsigned debuggerCapabilities() const;
2009-10-15 12:32:49 +02:00
virtual void exitDebugger();
virtual void quitDebugger();
2009-10-15 12:32:49 +02:00
virtual void detachDebugger();
virtual void shutdown();
2008-12-02 12:01:29 +01:00
2009-10-15 12:32:49 +02:00
virtual void executeDebuggerCommand(const QString &command);
virtual QString qtNamespace() const { return m_dumperHelper.qtNamespace(); }
2008-12-02 12:01:29 +01:00
2009-10-15 12:32:49 +02:00
private: ////////// General State //////////
2008-12-02 12:01:29 +01:00
2009-10-15 12:32:49 +02:00
void initializeVariables();
DebuggerStartMode startMode() const;
Q_SLOT void setAutoDerefPointers(const QVariant &on);
bool m_registerNamesListed;
2009-10-15 12:32:49 +02:00
private: ////////// Gdb Process Management //////////
AbstractGdbAdapter *createAdapter();
bool startGdb(const QStringList &args = QStringList(),
const QString &gdb = QString(),
const QString &settingsIdHint = QString());
void handleInferiorShutdown(const GdbResponse &response);
void handleGdbExit(const GdbResponse &response);
2009-10-15 12:32:49 +02:00
void handleAdapterStarted();
2010-07-08 18:10:50 +02:00
// Something went wrong with the adapter *before* adapterStarted() was emitted.
// Make sure to clean up everything before emitting this signal.
void handleAdapterStartFailed(const QString &msg,
const QString &settingsIdHint = QString());
2008-12-02 12:01:29 +01:00
// This triggers the initial breakpoint synchronization and causes
2010-07-08 18:10:50 +02:00
// finishInferiorSetup() being called once done.
void handleInferiorPrepared();
2010-07-08 18:10:50 +02:00
// This notifies the base of a successful inferior setup.
void finishInferiorSetup();
// The adapter is still running just fine, but it failed to acquire a debuggee.
2010-07-08 18:10:50 +02:00
void handleInferiorSetupFailed(const QString &msg);
2009-10-15 12:32:49 +02:00
// Something went wrong with the adapter *after* adapterStarted() was emitted.
// Make sure to clean up everything before emitting this signal.
2009-10-15 12:32:49 +02:00
void handleAdapterCrashed(const QString &msg);
2008-12-02 12:01:29 +01:00
private slots:
void handleGdbFinished(int, QProcess::ExitStatus status);
void handleGdbError(QProcess::ProcessError error);
void readGdbStandardOutput();
void readGdbStandardError();
void readDebugeeOutput(const QByteArray &data);
2009-10-15 12:32:49 +02:00
private:
QTextCodec *m_outputCodec;
QTextCodec::ConverterState m_outputCodecState;
QByteArray m_inbuffer;
bool m_busy;
2008-12-02 12:01:29 +01:00
2009-10-15 12:32:49 +02:00
AbstractGdbAdapter *m_gdbAdapter;
// Name of the convenience variable containing the last
// known function return value.
QByteArray m_resultVarName;
2009-10-15 12:32:49 +02:00
private: ////////// Gdb Command Management //////////
public: // Otherwise the Qt flag macros are unhappy.
enum GdbCommandFlag {
NoFlags = 0,
// The command needs a stopped inferior.
NeedsStop = 1,
// No need to wait for the reply before continuing inferior.
Discardable = 2,
// Trigger watch model rebuild when no such commands are pending anymore.
RebuildWatchModel = 4,
WatchUpdate = Discardable | RebuildWatchModel,
2010-06-28 14:55:19 +02:00
// We can live without receiving an answer.
NonCriticalResponse = 8,
// Callback expects GdbResultRunning instead of GdbResultDone.
RunRequest = 16,
// Callback expects GdbResultExit instead of GdbResultDone.
ExitRequest = 32,
// Auto-set inferior shutdown related states.
LosesChild = 64,
// Trigger breakpoint model rebuild when no such commands are pending anymore.
RebuildBreakpointModel = 128,
// This command needs to be send immediately.
Immediate = 256,
// This is a command that needs to be wrapped into -interpreter-exec console
ConsoleCommand = 512,
};
Q_DECLARE_FLAGS(GdbCommandFlags, GdbCommandFlag)
2009-10-15 12:32:49 +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;
QByteArray command;
QVariant cookie;
QTime postTime;
};
// Type and cookie are sender-internal data, opaque for the "event
2008-12-02 12:01:29 +01:00
// queue". resultNeeded == true increments m_pendingResults on
// send and decrements on receipt, effectively preventing
2008-12-02 12:01:29 +01:00
// watch model updates before everything is finished.
2009-09-21 11:09:38 +02:00
void flushCommand(const GdbCommand &cmd);
void postCommand(const QByteArray &command,
GdbCommandFlags flags,
GdbCommandCallback callback = 0,
const char *callbackName = 0,
const QVariant &cookie = QVariant());
void postCommand(const QByteArray &command,
GdbCommandCallback callback = 0,
const char *callbackName = 0,
const QVariant &cookie = QVariant());
void postCommand(const QByteArray &command,
2009-09-21 11:09:38 +02:00
AdapterCallback callback,
const char *callbackName,
const QVariant &cookie = QVariant());
void postCommand(const QByteArray &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);
void flushQueuedCommands();
Q_SLOT void commandTimeout();
2008-12-02 12:01:29 +01:00
void setTokenBarrier();
2009-10-15 12:32:49 +02:00
QHash<int, GdbCommand> m_cookieForToken;
int commandTimeoutTime() const;
QTimer *m_commandTimer;
2008-12-02 12:01:29 +01:00
2009-10-15 12:32:49 +02:00
QByteArray m_pendingConsoleStreamOutput;
QByteArray m_pendingLogStreamOutput;
// This contains the first token number for the current round
2009-10-15 12:32:49 +02:00
// of evaluation. Responses with older tokens are considers
// out of date and discarded.
int m_oldestAcceptableToken;
2008-12-02 12:01:29 +01:00
int m_pendingWatchRequests; // Watch updating commands in flight
int m_pendingBreakpointRequests; // Watch updating commands in flight
2009-09-21 11:09:38 +02:00
2009-10-15 12:32:49 +02:00
typedef void (GdbEngine::*CommandsDoneCallback)();
// This function is called after all previous responses have been received.
2009-10-15 12:32:49 +02:00
CommandsDoneCallback m_commandsDoneCallback;
2009-09-21 11:09:38 +02:00
2009-10-15 12:32:49 +02:00
QList<GdbCommand> m_commandsToRunOnTemporaryBreak;
2009-12-18 16:25:59 +01:00
int gdbVersion() const { return m_gdbVersion; }
2009-10-15 12:32:49 +02:00
private: ////////// Gdb Output, State & Capability Handling //////////
2009-09-21 11:09:38 +02:00
void handleResponse(const QByteArray &buff);
void handleStopResponse(const GdbMi &data);
2009-10-23 21:32:08 +02:00
void handleResultRecord(GdbResponse *response);
void handleStop1(const GdbResponse &response);
void handleStop1(const GdbMi &data);
2009-10-15 12:32:49 +02:00
StackFrame parseStackFrame(const GdbMi &mi, int level);
bool isSynchroneous() const { return hasPython(); }
virtual bool hasPython() const;
2009-10-15 12:32:49 +02:00
bool supportsThreads() const;
// Gdb initialization sequence
void handleShowVersion(const GdbResponse &response);
void handleHasPython(const GdbResponse &response);
2008-12-02 12:01:29 +01:00
int m_gdbVersion; // 6.8.0 is 60800
2009-10-15 12:32:49 +02:00
int m_gdbBuildVersion; // MAC only?
bool m_isMacGdb;
bool m_hasPython;
2009-10-15 12:32:49 +02:00
private: ////////// Inferior Management //////////
// This should be always the last call in a function.
2009-10-15 12:32:49 +02:00
Q_SLOT virtual void attemptBreakpointSynchronization();
2010-03-10 16:17:40 +01:00
virtual void executeStep();
virtual void executeStepOut();
virtual void executeNext();
virtual void executeStepI();
virtual void executeNextI();
2008-12-02 12:01:29 +01:00
2009-10-15 12:32:49 +02:00
void continueInferiorInternal();
void autoContinueInferior();
virtual void continueInferior();
virtual void interruptInferior();
void interruptInferiorTemporarily();
2008-12-02 12:01:29 +01:00
2010-03-10 16:17:40 +01:00
virtual void executeRunToLine(const QString &fileName, int lineNumber);
virtual void executeRunToFunction(const QString &functionName);
virtual void executeJumpToLine(const QString &fileName, int lineNumber);
virtual void executeReturn();
2008-12-02 12:01:29 +01:00
2010-03-10 16:17:40 +01:00
void handleExecuteContinue(const GdbResponse &response);
void handleExecuteStep(const GdbResponse &response);
void handleExecuteNext(const GdbResponse &response);
void handleExecuteReturn(const GdbResponse &response);
void handleExecuteJumpToLine(const GdbResponse &response);
void handleExecuteRunToLine(const GdbResponse &response);
//void handleExecuteRunToFunction(const GdbResponse &response);
2008-12-02 12:01:29 +01:00
2009-10-15 12:32:49 +02:00
void maybeHandleInferiorPidChanged(const QString &pid);
void handleInfoProc(const GdbResponse &response);
QByteArray m_entryPoint;
2010-03-22 16:17:06 +01:00
QFutureInterface<void> *m_progress;
2009-10-15 12:32:49 +02:00
private: ////////// View & Data Stuff //////////
virtual void selectThread(int index);
virtual void activateFrame(int index);
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 handleBreakDisable(const GdbResponse &response);
void handleBreakInsert1(const GdbResponse &response);
void handleBreakInsert2(const GdbResponse &response);
void handleBreakCondition(const GdbResponse &response);
void handleBreakInfo(const GdbResponse &response);
void handleWatchInsert(const GdbResponse &response);
void handleInfoLine(const GdbResponse &response);
2008-12-02 12:01:29 +01:00
void extractDataFromInfoBreak(const QString &output, BreakpointData *data);
void setBreakpointDataFromOutput(BreakpointData *data, const GdbMi &bkpt);
QByteArray breakpointLocation(const BreakpointData *data);
2008-12-02 12:01:29 +01:00
void sendInsertBreakpoint(int index);
QString breakLocation(const QString &file) const;
void reloadBreakListInternal();
2008-12-02 12:01:29 +01:00
//
// Modules specific stuff
//
2009-10-15 12:32:49 +02:00
virtual void loadSymbols(const QString &moduleName);
virtual void loadAllSymbols();
2010-05-03 19:12:52 +02:00
virtual void requestModuleSymbols(const QString &moduleName);
virtual void reloadModules();
void reloadModulesInternal();
void handleModulesList(const GdbResponse &response);
2008-12-02 12:01:29 +01:00
2009-10-15 12:32:49 +02:00
bool m_modulesListOutdated;
2008-12-02 12:01:29 +01:00
//
// Snapshot specific stuff
//
virtual void makeSnapshot();
void handleMakeSnapshot(const GdbResponse &response);
void handleActivateSnapshot(const GdbResponse &response);
void activateSnapshot(int index);
void activateSnapshot2();
2008-12-02 12:01:29 +01:00
//
// Register specific stuff
//
Q_SLOT virtual void reloadRegisters();
virtual 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
2009-10-15 12:32:49 +02:00
//
// Disassembler specific stuff
//
virtual void fetchDisassembler(DisassemblerViewAgent *agent);
void fetchDisassemblerByAddress(const DisassemblerAgentCookie &ac,
2009-10-15 12:32:49 +02:00
bool useMixedMode);
void fetchDisassemblerByCli(const DisassemblerAgentCookie &ac,
bool useMixedMode);
void fetchDisassemblerByAddressCli(const DisassemblerAgentCookie &ac);
void handleFetchDisassemblerByCli(const GdbResponse &response);
2009-10-15 12:32:49 +02:00
void handleFetchDisassemblerByLine(const GdbResponse &response);
void handleFetchDisassemblerByAddress1(const GdbResponse &response);
void handleFetchDisassemblerByAddress0(const GdbResponse &response);
QString parseDisassembler(const GdbMi &lines);
//
// Source file specific stuff
//
virtual void reloadSourceFiles();
void reloadSourceFilesInternal();
2009-10-15 12:32:49 +02:00
void handleQuerySources(const GdbResponse &response);
QString fullName(const QString &fileName);
#ifdef Q_OS_WIN
QString cleanupFullName(const QString &fileName);
#else
QString cleanupFullName(const QString &fileName) { return fileName; }
#endif
2009-10-15 12:32:49 +02: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
void invalidateSourcesList();
bool m_sourcesListOutdated;
bool m_sourcesListUpdating;
bool m_breakListOutdated;
2008-12-02 12:01:29 +01:00
//
// Stack specific stuff
//
2009-10-15 12:32:49 +02:00
void updateAll();
void updateAllClassic();
void updateAllPython();
void handleStackListFrames(const GdbResponse &response);
void handleStackSelectThread(const GdbResponse &response);
void handleStackSelectFrame(const GdbResponse &response);
void handleThreadListIds(const GdbResponse &response);
void handleThreadInfo(const GdbResponse &response);
Q_SLOT void reloadStack(bool forceGotoLocation);
Q_SLOT virtual void reloadFullStack();
2009-10-15 12:32:49 +02:00
int currentFrame() const;
2008-12-02 12:01:29 +01:00
2009-10-15 12:32:49 +02:00
QList<GdbMi> m_currentFunctionArgs;
QString m_currentFrame;
2008-12-02 12:01:29 +01:00
//
2009-10-15 12:32:49 +02:00
// Watch specific stuff
//
2010-02-11 13:21:38 +01:00
virtual void setToolTipExpression(const QPoint &mousePos,
TextEditor::ITextEditor *editor, int cursorPos);
2008-12-02 12:01:29 +01:00
2009-10-15 12:32:49 +02:00
virtual void assignValueInDebugger(const QString &expr, const QString &value);
virtual void fetchMemory(MemoryViewAgent *agent, QObject *token,
quint64 addr, quint64 length);
2009-10-15 12:32:49 +02:00
void handleFetchMemory(const GdbResponse &response);
virtual void watchPoint(const QPoint &);
void handleWatchPoint(const GdbResponse &response);
2008-12-02 12:01:29 +01:00
// FIXME: BaseClass. called to improve situation for a watch item
void updateSubItemClassic(const WatchData &data);
2008-12-02 12:01:29 +01:00
void virtual updateWatchData(const WatchData &data);
Q_SLOT void updateWatchDataHelper(const WatchData &data);
void rebuildWatchModel();
2009-10-15 12:32:49 +02:00
bool showToolTip();
2008-12-02 12:01:29 +01:00
void insertData(const WatchData &data);
void sendWatchParameters(const QByteArray &params0);
void createGdbVariableClassic(const WatchData &data);
2008-12-02 12:01:29 +01:00
void runDebuggingHelperClassic(const WatchData &data, bool dumpChildren);
void runDirectDebuggingHelperClassic(const WatchData &data, bool dumpChildren);
bool hasDebuggingHelperForType(const QString &type) const;
2008-12-02 12:01:29 +01:00
void handleVarListChildrenClassic(const GdbResponse &response);
void handleVarListChildrenHelperClassic(const GdbMi &child,
2009-10-15 12:32:49 +02:00
const WatchData &parent);
void handleVarCreate(const GdbResponse &response);
void handleVarAssign(const GdbResponse &response);
void handleEvaluateExpressionClassic(const GdbResponse &response);
void handleQueryDebuggingHelperClassic(const GdbResponse &response);
void handleDebuggingHelperValue2Classic(const GdbResponse &response);
void handleDebuggingHelperValue3Classic(const GdbResponse &response);
void handleDebuggingHelperEditValue(const GdbResponse &response);
void handleDebuggingHelperSetup(const GdbResponse &response);
void handleDebuggingHelperVersionCheckClassic(const GdbResponse &response);
2009-10-15 12:32:49 +02:00
Q_SLOT void createFullBacktrace();
void handleCreateFullBacktrace(const GdbResponse &response);
2009-10-15 12:32:49 +02:00
void updateLocals(const QVariant &cookie = QVariant());
void updateLocalsClassic(const QVariant &cookie);
void updateLocalsPython(const QByteArray &varList);
void handleStackFramePython(const GdbResponse &response);
void handleStackListLocalsClassic(const GdbResponse &response);
void handleStackListLocalsPython(const GdbResponse &response);
2009-10-15 12:32:49 +02:00
WatchData localVariable(const GdbMi &item,
const QStringList &uninitializedVariables,
QMap<QByteArray, int> *seen);
void setLocals(const QList<GdbMi> &locals);
void handleStackListArgumentsClassic(const GdbResponse &response);
2008-12-02 12:01:29 +01:00
QSet<QByteArray> m_processedNames;
2008-12-02 12:01:29 +01:00
//
// Dumper Management
//
bool checkDebuggingHelpers();
bool checkDebuggingHelpersClassic();
void setDebuggingHelperStateClassic(DebuggingHelperState);
void tryLoadDebuggingHelpersClassic();
void tryQueryDebuggingHelpersClassic();
Q_SLOT void recheckDebuggingHelperAvailabilityClassic();
Q_SLOT void setDebugDebuggingHelpersClassic(const QVariant &on);
2009-10-15 12:32:49 +02:00
Q_SLOT void setUseDebuggingHelpers(const QVariant &on);
2009-10-15 12:32:49 +02:00
DebuggingHelperState m_debuggingHelperState;
QtDumperHelper m_dumperHelper;
QString m_gdb;
2009-10-05 14:59:39 +02:00
//
// Convenience Functions
//
QString errorMessage(QProcess::ProcessError error);
QMessageBox *showMessageBox(int icon, const QString &title, const QString &text,
int buttons = 0);
2009-10-15 12:32:49 +02:00
QMainWindow *mainWindow() const;
AbstractGdbProcess *gdbProc() const;
static QString m_toolTipExpression;
static QPoint m_toolTipPos;
static QByteArray tooltipIName(const QString &exp);
// HACK:
StackFrame m_targetFrame;
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