1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #ifndef DEBUGMANAGER_H |
6 | #define DEBUGMANAGER_H |
7 | |
8 | #include "debugger/gdbmi/gdbdebugger.h" |
9 | |
10 | #include "dap/protocol.h" |
11 | |
12 | #include <QHash> |
13 | #include <QObject> |
14 | |
15 | class DebugManagerPrivate; |
16 | class DebugManager : public QObject |
17 | { |
18 | Q_OBJECT |
19 | |
20 | public: |
21 | static DebugManager *instance(); |
22 | |
23 | struct ResponseEntry { |
24 | enum class ResponseAction_t { |
25 | Permanent, |
26 | Temporal |
27 | }action; |
28 | |
29 | using ResponseHandler_t = std::function<void (const QVariant& v)>; |
30 | ResponseHandler_t handler; |
31 | }; |
32 | |
33 | void initDebugger(const QString &program, const QStringList &arguments); |
34 | |
35 | void quit(); |
36 | void terminate(); |
37 | void kill(); |
38 | void execute(); |
39 | void launchLocal(); |
40 | |
41 | qint64 getProcessId(); |
42 | |
43 | void breakRemoveAll(); |
44 | void breakInsert(const QString& path); |
45 | void removeBreakpointInFile(const QString &filePath); |
46 | void breakRemove(int bpid); |
47 | |
48 | void commandPause(); |
49 | void commandContinue(); |
50 | void commandNext(); |
51 | void commandStep(); |
52 | void commandFinish(); |
53 | |
54 | void threadInfo(); |
55 | void threadSelect(const int threadId); |
56 | |
57 | void stackListFrames(); |
58 | void stackListVariables(); |
59 | |
60 | void listSourceFiles(); |
61 | |
62 | dap::array<dap::StackFrame> allStackframes(); |
63 | dap::array<dap::Thread> allThreadList(); |
64 | dap::array<dap::Variable> allVariableList(); |
65 | |
66 | void disassemble(const QString &address); |
67 | |
68 | signals: |
69 | void streamConsole(const QString& text); |
70 | void streamDebugInternal(const QStringList &textList); |
71 | void asyncStopped(const dap::StoppedEvent &stoppedEvent); |
72 | void asyncExited(const dap::ExitedEvent &exitedEvent); |
73 | void asyncRunning(const QString& processName, const QString& theadId); |
74 | void libraryLoaded(const dap::ModuleEvent &moduleEvent); |
75 | void libraryUnloaded(const dap::ModuleEvent &moduleEvent); |
76 | void terminated(); |
77 | |
78 | void assemblerData(const QStringList &data); |
79 | void dbgProcessStarted(); |
80 | void dbgProcessFinished(); |
81 | |
82 | public slots: |
83 | void updateExceptResponse(const int token, const QVariant& payload); |
84 | void fireLocker(); |
85 | void fireStackLocker(); |
86 | |
87 | private: |
88 | explicit DebugManager(QObject *parent = nullptr); |
89 | virtual ~DebugManager(); |
90 | |
91 | void initProcess(); |
92 | |
93 | bool command(const QString &cmd); |
94 | void commandAndResponse(const QString& cmd, |
95 | const ResponseEntry::ResponseHandler_t& handler, |
96 | ResponseEntry::ResponseAction_t action = ResponseEntry::ResponseAction_t::Temporal); |
97 | bool isExecuting() const; |
98 | void waitLocker(); |
99 | |
100 | DebugManagerPrivate *const d; |
101 | }; |
102 | |
103 | |
104 | #endif // DEBUGMANAGER_H |
105 | |