Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

协程内调用 require "debugger":attach{} 会卡住 #302

Open
huanzai opened this issue Sep 6, 2024 · 3 comments
Open

协程内调用 require "debugger":attach{} 会卡住 #302

huanzai opened this issue Sep 6, 2024 · 3 comments

Comments

@huanzai
Copy link

huanzai commented Sep 6, 2024

require "debugger":start "127.0.0.1:12306":event "wait"
print "ok"

function test()
    local count = 0
    for i=1, 1000 do 
        count = count + 1
    end
end

function example()
    require "debugger":attach {}
    print("coroutine started")
    for i=1,5 do 
        test()
        print("do "..i)
        coroutine.yield()
    end
    print("coroutine finished")
end


local co = coroutine.create(example)

coroutine.resume(co)
coroutine.resume(co)
coroutine.resume(co)
coroutine.resume(co)
coroutine.resume(co)
coroutine.resume(co)

print "down!"

调 require "debugger":attach {} 时,会执行到

static void clear_client(lua_State* hL) {
        luadbg_State* L = get_client(hL);
        lua_pushnil(hL);
        lua_rawsetp(hL, LUA_REGISTRYINDEX, &DEBUG_CLIENT);
        if (L) {
            luadbg_close(L);  // 这里就停掉了。
        }
    }

这里 get_client 能拿到一个 L(luadbg_State*) 是主线程创建的,然后就被 luadbg_close 掉了

@actboy168
Copy link
Owner

attach 是为什么,同一个实例不需要 attach

@huanzai
Copy link
Author

huanzai commented Sep 6, 2024

[#128 ] 我看这里需要:在coroutine中调用require "debugger":attach{},通知调试器这个coroutine需要调试。

@huanzai
Copy link
Author

huanzai commented Sep 6, 2024

attach.zip
见这个例子,

  1. launch.json 的 stopOnEntry: false ,不加断点启动
  2. 在启动 debugger 后,再对 test1 加断点(test1.lua在协程内被加载)
  3. 此时断点不生效

所以想通过在协程中attach来激活协程的hook

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants