Skip to content

Commit af20149

Browse files
committed
debugger hot restart
1 parent 6f98ba2 commit af20149

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

extension/script/backend/bootstrap.lua

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,26 @@ local channel = require "bee.channel"
33

44
local m = {}
55

6+
-- Stores the name of the master channel
7+
---@type string | nil
8+
DbgMaster = DbgMaster
9+
610
local function hasMaster()
7-
return channel.query "DbgMaster" ~= nil
11+
return DbgMaster and channel.query(DbgMaster) ~= nil
812
end
913

1014
local function initMaster(rootpath, address)
1115
if hasMaster() then
1216
return
1317
end
14-
local chan = channel.create "DbgMaster"
18+
DbgMaster = "DbgMaster-" .. address
19+
local chan = channel.create(DbgMaster)
1520
local mt = thread.create(([[
1621
local rootpath = %q
1722
package.path = rootpath.."/script/?.lua"
1823
local log = require "common.log"
1924
log.file = rootpath.."/master.log"
25+
DbgMaster = %q
2026
local ok, err = xpcall(function()
2127
local socket = require "common.socket"(%q)
2228
local master = require "backend.master.mgr"
@@ -28,11 +34,15 @@ local function initMaster(rootpath, address)
2834
end
2935
]]):format(
3036
rootpath,
37+
DbgMaster,
3138
address
3239
))
3340
ExitGuard = setmetatable({}, {__gc=function()
3441
chan:push(nil, "EXIT")
3542
thread.wait(mt)
43+
local WorkerIdent = tostring(thread.id)
44+
local WorkerChannel = ('DbgWorker(%s)'):format(WorkerIdent)
45+
channel.destroy(WorkerChannel)
3646
end})
3747
end
3848

extension/script/backend/master/mgr.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ end
4343

4444
function mgr.init(io)
4545
socket = io
46-
masterThread = assert(channel.query 'DbgMaster')
46+
masterThread = assert(channel.query(DbgMaster))
4747
socket.event_close(event_close)
4848
return true
4949
end
@@ -260,6 +260,7 @@ function mgr.update()
260260
local event = require 'backend.master.event'
261261
event.terminated()
262262
socket.closeall()
263+
channel.destroy(DbgMaster)
263264
end
264265

265266
function mgr.setClient(c)

extension/script/backend/worker.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ local CMD = {}
3636
local WorkerIdent = tostring(thread.id)
3737
local WorkerChannel = ('DbgWorker(%s)'):format(WorkerIdent)
3838

39-
local masterThread = assert(channel.query 'DbgMaster')
39+
local masterThread = assert(channel.query(DbgMaster))
4040
local workerThread = channel.create(WorkerChannel)
4141

4242
local function workerThreadUpdate(timeout)

extension/script/debugger.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)