This is the core of our Lua debugger, called each time Lua is about * to start executing a new line. */
| 2813 | /* This is the core of our Lua debugger, called each time Lua is about |
| 2814 | * to start executing a new line. */ |
| 2815 | void luaLdbLineHook(lua_State *lua, lua_Debug *ar) { |
| 2816 | lua_getstack(lua,0,ar); |
| 2817 | lua_getinfo(lua,"Sl",ar); |
| 2818 | ldb.currentline = ar->currentline; |
| 2819 | |
| 2820 | int bp = ldbIsBreakpoint(ldb.currentline) || ldb.luabp; |
| 2821 | int timeout = 0; |
| 2822 | |
| 2823 | /* Events outside our script are not interesting. */ |
| 2824 | if(strstr(ar->short_src,"user_script") == NULL) return; |
| 2825 | |
| 2826 | /* Check if a timeout occurred. */ |
| 2827 | if (ar->event == LUA_HOOKCOUNT && ldb.step == 0 && bp == 0) { |
| 2828 | mstime_t elapsed = elapsedMs(g_pserver->lua_time_start); |
| 2829 | mstime_t timelimit = g_pserver->lua_time_limit ? |
| 2830 | g_pserver->lua_time_limit : 5000; |
| 2831 | if (elapsed >= timelimit) { |
| 2832 | timeout = 1; |
| 2833 | ldb.step = 1; |
| 2834 | } else { |
| 2835 | return; /* No timeout, ignore the COUNT event. */ |
| 2836 | } |
| 2837 | } |
| 2838 | |
| 2839 | if (ldb.step || bp) { |
| 2840 | const char *reason = "step over"; |
| 2841 | if (bp) reason = ldb.luabp ? "redis.breakpoint() called" : |
| 2842 | "break point"; |
| 2843 | else if (timeout) reason = "timeout reached, infinite loop?"; |
| 2844 | ldb.step = 0; |
| 2845 | ldb.luabp = 0; |
| 2846 | ldbLog(sdscatprintf(sdsempty(), |
| 2847 | "* Stopped at %d, stop reason = %s", |
| 2848 | ldb.currentline, reason)); |
| 2849 | ldbLogSourceLine(ldb.currentline); |
| 2850 | ldbSendLogs(); |
| 2851 | if (ldbRepl(lua) == C_ERR && timeout) { |
| 2852 | /* If the client closed the connection and we have a timeout |
| 2853 | * connection, let's kill the script otherwise the process |
| 2854 | * will remain blocked indefinitely. */ |
| 2855 | lua_pushstring(lua, "timeout during Lua debugging with client closing connection"); |
| 2856 | lua_error(lua); |
| 2857 | } |
| 2858 | g_pserver->lua_time_start = getMonotonicUs(); |
| 2859 | g_pserver->lua_time_snapshot = mstime(); |
| 2860 | } |
| 2861 | } |
nothing calls this directly
no test coverage detected