载入中...
搜索中...
未找到
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 <vector>
12
13struct SQVM;
14typedef struct SQVM* HSQUIRRELVM;
15
16namespace eve::dev {
17
18enum class PauseReason : uint8_t {
19 None = 0,
22 Step,
25};
26
27enum class RunMode : uint8_t {
28 Running = 0,
29 Paused, // frame-level or script-level pause
30 StepFrame, // run one game frame then pause
31 StepInto, // next script line (any call depth) — DAP stepIn
32 StepOver, // next script line at ≤ start depth — DAP next
33 StepOut, // next script line at < start depth — DAP stepOut
34};
35
37 std::string source; // normalized path or basename
38 int line = 0;
39 bool enabled = true;
40 bool verified = false;
41 std::string condition; // optional GDScript-style condition; empty = always
42 int id = 0;
43};
44
46 std::string expression;
47 std::string value; // last evaluated (display)
48 bool ok = false;
49};
50
52 int id = 0;
54 std::string name;
55};
56
58 std::string name;
59 std::string value;
60 std::string type;
61 bool expensive = false;
62 bool expandable = false; // container / instance: children available
63 int childCount = -1; // -1 = unknown
64};
65
67enum class VarKind : uint8_t {
68 Locals = 0, // frame locals
69 Globals = 1, // roottable
70};
71
84public:
85 static Debugger& instance();
86
87 Debugger(const Debugger&) = delete;
88 Debugger& operator=(const Debugger&) = delete;
89
90 void attach(HSQUIRRELVM vm);
91 void detach();
92 bool isAttached() const { return vm_ != nullptr; }
93 HSQUIRRELVM vm() const { return vm_; }
94
95 // ---- run control ----
96 void pause(PauseReason reason = PauseReason::PauseKey);
97 void resume();
98 void stepFrame();
100 void stepInto();
102 void stepOver();
104 void stepOut();
106 void stepLine() { stepInto(); }
111 void step();
112 bool isPaused() const { return mode_.load() == RunMode::Paused; }
113 RunMode mode() const { return mode_.load(); }
114 PauseReason lastPauseReason() const { return reason_.load(); }
115 const SourceLoc& pauseLocation() const { return pauseLoc_; }
117 int scriptStackDepth() const;
118
120 bool shouldRunUpdate();
122 void notifyFrameDone();
123
128 bool onScriptLine(const SourceLoc& loc);
130 void waitWhilePaused(const std::function<void()>& pump = {});
131
132 // ---- breakpoints ----
133 int setBreakpoint(std::string source, int line, bool enabled = true,
134 std::string condition = {});
135 bool clearBreakpoint(std::string source, int line);
136 void clearBreakpoints(const std::string& source = {});
137 std::vector<Breakpoint> breakpoints() const;
138 bool hasBreakpoint(const std::string& source, int line) const;
139
140 // ---- watches ----
141 void addWatch(std::string expression);
142 bool removeWatch(const std::string& expression);
143 void clearWatches();
144 std::vector<WatchEntry> watches() const;
146 void refreshWatches();
152 VariableInfo evaluate(const std::string& expression, int frameLevel = 0) const;
154 std::vector<VariableInfo> locals(int stackLevel = 0) const;
156 std::vector<VariableInfo> globals() const;
162 std::vector<VariableInfo> containerChildren(VarKind kind, int frame,
163 const std::vector<std::string>& path) const;
164 std::vector<StackFrameInfo> stackTrace(int maxFrames = 32) const;
165
166 // ---- error / breakpoint policy ----
168 void setBreakOnError(bool on) { breakOnError_.store(on); }
169 bool breakOnError() const { return breakOnError_.load(); }
171 void setBreakpointsEnabled(bool on) { bpsEnabled_.store(on); }
172 bool breakpointsEnabled() const { return bpsEnabled_.load(); }
174 using BreakpointEventFn = std::function<void(int id, const std::string& source, int line,
175 bool verified)>;
176 void setBreakpointEventFn(BreakpointEventFn fn) { bpEventFn_ = std::move(fn); }
177
178 using PumpFn = std::function<void()>;
179 void setPump(PumpFn pump) { pump_ = std::move(pump); }
180
182 static std::string normalizeSource(std::string source);
184 static std::string sourceBasename(const std::string& source);
189 static bool sourcesMatch(const std::string& a, const std::string& b);
190
191private:
192 Debugger() = default;
193
194 bool matchBreakpoint(const std::string& source, int line) const;
195 bool matchBreakpointAny(const std::string& source, int line) const;
196 bool conditionHolds(const Breakpoint& bp) const;
197 bool pushPathValue(HSQUIRRELVM vm, VarKind kind, int frame,
198 const std::vector<std::string>& path) const;
199 VariableInfo readLocal(HSQUIRRELVM vm, unsigned level, const std::string& name) const;
200 VariableInfo readRoot(HSQUIRRELVM vm, const std::string& name) const;
201 VariableInfo evaluateLegacy(const std::string& expression) const;
202 bool pushLocalValue(HSQUIRRELVM vm, unsigned level, const std::string& name) const;
203 void beginScriptStep(RunMode mode);
204
205 HSQUIRRELVM vm_ = nullptr;
206 std::atomic<RunMode> mode_{RunMode::Running};
207 std::atomic<PauseReason> reason_{PauseReason::None};
208 std::atomic<bool> breakOnError_{false};
209 std::atomic<bool> bpsEnabled_{true};
210 SourceLoc pauseLoc_;
211 mutable std::mutex mu_;
212 std::vector<Breakpoint> bps_;
213 std::vector<std::string> watchExprs_;
214 std::vector<WatchEntry> watchCache_;
215 int nextBpId_ = 1;
216 PumpFn pump_;
217 bool stepFrameArmed_ = false;
218 int stepStartDepth_ = 0;
220 SourceLoc stepSkipLoc_;
221 BreakpointEventFn bpEventFn_;
222};
223
224} // namespace eve::dev
struct SQVM * HSQUIRRELVM
struct SQVM * HSQUIRRELVM
Definition Debugger.hpp:14
int line
Tok kind
HSQUIRRELVM vm
Definition ECS.cpp:20
#define EVENGINE_API
宿主(eve / libmain)导出宏;插件从进程导入同一批符号。
Definition Export.h:16
uint32_t a
uint32_t b
const char * name
Definition RockMesh.cpp:21
SettlementPipeline::Stage fn
bool enabled
float step
Definition TreeMesh.cpp:196
Script + frame debugger: pause/step, breakpoints, watches.
Definition Debugger.hpp:83
bool isAttached() const
Definition Debugger.hpp:92
Debugger(const Debugger &)=delete
void setBreakOnError(bool on)
Break on script errors (Godot "Break on Error"). Default off.
Definition Debugger.hpp:168
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:175
HSQUIRRELVM vm() const
Definition Debugger.hpp:93
void setBreakpointEventFn(BreakpointEventFn fn)
Definition Debugger.hpp:176
bool isPaused() const
Definition Debugger.hpp:112
RunMode mode() const
Definition Debugger.hpp:113
Debugger & operator=(const Debugger &)=delete
std::function< void()> PumpFn
Definition Debugger.hpp:178
void setBreakpointsEnabled(bool on)
Master switch for all breakpoints ("skip all breakpoints").
Definition Debugger.hpp:171
const SourceLoc & pauseLocation() const
Definition Debugger.hpp:115
void setPump(PumpFn pump)
Definition Debugger.hpp:179
bool breakOnError() const
Definition Debugger.hpp:169
PauseReason lastPauseReason() const
Definition Debugger.hpp:114
void stepLine()
Alias for stepInto (historical name).
Definition Debugger.hpp:106
bool breakpointsEnabled() const
Definition Debugger.hpp:172
Script + native state snapshot for state hot reload.
Definition Snapshot.hpp:28
VarKind
Where a variable tree node is rooted (used by containerChildren/resolvePath).
Definition Debugger.hpp:67
std::string condition
Definition Debugger.hpp:41
std::string source
Definition Debugger.hpp:37
Source location in a Squirrel (or synthetic) script.
Definition CallGraph.hpp:16
std::string value
Definition Debugger.hpp:47
std::string expression
Definition Debugger.hpp:46