1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#ifndef GDBDEBUGGER_H
6#define GDBDEBUGGER_H
7
8#include "gdbmi.h"
9#include "debugger/debugger.h"
10
11#include "dap/protocol.h"
12
13#include <QObject>
14
15class GDBDebuggerPrivate;
16class GDBDebugger : public Debugger
17{
18 Q_OBJECT
19public:
20 explicit GDBDebugger(QObject *parent = nullptr);
21 virtual ~GDBDebugger() override;
22
23 QString program() override;
24 QStringList preArguments() override;
25
26 QString quit() override;
27 QString kill() override;
28
29 QString breakInsert(const QString& path) override;
30 QString breakRemove(int bpid) override;
31 QString breakRemoveAll() override;
32
33 QString launchLocal() override;
34
35 QString commandPause() override;
36 QString commandContinue() override;
37 QString commandNext() override;
38 QString commandStep() override;
39 QString commandFinish() override;
40
41 QString stackListFrames() override;
42 QString stackListVariables() override;
43
44 QString threadInfo() override;
45 QString threadSelect(const int threadId) override;
46
47 QString listSourceFiles() override;
48
49 dap::array<dap::StackFrame> allStackframes() override;
50 dap::array<dap::Thread> allThreadList() override;
51 dap::array<dap::Variable> allVariableList() override;
52
53 void handleOutputRecord(const QString &text) override;
54 void handleOutputStreamText(const QString &streamText) override;
55
56 void parseBreakPoint(const QVariant& var) override;
57 void removeBreakPoint(const int bpid) override;
58 void clearBreakPoint() override;
59 QList<int> breakpointsForFile(const QString &filePath) override;
60
61 bool isInferiorRunning() override;
62
63 QString disassemble(const QString &address) override;
64
65signals:
66 void streamDebugInternal(const QStringList& textList);
67 void streamConsole(const QString& text);
68 void asyncStopped(const dap::StoppedEvent &stoppedEvent);
69 void asyncExited(const dap::ExitedEvent &exitedEvent);
70 void asyncRunning(const QString& processName, const QString& theadId);
71 void libraryLoaded(const dap::ModuleEvent &moduleEvent);
72 void libraryUnloaded(const dap::ModuleEvent &moduleEvent);
73 void fireLocker();
74 void fireStackLocker();
75 void updateExceptResponse(const int token, const QVariant& payload);
76
77 void breakpointModified(const gdbmi::Breakpoint& bp);
78 void breakpointRemoved(const gdbmi::Breakpoint& bp);
79 void breakpointInserted(const gdbmi::Breakpoint& bp);
80
81 void threadGroupAdded(const gdbmi::Thread& thid);
82 void threadGroupRemoved(const gdbmi::Thread& thid);
83 void threadGroupStarted(const gdbmi::Thread& thid, const gdbmi::Thread& pid);
84 void threadGroupExited(const gdbmi::Thread& thid, const QString& exitCode);
85
86 void updateThreads(int currentId, const QList<gdbmi::Thread>& threads);
87 void updateCurrentFrame(const gdbmi::Frame& frame);
88 void updateStackFrame(const QList<gdbmi::Frame>& stackFrames);
89 void updateLocalVariables(const QList<gdbmi::Variable>& variableList);
90
91 void targetRemoteConnected();
92 void gdbError(const QString& msg);
93 void terminated();
94 void result(int token, const QString& reason, const QVariant& results);
95
96 void assemblerData(const QStringList &data);
97
98public slots:
99
100private:
101 void parseNotifyData(gdbmi::Record &record);
102 void parseResultData(gdbmi::Record &record);
103 void sendStoppedNotify(const gdbmi::AsyncContext &ctx);
104 void sendLibraryLoadedNotify(const gdbmi::Library &library, bool print);
105 void sendLibraryUnloadedNotify(const gdbmi::Library &library, bool print);
106 void parseDisassembleData(const gdbmi::Record &record);
107
108 GDBDebuggerPrivate *const d;
109};
110
111#endif // GDBDEBUGGER_H
112