| 89 | } |
| 90 | |
| 91 | void Debugger::Hook(lua_Debug *ar, lua_State *L) { |
| 92 | if (skipHook) { |
| 93 | return; |
| 94 | } |
| 95 | // 设置当前协程 |
| 96 | SetCurrentState(L); |
| 97 | |
| 98 | if (getDebugEvent(ar) == LUA_HOOKLINE) { |
| 99 | // 对luaTreadExecutors 执行加锁 |
| 100 | { |
| 101 | std::unique_lock<std::mutex> lock(luaThreadMtx); |
| 102 | if (!luaThreadExecutors.empty()) { |
| 103 | for (auto &executor: luaThreadExecutors) { |
| 104 | ExecuteWithSkipHook(executor); |
| 105 | } |
| 106 | luaThreadExecutors.clear(); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | // 处理 pause: 如果 manager 上有挂起的 Break 请求(DoAction(Break) |
| 111 | // 时无 hitDebugger),这里消费一下,把当前 debugger 设为 hitDebugger, |
| 112 | // 然后走原来的 DoAction(Break) 路径设置 hookState = stateBreak。 |
| 113 | // 下面读 hookState 时就会拿到 stateBreak, ProcessHook 在当前 LINE |
| 114 | // 事件上立刻命中 HandleBreak。 |
| 115 | if (manager->ConsumePendingBreak()) { |
| 116 | manager->SetHitDebugger(shared_from_this()); |
| 117 | DoAction(DebugAction::Break); |
| 118 | } |
| 119 | |
| 120 | auto bp = FindBreakPoint(ar); |
| 121 | if (bp && ProcessBreakPoint(bp)) { |
| 122 | HandleBreak(); |
| 123 | return; |
| 124 | } |
| 125 | // 加锁 |
| 126 | |
| 127 | std::shared_ptr<HookState> state = nullptr; |
| 128 | |
| 129 | { |
| 130 | std::lock_guard<std::mutex> lock(hookStateMtx); |
| 131 | state = hookState; |
| 132 | } |
| 133 | |
| 134 | if (state) { |
| 135 | state->ProcessHook(shared_from_this(), currentL, ar); |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | |
| 141 | void Debugger::Stop() { |
nothing calls this directly
no test coverage detected