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. */
| 2657 | * Return C_OK if the debugging session is continuing, otherwise |
| 2658 | * C_ERR if the client closed the connection or is timing out. */ |
| 2659 | int ldbRepl(lua_State *lua) { |
| 2660 | sds *argv; |
| 2661 | int argc; |
| 2662 | char* err = NULL; |
| 2663 | |
| 2664 | /* We continue processing commands until a command that should return |
| 2665 | * to the Lua interpreter is found. */ |
| 2666 | while(1) { |
| 2667 | while((argv = ldbReplParseCommand(&argc, &err)) == NULL) { |
| 2668 | char buf[1024]; |
| 2669 | if (err) { |
| 2670 | lua_pushstring(lua, err); |
| 2671 | lua_error(lua); |
| 2672 | } |
| 2673 | int nread = connRead(ldb.conn,buf,sizeof(buf)); |
| 2674 | if (nread <= 0) { |
| 2675 | /* Make sure the script runs without user input since the |
| 2676 | * client is no longer connected. */ |
| 2677 | ldb.step = 0; |
| 2678 | ldb.bpcount = 0; |
| 2679 | return C_ERR; |
| 2680 | } |
| 2681 | ldb.cbuf = sdscatlen(ldb.cbuf,buf,nread); |
| 2682 | /* after 1M we will exit with an error |
| 2683 | * so that the client will not blow the memory |
| 2684 | */ |
| 2685 | if (sdslen(ldb.cbuf) > 1<<20) { |
| 2686 | sdsfree(ldb.cbuf); |
| 2687 | ldb.cbuf = sdsempty(); |
| 2688 | lua_pushstring(lua, "max client buffer reached"); |
| 2689 | lua_error(lua); |
| 2690 | } |
| 2691 | } |
| 2692 | |
| 2693 | /* Flush the old buffer. */ |
| 2694 | sdsfree(ldb.cbuf); |
| 2695 | ldb.cbuf = sdsempty(); |
| 2696 | |
| 2697 | /* Execute the command. */ |
| 2698 | if (!strcasecmp(argv[0],"h") || !strcasecmp(argv[0],"help")) { |
| 2699 | ldbLog(sdsnew("Redis Lua debugger help:")); |
| 2700 | ldbLog(sdsnew("[h]elp Show this help.")); |
| 2701 | ldbLog(sdsnew("[s]tep Run current line and stop again.")); |
| 2702 | ldbLog(sdsnew("[n]ext Alias for step.")); |
| 2703 | ldbLog(sdsnew("[c]continue Run till next breakpoint.")); |
| 2704 | ldbLog(sdsnew("[l]list List source code around current line.")); |
| 2705 | ldbLog(sdsnew("[l]list [line] List source code around [line].")); |
| 2706 | ldbLog(sdsnew(" line = 0 means: current position.")); |
| 2707 | ldbLog(sdsnew("[l]list [line] [ctx] In this form [ctx] specifies how many lines")); |
| 2708 | ldbLog(sdsnew(" to show before/after [line].")); |
| 2709 | ldbLog(sdsnew("[w]hole List all source code. Alias for 'list 1 1000000'.")); |
| 2710 | ldbLog(sdsnew("[p]rint Show all the local variables.")); |
| 2711 | ldbLog(sdsnew("[p]rint <var> Show the value of the specified variable.")); |
| 2712 | ldbLog(sdsnew(" Can also show global vars KEYS and ARGV.")); |
| 2713 | ldbLog(sdsnew("[b]reak Show all breakpoints.")); |
| 2714 | ldbLog(sdsnew("[b]reak <line> Add a breakpoint to the specified line.")); |
| 2715 | ldbLog(sdsnew("[b]reak -<line> Remove breakpoint from the specified line.")); |
| 2716 | ldbLog(sdsnew("[b]reak 0 Remove all breakpoints.")); |
no test coverage detected