// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/scripting.c
// Function: ldbRepl
int ldbRepl(lua_State *lua) {
    sds *argv;
    int argc;

    /* We continue processing commands until a command that should return
     * to the Lua interpreter is found. */
    while(1) {
        while((argv = ldbReplParseCommand(&argc)) == NULL) {
            char buf[1024];
            int nread = read(ldb.fd,buf,sizeof(buf));
            if (nread <= 0) {
                /* Make sure the script runs without user input since the
                 * client is no longer connected. */
                ldb.step = 0;
                ldb.bpcount = 0;
                return C_ERR;
            }
            ldb.cbuf = sdscatlen(ldb.cbuf,buf,nread);
        }

        /* Flush the old buffer. */
        sdsfree(ldb.cbuf);
        ldb.cbuf = sdsempty();

        /* Execute the command. */
        if (!strcasecmp(argv[0],"h") || !strcasecmp(argv[0],"help")) {
ldbLog(sdsnew("Redis Lua debugger help:"));
ldbLog(sdsnew("[h]elp               Show this help."));
ldbLog(sdsnew("[s]tep               Run current line and stop again."));
ldbLog(sdsnew("[n]ext               Alias for step."));
ldbLog(sdsnew("[c]continue          Run till next breakpoint."));
ldbLog(sdsnew("[l]list              List source code around current line."));
ldbLog(sdsnew("[l]list [line]       List source code around [line]."));
ldbLog(sdsnew("                     line = 0 means: current position."));
ldbLog(sdsnew("[l]list [line] [ctx] In this form [ctx] specifies how many lines"));
ldbLog(sdsnew("                     to show before/after [line]."));
ldbLog(sdsnew("[w]hole              List all source code. Alias for 'list 1 1000000'."));
ldbLog(sdsnew("[p]rint              Show all the local variables."));
ldbLog(sdsnew("[p]rint <var>        Show the value of the specified variable."));
ldbLog(sdsnew("                     Can also show global vars KEYS and ARGV."));
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("[m]axlen [len]       Trim logged Redis replies and Lua var dumps to len."));
ldbLog(sdsnew("                     Specifying zero as <len> means unlimited."));
ldbLog(sdsnew("[a]bort              Stop the execution of the script. In sync"));
ldbLog(sdsnew("                     mode dataset changes will be retained."));
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")) {
            ldb.step = 1;
            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],"m") || !strcasecmp(argv[0],"maxlen")) {
            ldbMaxlen(argv,argc);
            ldbSendLogs();
        } else if (!strcasecmp(argv[0],"b") || !strcasecmp(argv[0],"break")) {
            ldbBreak(argv,argc);
            ldbSendLogs();
        } else if (!strcasecmp(argv[0],"e") || !strcasecmp(argv[0],"eval")) {
            ldbEval(lua,argv,argc);
            ldbSendLogs();
        } else if (!strcasecmp(argv[0],"a") || !strcasecmp(argv[0],"abort")) {
            lua_pushstring(lua, "script aborted for user request");
            lua_error(lua);
        } else if (argc > 1 &&
                   (!strcasecmp(argv[0],"r") || !strcasecmp(argv[0],"redis"))) {
            ldbRedis(lua,argv,argc);
            ldbSendLogs();
        } else if ((!strcasecmp(argv[0],"p") || !strcasecmp(argv[0],"print"))) {
            if (argc == 2)
                ldbPrint(lua,argv[1]);
            else
                ldbPrintAll(lua);
            ldbSendLogs();
        } else if (!strcasecmp(argv[0],"l") || !strcasecmp(argv[0],"list")){
            int around = ldb.currentline, ctx = 5;
            if (argc > 1) {
                int num = atoi(argv[1]);
                if (num > 0) around = num;
            }
            if (argc > 2) ctx = atoi(argv[2]);
            ldbList(around,ctx);
            ldbSendLogs();
        } else if (!strcasecmp(argv[0],"w") || !strcasecmp(argv[0],"whole")){
            ldbList(1,1000000);
            ldbSendLogs();
        } else {
            ldbLog(sdsnew("<error> Unknown Redis Lua debugger command or "
                          "wrong number of arguments."));
            ldbSendLogs();
        }

        /* Free the command vector. */
        sdsfreesplitres(argv,argc);
    }

    /* Free the current command argv if we break inside the while loop. */
    sdsfreesplitres(argv,argc);
    return C_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x418, %rsp            # imm = 0x418
