From a076e421e9ac3401b35557d259e8e59961ff29a0 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 11 Nov 2015 22:56:38 +0100 Subject: [PATCH] Lua debugger: redis command implemented. --- src/scripting.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/scripting.c b/src/scripting.c index b98f94a1..5353bfa7 100644 --- a/src/scripting.c +++ b/src/scripting.c @@ -2018,6 +2018,26 @@ void ldbEval(lua_State *lua, sds *argv, int argc) { lua_pop(lua,1); } +/* Implement the debugger "redis" command. We use a trick in order to make + * the implementation very simple: we just call the Lua redis.call() command + * implementation, with ldb.step enabled, so as a side effect the Redis command + * and its reply are logged. */ +void ldbRedis(lua_State *lua, sds *argv, int argc) { + int j, saved_rc = server.lua_replicate_commands; + + lua_getglobal(lua,"redis"); + lua_pushstring(lua,"call"); + lua_gettable(lua,-2); /* Stack: redis, redis.call */ + for (j = 1; j < argc; j++) + lua_pushlstring(lua,argv[j],sdslen(argv[j])); + ldb.step = 1; /* Force redis.call() to log. */ + server.lua_replicate_commands = 1; + lua_pcall(lua,argc-1,1,0); /* Stack: redis, result */ + ldb.step = 0; /* Disable logging. */ + server.lua_replicate_commands = saved_rc; + lua_pop(lua,2); /* Discard the result and clean the stack. */ +} + /* Read debugging commands from client. */ void ldbRepl(lua_State *lua) { sds *argv; @@ -2057,7 +2077,8 @@ ldbLog(sdsnew("[b]eark Show all breakpoints.")); ldbLog(sdsnew("[b]eark Add a breakpoint to the specified line.")); ldbLog(sdsnew("[b]eark - Remove breakpoint from the specified line.")); ldbLog(sdsnew("[b]eark 0 Remove all breakpoints.")); -ldbLog(sdsnew("[e]eval Execute some Lua code in a new callframe.")); +ldbLog(sdsnew("[e]eval Execute some Lua code (in a different callframe).")); +ldbLog(sdsnew("[r]edis Execute a Redis command.")); ldbSendLogs(); } else if (!strcasecmp(argv[0],"s") || !strcasecmp(argv[0],"step") || !strcasecmp(argv[0],"n") || !strcasecmp(argv[0],"next")) { @@ -2071,6 +2092,10 @@ ldbLog(sdsnew("[e]eval Execute some Lua code in a new callframe.")); } else if (!strcasecmp(argv[0],"e") || !strcasecmp(argv[0],"eval")) { ldbEval(lua,argv,argc); ldbSendLogs(); + } else if (argc > 1 && + (!strcasecmp(argv[0],"r") || !strcasecmp(argv[0],"redis"))) { + ldbRedis(lua,argv,argc); + ldbSendLogs(); } else if (argc == 2 && (!strcasecmp(argv[0],"p") || !strcasecmp(argv[0],"print"))) {