Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/luadebug/visitor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ end
function visitor.costatus(co)
end

---
---@param co refvalue
---@return lightuserdata?
---co不是thread返回nil,否则返回co在调试目标中的地址。该地址能作为协程的标识跨VM传递。
---
function visitor.threadptr(co)
end

---
---@return integer
---等价于`collectgarbage "count"`。
Expand Down
15 changes: 11 additions & 4 deletions extension/script/backend/worker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -945,12 +945,19 @@ end

function event.thread(co, type)
if not debuggeeReady() then return end
-- L是触发事件的协程,即co的调用方(父协程)
local L = hookmgr.gethost()
if co then
if type == 0 then
coroutineTree[L] = co
elseif type == 1 then
coroutineTree[co] = nil
-- co是调试目标里的协程,转成地址才能在调试器侧标识它
co = rdebug.threadptr and rdebug.threadptr(co)
if co then
if type == 0 then
coroutineTree[co] = L
hookmgr.updatehookmask(co)
return
elseif type == 1 then
coroutineTree[co] = nil
end
end
end
hookmgr.updatehookmask(L)
Expand Down
10 changes: 10 additions & 0 deletions src/luadebug/rdebug_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,15 @@ namespace luadebug::visitor {
return 1;
}

static int visitor_threadptr(luadbg_State* L, lua_State* hL, protected_area& area) {
if (!copy_from_dbg(L, hL, area, 1, LUADBG_TTHREAD)) {
return 0;
}
luadbg_pushlightuserdata(L, lua_tothread(hL, -1));
lua_pop(hL, 1);
return 1;
}

static int visitor_gccount(luadbg_State* L, lua_State* hL, protected_area& area) {
int k = lua_gc(hL, LUA_GCCOUNT, 0);
int b = lua_gc(hL, LUA_GCCOUNTB, 0);
Expand Down Expand Up @@ -1319,6 +1328,7 @@ namespace luadebug::visitor {
{ "watch", protected_call<visitor_watch> },
{ "cleanwatch", protected_call<visitor_cleanwatch> },
{ "costatus", protected_call<visitor_costatus> },
{ "threadptr", protected_call<visitor_threadptr> },
{ "gccount", protected_call<visitor_gccount> },
{ "cfunctioninfo", protected_call<visitor_cfunctioninfo> },
#if LUA_VERSION_NUM >= 503
Expand Down
Loading