| 34 | } |
| 35 | |
| 36 | std::shared_ptr<Debugger> EmmyDebuggerManager::AddDebugger(lua_State* L) |
| 37 | { |
| 38 | std::lock_guard<std::mutex> lock(debuggerMtx); |
| 39 | |
| 40 | auto identify = GetUniqueIdentify(L); |
| 41 | |
| 42 | std::shared_ptr<Debugger> debugger = nullptr; |
| 43 | |
| 44 | auto it = debuggers.find(identify); |
| 45 | |
| 46 | if (it == debuggers.end()) |
| 47 | { |
| 48 | if (luaVersion != LuaVersion::LUA_JIT) |
| 49 | { |
| 50 | debugger = std::make_shared<Debugger>(reinterpret_cast<lua_State*>(identify), this); |
| 51 | } |
| 52 | else |
| 53 | { |
| 54 | // 如果首次add 的state不是main state,则main state视为空指针 |
| 55 | // 但不影响luajit附加调试和远程调试 |
| 56 | lua_State* mainState = nullptr; |
| 57 | |
| 58 | int ret = lua_pushthread(L); |
| 59 | lua_pop(L, 1); |
| 60 | if (ret == 1) |
| 61 | { |
| 62 | mainState = L; |
| 63 | } |
| 64 | |
| 65 | debugger = std::make_shared<Debugger>(mainState, this); |
| 66 | } |
| 67 | debuggers.insert({identify, debugger}); |
| 68 | } |
| 69 | else |
| 70 | { |
| 71 | debugger = it->second; |
| 72 | } |
| 73 | |
| 74 | debugger->SetCurrentState(L); |
| 75 | return debugger; |
| 76 | } |
| 77 | |
| 78 | |
| 79 | std::shared_ptr<Debugger> EmmyDebuggerManager::RemoveDebugger(lua_State* L) |
no test coverage detected