movq %rdi, 0x8(%rsp)
movq %rsp, %r14
leaq 0x10(%rsp), %r15
leaq 0x5cb4d(%rip), %r12     # 0xc2bf3
leaq 0x4afaa(%rip), %r13     # 0xb1057
movq %r14, %rdi
callq 0x652af
testq %rax, %rax
je 0x6659d
movq %rax, %rbp
movq 0xa82e0(%rip), %rdi     # 0x10e3a8
callq 0x311c8
callq 0x3114c
movq %rax, 0xa82cf(%rip)     # 0x10e3a8
movq (%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x262f0
testl %eax, %eax
je 0x66343
movq %rbx, %rdi
movq %r13, %rsi
callq 0x262f0
testl %eax, %eax
je 0x66343
movq %rbx, %rdi
leaq 0x574ba(%rip), %rsi     # 0xbd5c7
callq 0x262f0
testl %eax, %eax
je 0x666c4
movq %rbx, %rdi
leaq 0x55cfd(%rip), %rsi     # 0xbbe21
callq 0x262f0
testl %eax, %eax
je 0x666c4
movq %rbx, %rdi
leaq 0x5563c(%rip), %rsi     # 0xbb777
callq 0x262f0
testl %eax, %eax
je 0x666c4
movq %rbx, %rdi
leaq 0x55cd4(%rip), %rsi     # 0xbbe26
callq 0x262f0
testl %eax, %eax
je 0x666c4
movq %rbx, %rdi
leaq 0x4b526(%rip), %rsi     # 0xb168f
callq 0x262f0
testl %eax, %eax
je 0x666ce
movq %rbx, %rdi
leaq 0x51cac(%rip), %rsi     # 0xb7e2c
callq 0x262f0
testl %eax, %eax
je 0x666ce
movq %rbx, %rdi
leaq 0x4b501(%rip), %rsi     # 0xb1698
callq 0x262f0
testl %eax, %eax
je 0x665db
movq %rbx, %rdi
leaq 0x5e307(%rip), %rsi     # 0xc44b5
callq 0x262f0
testl %eax, %eax
je 0x665db
movq %rbx, %rdi
leaq 0x59c5f(%rip), %rsi     # 0xbfe24
callq 0x262f0
testl %eax, %eax
je 0x665e7
movq %rbx, %rdi
leaq 0x55c4f(%rip), %rsi     # 0xbbe2b
callq 0x262f0
testl %eax, %eax
je 0x665e7
movq %rbx, %rdi
leaq 0x5c158(%rip), %rsi     # 0xc234b
callq 0x262f0
testl %eax, %eax
je 0x665f4
movq %rbx, %rdi
leaq 0x5b252(%rip), %rsi     # 0xc145c
callq 0x262f0
testl %eax, %eax
je 0x665f4
movq %rbx, %rdi
leaq 0x5c134(%rip), %rsi     # 0xc2355
callq 0x262f0
testl %eax, %eax
je 0x66601
movq %rbx, %rdi
leaq 0x55276(%rip), %rsi     # 0xbb4ae
callq 0x262f0
testl %eax, %eax
je 0x66601
movq %rbx, %rdi
leaq 0x5c15a(%rip), %rsi     # 0xc23a9
callq 0x262f0
testl %eax, %eax
je 0x66626
movq %rbx, %rdi
leaq 0x5e0db(%rip), %rsi     # 0xc4341
callq 0x262f0
testl %eax, %eax
je 0x66626
movl (%rsp), %eax
movl %eax, 0x4(%rsp)
cmpl $0x2, %eax
jl 0x662ad
movq %rbx, %rdi
leaq 0x4b40c(%rip), %rsi     # 0xb1695
callq 0x262f0
testl %eax, %eax
je 0x6665b
movq %rbx, %rdi
leaq 0x48d18(%rip), %rsi     # 0xaefb8
callq 0x262f0
testl %eax, %eax
je 0x6665b
movq %rbx, %rdi
leaq 0x52b06(%rip), %rsi     # 0xb8dbd
callq 0x262f0
testl %eax, %eax
je 0x66644
movq %rbx, %rdi
leaq 0x5e14c(%rip), %rsi     # 0xc441a
callq 0x262f0
testl %eax, %eax
je 0x66644
movq %rbx, %rdi
leaq 0x54498(%rip), %rsi     # 0xba77d
callq 0x262f0
testl %eax, %eax
je 0x6667a
movq %rbx, %rdi
leaq 0x4c3aa(%rip), %rsi     # 0xb26a6
callq 0x262f0
testl %eax, %eax
je 0x6667a
movq %rbx, %rdi
leaq 0x4c38c(%rip), %rsi     # 0xb269f
callq 0x262f0
testl %eax, %eax
je 0x666a3
movq %rbx, %rdi
leaq 0x55b28(%rip), %rsi     # 0xbbe52
callq 0x262f0
testl %eax, %eax
je 0x666a3
leaq 0x55b1a(%rip), %rdi     # 0xbbe58
jmp 0x6658e
leaq 0x554aa(%rip), %rdi     # 0xbb7f4
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x554af(%rip), %rdi     # 0xbb80d
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x554c0(%rip), %rdi     # 0xbb832
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x554e2(%rip), %rdi     # 0xbb868
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x554f3(%rip), %rdi     # 0xbb88d
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x5550e(%rip), %rdi     # 0xbb8bc
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x55535(%rip), %rdi     # 0xbb8f7
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x55556(%rip), %rdi     # 0xbb92c
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x55579(%rip), %rdi     # 0xbb963
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x555a6(%rip), %rdi     # 0xbb9a4
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x555c4(%rip), %rdi     # 0xbb9d6
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x555f7(%rip), %rdi     # 0xbba1d
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x55616(%rip), %rdi     # 0xbba50
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x55641(%rip), %rdi     # 0xbba8f
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x5566b(%rip), %rdi     # 0xbbacd
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x55682(%rip), %rdi     # 0xbbaf8
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x556ab(%rip), %rdi     # 0xbbb35
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x556d7(%rip), %rdi     # 0xbbb75
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x556f0(%rip), %rdi     # 0xbbba2
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x55703(%rip), %rdi     # 0xbbbc9
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x55736(%rip), %rdi     # 0xbbc10
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x55750(%rip), %rdi     # 0xbbc3e
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x55785(%rip), %rdi     # 0xbbc87
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x557b0(%rip), %rdi     # 0xbbcc6
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x557db(%rip), %rdi     # 0xbbd05
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x4bec7(%rip), %rdi     # 0xb2405
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x557ef(%rip), %rdi     # 0xbbd41
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x5580d(%rip), %rdi     # 0xbbd73
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x55834(%rip), %rdi     # 0xbbdae
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
leaq 0x55864(%rip), %rdi     # 0xbbdf2
callq 0x3115a
movq %rax, %rdi
callq 0x627e8
jmp 0x66611
movl 0xa7cbd(%rip), %edi     # 0x10e260
movl $0x400, %edx            # imm = 0x400
movq %r15, %rsi
callq 0x26340
testl %eax, %eax
jle 0x666dd
movq 0xa7de9(%rip), %rdi     # 0x10e3a8
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %r15, %rsi
movq %rax, %rdx
callq 0x31758
movq %rax, 0xa7dd2(%rip)     # 0x10e3a8
jmp 0x660ad
movq 0x8(%rsp), %rdi
callq 0x65f35
jmp 0x66611
movl (%rsp), %esi
movq %rbp, %rdi
callq 0x66009
jmp 0x66611
movl (%rsp), %esi
movq %rbp, %rdi
callq 0x65bbd
jmp 0x66611
movl (%rsp), %edx
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x65d25
callq 0x64df5
movl (%rsp), %esi
movq %rbp, %rdi
callq 0x321be
jmp 0x660ad
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
leaq 0x557fd(%rip), %rsi     # 0xbbe32
callq 0x78aec
movq %rbx, %rdi
callq 0x793e7
jmp 0x66616
cmpl $0x2, 0x4(%rsp)
jne 0x6666e
movq 0x8(%rbp), %rsi
movq 0x8(%rsp), %rdi
callq 0x65a1e
jmp 0x66611
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
movl 0x4(%rsp), %edx
callq 0x65e6b
jmp 0x66611
movq 0x8(%rsp), %rdi
callq 0x65aff
jmp 0x66611
movl 0xa7d24(%rip), %ebx     # 0x10e3a4
movl 0x4(%rsp), %eax
cmpl $0x2, %eax
jl 0x6669e
movq 0x8(%rbp), %rdi
callq 0x26760
testl %eax, %eax
cmovgl %eax, %ebx
cmpl $0x2, 0x4(%rsp)
jne 0x666ad
pushq $0x5
popq %rsi
jmp 0x666b8
pushq $0x1
popq %rdi
movl $0xf4240, %esi          # imm = 0xF4240
jmp 0x666ba
movq 0x10(%rbp), %rdi
callq 0x26760
movl %eax, %esi
movl %ebx, %edi
callq 0x65471
jmp 0x66611
movl $0x1, 0xa7cbe(%rip)     # 0x10e38c
movl (%rsp), %esi
movq %rbp, %rdi
callq 0x321be
xorl %eax, %eax
jmp 0x666e8
andq $0x0, 0xa7ca3(%rip)     # 0x10e388
pushq $-0x1
popq %rax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop