RedPanda-CPP/RedPandaIDE/debugger.h

229 lines
5.5 KiB
C
Raw Normal View History

2021-07-03 21:57:50 +08:00
#ifndef DEBUGGER_H
#define DEBUGGER_H
2021-07-17 19:32:23 +08:00
#include <QAbstractTableModel>
2021-07-03 21:57:50 +08:00
#include <QList>
#include <QList>
2021-07-17 19:32:23 +08:00
#include <QMap>
2021-07-03 21:57:50 +08:00
#include <QMutex>
#include <QObject>
2021-07-19 23:02:32 +08:00
#include <QProcess>
2021-07-03 21:57:50 +08:00
#include <QQueue>
#include <QQueue>
2021-07-19 23:02:32 +08:00
#include <QThread>
2021-07-03 21:57:50 +08:00
#include <memory>
enum class DebugCommandSource {
Console,
Other
};
enum class AnnotationType {
TPrePrompt, TPrompt, TPostPrompt,
TSource,
TDisplayBegin, TDisplayEnd,
TDisplayExpression,
TFrameSourceFile, TFrameSourceBegin, TFrameSourceLine, TFrameFunctionName, TFrameWhere,
TFrameArgs,
TFrameBegin, TFrameEnd,
TErrorBegin, TErrorEnd,
TArrayBegin, TArrayEnd,
TElt, TEltRep, TEltRepEnd,
TExit,
TSignal, TSignalName, TSignalNameEnd, TSignalString, TSignalStringEnd,
TValueHistoryValue, TValueHistoryBegin, TValueHistoryEnd,
TArgBegin, TArgEnd, TArgValue, TArgNameEnd,
TFieldBegin, TFieldEnd, TFieldValue, TFieldNameEnd,
TInfoReg, TInfoAsm,
TUnknown, TEOF,
TLocal, TParam
};
struct DebugCommand{
QString command;
QString params;
bool updateWatch;
bool showInConsole;
DebugCommandSource source;
};
using PDebugCommand = std::shared_ptr<DebugCommand>;
2021-07-17 19:32:23 +08:00
struct WatchVar {
QString name;
int gdbIndex;
};
using PWatchVar = std::shared_ptr<WatchVar>;
2021-07-24 08:12:51 +08:00
class Editor;
2021-07-03 21:57:50 +08:00
struct Breakpoint {
int line;
2021-07-24 08:12:51 +08:00
Editor * editor;
2021-07-03 21:57:50 +08:00
QString condition;
};
using PBreakpoint = std::shared_ptr<Breakpoint>;
struct Trace {
QString funcname;
QString filename;
int line;
};
using PTrace = std::shared_ptr<Trace>;
struct Register {
QString name;
2021-07-17 19:32:23 +08:00
QString hexValue;
QString decValue;
2021-07-03 21:57:50 +08:00
};
using PRegister = std::shared_ptr<Register>;
2021-07-17 19:32:23 +08:00
class BreakpointModel: public QAbstractTableModel {
// QAbstractItemModel interface
public:
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
void addBreakpoint(PBreakpoint p);
void clear();
void removeBreakpoint(int row);
private:
QList<PBreakpoint> mList;
};
class BacktraceModel : public QAbstractTableModel {
// QAbstractItemModel interface
public:
int rowCount(const QModelIndex &parent) const override;
int columnCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
void addTrace(PTrace p);
void clear();
void removeTrace(int row);
private:
QList<PTrace> mList;
};
2021-07-03 21:57:50 +08:00
class DebugReader;
class Debugger : public QObject
{
Q_OBJECT
public:
explicit Debugger(QObject *parent = nullptr);
2021-07-24 08:12:51 +08:00
void addBreakpoint(int line);
void sendBreakpointToDebugger(int index);
bool useUTF8() const;
void setUseUTF8(bool useUTF8);
const BacktraceModel* getBacktraceModel() const;
2021-07-03 21:57:50 +08:00
signals:
private:
bool mExecuting;
bool mCommandChanged;
QList<PBreakpoint> mBreakpointList;
bool mUseUTF8;
QString getBreakpointFile();
2021-07-24 08:12:51 +08:00
BacktraceModel mBacktraceModel;
friend class DebugReader;
2021-07-03 21:57:50 +08:00
};
2021-07-19 23:02:32 +08:00
class DebugReader : public QThread
2021-07-03 21:57:50 +08:00
{
Q_OBJECT
public:
explicit DebugReader(QObject *parent = nullptr);
2021-07-19 23:02:32 +08:00
void postCommand(const QString &Command, const QString &Params,
bool UpdateWatch, bool ShowInConsole, DebugCommandSource Source);
2021-07-18 08:52:53 +08:00
signals:
void parseStarted();
void invalidateAllVars();
void parseFinished();
2021-07-19 23:02:32 +08:00
void writeToDebugFailed();
void pauseWatchUpdate();
void updateWatch();
void processError(QProcess::ProcessError error);
2021-07-03 21:57:50 +08:00
private:
void clearCmdQueue();
bool findAnnotation(AnnotationType annotation);
AnnotationType getAnnotation(const QString& s);
2021-07-19 23:02:32 +08:00
AnnotationType getLastAnnotation(const QByteArray& text);
2021-07-03 21:57:50 +08:00
AnnotationType getNextAnnotation();
2021-07-17 19:32:23 +08:00
QString getNextFilledLine();
QString getNextLine();
QString getNextWord();
QString getRemainingLine();
void handleDisassembly();
void handleDisplay();
void handleError();
void handleExit();
void handleFrames();
void handleLocalOutput();
void handleLocals();
void handleParams();
void handleRegisters();
2021-07-18 00:18:07 +08:00
void handleSignal();
void handleSource();
void handleValueHistoryValue();
AnnotationType peekNextAnnotation();
void processDebugOutput();
2021-07-18 08:52:53 +08:00
QString processEvalOutput();
void processWatchOutput(PWatchVar WatchVar);
2021-07-19 23:02:32 +08:00
void runNextCmd();
void skipSpaces();
void skipToAnnotation();
2021-07-03 21:57:50 +08:00
private:
2021-07-19 23:02:32 +08:00
QMutex mCmdQueueMutex;
2021-07-03 21:57:50 +08:00
QQueue<PDebugCommand> mCmdQueue;
int mUpdateCount;
bool mInvalidateAllVars;
//fOnInvalidateAllVars: TInvalidateAllVarsEvent;
bool mCmdRunning;
PDebugCommand mCurrentCmd;
QList<PRegister> mRegisters;
QStringList mDisassembly;
2021-07-24 08:12:51 +08:00
2021-07-17 19:32:23 +08:00
2021-07-19 23:02:32 +08:00
QProcess mProcess;
2021-07-17 19:32:23 +08:00
QMap<QString,PWatchVar> mWatchVarList; // contains all parents
2021-07-03 21:57:50 +08:00
//fWatchView: TTreeView;
int mIndex;
int mBreakPointLine;
QString mBreakPointFile;
QString mOutput;
QString mEvalValue;
QString mSignal;
bool mUseUTF8;
// attempt to cut down on Synchronize calls
bool dobacktraceready;
bool dodisassemblerready;
bool doregistersready;
bool dorescanwatches;
bool doevalready;
bool doprocessexited;
bool doupdatecpuwindow;
bool doupdateexecution;
bool doreceivedsignal;
bool doreceivedsfwarning;
2021-07-19 23:02:32 +08:00
bool mStop;
// QThread interface
protected:
void run() override;
2021-07-03 21:57:50 +08:00
};
#endif // DEBUGGER_H