Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
7492237c
Commit
7492237c
authored
Nov 12, 2015
by
antirez
Browse files
Lua debugger: redis.debug() implemented.
parent
23a4d70e
Changes
2
Show whitespace changes
Inline
Side-by-side
src/redis-cli.c
View file @
7492237c
...
...
@@ -523,6 +523,7 @@ sds sdscatcolor(sds o, char *s, size_t len, char *color) {
sds
sdsCatColorizedLdbReply
(
sds
o
,
char
*
s
,
size_t
len
)
{
char
*
color
=
"white"
;
if
(
strstr
(
s
,
"<debug>"
))
color
=
"bold"
;
if
(
strstr
(
s
,
"<redis>"
))
color
=
"green"
;
if
(
strstr
(
s
,
"<reply>"
))
color
=
"cyan"
;
if
(
strstr
(
s
,
"<error>"
))
color
=
"red"
;
...
...
src/scripting.c
View file @
7492237c
...
...
@@ -52,6 +52,7 @@ void evalGenericCommandWithDebugging(client *c, int evalsha);
void luaLdbLineHook(lua_State *lua, lua_Debug *ar);
void ldbLog(sds entry);
void ldbLogRedisReply(char *reply, size_t maxlen);
sds ldbCatStackValue(sds s, lua_State *lua, int idx);
/* Debugger shared state is stored inside this global structure. */
#define LDB_BREAKPOINTS_MAX 64 /* Max number of breakpoints. */
...
...
@@ -718,6 +719,23 @@ int luaRedisBreakpointCommand(lua_State *lua) {
return 1;
}
/* redis.debug()
*
* Log a string message into the output console.
* Can take multiple arguments that will be separated by commas.
* Nothing is returned to the caller. */
int luaRedisDebugCommand(lua_State *lua) {
if (!ldb.active) return 0;
int argc = lua_gettop(lua);
sds log = sdscatprintf(sdsempty(),"<debug> line %d: ", ldb.currentline);
while(argc--) {
log = ldbCatStackValue(log,lua,-1 - argc);
if (argc != 0) log = sdscatlen(log,", ",2);
}
ldbLog(log);
return 0;
}
/* redis.set_repl()
*
* Set the propagation of write commands executed in the context of the
...
...
@@ -965,6 +983,11 @@ void scriptingInit(int setup) {
lua_pushcfunction(lua,luaRedisBreakpointCommand);
lua_settable(lua,-3);
/* redis.debug */
lua_pushstring(lua,"debug");
lua_pushcfunction(lua,luaRedisDebugCommand);
lua_settable(lua,-3);
/* Finally set the table as 'redis' global var. */
lua_setglobal(lua,"redis");
...
...
@@ -2079,6 +2102,11 @@ ldbLog(sdsnew("[b]eark -<line> Remove breakpoint from the specified line."));
ldbLog(sdsnew("[b]eark 0 Remove all breakpoints."));
ldbLog(sdsnew("[e]eval <code> Execute some Lua code (in a different callframe)."));
ldbLog(sdsnew("[r]edis <cmd> Execute a Redis command."));
ldbLog(sdsnew(""));
ldbLog(sdsnew("Debugger functions you can call from Lua scripts:"));
ldbLog(sdsnew("redis.debug() Produce logs in the debugger console."));
ldbLog(sdsnew("redis.breakpoint() Stop execution like if there was a breakpoing."));
ldbLog(sdsnew(" in the next line of code."));
ldbSendLogs();
} else if (!strcasecmp(argv[0],"s") || !strcasecmp(argv[0],"step") ||
!strcasecmp(argv[0],"n") || !strcasecmp(argv[0],"next")) {
...
...
@@ -2128,12 +2156,12 @@ void luaLdbLineHook(lua_State *lua, lua_Debug *ar) {
lua_getinfo(lua,"Sl",ar);
if(strstr(ar->short_src,"user_script") == NULL) return;
int bp = ldbIsBreakpoint(ar->currentline) || ldb.luabp;
ldb.currentline = ar->currentline;
int bp = ldbIsBreakpoint(ldb.currentline) || ldb.luabp;
if (ldb.step || bp) {
char *reason = "step over";
if (bp) reason = ldb.luabp ? "redis.breakpoint() called" :
"break point";
ldb.currentline = ar->currentline;
ldb.step = 0;
ldb.luabp = 0;
ldbLog(sdscatprintf(sdsempty(),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment