disable debugging if server is not running & make detach complete

This commit is contained in:
MihailRis 2025-10-09 01:14:49 +03:00
parent 1a7bcf9865
commit d861595f78
2 changed files with 53 additions and 33 deletions

View File

@ -9,6 +9,7 @@ local _debug_getinfo = debug.getinfo
local _debug_getlocal = debug.getlocal
local __pause = debug.pause
local __error = error
local __sethook = debug.sethook
-- 'return' hook not called for some functions
-- todo: speedup
@ -21,7 +22,9 @@ local function calc_stack_size()
return count
end
debug.sethook(function (e, line)
local is_debugging = debug.is_debugging()
if is_debugging then
__sethook(function (e, line)
if e == "return" then
local info = _debug_getinfo(2)
if info.func == current_func then
@ -57,7 +60,8 @@ debug.sethook(function (e, line)
current_func_stack_size = calc_stack_size()
__pause("breakpoint")
debug.pull_events()
end, "lr")
end, "lr")
end
local DBG_EVENT_SET_BREAKPOINT = 1
local DBG_EVENT_RM_BREAKPOINT = 2
@ -71,6 +75,13 @@ debug.__pull_events = nil
debug.__sendvalue = nil
function debug.pull_events()
if not is_debugging then
return
end
if not debug.is_debugging() then
is_debugging = false
__sethook()
end
local events = __pull_events()
if not events then
return
@ -122,7 +133,9 @@ function debug.remove_breakpoint(source, line)
end
function error(message, level)
if is_debugging then
__pause("exception", message)
end
__error(message, level)
end

View File

@ -376,6 +376,10 @@ static int l_debug_pull_events(lua::State* L) {
return 1;
}
static int l_debug_is_debugging(lua::State* L) {
return lua::pushboolean(L, engine->getDebuggingServer() != nullptr);
}
void initialize_libs_extends(lua::State* L) {
if (lua::getglobal(L, "debug")) {
lua::pushcfunction(L, lua::wrap<l_debug_error>);
@ -399,6 +403,9 @@ void initialize_libs_extends(lua::State* L) {
lua::pushcfunction(L, lua::wrap<l_debug_sendvalue>);
lua::setfield(L, "__sendvalue");
lua::pushcfunction(L, lua::wrap<l_debug_is_debugging>);
lua::setfield(L, "is_debugging");
lua::pop(L);
}
if (lua::getglobal(L, "math")) {