Unverified Commit 811c5d7a authored by AcherTT's avatar AcherTT Committed by GitHub
Browse files

Add debug script command (#13289)

Add two new debug commands for outputing script.
1. `DEBUG SCRIPT LIST`
   Output all scripts.
2. `DEBUG SCRIPT <sha1>`
    Output a specific script.
    
Close #3846
parent a03b6e29
......@@ -15,6 +15,7 @@
#include "fpconv_dtoa.h"
#include "cluster.h"
#include "threads_mngr.h"
#include "script.h"
#include <arpa/inet.h>
#include <signal.h>
......@@ -1013,6 +1014,29 @@ NULL
} else if (!strcasecmp(c->argv[1]->ptr, "dict-resizing") && c->argc == 3) {
server.dict_resizing = atoi(c->argv[2]->ptr);
addReply(c, shared.ok);
} else if (!strcasecmp(c->argv[1]->ptr,"script") && c->argc == 3) {
if (!strcasecmp(c->argv[2]->ptr,"list")) {
dictIterator *di = dictGetIterator(getLuaScripts());
dictEntry *de;
while ((de = dictNext(di)) != NULL) {
luaScript *script = dictGetVal(de);
sds *sha = dictGetKey(de);
serverLog(LL_WARNING, "SCRIPT SHA: %s\n%s", (char*)sha, (char*)script->body->ptr);
}
dictReleaseIterator(di);
} else if (sdslen(c->argv[2]->ptr) == 40) {
dictEntry *de;
if ((de = dictFind(getLuaScripts(), c->argv[2]->ptr)) == NULL) {
addReplyErrorObject(c, shared.noscripterr);
return;
}
luaScript *script = dictGetVal(de);
serverLog(LL_WARNING, "SCRIPT SHA: %s\n%s", (char*)c->argv[2]->ptr, (char*)script->body->ptr);
} else {
addReplySubcommandSyntaxError(c);
return;
}
addReply(c,shared.ok);
} else if(!handleDebugClusterCommand(c)) {
addReplySubcommandSyntaxError(c);
return;
......
......@@ -1737,3 +1737,7 @@ void luaLdbLineHook(lua_State *lua, lua_Debug *ar) {
rctx->start_time = getMonotonicUs();
}
}
dict *getLuaScripts(void) {
return lctx.lua_scripts;
}
......@@ -74,6 +74,7 @@ extern scriptFlag scripts_flags_def[];
void luaEnvInit(void);
lua_State *createLuaState(void);
dict *getLuaScripts(void);
uint64_t scriptFlagsToCmdFlags(uint64_t cmd_flags, uint64_t script_flags);
int scriptPrepareForRun(scriptRunCtx *r_ctx, client *engine_client, client *caller, const char *funcname, uint64_t script_flags, int ro);
void scriptResetRun(scriptRunCtx *r_ctx);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment