diff --git a/debugger/src/internal/debug_bridge.cpp b/debugger/src/internal/debug_bridge.cpp
index b14a513..fdb204d 100644
--- a/debugger/src/internal/debug_bridge.cpp
+++ b/debugger/src/internal/debug_bridge.cpp
@@ -124,6 +124,7 @@ StackTraceResponse DebugBridge::getStackTrace() {
StackTraceResponse response;
lua_State* L = break_vm_;
+ lua_utils::DisableDebugStep _(break_vm_);
updateVariables();
auto frames = updateStackFrames();
@@ -337,11 +338,9 @@ void DebugBridge::onConnect(dap::Session* session) {
void DebugBridge::onDisconnect() {
task_pool_.post([this] { clearBreakPoints(); });
- std::scoped_lock lock(break_mutex_);
- if (!resume_) {
- resume_ = true;
- resume_cv_.notify_one();
- }
+
+ processSingleStep(nullptr);
+ resumeInternal();
session_ = nullptr;
}
diff --git a/debugger/src/internal/scope.h b/debugger/src/internal/scope.h
index 7cd10e4..d949f5a 100644
--- a/debugger/src/internal/scope.h
+++ b/debugger/src/internal/scope.h
@@ -14,6 +14,7 @@ enum class ScopeType {
Local,
UpValue,
Table,
+ UserData,
Unknown,
};
@@ -59,13 +60,17 @@ class Scope final {
static Scope createTable(lua_State* L, int index = -1) {
const TValue* t = luaA_toobject(L, index);
auto* address = hvalue(t);
- return createFromAddress
(L, index, address);
+ auto scope = createFromAddress(L, index, address);
+ scope.type_ = ScopeType::Table;
+ return scope;
}
static Scope createUserData(lua_State* L, int index = -1) {
const TValue* u = luaA_toobject(L, index);
auto* address = uvalue(u);
- return createFromAddress(L, index, address);
+ auto scope = createFromAddress(L, index, address);
+ scope.type_ = ScopeType::UserData;
+ return scope;
}
explicit Scope(int key) : key_(key) { type_ = ScopeType::Unknown; }
@@ -102,7 +107,6 @@ class Scope final {
Scope scope;
scope.L_ = L;
scope.createKey(std::hash{}(address));
- scope.type_ = ScopeType::Table;
scope.ref_ = lua_ref(L, index);
return scope;
}
diff --git a/debugger/src/internal/utils/lua_utils.cpp b/debugger/src/internal/utils/lua_utils.cpp
index ce1106f..beb0fa0 100644
--- a/debugger/src/internal/utils/lua_utils.cpp
+++ b/debugger/src/internal/utils/lua_utils.cpp
@@ -12,14 +12,7 @@
namespace luau::debugger::lua_utils {
std::optional eval(lua_State* L, const std::string& code, int env) {
- auto main_vm = lua_mainthread(L);
- auto callbacks = lua_callbacks(main_vm);
- auto old_step = callbacks->debugstep;
-
- // Avoid break by debugstep when executing `eval`
- auto _ = utils::makeRAII(
- [callbacks]() { callbacks->debugstep = nullptr; },
- [callbacks, old_step]() { callbacks->debugstep = old_step; });
+ DisableDebugStep _(L);
lua_setsafeenv(L, LUA_ENVIRONINDEX, false);
auto env_idx = lua_absindex(L, env);
diff --git a/debugger/src/internal/utils/lua_utils.h b/debugger/src/internal/utils/lua_utils.h
index 0680294..23dd96e 100644
--- a/debugger/src/internal/utils/lua_utils.h
+++ b/debugger/src/internal/utils/lua_utils.h
@@ -37,4 +37,21 @@ class StackGuard {
int top_;
};
+class DisableDebugStep {
+ public:
+ DisableDebugStep(lua_State* L) {
+ main_vm_ = lua_mainthread(L);
+ callbacks_ = lua_callbacks(main_vm_);
+ old_debug_step_ = callbacks_->debugstep;
+ callbacks_->debugstep = nullptr;
+ }
+ ~DisableDebugStep() { callbacks_->debugstep = old_debug_step_; }
+
+ private:
+ lua_State* main_vm_;
+ lua_Callbacks* callbacks_;
+ using DebugStep = void (*)(lua_State*, lua_Debug*);
+ DebugStep old_debug_step_;
+};
+
} // namespace luau::debugger::lua_utils
\ No newline at end of file