| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #ifndef RAWDEBUGSESSION_H |
| 6 | #define RAWDEBUGSESSION_H |
| 7 | |
| 8 | #include "dap/session.h" |
| 9 | #include "dap/protocol.h" |
| 10 | #include "dap/future.h" |
| 11 | |
| 12 | #include <QObject> |
| 13 | |
| 14 | #include <memory> |
| 15 | #include <any> |
| 16 | |
| 17 | namespace dap { |
| 18 | |
| 19 | /** |
| 20 | * @brief RawDebugSession is implemented by orignal |
| 21 | * DAP protocol,used by top level class DapDebugger. |
| 22 | */ |
| 23 | class RawDebugSession : public QObject |
| 24 | { |
| 25 | Q_OBJECT |
| 26 | public: |
| 27 | template<typename T> |
| 28 | using promiseEx = future<ResponseOrError<typename T::Response>>; |
| 29 | |
| 30 | using ErrorHandler = std::function<void(const std::string&)>; |
| 31 | |
| 32 | // value type returned. |
| 33 | #define Promise RawDebugSession::promiseEx |
| 34 | |
| 35 | explicit RawDebugSession(std::shared_ptr<Session>&, QObject *parent = nullptr); |
| 36 | |
| 37 | bool initialize(); |
| 38 | |
| 39 | void start(); |
| 40 | Promise<InitializeRequest> initialize(const InitializeRequest &request); |
| 41 | bool disconnect(const DisconnectRequest &request); |
| 42 | |
| 43 | Promise<LaunchRequest> launch(const LaunchRequest &request); |
| 44 | Promise<AttachRequest> attach(const AttachRequest &request); |
| 45 | |
| 46 | bool terminate(bool restart); |
| 47 | bool restart(const RestartRequest &request); |
| 48 | Promise<NextRequest> next(const NextRequest &request); |
| 49 | Promise<StepInRequest> stepIn(const StepInRequest &request); |
| 50 | Promise<StepOutRequest> stepOut(const StepOutRequest &request); |
| 51 | Promise<ContinueRequest> continueDbg(const ContinueRequest &request); |
| 52 | Promise<PauseRequest> pause(const PauseRequest &args); |
| 53 | Promise<TerminateThreadsRequest> terminateThreads(const TerminateThreadsRequest &request); |
| 54 | Promise<SetVariableRequest> setVariable(const SetVariableRequest &request); |
| 55 | Promise<SetExpressionRequest> setExpression(const SetExpressionRequest &request); |
| 56 | Promise<RestartFrameRequest> restartFrame(const RestartFrameRequest &request); |
| 57 | Promise<StepInTargetsRequest> stepInTargets(const StepInTargetsRequest &request); |
| 58 | Promise<CompletionsRequest> completions(const CompletionsRequest &request); |
| 59 | Promise<SetBreakpointsRequest> setBreakpoints(const SetBreakpointsRequest &request); |
| 60 | Promise<SetFunctionBreakpointsRequest> setFunctionBreakpoints(const SetFunctionBreakpointsRequest &request); |
| 61 | Promise<DataBreakpointInfoRequest> dataBreakpointInfo(const DataBreakpointInfoRequest &request); |
| 62 | Promise<SetDataBreakpointsRequest> setDataBreakpoints(const SetDataBreakpointsRequest &request); |
| 63 | Promise<SetExceptionBreakpointsRequest> setExceptionBreakpoints(const SetExceptionBreakpointsRequest &request); |
| 64 | Promise<BreakpointLocationsRequest> breakpointLocations(const BreakpointLocationsRequest &request); |
| 65 | Promise<ConfigurationDoneRequest> configurationDone(); |
| 66 | Promise<StackTraceRequest> stackTrace(const StackTraceRequest &request); |
| 67 | Promise<ExceptionInfoRequest> exceptionInfo(const ExceptionInfoRequest &request); |
| 68 | Promise<ScopesRequest> scopes(const ScopesRequest &request); |
| 69 | Promise<VariablesRequest> variables(const VariablesRequest &request); |
| 70 | Promise<SourceRequest> source(const SourceRequest &request); |
| 71 | Promise<LoadedSourcesRequest> loadedSources(const LoadedSourcesRequest &request); |
| 72 | Promise<ThreadsRequest> threads(); |
| 73 | Promise<EvaluateRequest> evaluate(const EvaluateRequest &request); |
| 74 | Promise<StepBackRequest> stepBack(const StepBackRequest &request); |
| 75 | Promise<ReverseContinueRequest> reverseContinue(const ReverseContinueRequest &request); |
| 76 | Promise<GotoTargetsRequest> gotoTargets(const GotoTargetsRequest &request); |
| 77 | Promise<GotoRequest> goto_(const GotoRequest &request); |
| 78 | Promise<SetInstructionBreakpointsRequest> setInstructionBreakpoints(const SetInstructionBreakpointsRequest &request); |
| 79 | Promise<DisassembleRequest> disassemble(const DisassembleRequest &request); |
| 80 | Promise<CancelRequest> cancel(const CancelRequest &request); |
| 81 | |
| 82 | const dap::Capabilities &capabilities() const; |
| 83 | bool shutdown(optional<boolean> terminateDebuggee, optional<boolean> restart = false); |
| 84 | |
| 85 | bool readyForBreakpoints() const; |
| 86 | void setReadyForBreakpoints(bool bReady); |
| 87 | signals: |
| 88 | |
| 89 | public slots: |
| 90 | |
| 91 | private: |
| 92 | void registerHandlers(); |
| 93 | void mergeCapabilities(const InitializeResponse &capabilities); |
| 94 | |
| 95 | // Send sends the request to the debugger, waits for the request to complete, |
| 96 | // and then assigns the response to |res|. |
| 97 | // Returns true on success, false on error. |
| 98 | template <typename REQUEST, typename RESPONSE> |
| 99 | bool send(const REQUEST& request, RESPONSE* res); |
| 100 | |
| 101 | // Send sends the request to the debugger, and waits for the request to |
| 102 | // complete. |
| 103 | // Returns true on success, false on error. |
| 104 | template <typename REQUEST> |
| 105 | bool syncSend(const REQUEST& request); |
| 106 | |
| 107 | // Send sends the request to the debugger and return future result. |
| 108 | template <typename REQUEST> |
| 109 | Promise<REQUEST> send(const REQUEST &request); |
| 110 | |
| 111 | void onError(const std::string& error); |
| 112 | |
| 113 | /** |
| 114 | * private parameters. |
| 115 | */ |
| 116 | ErrorHandler errHandler; |
| 117 | |
| 118 | std::shared_ptr<Session> session; |
| 119 | |
| 120 | bool allThreadsContinued = true; |
| 121 | bool _readyForBreakpoints = false; |
| 122 | Capabilities _capabilities; |
| 123 | |
| 124 | // shutdown |
| 125 | bool inShutdown = false; |
| 126 | bool terminated = false; |
| 127 | }; |
| 128 | |
| 129 | } // end dap namespace. |
| 130 | |
| 131 | #endif // RAWDEBUGSESSION_H |
| 132 | |