This is the core of our Lua debugger, called each time Lua is about * to start executing a new line. */
| 2788 | /* This is the core of our Lua debugger, called each time Lua is about |
| 2789 | * to start executing a new line. */ |
| 2790 | void luaLdbLineHook(lua_State *lua, lua_Debug *ar) { |
| 2791 | lua_getstack(lua,0,ar); |
| 2792 | lua_getinfo(lua,"Sl",ar); |
| 2793 | ldb.currentline = ar->currentline; |
| 2794 | |
| 2795 | int bp = ldbIsBreakpoint(ldb.currentline) || ldb.luabp; |
| 2796 | int timeout = 0; |
| 2797 | |
| 2798 | /* Events outside our script are not interesting. */ |
| 2799 | if(strstr(ar->short_src,"user_script") == NULL) return; |
| 2800 | |
| 2801 | /* Check if a timeout occurred. */ |
| 2802 | if (ar->event == LUA_HOOKCOUNT && ldb.step == 0 && bp == 0) { |
| 2803 | mstime_t elapsed = elapsedMs(server.lua_time_start); |
| 2804 | mstime_t timelimit = server.lua_time_limit ? |
| 2805 | server.lua_time_limit : 5000; |
| 2806 | if (elapsed >= timelimit) { |
| 2807 | timeout = 1; |
| 2808 | ldb.step = 1; |
| 2809 | } else { |
| 2810 | return; /* No timeout, ignore the COUNT event. */ |
| 2811 | } |
| 2812 | } |
| 2813 | |
| 2814 | if (ldb.step || bp) { |
| 2815 | char *reason = "step over"; |
| 2816 | if (bp) reason = ldb.luabp ? "redis.breakpoint() called" : |
| 2817 | "break point"; |
| 2818 | else if (timeout) reason = "timeout reached, infinite loop?"; |
| 2819 | ldb.step = 0; |
| 2820 | ldb.luabp = 0; |
| 2821 | ldbLog(sdscatprintf(sdsempty(), |
| 2822 | "* Stopped at %d, stop reason = %s", |
| 2823 | ldb.currentline, reason)); |
| 2824 | ldbLogSourceLine(ldb.currentline); |
| 2825 | ldbSendLogs(); |
| 2826 | if (ldbRepl(lua) == C_ERR && timeout) { |
| 2827 | /* If the client closed the connection and we have a timeout |
| 2828 | * connection, let's kill the script otherwise the process |
| 2829 | * will remain blocked indefinitely. */ |
| 2830 | lua_pushstring(lua, "timeout during Lua debugging with client closing connection"); |
| 2831 | lua_error(lua); |
| 2832 | } |
| 2833 | server.lua_time_start = getMonotonicUs(); |
| 2834 | server.lua_time_snapshot = mstime(); |
| 2835 | } |
| 2836 | } |
nothing calls this directly
no test coverage detected