diff --git a/src/eval.c b/src/eval.c index 10372be329..e50acd179c 100644 --- a/src/eval.c +++ b/src/eval.c @@ -1497,19 +1497,19 @@ void ldbRedis(lua_State *lua, sds *argv, int argc) { /* Increase the Lua stack if needed to make sure there is enough room * to push 'argc + 1' elements to the stack. On failure, return error. * Notice that we need, in worst case, 'argc + 1' elements because we push all the arguments - * given by the user (without the first argument) and we also push the 'redis' global table and - * 'redis.call' function so: - * (1 (redis table)) + (1 (redis.call function)) + (argc - 1 (all arguments without the first)) = argc + 1*/ + * given by the user (without the first argument) and we also push the 'server' global table and + * 'server.call' function so: + * (1 (server table)) + (1 (server.call function)) + (argc - 1 (all arguments without the first)) = argc + 1*/ ldbLogRedisReply("max lua stack reached"); return; } - lua_getglobal(lua, "redis"); + lua_getglobal(lua, "server"); lua_pushstring(lua, "call"); - lua_gettable(lua, -2); /* Stack: redis, redis.call */ + lua_gettable(lua, -2); /* Stack: server, server.call */ for (j = 1; j < argc; j++) lua_pushlstring(lua, argv[j], sdslen(argv[j])); - ldb.step = 1; /* Force redis.call() to log. */ - lua_pcall(lua, argc - 1, 1, 0); /* Stack: redis, result */ + ldb.step = 1; /* Force server.call() to log. */ + lua_pcall(lua, argc - 1, 1, 0); /* Stack: server, result */ ldb.step = 0; /* Disable logging. */ lua_pop(lua, 2); /* Discard the result and clean the stack. */ } @@ -1612,15 +1612,15 @@ int ldbRepl(lua_State *lua) { ldbLog(sdsnew("[b]reak 0 Remove all breakpoints.")); ldbLog(sdsnew("[t]race Show a backtrace.")); ldbLog(sdsnew("[e]val Execute some Lua code (in a different callframe).")); - ldbLog(sdsnew("[r]edis Execute a Redis command.")); - ldbLog(sdsnew("[m]axlen [len] Trim logged Redis replies and Lua var dumps to len.")); + ldbLog(sdsnew("[v]alkey Execute a command.")); + ldbLog(sdsnew("[m]axlen [len] Trim logged replies and Lua var dumps to len.")); ldbLog(sdsnew(" Specifying zero as means unlimited.")); ldbLog(sdsnew("[a]bort Stop the execution of the script. In sync")); ldbLog(sdsnew(" mode dataset changes will be retained.")); ldbLog(sdsnew("")); ldbLog(sdsnew("Debugger functions you can call from Lua scripts:")); - ldbLog(sdsnew("redis.debug() Produce logs in the debugger console.")); - ldbLog(sdsnew("redis.breakpoint() Stop execution like if there was a breakpoint in the")); + ldbLog(sdsnew("server.debug() Produce logs in the debugger console.")); + ldbLog(sdsnew("server.breakpoint() Stop execution like if there was a breakpoint in the")); ldbLog(sdsnew(" next line of code.")); ldbSendLogs(); } else if (!strcasecmp(argv[0], "s") || !strcasecmp(argv[0], "step") || !strcasecmp(argv[0], "n") || @@ -1644,8 +1644,12 @@ int ldbRepl(lua_State *lua) { } else if (!strcasecmp(argv[0], "a") || !strcasecmp(argv[0], "abort")) { luaPushError(lua, "script aborted for user request"); luaError(lua); - } else if (argc > 1 && (!strcasecmp(argv[0], "r") || !strcasecmp(argv[0], REDIS_API_NAME) || + } else if (argc > 1 && ((!strcasecmp(argv[0], "r") || !strcasecmp(argv[0], "redis")) || + (!strcasecmp(argv[0], "v") || !strcasecmp(argv[0], "valkey")) || !strcasecmp(argv[0], SERVER_API_NAME))) { + /* [r]redis or [v]alkey calls a command. We accept "server" too, but + * not "s" because that's "step". Neither can we use [c]all because + * "c" is continue. */ ldbRedis(lua, argv, argc); ldbSendLogs(); } else if ((!strcasecmp(argv[0], "p") || !strcasecmp(argv[0], "print"))) { @@ -1667,7 +1671,7 @@ int ldbRepl(lua_State *lua) { ldbList(1, 1000000); ldbSendLogs(); } else { - ldbLog(sdsnew(" Unknown Redis Lua debugger command or " + ldbLog(sdsnew(" Unknown Lua debugger command or " "wrong number of arguments.")); ldbSendLogs(); } @@ -1711,7 +1715,7 @@ void luaLdbLineHook(lua_State *lua, lua_Debug *ar) { if (ldb.step || bp) { char *reason = "step over"; if (bp) - reason = ldb.luabp ? "redis.breakpoint() called" : "break point"; + reason = ldb.luabp ? "server.breakpoint() called" : "break point"; else if (timeout) reason = "timeout reached, infinite loop?"; ldb.step = 0; diff --git a/src/script_lua.c b/src/script_lua.c index cc5b2d472e..cfe1959259 100644 --- a/src/script_lua.c +++ b/src/script_lua.c @@ -897,7 +897,7 @@ static int luaRedisGenericCommand(lua_State *lua, int raise_error) { /* Log the command if debugging is active. */ if (ldbIsEnabled()) { - sds cmdlog = sdsnew(""); + sds cmdlog = sdsnew(""); for (j = 0; j < c->argc; j++) { if (j == 10) { cmdlog = sdscatprintf(cmdlog, " ... (%d more)", c->argc - j - 1); diff --git a/src/valkey-cli.c b/src/valkey-cli.c index 333a39752f..e3fb7fb5d2 100644 --- a/src/valkey-cli.c +++ b/src/valkey-cli.c @@ -1907,6 +1907,7 @@ sds sdsCatColorizedLdbReply(sds o, char *s, size_t len) { char *color = "white"; if (strstr(s, "")) color = "bold"; + if (strstr(s, "")) color = "green"; if (strstr(s, "")) color = "green"; if (strstr(s, "")) color = "cyan"; if (strstr(s, "")) color = "red"; diff --git a/tests/unit/scripting.tcl b/tests/unit/scripting.tcl index ea5c1b899f..a4ab545803 100644 --- a/tests/unit/scripting.tcl +++ b/tests/unit/scripting.tcl @@ -1525,13 +1525,13 @@ start_server {tags {"scripting needs:debug external:skip"}} { r script debug sync r eval {return 'hello'} 0 catch {r 'hello\0world'} e - assert_match {*Unknown Redis Lua debugger command*} $e + assert_match {*Unknown Lua debugger command*} $e catch {r 'hello\0'} e - assert_match {*Unknown Redis Lua debugger command*} $e + assert_match {*Unknown Lua debugger command*} $e catch {r '\0hello'} e - assert_match {*Unknown Redis Lua debugger command*} $e + assert_match {*Unknown Lua debugger command*} $e catch {r '\0hello\0'} e - assert_match {*Unknown Redis Lua debugger command*} $e + assert_match {*Unknown Lua debugger command*} $e } test {Test scripting debug lua stack overflow} {