MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / ldbRepl

Function ldbRepl

src/scripting.cpp:2684–2811  ·  view source on GitHub ↗

Read debugging commands from client. * Return C_OK if the debugging session is continuing, otherwise * C_ERR if the client closed the connection or is timing out. */

Source from the content-addressed store, hash-verified

2682 * Return C_OK if the debugging session is continuing, otherwise
2683 * C_ERR if the client closed the connection or is timing out. */
2684int ldbRepl(lua_State *lua) {
2685 sds *argv;
2686 int argc;
2687 char* err = NULL;
2688
2689 /* We continue processing commands until a command that should return
2690 * to the Lua interpreter is found. */
2691 while(1) {
2692 while((argv = ldbReplParseCommand(&argc, &err)) == NULL) {
2693 char buf[1024];
2694 if (err) {
2695 lua_pushstring(lua, err);
2696 lua_error(lua);
2697 }
2698 int nread = connRead(ldb.conn,buf,sizeof(buf));
2699 if (nread <= 0) {
2700 /* Make sure the script runs without user input since the
2701 * client is no longer connected. */
2702 ldb.step = 0;
2703 ldb.bpcount = 0;
2704 return C_ERR;
2705 }
2706 ldb.cbuf = sdscatlen(ldb.cbuf,buf,nread);
2707 /* after 1M we will exit with an error
2708 * so that the client will not blow the memory
2709 */
2710 if (sdslen(ldb.cbuf) > 1<<20) {
2711 sdsfree(ldb.cbuf);
2712 ldb.cbuf = sdsempty();
2713 lua_pushstring(lua, "max client buffer reached");
2714 lua_error(lua);
2715 }
2716 }
2717
2718 /* Flush the old buffer. */
2719 sdsfree(ldb.cbuf);
2720 ldb.cbuf = sdsempty();
2721
2722 /* Execute the command. */
2723 if (!strcasecmp(argv[0],"h") || !strcasecmp(argv[0],"help")) {
2724ldbLog(sdsnew("Redis Lua debugger help:"));
2725ldbLog(sdsnew("[h]elp Show this help."));
2726ldbLog(sdsnew("[s]tep Run current line and stop again."));
2727ldbLog(sdsnew("[n]ext Alias for step."));
2728ldbLog(sdsnew("[c]continue Run till next breakpoint."));
2729ldbLog(sdsnew("[l]list List source code around current line."));
2730ldbLog(sdsnew("[l]list [line] List source code around [line]."));
2731ldbLog(sdsnew(" line = 0 means: current position."));
2732ldbLog(sdsnew("[l]list [line] [ctx] In this form [ctx] specifies how many lines"));
2733ldbLog(sdsnew(" to show before/after [line]."));
2734ldbLog(sdsnew("[w]hole List all source code. Alias for 'list 1 1000000'."));
2735ldbLog(sdsnew("[p]rint Show all the local variables."));
2736ldbLog(sdsnew("[p]rint <var> Show the value of the specified variable."));
2737ldbLog(sdsnew(" Can also show global vars KEYS and ARGV."));
2738ldbLog(sdsnew("[b]reak Show all breakpoints."));
2739ldbLog(sdsnew("[b]reak <line> Add a breakpoint to the specified line."));
2740ldbLog(sdsnew("[b]reak -<line> Remove breakpoint from the specified line."));
2741ldbLog(sdsnew("[b]reak 0 Remove all breakpoints."));

Callers 1

luaLdbLineHookFunction · 0.85

Calls 15

ldbReplParseCommandFunction · 0.85
lua_pushstringFunction · 0.85
lua_errorFunction · 0.85
connReadFunction · 0.85
sdscatlenFunction · 0.85
sdslenFunction · 0.85
sdsfreeFunction · 0.85
sdsemptyFunction · 0.85
ldbLogFunction · 0.85
sdsnewFunction · 0.85
ldbSendLogsFunction · 0.85
ldbTraceFunction · 0.85

Tested by

no test coverage detected