2010-11-18 13:51:15 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2010-11-18 13:51:15 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2010-11-18 13:51:15 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2010-11-18 13:51:15 +01:00
|
|
|
**
|
2010-12-17 17:14:20 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 17:14:20 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 17:14:20 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-05-06 15:05:37 +02:00
|
|
|
** Nokia at info@qt.nokia.com.
|
2010-11-18 13:51:15 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifndef DEBUGGER_CDBENGINE_H
|
|
|
|
|
#define DEBUGGER_CDBENGINE_H
|
|
|
|
|
|
|
|
|
|
#include "debuggerengine.h"
|
2011-02-03 16:26:23 +01:00
|
|
|
#include "breakpoint.h"
|
2010-11-18 13:51:15 +01:00
|
|
|
|
|
|
|
|
#include <QtCore/QSharedPointer>
|
|
|
|
|
#include <QtCore/QProcess>
|
2011-02-28 14:33:35 +01:00
|
|
|
#include <QtCore/QVariantList>
|
2010-11-18 13:51:15 +01:00
|
|
|
#include <QtCore/QMap>
|
|
|
|
|
#include <QtCore/QTime>
|
2011-03-04 17:28:15 +01:00
|
|
|
#include <QtCore/QPair>
|
|
|
|
|
#include <QtCore/QList>
|
2010-11-18 13:51:15 +01:00
|
|
|
|
2011-01-19 10:25:32 +01:00
|
|
|
namespace Utils {
|
|
|
|
|
class ConsoleProcess;
|
|
|
|
|
}
|
2010-11-18 13:51:15 +01:00
|
|
|
namespace Debugger {
|
2011-01-11 11:06:15 +01:00
|
|
|
namespace Internal {
|
2010-11-18 13:51:15 +01:00
|
|
|
|
2010-12-14 12:29:32 +01:00
|
|
|
class DisassemblerAgent;
|
2010-11-18 13:51:15 +01:00
|
|
|
struct CdbBuiltinCommand;
|
|
|
|
|
struct CdbExtensionCommand;
|
|
|
|
|
struct CdbOptions;
|
2011-04-19 13:57:25 +02:00
|
|
|
struct MemoryViewCookie;
|
2010-12-09 17:04:43 +01:00
|
|
|
class ByteArrayInputStream;
|
2011-01-25 18:35:31 +01:00
|
|
|
class GdbMi;
|
2010-11-18 13:51:15 +01:00
|
|
|
|
|
|
|
|
class CdbEngine : public Debugger::DebuggerEngine
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
typedef QSharedPointer<CdbOptions> OptionsPtr;
|
|
|
|
|
|
|
|
|
|
enum CommandFlags { QuietCommand = 0x1 };
|
|
|
|
|
// Flag bits for a sequence of commands
|
|
|
|
|
enum CommandSequenceFlags {
|
|
|
|
|
CommandListStack = 0x1,
|
|
|
|
|
CommandListThreads = 0x2,
|
|
|
|
|
CommandListRegisters = 0x4,
|
2011-02-03 16:26:23 +01:00
|
|
|
CommandListModules = 0x8,
|
|
|
|
|
CommandListBreakPoints = 0x10
|
2010-11-18 13:51:15 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef QSharedPointer<CdbBuiltinCommand> CdbBuiltinCommandPtr;
|
|
|
|
|
typedef QSharedPointer<CdbExtensionCommand> CdbExtensionCommandPtr;
|
|
|
|
|
typedef void (CdbEngine::*BuiltinCommandHandler)(const CdbBuiltinCommandPtr &);
|
|
|
|
|
typedef void (CdbEngine::*ExtensionCommandHandler)(const CdbExtensionCommandPtr &);
|
|
|
|
|
|
2011-01-12 12:10:12 +01:00
|
|
|
explicit CdbEngine(const DebuggerStartParameters &sp,
|
|
|
|
|
DebuggerEngine *masterEngine,
|
|
|
|
|
const OptionsPtr &options);
|
|
|
|
|
|
2010-11-18 13:51:15 +01:00
|
|
|
virtual ~CdbEngine();
|
|
|
|
|
// Factory function that returns 0 if the debug engine library cannot be found.
|
|
|
|
|
|
2011-02-17 10:08:57 +01:00
|
|
|
virtual bool setToolTipExpression(const QPoint &mousePos, TextEditor::ITextEditor *editor,
|
2011-02-11 15:00:13 +01:00
|
|
|
const DebuggerToolTipContext &ctx);
|
2010-11-18 13:51:15 +01:00
|
|
|
virtual void setupEngine();
|
|
|
|
|
virtual void setupInferior();
|
|
|
|
|
virtual void runEngine();
|
|
|
|
|
virtual void shutdownInferior();
|
|
|
|
|
virtual void shutdownEngine();
|
|
|
|
|
virtual void detachDebugger();
|
2011-01-11 11:06:15 +01:00
|
|
|
virtual void updateWatchData(const WatchData &data,
|
|
|
|
|
const WatchUpdateFlags & flags = WatchUpdateFlags());
|
2010-11-18 13:51:15 +01:00
|
|
|
virtual unsigned debuggerCapabilities() const;
|
2011-01-18 11:40:45 +01:00
|
|
|
virtual void watchPoint(const QPoint &);
|
2010-11-18 13:51:15 +01:00
|
|
|
virtual void setRegisterValue(int regnr, const QString &value);
|
|
|
|
|
|
|
|
|
|
virtual void executeStep();
|
|
|
|
|
virtual void executeStepOut();
|
|
|
|
|
virtual void executeNext();
|
|
|
|
|
virtual void executeStepI();
|
|
|
|
|
virtual void executeNextI();
|
|
|
|
|
|
|
|
|
|
virtual void continueInferior();
|
|
|
|
|
virtual void interruptInferior();
|
|
|
|
|
|
2011-02-23 10:16:11 +01:00
|
|
|
virtual void executeRunToLine(const ContextData &data);
|
2010-11-18 13:51:15 +01:00
|
|
|
virtual void executeRunToFunction(const QString &functionName);
|
2011-02-23 10:16:11 +01:00
|
|
|
virtual void executeJumpToLine(const ContextData &data);
|
2011-01-11 11:06:15 +01:00
|
|
|
virtual void assignValueInDebugger(const WatchData *w, const QString &expr, const QVariant &value);
|
2010-11-18 13:51:15 +01:00
|
|
|
virtual void executeDebuggerCommand(const QString &command);
|
|
|
|
|
|
|
|
|
|
virtual void activateFrame(int index);
|
|
|
|
|
virtual void selectThread(int index);
|
|
|
|
|
|
2010-11-26 13:06:03 +01:00
|
|
|
virtual bool stateAcceptsBreakpointChanges() const;
|
2011-06-24 16:25:30 +02:00
|
|
|
virtual bool acceptsBreakpoint(BreakpointModelId id) const;
|
2010-11-18 13:51:15 +01:00
|
|
|
virtual void attemptBreakpointSynchronization();
|
|
|
|
|
|
2011-01-11 11:06:15 +01:00
|
|
|
virtual void fetchDisassembler(DisassemblerAgent *agent);
|
|
|
|
|
virtual void fetchMemory(MemoryAgent *, QObject *, quint64 addr, quint64 length);
|
2011-02-28 14:33:35 +01:00
|
|
|
virtual void changeMemory(Internal::MemoryAgent *, QObject *, quint64 addr, const QByteArray &data);
|
2010-11-18 13:51:15 +01:00
|
|
|
|
|
|
|
|
virtual void reloadModules();
|
|
|
|
|
virtual void loadSymbols(const QString &moduleName);
|
|
|
|
|
virtual void loadAllSymbols();
|
|
|
|
|
virtual void requestModuleSymbols(const QString &moduleName);
|
|
|
|
|
|
|
|
|
|
virtual void reloadRegisters();
|
|
|
|
|
virtual void reloadSourceFiles();
|
|
|
|
|
virtual void reloadFullStack();
|
|
|
|
|
|
2010-11-19 16:13:22 +01:00
|
|
|
static QString extensionLibraryName(bool is64Bit);
|
2010-11-18 13:51:15 +01:00
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
void readyReadStandardOut();
|
|
|
|
|
void readyReadStandardError();
|
|
|
|
|
void processError();
|
|
|
|
|
void processFinished();
|
|
|
|
|
void postCommand(const QByteArray &cmd, unsigned flags);
|
|
|
|
|
void postBuiltinCommand(const QByteArray &cmd,
|
|
|
|
|
unsigned flags,
|
|
|
|
|
BuiltinCommandHandler handler,
|
|
|
|
|
unsigned nextCommandFlag = 0,
|
|
|
|
|
const QVariant &cookie = QVariant());
|
|
|
|
|
|
|
|
|
|
void postExtensionCommand(const QByteArray &cmd,
|
|
|
|
|
const QByteArray &arguments,
|
|
|
|
|
unsigned flags,
|
|
|
|
|
ExtensionCommandHandler handler,
|
|
|
|
|
unsigned nextCommandFlag = 0,
|
|
|
|
|
const QVariant &cookie = QVariant());
|
|
|
|
|
|
|
|
|
|
void postCommandSequence(unsigned mask);
|
|
|
|
|
void operateByInstructionTriggered(bool);
|
|
|
|
|
|
2011-05-11 16:27:33 +02:00
|
|
|
void consoleStubError(const QString &);
|
2011-01-19 10:25:32 +01:00
|
|
|
void consoleStubProcessStarted();
|
|
|
|
|
void consoleStubExited();
|
|
|
|
|
|
2010-11-18 13:51:15 +01:00
|
|
|
private:
|
2011-06-24 16:25:30 +02:00
|
|
|
typedef QHash<BreakpointModelId, BreakpointResponse> PendingBreakPointMap;
|
2011-03-04 17:28:15 +01:00
|
|
|
typedef QPair<QString, QString> SourcePathMapping;
|
|
|
|
|
struct NormalizedSourceFileName // Struct for caching mapped/normalized source files.
|
|
|
|
|
{
|
|
|
|
|
NormalizedSourceFileName(const QString &fn = QString(), bool e = false) : fileName(fn), exists(e) {}
|
|
|
|
|
|
|
|
|
|
QString fileName;
|
|
|
|
|
bool exists;
|
|
|
|
|
};
|
2011-02-03 16:26:23 +01:00
|
|
|
|
2011-01-18 11:40:45 +01:00
|
|
|
enum SpecialStopMode
|
|
|
|
|
{
|
|
|
|
|
NoSpecialStop,
|
|
|
|
|
SpecialStopSynchronizeBreakpoints,
|
2011-02-28 14:33:35 +01:00
|
|
|
SpecialStopGetWidgetAt,
|
|
|
|
|
CustomSpecialStop // Associated with m_specialStopData, handleCustomSpecialStop()
|
2011-01-18 11:40:45 +01:00
|
|
|
};
|
2011-01-25 18:35:31 +01:00
|
|
|
enum ParseStackResultFlags // Flags returned by parseStackTrace
|
|
|
|
|
{
|
|
|
|
|
ParseStackStepInto = 1 // Need to execute a step, hit on a call frame in "Step into"
|
|
|
|
|
};
|
|
|
|
|
|
2010-11-18 13:51:15 +01:00
|
|
|
|
2011-01-19 10:25:32 +01:00
|
|
|
bool startConsole(const DebuggerStartParameters &sp, QString *errorMessage);
|
2011-02-08 12:08:59 +01:00
|
|
|
void init();
|
2011-01-25 18:35:31 +01:00
|
|
|
unsigned examineStopReason(const GdbMi &stopReason, QString *message,
|
2011-03-23 15:08:57 +01:00
|
|
|
QString *exceptionBoxMessage,
|
|
|
|
|
bool conditionalBreakPointTriggered = false);
|
|
|
|
|
void processStop(const GdbMi &stopReason, bool conditionalBreakPointTriggered = false);
|
2010-12-16 12:17:54 +01:00
|
|
|
bool commandsPending() const;
|
2010-11-18 13:51:15 +01:00
|
|
|
void handleExtensionMessage(char t, int token, const QByteArray &what, const QByteArray &message);
|
|
|
|
|
bool doSetupEngine(QString *errorMessage);
|
2011-01-19 10:25:32 +01:00
|
|
|
bool launchCDB(const DebuggerStartParameters &sp, QString *errorMessage);
|
2010-11-18 13:51:15 +01:00
|
|
|
void handleSessionAccessible(unsigned long cdbExState);
|
|
|
|
|
void handleSessionInaccessible(unsigned long cdbExState);
|
|
|
|
|
void handleSessionIdle(const QByteArray &message);
|
|
|
|
|
void doInterruptInferior(SpecialStopMode sm);
|
2011-02-28 14:33:35 +01:00
|
|
|
void doInterruptInferiorCustomSpecialStop(const QVariant &v);
|
2010-11-18 13:51:15 +01:00
|
|
|
void doContinueInferior();
|
|
|
|
|
inline void parseOutputLine(QByteArray line);
|
|
|
|
|
inline bool isCdbProcessRunning() const { return m_process.state() != QProcess::NotRunning; }
|
2010-11-19 16:13:22 +01:00
|
|
|
bool canInterruptInferior() const;
|
2010-11-22 13:50:40 +01:00
|
|
|
void syncOperateByInstruction(bool operateByInstruction);
|
2011-01-18 11:40:45 +01:00
|
|
|
void postWidgetAtCommand();
|
2011-02-28 14:33:35 +01:00
|
|
|
void handleCustomSpecialStop(const QVariant &v);
|
2011-04-19 13:57:25 +02:00
|
|
|
void postFetchMemory(const MemoryViewCookie &c);
|
2011-03-23 15:08:57 +01:00
|
|
|
void evaluateExpression(QByteArray exp, const QVariant &cookie = QVariant());
|
2010-11-18 13:51:15 +01:00
|
|
|
|
|
|
|
|
// Builtin commands
|
|
|
|
|
void dummyHandler(const CdbBuiltinCommandPtr &);
|
2010-11-22 13:50:40 +01:00
|
|
|
void handleStackTrace(const CdbExtensionCommandPtr &);
|
2010-11-18 13:51:15 +01:00
|
|
|
void handleRegisters(const CdbBuiltinCommandPtr &);
|
|
|
|
|
void handleDisassembler(const CdbBuiltinCommandPtr &);
|
|
|
|
|
void handleJumpToLineAddressResolution(const CdbBuiltinCommandPtr &);
|
2011-03-23 15:08:57 +01:00
|
|
|
void handleExpression(const CdbExtensionCommandPtr &);
|
2011-03-01 16:25:11 +01:00
|
|
|
void jumpToAddress(quint64 address);
|
2010-11-18 13:51:15 +01:00
|
|
|
// Extension commands
|
|
|
|
|
void handleThreads(const CdbExtensionCommandPtr &);
|
|
|
|
|
void handlePid(const CdbExtensionCommandPtr &reply);
|
|
|
|
|
void handleLocals(const CdbExtensionCommandPtr &reply);
|
2011-01-14 16:50:31 +01:00
|
|
|
void handleAddWatch(const CdbExtensionCommandPtr &reply);
|
2010-11-18 13:51:15 +01:00
|
|
|
void handleExpandLocals(const CdbExtensionCommandPtr &reply);
|
|
|
|
|
void handleRegisters(const CdbExtensionCommandPtr &reply);
|
|
|
|
|
void handleModules(const CdbExtensionCommandPtr &reply);
|
|
|
|
|
void handleMemory(const CdbExtensionCommandPtr &);
|
2011-01-18 11:40:45 +01:00
|
|
|
void handleWidgetAt(const CdbExtensionCommandPtr &);
|
2011-02-03 16:26:23 +01:00
|
|
|
void handleBreakPoints(const CdbExtensionCommandPtr &);
|
|
|
|
|
void handleBreakPoints(const GdbMi &value);
|
2011-03-04 17:28:15 +01:00
|
|
|
NormalizedSourceFileName sourceMapNormalizeFileNameFromDebugger(const QString &f);
|
2010-11-18 13:51:15 +01:00
|
|
|
void updateLocalVariable(const QByteArray &iname);
|
2011-02-11 15:00:13 +01:00
|
|
|
void updateLocals(bool forNewStackFrame = false);
|
2010-11-18 13:51:15 +01:00
|
|
|
int elapsedLogTime() const;
|
2010-12-09 17:04:43 +01:00
|
|
|
void addLocalsOptions(ByteArrayInputStream &s) const;
|
2011-01-25 18:35:31 +01:00
|
|
|
unsigned parseStackTrace(const GdbMi &data, bool sourceStepInto);
|
|
|
|
|
void parseThreads(const GdbMi &, int forceCurrentThreadId = -1);
|
2010-11-18 13:51:15 +01:00
|
|
|
|
|
|
|
|
const QByteArray m_creatorExtPrefix;
|
|
|
|
|
const QByteArray m_tokenPrefix;
|
|
|
|
|
const OptionsPtr m_options;
|
|
|
|
|
|
|
|
|
|
QProcess m_process;
|
2011-01-19 10:25:32 +01:00
|
|
|
QScopedPointer<Utils::ConsoleProcess> m_consoleStub;
|
|
|
|
|
DebuggerStartMode m_effectiveStartMode;
|
2010-11-18 13:51:15 +01:00
|
|
|
QByteArray m_outputBuffer;
|
2011-02-04 15:08:31 +01:00
|
|
|
//! Debugger accessible (expecting commands)
|
2010-11-18 13:51:15 +01:00
|
|
|
bool m_accessible;
|
|
|
|
|
SpecialStopMode m_specialStopMode;
|
|
|
|
|
int m_nextCommandToken;
|
|
|
|
|
QList<CdbBuiltinCommandPtr> m_builtinCommandQueue;
|
2011-02-04 15:08:31 +01:00
|
|
|
int m_currentBuiltinCommandIndex; //!< Current command whose output is recorded.
|
2010-11-18 13:51:15 +01:00
|
|
|
QList<CdbExtensionCommandPtr> m_extensionCommandQueue;
|
2011-03-04 17:28:15 +01:00
|
|
|
QMap<QString, NormalizedSourceFileName> m_normalizedFileCache;
|
2011-02-04 15:08:31 +01:00
|
|
|
const QByteArray m_extensionCommandPrefixBA; //!< Library name used as prefix
|
|
|
|
|
bool m_operateByInstructionPending; //!< Creator operate by instruction action changed.
|
2010-11-18 13:51:15 +01:00
|
|
|
bool m_operateByInstruction;
|
|
|
|
|
bool m_notifyEngineShutdownOnTermination;
|
|
|
|
|
bool m_hasDebuggee;
|
|
|
|
|
QTime m_logTime;
|
|
|
|
|
mutable int m_elapsedLogTime;
|
2011-01-04 12:40:52 +01:00
|
|
|
QByteArray m_extensionMessageBuffer;
|
2011-01-05 11:34:35 +01:00
|
|
|
bool m_sourceStepInto;
|
2011-01-18 11:40:45 +01:00
|
|
|
int m_watchPointX;
|
|
|
|
|
int m_watchPointY;
|
2011-02-03 16:26:23 +01:00
|
|
|
PendingBreakPointMap m_pendingBreakpointMap;
|
|
|
|
|
QHash<QString, QString> m_fileNameModuleHash;
|
2011-02-08 12:08:59 +01:00
|
|
|
bool m_ignoreCdbOutput;
|
2011-02-28 14:33:35 +01:00
|
|
|
QVariantList m_customSpecialStopData;
|
2011-03-04 17:28:15 +01:00
|
|
|
QList<SourcePathMapping> m_sourcePathMappings;
|
2010-11-18 13:51:15 +01:00
|
|
|
};
|
|
|
|
|
|
2011-01-11 11:06:15 +01:00
|
|
|
} // namespace Internal
|
2010-11-18 13:51:15 +01:00
|
|
|
} // namespace Debugger
|
|
|
|
|
|
|
|
|
|
#endif // DEBUGGER_CDBENGINE_H
|