MCPcopy Create free account
hub / github.com/F-Stack/f-stack / luaLdbLineHook

Function luaLdbLineHook

app/redis-6.2.6/src/scripting.c:2790–2836  ·  view source on GitHub ↗

This is the core of our Lua debugger, called each time Lua is about * to start executing a new line. */

Source from the content-addressed store, hash-verified

2788/* This is the core of our Lua debugger, called each time Lua is about
2789 * to start executing a new line. */
2790void 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}

Callers

nothing calls this directly

Calls 14

ldbIsBreakpointFunction · 0.85
strstrFunction · 0.85
elapsedMsFunction · 0.85
ldbLogFunction · 0.85
sdscatprintfFunction · 0.85
sdsemptyFunction · 0.85
ldbLogSourceLineFunction · 0.85
ldbSendLogsFunction · 0.85
ldbReplFunction · 0.85
mstimeFunction · 0.70
lua_getstackFunction · 0.50
lua_getinfoFunction · 0.50

Tested by

no test coverage detected