Commit 58573f1d authored by antirez's avatar antirez
Browse files

Lua debugger: redis-cli can restart Lua debugging sessions.

parent 0cc19174
...@@ -1106,6 +1106,12 @@ static void repl(void) { ...@@ -1106,6 +1106,12 @@ static void repl(void) {
strcasecmp(argv[0],"exit") == 0) strcasecmp(argv[0],"exit") == 0)
{ {
exit(0); exit(0);
} else if (strcasecmp(argv[0],"restart") == 0) {
if (config.eval_ldb) {
return; /* Return to evalMode to restart the session. */
} else {
printf("Use 'restart' only in Lua debugging mode.");
}
} else if (argc == 3 && !strcasecmp(argv[0],"connect")) { } else if (argc == 3 && !strcasecmp(argv[0],"connect")) {
sdsfree(config.hostip); sdsfree(config.hostip);
config.hostip = sdsnew(argv[1]); config.hostip = sdsnew(argv[1]);
...@@ -1169,59 +1175,83 @@ static int noninteractive(int argc, char **argv) { ...@@ -1169,59 +1175,83 @@ static int noninteractive(int argc, char **argv) {
*--------------------------------------------------------------------------- */ *--------------------------------------------------------------------------- */
static int evalMode(int argc, char **argv) { static int evalMode(int argc, char **argv) {
sds script = sdsempty(); sds script = NULL;
FILE *fp; FILE *fp;
char buf[1024]; char buf[1024];
size_t nread; size_t nread;
char **argv2; char **argv2;
int j, got_comma = 0, keys = 0; int j, got_comma, keys;
int retval = REDIS_OK;
/* Load the script from the file, as an sds string. */ while(1) {
fp = fopen(config.eval,"r"); if (config.eval_ldb) {
if (!fp) { printf(
fprintf(stderr, "Lua debugging session started, please use:\n"
"Can't open file '%s': %s\n", config.eval, strerror(errno)); "quit -- End the session.\n"
exit(1); "restart -- Restart the script in debug mode again.\n"
} "help -- Show Lua script debugging commands.\n\n"
while((nread = fread(buf,1,sizeof(buf),fp)) != 0) { );
script = sdscatlen(script,buf,nread); }
}
fclose(fp);
/* If we are debugging a script, enable the Lua debugger. */ sdsfree(script);
if (config.eval_ldb) { script = sdsempty();
redisReply *reply = redisCommand(context, got_comma = 0;
config.eval_ldb_sync ? "SCRIPT DEBUG sync": "SCRIPT DEBUG yes"); keys = 0;
if (reply) freeReplyObject(reply);
}
/* Create our argument vector */ /* Load the script from the file, as an sds string. */
argv2 = zmalloc(sizeof(sds)*(argc+3)); fp = fopen(config.eval,"r");
argv2[0] = sdsnew("EVAL"); if (!fp) {
argv2[1] = script; fprintf(stderr,
for (j = 0; j < argc; j++) { "Can't open file '%s': %s\n", config.eval, strerror(errno));
if (!got_comma && argv[j][0] == ',' && argv[j][1] == 0) { exit(1);
got_comma = 1; }
continue; while((nread = fread(buf,1,sizeof(buf),fp)) != 0) {
script = sdscatlen(script,buf,nread);
}
fclose(fp);
/* If we are debugging a script, enable the Lua debugger. */
if (config.eval_ldb) {
redisReply *reply = redisCommand(context,
config.eval_ldb_sync ?
"SCRIPT DEBUG sync": "SCRIPT DEBUG yes");
if (reply) freeReplyObject(reply);
}
/* Create our argument vector */
argv2 = zmalloc(sizeof(sds)*(argc+3));
argv2[0] = sdsnew("EVAL");
argv2[1] = script;
for (j = 0; j < argc; j++) {
if (!got_comma && argv[j][0] == ',' && argv[j][1] == 0) {
got_comma = 1;
continue;
}
argv2[j+3-got_comma] = sdsnew(argv[j]);
if (!got_comma) keys++;
} }
argv2[j+3-got_comma] = sdsnew(argv[j]); argv2[2] = sdscatprintf(sdsempty(),"%d",keys);
if (!got_comma) keys++;
} /* Call it */
argv2[2] = sdscatprintf(sdsempty(),"%d",keys); int eval_ldb = config.eval_ldb; /* Save it, may be reverteed. */
retval = issueCommand(argc+3-got_comma, argv2);
/* Call it */ if (eval_ldb) {
int eval_ldb = config.eval_ldb; /* Save it, may be reverteed. */ if (!config.eval_ldb) {
int retval = issueCommand(argc+3-got_comma, argv2); /* If the debugging session ended immediately, there was an
if (eval_ldb) { * error compiling the script. Show it and don't enter
if (!config.eval_ldb) { * the REPL at all. */
/* If the debugging session ended immediately, there was an printf("Eval debugging session can't start:\n");
* error compiling the script. Show it and don't enter cliReadReply(0);
* the REPL at all. */ break; /* Return to the caller. */
printf("Eval debugging session can't start:\n"); } else {
cliReadReply(0); strncpy(config.prompt,"lua debugger> ",sizeof(config.prompt));
repl();
/* Restart the session if repl() returned. */
cliConnect(1);
printf("\n");
}
} else { } else {
strncpy(config.prompt,"lua debugger> ",sizeof(config.prompt)); break; /* Return to the caller. */
repl();
} }
} }
return retval; return retval;
......
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