载入中...
搜索中...
未找到
Debugger.hpp
浏览该文件的文档.
1#pragma once
2
3#include "common/Export.h"
5
6#include <atomic>
7#include <cstdint>
8#include <functional>
9#include <mutex>
10#include <string>
11#include <unordered_map>
12#include <vector>
13
14struct SQVM;
15typedef struct SQVM* HSQUIRRELVM;
16
17namespace eve::dev {
18
19enum class PauseReason : uint8_t {
20 None = 0,
23 Step,
27};
28
29enum class RunMode : uint8_t {
30 Running = 0,
31 Paused, // frame-level or script-level pause
32 StepFrame, // run one game frame then pause
33 StepInto, // next script line (any call depth) — DAP stepIn
34 StepOver, // next script line at ≤ start depth — DAP next
35 StepOut, // next script line at < start depth — DAP stepOut
36};
37
39 std::string source; // normalized path or basename
40 int line = 0;
41 bool enabled = true;
42 bool verified = false;
43 std::string condition; // optional GDScript-style condition; empty = always
44 int id = 0;
45};
46
48 std::string expression;
49 std::string value; // last evaluated (display)
50 bool ok = false;
51};
52
58
60 std::string name;
61 std::string value;
62 std::string type;
63 bool expensive = false;
64 bool expandable = false; // container / instance: children available
65 int childCount = -1; // -1 = unknown
66};
67
69enum class VarKind : uint8_t {
70 Locals = 0, // frame locals
71 Globals = 1, // roottable
72 // Closure upvalues are children of a closure value, not a third root.
73};
74
87public:
88 static Debugger& instance();
89
90 Debugger(const Debugger&) = delete;
91 Debugger& operator=(const Debugger&) = delete;
92
93 void attach(HSQUIRRELVM vm);
94 void detach();
95 bool isAttached() const { return vm_ != nullptr; }
96 HSQUIRRELVM vm() const { return vm_; }
97
98 // ---- run control ----
104 void pause(PauseReason reason = PauseReason::PauseKey);
111 void pauseAt(PauseReason reason, SourceLoc loc);
112 void resume();
113 void stepFrame();
119 void stepFrames(int count);
121 void stepInto();
123 void stepOver();
125 void stepOut();
127 void stepLine() { stepInto(); }
132 void step();
133 bool isPaused() const { return mode_.load() == RunMode::Paused; }
134 RunMode mode() const { return mode_.load(); }
135 PauseReason lastPauseReason() const { return reason_.load(); }
136 const SourceLoc& pauseLocation() const { return pauseLoc_; }
138 int scriptStackDepth() const;
139
141 bool shouldRunUpdate();
143 void notifyFrameDone();
144
150 void setCallGraph(CallGraph* graph);
157 void setVirtualSource(std::string source, std::string text);
158
164 std::string onCall(SourceLoc loc);
169 void onReturn(const SourceLoc& loc);
170
175 bool onScriptLine(const SourceLoc& loc);
177 void waitWhilePaused(const std::function<void()>& pump = {});
178
179 // ---- breakpoints ----
185 int setBreakpoint(std::string source, int line, bool enabled = true,
186 std::string condition = {});
187 bool clearBreakpoint(std::string source, int line);
188 void clearBreakpoints(const std::string& source = {});
190 bool setBreakpointEnabled(int id, bool enabled);
191 std::vector<Breakpoint> breakpoints() const;
196 bool hasBreakpoint(const std::string& source, int line) const;
197
198 // ---- watches ----
199 void addWatch(std::string expression);
200 bool removeWatch(const std::string& expression);
201 void clearWatches();
202 std::vector<WatchEntry> watches() const;
204 void refreshWatches();
210 VariableInfo evaluate(const std::string& expression, int frameLevel = 0) const;
212 std::vector<VariableInfo> locals(int stackLevel = 0) const;
214 std::vector<VariableInfo> globals() const;
220 std::vector<VariableInfo> containerChildren(VarKind kind, int frame,
221 const std::vector<std::string>& path) const;
222 std::vector<StackFrameInfo> stackTrace(int maxFrames = 32) const;
223
224 // ---- error / breakpoint policy ----
226 void setBreakOnError(bool on) { breakOnError_.store(on); }
227 bool breakOnError() const { return breakOnError_.load(); }
229 void setBreakpointsEnabled(bool on) { bpsEnabled_.store(on); }
230 bool breakpointsEnabled() const { return bpsEnabled_.load(); }
232 using BreakpointEventFn = std::function<void(int id, const std::string& source, int line,
233 bool verified)>;
234 void setBreakpointEventFn(BreakpointEventFn fn) { bpEventFn_ = std::move(fn); }
235
236 using PumpFn = std::function<void()>;
237 void setPump(PumpFn pump) { pump_ = std::move(pump); }
238
240 static std::string normalizeSource(std::string source);
242 static std::string sourceBasename(const std::string& source);
249 static bool sourcesMatch(const std::string& a, const std::string& b);
250
251private:
252 Debugger() = default;
253
254 bool matchBreakpoint(const std::string& source, int line) const;
255 bool matchBreakpointAny(const std::string& source, int line) const;
256 bool conditionHolds(const Breakpoint& bp) const;
257 bool pushPathValue(HSQUIRRELVM vm, VarKind kind, int frame,
258 const std::vector<std::string>& path) const;
259 VariableInfo readLocal(HSQUIRRELVM vm, unsigned level, const std::string& name) const;
260 VariableInfo readRoot(HSQUIRRELVM vm, const std::string& name) const;
261 VariableInfo evaluateLegacy(const std::string& expression) const;
262 bool pushLocalValue(HSQUIRRELVM vm, unsigned level, const std::string& name) const;
263 void beginScriptStep(RunMode mode);
264 CallGraph& activeGraph();
265 const CallGraph& activeGraph() const;
266 std::string resolveCallName(const SourceLoc& loc) const;
267 std::string lineAt(const std::string& source, int line) const;
268 std::string nameFromPrototype(int level, const char* rawName, const SourceLoc& loc) const;
269 void applyCallGraphNames(std::vector<StackFrameInfo>& frames) const;
270
271 HSQUIRRELVM vm_ = nullptr;
272 std::atomic<RunMode> mode_{RunMode::Running};
273 std::atomic<PauseReason> reason_{PauseReason::None};
274 std::atomic<bool> breakOnError_{false};
275 std::atomic<bool> bpsEnabled_{true};
276 SourceLoc pauseLoc_;
277 mutable std::mutex mu_;
278 std::vector<Breakpoint> bps_;
279 std::vector<std::string> watchExprs_;
280 std::vector<WatchEntry> watchCache_;
281 int nextBpId_ = 1;
282 PumpFn pump_;
283 bool stepFrameArmed_ = false;
284 int remainingHostFrames_ = 0;
285 int stepStartDepth_ = 0;
287 SourceLoc stepSkipLoc_;
288 BreakpointEventFn bpEventFn_;
289 CallGraph* callGraph_ = nullptr;
290 CallGraph ownGraph_;
291 std::unordered_map<std::string, std::string> virtualSources_;
292};
293
294} // namespace eve::dev
struct SQVM * HSQUIRRELVM
struct SQVM * HSQUIRRELVM
Definition Debugger.hpp:15
eve::Value condition
HSQUIRRELVM vm
Definition ECS.cpp:20
#define EVENGINE_API_FOUNDATION_INLINE
仅供"只有内联成员"的类型使用的组宏:拥有者 dllexport,消费方不导入。
Definition Export.h:170
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
std::string text
TokenKind kind
std::string name
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
int level
std::map< std::string, std::vector< std::string > > graph
Definition Package.cpp:59
std::string path
Definition PlayHost.cpp:110
std::uint32_t count
float step
Definition TreeMesh.cpp:314
const UnitySourceAsset & source
Runtime call graph + dynamic data-flow tracer with backward slicing.
Definition CallGraph.hpp:81
Script + frame debugger: pause/step, breakpoints, watches.
Definition Debugger.hpp:86
bool isAttached() const
Definition Debugger.hpp:95
Debugger(const Debugger &)=delete
void setBreakOnError(bool on)
Break on script errors (Godot "Break on Error"). Default off.
Definition Debugger.hpp:226
std::function< void(int id, const std::string &source, int line, bool verified)> BreakpointEventFn
Called once when a breakpoint line is first observed by the line hook.
Definition Debugger.hpp:233
HSQUIRRELVM vm() const
Definition Debugger.hpp:96
void setBreakpointEventFn(BreakpointEventFn fn)
Definition Debugger.hpp:234
bool isPaused() const
Definition Debugger.hpp:133
RunMode mode() const
Definition Debugger.hpp:134
Debugger & operator=(const Debugger &)=delete
std::function< void()> PumpFn
Definition Debugger.hpp:236
void setBreakpointsEnabled(bool on)
Master switch for all breakpoints ("skip all breakpoints").
Definition Debugger.hpp:229
const SourceLoc & pauseLocation() const
Definition Debugger.hpp:136
void setPump(PumpFn pump)
Definition Debugger.hpp:237
bool breakOnError() const
Definition Debugger.hpp:227
PauseReason lastPauseReason() const
Definition Debugger.hpp:135
void stepLine()
Alias for stepInto (historical name).
Definition Debugger.hpp:127
bool breakpointsEnabled() const
Definition Debugger.hpp:230
Script + native state snapshot for state hot reload.
Definition Snapshot.hpp:29
VarKind
Where a variable tree node is rooted (used by containerChildren).
Definition Debugger.hpp:69
std::vector< OnnxNamedTensor > evaluate(const ModelData &, std::span< const OnnxNamedTensor >, const std::vector< std::string > &, OnnxCompute *, OnnxRunOptions options)
Evaluate.
SettlementPipeline::Stage fn
bool enabled
std::string condition
Definition Debugger.hpp:43
std::string source
Definition Debugger.hpp:39
Source location in a Squirrel (or synthetic) script.
Definition CallGraph.hpp:16
std::string value
Definition Debugger.hpp:49
std::string expression
Definition Debugger.hpp:48