Lua debugger: trace command implemented.

This commit is contained in:
antirez 2015-11-16 13:58:17 +01:00
parent 22959e07dc
commit c560c645e9

View File

@ -2145,6 +2145,26 @@ void ldbRedis(lua_State *lua, sds *argv, int argc) {
lua_pop(lua,2); /* Discard the result and clean the stack. */
}
/* Implements "trace" command of the Lua debugger. It just prints a backtrace
* querying Lua starting from the current callframe back to the outer one. */
void ldbTrace(lua_State *lua) {
lua_Debug ar;
int level = 0;
while(lua_getstack(lua,level,&ar)) {
lua_getinfo(lua,"Snl",&ar);
if(strstr(ar.short_src,"user_script") == NULL) continue;
ldbLog(sdscatprintf(sdsempty(),"%s %s:",
(level == 0) ? "In" : "From",
ar.name ? ar.name : "top level"));
ldbLogSourceLine(ar.currentline);
level++;
}
if (level == 0) {
ldbLog(sdsnew("<error> Can't retrieve Lua stack."));
}
}
/* Read debugging commands from client. */
void ldbRepl(lua_State *lua) {
sds *argv;
@ -2190,6 +2210,7 @@ ldbLog(sdsnew("[b]reak Show all breakpoints."));
ldbLog(sdsnew("[b]reak <line> Add a breakpoint to the specified line."));
ldbLog(sdsnew("[b]reak -<line> Remove breakpoint from the specified line."));
ldbLog(sdsnew("[b]reak 0 Remove all breakpoints."));
ldbLog(sdsnew("[t]race Show a backtrace."));
ldbLog(sdsnew("[e]eval <code> Execute some Lua code (in a different callframe)."));
ldbLog(sdsnew("[r]edis <cmd> Execute a Redis command."));
ldbLog(sdsnew("[a]abort Stop the execution of the script. In sync"));
@ -2206,6 +2227,9 @@ ldbLog(sdsnew(" in the next line of code."));
break;
} else if (!strcasecmp(argv[0],"c") || !strcasecmp(argv[0],"continue")){
break;
} else if (!strcasecmp(argv[0],"t") || !strcasecmp(argv[0],"trace")) {
ldbTrace(lua);
ldbSendLogs();
} else if (!strcasecmp(argv[0],"b") || !strcasecmp(argv[0],"break")) {
ldbBreak(argv,argc);
ldbSendLogs();