From e386cd8ccf9698a8218208e75528a460cb4cc277 Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 12 Nov 2015 08:48:59 +0100 Subject: [PATCH] Lua debugger: clear end of session protocol. When the debugger exits now it produces an tag that informs redis-cli (or other debugging clients) that the session terminated. This way the client knows there is yet another reply to read (the one of the EVAL script itself), and can switch to non-debugging mode ASAP. --- src/redis-cli.c | 28 +++++++++++++++++++--------- src/scripting.c | 4 ++++ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index e620da94..67b707ad 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -112,6 +112,7 @@ static struct config { char prompt[128]; char *eval; int eval_ldb; + int eval_ldb_end; int last_cmd_type; } config; @@ -377,14 +378,6 @@ static int cliConnect(int force) { if (context == NULL || force) { if (context != NULL) { redisFree(context); - /* Disconnection from the server signals end of EVAL - * debugging session. */ - if (config.eval_ldb) { - printf("\n(Lua debugging session terminated)\n\n"); - config.eval_ldb = 0; - config.output = OUTPUT_STANDARD; - cliRefreshPrompt(); - } } if (config.hostsocket == NULL) { @@ -553,7 +546,16 @@ static sds cliFormatReplyRaw(redisReply *r) { /* The Lua debugger replies with arrays of simple (status) * strings. We colorize the output for more fun if this * is a debugging session. */ - out = sdsCatColorizedLdbReply(out,r->str,r->len); + + /* Detect the end of a debugging session. */ + if (strstr(r->str,"") == r->str) { + config.eval_ldb = 0; + config.eval_ldb_end = 1; /* Signal the caller session ended. */ + config.output = OUTPUT_STANDARD; + cliRefreshPrompt(); + } else { + out = sdsCatColorizedLdbReply(out,r->str,r->len); + } } else { out = sdscatlen(out,r->str,r->len); } @@ -1109,6 +1111,14 @@ static void repl(void) { issueCommandRepeat(argc-skipargs, argv+skipargs, repeat); + /* If our debugging session ended, show the EVAL final + * reply. */ + if (config.eval_ldb_end) { + config.eval_ldb_end = 0; + cliReadReply(0); + printf("\n(Lua debugging session ended)\n\n"); + } + elapsed = mstime()-start_time; if (elapsed >= 500) { printf("(%.2fs)\n",(double)elapsed/1000); diff --git a/src/scripting.c b/src/scripting.c index 64776fc4..37f7ea62 100644 --- a/src/scripting.c +++ b/src/scripting.c @@ -1593,6 +1593,10 @@ int ldbStartSession(client *c) { /* End a debugging session after the EVAL call with debugging enabled * returned. */ void ldbEndSession(client *c) { + /* Emit the remaining logs and an mark. */ + ldbLog(sdsnew("")); + ldbSendLogs(); + /* If it's a fork()ed session, we just exit. */ if (ldb.forked) { writeToClient(c->fd, c, 0);