载入中...
搜索中...
未找到
DebugAdapter.hpp
浏览该文件的文档.
1#pragma once
2
3#include "common/Export.h"
5
6#include <atomic>
7#include <cstdint>
8#include <memory>
9#include <mutex>
10#include <string>
11#include <unordered_map>
12#include <vector>
13
14#include <Poco/SharedPtr.h>
15
16namespace Poco::Net {
17class ServerSocket;
18class StreamSocket;
19}
20
21namespace Poco::JSON {
22class Object;
23}
24
25namespace eve::dev {
26
39public:
40 static DebugAdapter& instance();
41
42 DebugAdapter(const DebugAdapter&) = delete;
44
46 int listen(uint16_t port);
47 void stop();
48 bool isListening() const { return listening_.load(); }
49 int port() const { return port_.load(); }
50 bool hasClient() const { return hasClient_.load(); }
51
53 void setSourceRoot(std::string root);
54 const std::string& sourceRoot() const { return sourceRoot_; }
56 void registerSource(std::string name, std::string content);
57
59 void poll();
60
62 bool isConfigured() const { return configured_; }
63
69 bool waitUntilConfigured(int timeoutMs = 15000);
70
72 void notifyStopped(PauseReason reason, const SourceLoc& loc,
73 const std::string& description = {});
74 void notifyContinued();
75 void notifyTerminated();
77 const std::string& lastException() const { return lastException_; }
78
79private:
80 // Defined in .cpp so unique_ptr<incomplete Poco sockets> is legal on MSVC.
83
84 void acceptNonBlocking();
85 void readAndDispatch();
86 bool sendMessage(const std::string& json);
87 void handleRequest(const std::string& json);
88 std::string makeResponse(int seq, int requestSeq, const std::string& command, bool ok,
89 const std::string& bodyJson, const std::string& message = {});
90 std::string makeEvent(const std::string& event, const std::string& bodyJson);
91 static std::string reasonString(PauseReason r);
93 std::string resolveSourcePath(std::string source) const;
95 void rememberSourcePath(const std::string& path);
97 void discoverEngineScriptAliases();
99 void handleBreakpointEvent(int id, const std::string& source, int line, bool verified);
101 int varRefForFrame(int frameId);
103 int allocVarRef(int kind, int frame, std::vector<std::string> path);
105 Poco::SharedPtr<Poco::JSON::Object> makeSourceObject(const std::string& source) const;
106
107 struct VarScope {
108 int kind = 0; // 0 = locals, 1 = globals
109 int frame = 0;
110 std::vector<std::string> path;
111 };
112
113 std::atomic<bool> listening_{false};
114 std::atomic<bool> hasClient_{false};
115 std::atomic<int> port_{0};
116 std::atomic<int> seq_{1};
117 std::recursive_mutex ioMu_;
118 std::unique_ptr<Poco::Net::ServerSocket> server_;
119 std::unique_ptr<Poco::Net::StreamSocket> client_;
120 std::string recvBuf_;
121 std::string sourceRoot_;
123 std::unordered_map<std::string, std::string> sourceAliases_;
124 bool configured_ = false;
125 bool stopOnEntry_ = false;
126 int varRefLocals_ = 1;
127 int varRefWatches_ = 2;
128 int varRefGlobals_ = 5000;
129 int varRefFrameBase_ = 1000;
130 int nextVarRef_ = 10000;
131 std::vector<VariableInfo> varCache_;
132 std::unordered_map<int, VarScope> varScopes_;
133 std::string lastException_;
134 std::unordered_map<std::string, std::string> sourceContents_;
135 std::unordered_map<int, std::string> sourceRefContents_;
136};
137
138} // namespace eve::dev
int root
Definition AnimSmr.cpp:119
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
std::string message
double r
TokenKind kind
std::string description
std::string name
std::string path
Definition PlayHost.cpp:110
const UnitySourceAsset & source
Minimal Debug Adapter Protocol (DAP) server for VS Code.
const std::string & lastException() const
Last exception message delivered via notifyStopped(Exception, ...).
bool isConfigured() const
True after the IDE sends configurationDone (breakpoints are installed).
DebugAdapter & operator=(const DebugAdapter &)=delete
const std::string & sourceRoot() const
DebugAdapter(const DebugAdapter &)=delete
Source location in a Squirrel (or synthetic) script.
Definition CallGraph.hpp:16