disable debugging if server is not running & make detach complete
This commit is contained in:
parent
1a7bcf9865
commit
d861595f78
@ -9,6 +9,7 @@ local _debug_getinfo = debug.getinfo
|
|||||||
local _debug_getlocal = debug.getlocal
|
local _debug_getlocal = debug.getlocal
|
||||||
local __pause = debug.pause
|
local __pause = debug.pause
|
||||||
local __error = error
|
local __error = error
|
||||||
|
local __sethook = debug.sethook
|
||||||
|
|
||||||
-- 'return' hook not called for some functions
|
-- 'return' hook not called for some functions
|
||||||
-- todo: speedup
|
-- todo: speedup
|
||||||
@ -21,7 +22,9 @@ local function calc_stack_size()
|
|||||||
return count
|
return count
|
||||||
end
|
end
|
||||||
|
|
||||||
debug.sethook(function (e, line)
|
local is_debugging = debug.is_debugging()
|
||||||
|
if is_debugging then
|
||||||
|
__sethook(function (e, line)
|
||||||
if e == "return" then
|
if e == "return" then
|
||||||
local info = _debug_getinfo(2)
|
local info = _debug_getinfo(2)
|
||||||
if info.func == current_func then
|
if info.func == current_func then
|
||||||
@ -58,6 +61,7 @@ debug.sethook(function (e, line)
|
|||||||
__pause("breakpoint")
|
__pause("breakpoint")
|
||||||
debug.pull_events()
|
debug.pull_events()
|
||||||
end, "lr")
|
end, "lr")
|
||||||
|
end
|
||||||
|
|
||||||
local DBG_EVENT_SET_BREAKPOINT = 1
|
local DBG_EVENT_SET_BREAKPOINT = 1
|
||||||
local DBG_EVENT_RM_BREAKPOINT = 2
|
local DBG_EVENT_RM_BREAKPOINT = 2
|
||||||
@ -71,6 +75,13 @@ debug.__pull_events = nil
|
|||||||
debug.__sendvalue = nil
|
debug.__sendvalue = nil
|
||||||
|
|
||||||
function debug.pull_events()
|
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()
|
local events = __pull_events()
|
||||||
if not events then
|
if not events then
|
||||||
return
|
return
|
||||||
@ -122,7 +133,9 @@ function debug.remove_breakpoint(source, line)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function error(message, level)
|
function error(message, level)
|
||||||
|
if is_debugging then
|
||||||
__pause("exception", message)
|
__pause("exception", message)
|
||||||
|
end
|
||||||
__error(message, level)
|
__error(message, level)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -376,6 +376,10 @@ static int l_debug_pull_events(lua::State* L) {
|
|||||||
return 1;
|
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) {
|
void initialize_libs_extends(lua::State* L) {
|
||||||
if (lua::getglobal(L, "debug")) {
|
if (lua::getglobal(L, "debug")) {
|
||||||
lua::pushcfunction(L, lua::wrap<l_debug_error>);
|
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::pushcfunction(L, lua::wrap<l_debug_sendvalue>);
|
||||||
lua::setfield(L, "__sendvalue");
|
lua::setfield(L, "__sendvalue");
|
||||||
|
|
||||||
|
lua::pushcfunction(L, lua::wrap<l_debug_is_debugging>);
|
||||||
|
lua::setfield(L, "is_debugging");
|
||||||
|
|
||||||
lua::pop(L);
|
lua::pop(L);
|
||||||
}
|
}
|
||||||
if (lua::getglobal(L, "math")) {
|
if (lua::getglobal(L, "math")) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user