Skip to content

先创建协程再附加进程,协程内的断点无法触发 #128

Closed

Description

@sumneko
local dbg = require "debugger"
dbg:start "127.0.0.1:12306"

dbg:event "wait" --@A

local function f()
    print(111) --@B
end
local co = coroutine.create(function ()
    f()
end)

dbg:event "wait" --@C

coroutine.resume(co)

以上测试代码,在 --@B 处断点,如果你在 --@A 处让调试器附加了进程,就可以成功断点。如果将 --@A 移除,使得调试器在 --@C 处附加了进程,就无法断点

Activity

  1. changed the title [-]附加进程后,无法在已创建协程的内部断点[/-] [+]先创建协程再附加进程,协程内的断点无法触发[/+] on Apr 26, 2021
  2. actboy168 commented on Apr 26, 2021

    @actboy168
    Owner

    这个问题是因为lua无法设置全局的hook,lua只会在创建coroutine时从父亲那里复制一次hook。也就是说调试器加载时已经存在的coroutine,将无法被调试器发现。

    解决这个问题的办法有三个:
    1.在所有的coroutine创建前,加载调试器。
    2.在coroutine中调用require "debugger":attach{},通知调试器这个coroutine需要调试。
    3.使用launch.dll中的autoattach,不过目前这个没有做封装,因为我觉得得不偿失。

  3. actboy168 commented on Apr 27, 2021

    @actboy168
    Owner

    仔细想了一下,检测coroutine的hook目前是调试器自己实现的,没有必要遵循lua自己的规则。所以对于threadhook,我改为了只考虑主线程的hookmask,同时设置threadhook也会设置主线程的hookmask。应该能解决这个问题。

  4. sumneko commented on May 12, 2021

    @sumneko
    CollaboratorAuthor

    测试了一下问题已经解决

  5. marissagloop commented on Apr 20, 2024

    @marissagloop

    skynet的调试也用同样方法搞定

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions