载入中...
搜索中...
未找到
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
38public:
39 static DebugAdapter& instance();
40
41 DebugAdapter(const DebugAdapter&) = delete;
43
45 int listen(uint16_t port);
46 void stop();
47 bool isListening() const { return listening_.load(); }
48 int port() const { return port_.load(); }
49 bool hasClient() const { return hasClient_.load(); }
50
52 void setSourceRoot(std::string root);
53 const std::string& sourceRoot() const { return sourceRoot_; }
55 void registerSource(std::string name, std::string content);
56
58 void poll();
59
61 bool isConfigured() const { return configured_; }
62
68 bool waitUntilConfigured(int timeoutMs = 15000);
69
71 void notifyStopped(PauseReason reason, const SourceLoc& loc,
72 const std::string& description = {});
73 void notifyContinued();
74 void notifyTerminated();
76 const std::string& lastException() const { return lastException_; }
77
78private:
79 // Defined in .cpp so unique_ptr<incomplete Poco sockets> is legal on MSVC.
82
83 void acceptNonBlocking();
84 void readAndDispatch();
85 bool sendMessage(const std::string& json);
86 void handleRequest(const std::string& json);
87 std::string makeResponse(int seq, int requestSeq, const std::string& command, bool ok,
88 const std::string& bodyJson, const std::string& message = {});
89 std::string makeEvent(const std::string& event, const std::string& bodyJson);
90 static std::string reasonString(PauseReason r);
92 std::string resolveSourcePath(std::string source) const;
94 void rememberSourcePath(const std::string& path);
96 void discoverEngineScriptAliases();
98 void handleBreakpointEvent(int id, const std::string& source, int line, bool verified);
100 int varRefForFrame(int frameId);
102 int allocVarRef(int kind, int frame, std::vector<std::string> path);
104 Poco::SharedPtr<Poco::JSON::Object> makeSourceObject(const std::string& source) const;
105
106 struct VarScope {
107 int kind = 0; // 0 = locals, 1 = globals
108 int frame = 0;
109 std::vector<std::string> path;
110 };
111
112 std::atomic<bool> listening_{false};
113 std::atomic<bool> hasClient_{false};
114 std::atomic<int> port_{0};
115 std::atomic<int> seq_{1};
116 std::recursive_mutex ioMu_;
117 std::unique_ptr<Poco::Net::ServerSocket> server_;
118 std::unique_ptr<Poco::Net::StreamSocket> client_;
119 std::string recvBuf_;
120 std::string sourceRoot_;
122 std::unordered_map<std::string, std::string> sourceAliases_;
123 bool configured_ = false;
124 bool stopOnEntry_ = false;
125 int varRefLocals_ = 1;
126 int varRefWatches_ = 2;
127 int varRefGlobals_ = 5000;
128 int varRefFrameBase_ = 1000;
129 int nextVarRef_ = 10000;
130 std::vector<VariableInfo> varCache_;
131 std::unordered_map<int, VarScope> varScopes_;
132 std::string lastException_;
133 std::unordered_map<std::string, std::string> sourceContents_;
134 std::unordered_map<int, std::string> sourceRefContents_;
135};
136
137} // namespace eve::dev
int line
Tok kind
#define EVENGINE_API
宿主(eve / libmain)导出宏;插件从进程导入同一批符号。
Definition Export.h:16
const char * name
Definition RockMesh.cpp:21
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