forked from qt-creator/qt-creator
Debugger: Merge *Adapter classes into GdbEngine
The main reason for having the adapters (complex target specific state handling) is mostly gone now, leaving us mainly with the drawbacks of the solution: An additional indirection, and using a hierarchy for code sharing. So drop that, and use if/else chains instead of virtual functions now, and start simplifying the result. Change-Id: Idcf3a28da103c01cfa80cf9bab8ef51fe879b6d7 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -33,64 +33,69 @@
|
||||
#include <debugger/watchutils.h>
|
||||
#include <debugger/debuggeritem.h>
|
||||
#include <debugger/debuggertooltipmanager.h>
|
||||
#include <debugger/outputcollector.h>
|
||||
|
||||
#include <coreplugin/id.h>
|
||||
|
||||
#include <utils/qtcprocess.h>
|
||||
#include <utils/consoleprocess.h>
|
||||
|
||||
#include <QProcess>
|
||||
#include <QTextCodec>
|
||||
#include <QTimer>
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace Debugger {
|
||||
namespace Internal {
|
||||
|
||||
class GdbProcess;
|
||||
class BreakpointParameters;
|
||||
class BreakpointResponse;
|
||||
class DebugInfoTask;
|
||||
class DebugInfoTaskHandler;
|
||||
class DebuggerResponse;
|
||||
class DisassemblerAgentCookie;
|
||||
class GdbMi;
|
||||
class MemoryAgentCookie;
|
||||
class BreakpointParameters;
|
||||
class BreakpointResponse;
|
||||
|
||||
class DisassemblerAgentCookie;
|
||||
class DisassemblerLines;
|
||||
struct CoreInfo
|
||||
{
|
||||
QString rawStringFromCore;
|
||||
QString foundExecutableName; // empty if no corresponding exec could be found
|
||||
bool isCore = false;
|
||||
|
||||
static CoreInfo readExecutableNameFromCore(const ProjectExplorer::StandardRunnable &debugger,
|
||||
const QString &coreFile);
|
||||
};
|
||||
|
||||
class GdbEngine : public DebuggerEngine
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GdbEngine(bool useTerminal);
|
||||
~GdbEngine() override;
|
||||
explicit GdbEngine(bool useTerminal, DebuggerStartMode startMode);
|
||||
~GdbEngine() final;
|
||||
|
||||
private: ////////// General Interface //////////
|
||||
DebuggerEngine *cppEngine() override { return this; }
|
||||
DebuggerEngine *cppEngine() final { return this; }
|
||||
|
||||
virtual void handleGdbStartFailed();
|
||||
void notifyInferiorSetupFailed() override;
|
||||
void prepareForRestart() override;
|
||||
void handleGdbStartFailed();
|
||||
void notifyInferiorSetupFailed() final;
|
||||
void prepareForRestart() final;
|
||||
|
||||
bool hasCapability(unsigned) const override;
|
||||
void detachDebugger() override;
|
||||
void shutdownInferior() override;
|
||||
void abortDebugger() override;
|
||||
void resetInferior() override;
|
||||
bool hasCapability(unsigned) const final;
|
||||
void detachDebugger() final;
|
||||
void shutdownInferior() final;
|
||||
void abortDebugger() final;
|
||||
void resetInferior() final;
|
||||
|
||||
bool acceptsDebuggerCommands() const override;
|
||||
void executeDebuggerCommand(const QString &command, DebuggerLanguages languages) override;
|
||||
bool acceptsDebuggerCommands() const final;
|
||||
void executeDebuggerCommand(const QString &command, DebuggerLanguages languages) final;
|
||||
|
||||
private: ////////// General State //////////
|
||||
////////// General State //////////
|
||||
|
||||
DebuggerStartMode startMode() const;
|
||||
void reloadLocals();
|
||||
const DebuggerStartMode m_startMode;
|
||||
bool m_registerNamesListed = false;
|
||||
|
||||
bool m_registerNamesListed;
|
||||
|
||||
protected: ////////// Gdb Process Management //////////
|
||||
////////// Gdb Process Management //////////
|
||||
|
||||
void startGdb(const QStringList &args = QStringList());
|
||||
void handleInferiorShutdown(const DebuggerResponse &response);
|
||||
@@ -123,9 +128,6 @@ protected: ////////// Gdb Process Management //////////
|
||||
// Make sure to clean up everything before emitting this signal.
|
||||
void handleAdapterCrashed(const QString &msg);
|
||||
|
||||
private:
|
||||
friend class GdbPlainEngine;
|
||||
friend class GdbCoreEngine;
|
||||
void handleGdbFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
||||
void handleGdbError(QProcess::ProcessError error);
|
||||
void readGdbStandardOutput();
|
||||
@@ -138,17 +140,16 @@ private:
|
||||
QTextCodec::ConverterState m_inferiorOutputCodecState;
|
||||
|
||||
QByteArray m_inbuffer;
|
||||
bool m_busy;
|
||||
bool m_busy = false;
|
||||
|
||||
// Name of the convenience variable containing the last
|
||||
// known function return value.
|
||||
QString m_resultVarName;
|
||||
|
||||
protected: ////////// Gdb Command Management //////////
|
||||
////////// Gdb Command Management //////////
|
||||
|
||||
void runCommand(const DebuggerCommand &command) override;
|
||||
void runCommand(const DebuggerCommand &command) final;
|
||||
|
||||
private:
|
||||
void commandTimeout();
|
||||
void setTokenBarrier();
|
||||
|
||||
@@ -166,19 +167,19 @@ private:
|
||||
// This 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_nonDiscardableCount;
|
||||
int m_oldestAcceptableToken = -1;
|
||||
int m_nonDiscardableCount = 0;
|
||||
|
||||
int m_pendingBreakpointRequests; // Watch updating commands in flight
|
||||
int m_pendingBreakpointRequests = 0; // Watch updating commands in flight
|
||||
|
||||
typedef void (GdbEngine::*CommandsDoneCallback)();
|
||||
// This function is called after all previous responses have been received.
|
||||
CommandsDoneCallback m_commandsDoneCallback;
|
||||
CommandsDoneCallback m_commandsDoneCallback = nullptr;
|
||||
|
||||
bool m_rerunPending;
|
||||
bool m_rerunPending = false;
|
||||
|
||||
////////// Gdb Output, State & Capability Handling //////////
|
||||
|
||||
private: ////////// Gdb Output, State & Capability Handling //////////
|
||||
protected:
|
||||
Q_INVOKABLE void handleResponse(const QString &buff);
|
||||
void handleAsyncOutput(const QString &asyncClass, const GdbMi &result);
|
||||
void handleStopResponse(const GdbMi &data);
|
||||
@@ -188,42 +189,40 @@ protected:
|
||||
void handleStop3();
|
||||
void resetCommandQueue();
|
||||
|
||||
bool isSynchronous() const override { return true; }
|
||||
bool isSynchronous() const final { return true; }
|
||||
|
||||
// Gdb initialization sequence
|
||||
void handleShowVersion(const DebuggerResponse &response);
|
||||
void handleListFeatures(const DebuggerResponse &response);
|
||||
void handlePythonSetup(const DebuggerResponse &response);
|
||||
|
||||
int m_gdbVersion; // 7.6.1 is 70601
|
||||
int m_pythonVersion; // 2.7.2 is 20702
|
||||
bool m_isQnxGdb;
|
||||
int m_gdbVersion = 100; // 7.6.1 is 70601
|
||||
int m_pythonVersion = 0; // 2.7.2 is 20702
|
||||
bool m_isQnxGdb = false;
|
||||
|
||||
private: ////////// Inferior Management //////////
|
||||
////////// Inferior Management //////////
|
||||
|
||||
// This should be always the last call in a function.
|
||||
bool stateAcceptsBreakpointChanges() const override;
|
||||
bool acceptsBreakpoint(Breakpoint bp) const override;
|
||||
void insertBreakpoint(Breakpoint bp) override;
|
||||
void removeBreakpoint(Breakpoint bp) override;
|
||||
void changeBreakpoint(Breakpoint bp) override;
|
||||
bool stateAcceptsBreakpointChanges() const final;
|
||||
bool acceptsBreakpoint(Breakpoint bp) const final;
|
||||
void insertBreakpoint(Breakpoint bp) final;
|
||||
void removeBreakpoint(Breakpoint bp) final;
|
||||
void changeBreakpoint(Breakpoint bp) final;
|
||||
|
||||
void executeStep() override;
|
||||
void executeStepOut() override;
|
||||
void executeNext() override;
|
||||
void executeStepI() override;
|
||||
void executeNextI() override;
|
||||
void executeStep() final;
|
||||
void executeStepOut() final;
|
||||
void executeNext() final;
|
||||
void executeStepI() final;
|
||||
void executeNextI() final;
|
||||
|
||||
protected:
|
||||
void continueInferiorInternal();
|
||||
void continueInferior() override;
|
||||
void interruptInferior() override;
|
||||
virtual void interruptInferior2() {}
|
||||
void continueInferior() final;
|
||||
void interruptInferior() final;
|
||||
|
||||
void executeRunToLine(const ContextData &data) override;
|
||||
void executeRunToFunction(const QString &functionName) override;
|
||||
void executeJumpToLine(const ContextData &data) override;
|
||||
void executeReturn() override;
|
||||
void executeRunToLine(const ContextData &data) final;
|
||||
void executeRunToFunction(const QString &functionName) final;
|
||||
void executeJumpToLine(const ContextData &data) final;
|
||||
void executeReturn() final;
|
||||
|
||||
void handleExecuteContinue(const DebuggerResponse &response);
|
||||
void handleExecuteStep(const DebuggerResponse &response);
|
||||
@@ -234,10 +233,10 @@ private: ////////// Inferior Management //////////
|
||||
|
||||
QString msgPtraceError(DebuggerStartMode sm);
|
||||
|
||||
private: ////////// View & Data Stuff //////////
|
||||
////////// View & Data Stuff //////////
|
||||
|
||||
void selectThread(ThreadId threadId) override;
|
||||
void activateFrame(int index) override;
|
||||
void selectThread(ThreadId threadId) final;
|
||||
void activateFrame(int index) final;
|
||||
void handleAutoContinueInferior();
|
||||
|
||||
//
|
||||
@@ -265,14 +264,13 @@ private: ////////// View & Data Stuff //////////
|
||||
//
|
||||
// Modules specific stuff
|
||||
//
|
||||
protected:
|
||||
void loadSymbols(const QString &moduleName) override;
|
||||
void loadAllSymbols() override;
|
||||
void loadSymbolsForStack() override;
|
||||
void requestModuleSymbols(const QString &moduleName) override;
|
||||
void requestModuleSections(const QString &moduleName) override;
|
||||
void reloadModules() override;
|
||||
void examineModules() override;
|
||||
void loadSymbols(const QString &moduleName) final;
|
||||
void loadAllSymbols() final;
|
||||
void loadSymbolsForStack() final;
|
||||
void requestModuleSymbols(const QString &moduleName) final;
|
||||
void requestModuleSections(const QString &moduleName) final;
|
||||
void reloadModules() final;
|
||||
void examineModules() final;
|
||||
|
||||
void reloadModulesInternal();
|
||||
void handleModulesList(const DebuggerResponse &response);
|
||||
@@ -281,14 +279,14 @@ private: ////////// View & Data Stuff //////////
|
||||
//
|
||||
// Snapshot specific stuff
|
||||
//
|
||||
virtual void createSnapshot() override;
|
||||
void createSnapshot() final;
|
||||
void handleMakeSnapshot(const DebuggerResponse &response, const QString &coreFile);
|
||||
|
||||
//
|
||||
// Register specific stuff
|
||||
//
|
||||
void reloadRegisters() override;
|
||||
void setRegisterValue(const QString &name, const QString &value) override;
|
||||
void reloadRegisters() final;
|
||||
void setRegisterValue(const QString &name, const QString &value) final;
|
||||
void handleRegisterListNames(const DebuggerResponse &response);
|
||||
void handleRegisterListing(const DebuggerResponse &response);
|
||||
void handleRegisterListValues(const DebuggerResponse &response);
|
||||
@@ -299,7 +297,7 @@ private: ////////// View & Data Stuff //////////
|
||||
// Disassembler specific stuff
|
||||
//
|
||||
// Chain of fallbacks: PointMixed -> PointPlain -> RangeMixed -> RangePlain.
|
||||
void fetchDisassembler(DisassemblerAgent *agent) override;
|
||||
void fetchDisassembler(DisassemblerAgent *agent) final;
|
||||
void fetchDisassemblerByCliPointMixed(const DisassemblerAgentCookie &ac);
|
||||
void fetchDisassemblerByCliRangeMixed(const DisassemblerAgentCookie &ac);
|
||||
void fetchDisassemblerByCliRangePlain(const DisassemblerAgentCookie &ac);
|
||||
@@ -308,7 +306,7 @@ private: ////////// View & Data Stuff //////////
|
||||
//
|
||||
// Source file specific stuff
|
||||
//
|
||||
void reloadSourceFiles() override;
|
||||
void reloadSourceFiles() final;
|
||||
void reloadSourceFilesInternal();
|
||||
void handleQuerySources(const DebuggerResponse &response);
|
||||
|
||||
@@ -320,13 +318,12 @@ private: ////////// View & Data Stuff //////////
|
||||
QMap<QString, QString> m_fullToShortName;
|
||||
QMultiMap<QString, QString> m_baseNameToFullName;
|
||||
|
||||
bool m_sourcesListUpdating;
|
||||
bool m_sourcesListUpdating = false;
|
||||
|
||||
//
|
||||
// Stack specific stuff
|
||||
//
|
||||
protected:
|
||||
void updateAll() override;
|
||||
void updateAll() final;
|
||||
void handleStackListFrames(const DebuggerResponse &response, bool isFull);
|
||||
void handleStackSelectThread(const DebuggerResponse &response);
|
||||
void handleThreadListIds(const DebuggerResponse &response);
|
||||
@@ -334,20 +331,21 @@ protected:
|
||||
void handleThreadNames(const DebuggerResponse &response);
|
||||
DebuggerCommand stackCommand(int depth);
|
||||
void reloadStack();
|
||||
void reloadFullStack() override;
|
||||
void loadAdditionalQmlStack() override;
|
||||
void reloadFullStack() final;
|
||||
void loadAdditionalQmlStack() final;
|
||||
int currentFrame() const;
|
||||
|
||||
//
|
||||
// Watch specific stuff
|
||||
//
|
||||
virtual void assignValueInDebugger(WatchItem *item,
|
||||
const QString &expr, const QVariant &value) override;
|
||||
void reloadLocals();
|
||||
void assignValueInDebugger(WatchItem *item,
|
||||
const QString &expr, const QVariant &value) final;
|
||||
|
||||
void fetchMemory(MemoryAgent *agent, quint64 addr, quint64 length) override;
|
||||
void fetchMemory(MemoryAgent *agent, quint64 addr, quint64 length) final;
|
||||
void fetchMemoryHelper(const MemoryAgentCookie &cookie);
|
||||
void handleChangeMemory(const DebuggerResponse &response);
|
||||
void changeMemory(MemoryAgent *agent, quint64 addr, const QByteArray &data) override;
|
||||
void changeMemory(MemoryAgent *agent, quint64 addr, const QByteArray &data) final;
|
||||
void handleFetchMemory(const DebuggerResponse &response, MemoryAgentCookie ac);
|
||||
|
||||
void showToolTip();
|
||||
@@ -358,7 +356,7 @@ protected:
|
||||
|
||||
void createFullBacktrace();
|
||||
|
||||
void doUpdateLocals(const UpdateParameters ¶meters) override;
|
||||
void doUpdateLocals(const UpdateParameters ¶meters) final;
|
||||
void handleFetchVariables(const DebuggerResponse &response);
|
||||
|
||||
void setLocals(const QList<GdbMi> &locals);
|
||||
@@ -366,7 +364,7 @@ protected:
|
||||
//
|
||||
// Dumper Management
|
||||
//
|
||||
void reloadDebuggingHelpers() override;
|
||||
void reloadDebuggingHelpers() final;
|
||||
|
||||
//
|
||||
// Convenience Functions
|
||||
@@ -374,19 +372,18 @@ protected:
|
||||
void showExecutionError(const QString &message);
|
||||
QString failedToStartMessage();
|
||||
|
||||
static QString tooltipIName(const QString &exp);
|
||||
|
||||
// For short-circuiting stack and thread list evaluation.
|
||||
bool m_stackNeeded;
|
||||
bool m_stackNeeded = false;
|
||||
|
||||
// For suppressing processing *stopped and *running responses
|
||||
// while updating locals.
|
||||
bool m_inUpdateLocals;
|
||||
bool m_inUpdateLocals = false;
|
||||
|
||||
// HACK:
|
||||
QString m_currentThread;
|
||||
QString m_lastWinException;
|
||||
QString m_lastMissingDebugInfo;
|
||||
const bool m_useTerminal;
|
||||
bool m_terminalTrap;
|
||||
bool usesExecInterrupt() const;
|
||||
bool usesTargetAsync() const;
|
||||
@@ -401,7 +398,7 @@ protected:
|
||||
void requestDebugInformation(const DebugInfoTask &task);
|
||||
DebugInfoTaskHandler *m_debugInfoTaskHandler;
|
||||
|
||||
bool m_systemDumpersLoaded;
|
||||
bool m_systemDumpersLoaded = false;
|
||||
|
||||
static QString msgGdbStopFailed(const QString &why);
|
||||
static QString msgInferiorStopFailed(const QString &why);
|
||||
@@ -410,14 +407,63 @@ protected:
|
||||
static QString msgInferiorRunOk();
|
||||
static QString msgConnectRemoteServerFailed(const QString &why);
|
||||
|
||||
void debugLastCommand() override;
|
||||
void debugLastCommand() final;
|
||||
DebuggerCommand m_lastDebuggableCommand;
|
||||
|
||||
protected:
|
||||
bool isPlainEngine() const;
|
||||
bool isCoreEngine() const;
|
||||
bool isRemoteEngine() const;
|
||||
bool isAttachEngine() const;
|
||||
bool isTermEngine() const;
|
||||
|
||||
void setupEngine() final;
|
||||
void setupInferior() final;
|
||||
void runEngine() final;
|
||||
void shutdownEngine() final;
|
||||
|
||||
void interruptInferior2();
|
||||
|
||||
// Plain
|
||||
void handleExecRun(const DebuggerResponse &response);
|
||||
void handleFileExecAndSymbols(const DebuggerResponse &response);
|
||||
|
||||
// Attach
|
||||
void handleAttach(const DebuggerResponse &response);
|
||||
|
||||
// Remote
|
||||
void callTargetRemote();
|
||||
void handleSetTargetAsync(const DebuggerResponse &response);
|
||||
void handleTargetRemote(const DebuggerResponse &response);
|
||||
void handleTargetExtendedRemote(const DebuggerResponse &response);
|
||||
void handleTargetExtendedAttach(const DebuggerResponse &response);
|
||||
void handleTargetQnx(const DebuggerResponse &response);
|
||||
void handleSetNtoExecutable(const DebuggerResponse &response);
|
||||
void handleInterruptInferior(const DebuggerResponse &response);
|
||||
void interruptLocalInferior(qint64 pid);
|
||||
|
||||
protected:
|
||||
// Terminal
|
||||
void handleStubAttached(const DebuggerResponse &response);
|
||||
void stubExited();
|
||||
void stubError(const QString &msg);
|
||||
Utils::ConsoleProcess m_stubProc;
|
||||
|
||||
// Core
|
||||
void handleTargetCore(const DebuggerResponse &response);
|
||||
void handleCoreRoundTrip(const DebuggerResponse &response);
|
||||
void unpackCoreIfNeeded();
|
||||
QString coreFileName() const;
|
||||
QString coreName() const;
|
||||
|
||||
void continueSetupEngine();
|
||||
|
||||
QString m_executable;
|
||||
QString m_coreName;
|
||||
QString m_tempCoreName;
|
||||
QProcess *m_coreUnpackProcess = nullptr;
|
||||
QFile m_tempCoreFile;
|
||||
|
||||
Utils::QtcProcess m_gdbProc;
|
||||
OutputCollector m_outputCollector;
|
||||
QString m_errorString;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user