Skip to content

Commit 787c8fa

Browse files
authored
feat: debugger hot restart (actboy168#318)
* debugger hot restart * revert unnecessary changes * dbg:attach default * fix last cr-lf * close worker channel in the right place
1 parent a37fecf commit 787c8fa

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

extension/script/backend/bootstrap.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ local function initMaster(rootpath, address)
3333
ExitGuard = setmetatable({}, {__gc=function()
3434
chan:push(nil, "EXIT")
3535
thread.wait(mt)
36+
channel.destroy("DbgMaster")
3637
end})
3738
end
3839

extension/script/backend/worker.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,7 @@ end
829829

830830
function event.exit()
831831
sendToMaster 'exitWorker' {}
832+
channel.destroy(WorkerChannel)
832833
end
833834

834835
hookmgr.init(function(name, ...)

extension/script/debugger.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ function dbg:start(cfg)
187187
end
188188

189189
function dbg:attach(cfg)
190-
initDebugger(self, cfg)
190+
initDebugger(self, cfg or {})
191191

192192
self.rdebug.start(([[
193193
local rootpath = %q
@@ -199,6 +199,10 @@ function dbg:attach(cfg)
199199
return self
200200
end
201201

202+
function dbg:stop()
203+
self.rdebug.clear()
204+
end
205+
202206
function dbg:event(...)
203207
self.rdebug.event(...)
204208
return self

src/luadebug/rdebug_hookmgr.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,10 @@ struct hookmgr {
568568
}
569569
luadebug::eventfree::destroy(hL, eventfree);
570570
lua_sethook(hL, 0, 0, 0);
571+
#if defined(LUADEBUG_DISABLE_THUNK)
572+
// clear hook manager pointer stored in thunk:
573+
thunk_set(hL, &THUNK_MGR, intptr_t(nullptr));
574+
#endif
571575
#if defined(LUA_HOOKEXCEPTION)
572576
exception_open(hL, 0);
573577
#endif
@@ -594,11 +598,13 @@ struct hookmgr {
594598
#else
595599
static int full_hook_callback(lua_State* hL, lua_Debug* ar) {
596600
hookmgr* mgr = (hookmgr*)thunk_get(hL, &THUNK_MGR);
601+
if (!mgr) return 0;
597602
mgr->full_hook(hL, ar);
598603
return 0;
599604
}
600605
static int idle_hook_callback(lua_State* hL, lua_Debug* ar) {
601606
hookmgr* mgr = (hookmgr*)thunk_get(hL, &THUNK_MGR);
607+
if (!mgr) return 0;
602608
mgr->idle_hook(hL, ar);
603609
return 0;
604610
}

0 commit comments

Comments
 (0)