Files
qt-creator/src/plugins/debugger/cdb/cdbengine.h

246 lines
9.9 KiB
C
Raw Normal View History

/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
2010-12-17 17:14:20 +01:00
**
****************************************************************************/
#pragma once
#include <debugger/debuggerengine.h>
#include <debugger/breakhandler.h>
#include <cplusplus/CppDocument.h>
#include <projectexplorer/devicesupport/idevice.h>
#include <QTime>
namespace Debugger {
namespace Internal {
class CdbCommand;
struct MemoryViewCookie;
class StringInputStream;
class CdbEngine : public DebuggerEngine
{
Q_OBJECT
public:
using CdbCommandPtr = QSharedPointer<CdbCommand>;
using CommandHandler = std::function<void (const DebuggerResponse &)>;
explicit CdbEngine();
~CdbEngine() override;
bool canHandleToolTip(const DebuggerToolTipContext &context) const override;
void setupEngine() override;
void runEngine() override;
void shutdownInferior() override;
void shutdownEngine() override;
void abortDebuggerProcess() override;
void detachDebugger() override;
bool hasCapability(unsigned cap) const override;
void watchPoint(const QPoint &) override;
void setRegisterValue(const QString &name, const QString &value) override;
void executeStepOver(bool byInstruction) override;
void executeStepIn(bool byInstruction) override;
void executeStepOut() override;
void continueInferior() override;
void interruptInferior() override;
void executeRunToLine(const ContextData &data) override;
void executeRunToFunction(const QString &functionName) override;
void executeJumpToLine(const ContextData &data) override;
void assignValueInDebugger(WatchItem *w, const QString &expr, const QVariant &value) override;
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
void executeDebuggerCommand(const QString &command) override;
void activateFrame(int index) override;
void selectThread(const Thread &thread) override;
bool stateAcceptsBreakpointChanges() const override;
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
bool acceptsBreakpoint(const BreakpointParameters &params) const override;
void insertBreakpoint(const Breakpoint &bp) override;
void removeBreakpoint(const Breakpoint &bp) override;
void updateBreakpoint(const Breakpoint &bp) override;
void enableSubBreakpoint(const SubBreakpoint &sbp, bool on) override;
void fetchDisassembler(DisassemblerAgent *agent) override;
void fetchMemory(MemoryAgent *, quint64 addr, quint64 length) override;
void changeMemory(MemoryAgent *, quint64 addr, const QByteArray &data) override;
void reloadModules() override;
void loadSymbols(const QString &moduleName) override;
void loadAllSymbols() override;
void requestModuleSymbols(const QString &moduleName) override;
void reloadRegisters() override;
void reloadSourceFiles() override;
void reloadFullStack() override;
void loadAdditionalQmlStack() override;
void listBreakpoints();
static QString extensionLibraryName(bool is64Bit);
private:
void readyReadStandardOut();
void readyReadStandardError();
void processError();
void processFinished();
void runCommand(const DebuggerCommand &cmd) override;
void adjustOperateByInstruction(bool);
void createFullBacktrace();
void handleDoInterruptInferior(const QString &errorMessage);
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02: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;
};
enum StopMode {
NoStopRequested,
Interrupt,
Callback
};
enum ParseStackResultFlags // Flags returned by parseStackTrace
{
ParseStackStepInto = 1, // Need to execute a step, hit on a call frame in "Step into"
ParseStackStepOut = 2, // Need to step out, hit on a frame without debug information
ParseStackWow64 = 3 // Hit on a frame with 32bit emulation, switch debugger to 32 bit mode
};
enum CommandFlags {
NoFlags = 0,
BuiltinCommand,
ExtensionCommand,
ScriptCommand
};
2011-02-08 12:08:59 +01:00
void init();
unsigned examineStopReason(const GdbMi &stopReason, QString *message,
QString *exceptionBoxMessage,
bool conditionalBreakPointTriggered = false);
void processStop(const GdbMi &stopReason, bool conditionalBreakPointTriggered = false);
bool commandsPending() const;
void handleExtensionMessage(char t, int token, const QString &what, const QString &message);
bool doSetupEngine(QString *errorMessage);
void handleSessionAccessible(unsigned long cdbExState);
void handleSessionInaccessible(unsigned long cdbExState);
void handleSessionIdle(const QString &message);
using InterruptCallback = std::function<void()>;
void doInterruptInferior(const InterruptCallback &cb = InterruptCallback());
void doContinueInferior();
void parseOutputLine(QString line);
bool isCdbProcessRunning() const { return m_process.state() != QProcess::NotRunning; }
bool canInterruptInferior() const;
inline void postDisassemblerCommand(quint64 address, DisassemblerAgent *agent);
void postDisassemblerCommand(quint64 address, quint64 endAddress,
DisassemblerAgent *agent);
void postResolveSymbol(const QString &module, const QString &function,
DisassemblerAgent *agent);
void showScriptMessages(const QString &message) const;
void handleInitialSessionIdle();
// Builtin commands
void handleStackTrace(const DebuggerResponse &);
void handleRegisters(const DebuggerResponse &);
void handleJumpToLineAddressResolution(const DebuggerResponse &response, const ContextData &context);
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
void handleExpression(const DebuggerResponse &command, const Breakpoint &bp, const GdbMi &stopReason);
void handleResolveSymbol(const DebuggerResponse &command, const QString &symbol, DisassemblerAgent *agent);
void handleResolveSymbolHelper(const QList<quint64> &addresses, DisassemblerAgent *agent);
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
void handleBreakInsert(const DebuggerResponse &response, const Breakpoint &bp);
void handleCheckWow64(const DebuggerResponse &response, const GdbMi &stack);
void ensureUsing32BitStackInWow64(const DebuggerResponse &response, const GdbMi &stack);
void handleSwitchWow64Stack(const DebuggerResponse &response);
void jumpToAddress(quint64 address);
// Extension commands
void handleThreads(const DebuggerResponse &response);
void handleLocals(const DebuggerResponse &response, bool partialUpdate);
void handleExpandLocals(const DebuggerResponse &response);
void handleRegistersExt(const DebuggerResponse &response);
void handleModules(const DebuggerResponse &response);
void handleWidgetAt(const DebuggerResponse &response);
void handleBreakPoints(const DebuggerResponse &response);
void handleAdditionalQmlStack(const DebuggerResponse &response);
void setupScripting(const DebuggerResponse &response);
NormalizedSourceFileName sourceMapNormalizeFileNameFromDebugger(const QString &f);
void doUpdateLocals(const UpdateParameters &params) override;
void updateAll() override;
int elapsedLogTime() const;
unsigned parseStackTrace(const GdbMi &data, bool sourceStepInto);
void mergeStartParametersSourcePathMap();
const QString m_tokenPrefix;
void handleSetupFailure(const QString &errorMessage);
QProcess m_process;
DebuggerStartMode m_effectiveStartMode = NoStartMode;
QByteArray m_outputBuffer;
//! Debugger accessible (expecting commands)
bool m_accessible = false;
StopMode m_stopMode = NoStopRequested;
ProjectExplorer::DeviceProcessSignalOperation::Ptr m_signalOperation;
int m_nextCommandToken = 0;
QHash<int, DebuggerCommand> m_commandForToken;
QString m_currentBuiltinResponse;
int m_currentBuiltinResponseToken = -1;
QMap<QString, NormalizedSourceFileName> m_normalizedFileCache;
const QString m_extensionCommandPrefix; //!< Library name used as prefix
bool m_lastOperateByInstruction = true; // Default CDB setting.
bool m_hasDebuggee = false;
enum Wow64State {
wow64Uninitialized,
noWow64Stack,
wow64Stack32Bit,
wow64Stack64Bit
} m_wow64State = wow64Uninitialized;
QTime m_logTime;
mutable int m_elapsedLogTime = 0;
QString m_extensionMessageBuffer;
bool m_sourceStepInto = false;
int m_watchPointX = 0;
int m_watchPointY = 0;
Debugger: Make most views per-engine instead of singletons This is a step towards properly supporting multiple debugger sessions side-by-side. The combined C++-and-QML engine has been removed, instead a combined setup creates now two individual engines, under a single DebuggerRunTool but mostly independent with no combined state machine. This requires a few more clicks in some cases, but makes it easier to direct e.g. interrupt requests to the interesting engine. Care has been taken to not change the UX of the single debugger session use case if possible. The fat debug button operates as-before in that case, i.e. switches to Interrupt if the single active runconfiguration runs in the debugger etc. Most views are made per-engine, running an engine creates a new Perspective, which is destroyed when the run control dies. The snapshot view remains global and becomes primary source of information on a "current engine" that receives all menu and otherwise global input. There is a new global "Breakpoint Preset" view containing all "static" breakpoint data. When an engine starts up it "claims" breakpoint it believes it can handle, but operates on a copy of the static data. The markers of the static version are suppressed as long as an engine controls a breakpoint (that inclusive all resolved locations), but are re-instatet once the engine quits. The old Breakpoint class that already contained this split per-instance was split into a new Breakpoint and a GlobalBreakpoint class, with a per-engine model for Breakpoints, and a singleton model containing GlobalBreakpoints. There is a new CppDebuggerEngine intermediate level serving as base for C++ (or, rather, "compiled") binary debugging, i.e. {Gdb,Lldb,Cdb}Engine, taking over bits of the current DebuggerEngine base that are not applicable to non-binary debuggers. Change-Id: I9994f4c188379b4aee0c4f379edd4759fbb0bd43 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: hjk <hjk@qt.io>
2018-07-31 12:30:48 +02:00
QSet<Breakpoint> m_pendingBreakpointMap;
bool m_autoBreakPointCorrection = false;
QMultiHash<QString, quint64> m_symbolAddressCache;
bool m_ignoreCdbOutput = false;
QList<InterruptCallback> m_interrupCallbacks;
QList<SourcePathMapping> m_sourcePathMappings;
QScopedPointer<GdbMi> m_coreStopReason;
int m_pythonVersion = 0; // 0xMMmmpp MM = major; mm = minor; pp = patch
bool m_initialSessionIdleHandled = false;
mutable CPlusPlus::Snapshot m_codeModelSnapshot;
};
} // namespace Internal
} // namespace Debugger