static int gdb_handle_packet(GDBState *s, const char *line_buf)

{

    CPUArchState *env;

    const char *p;

    uint32_t thread;

    int ch, reg_size, type, res;

    char buf[MAX_PACKET_LENGTH];

    uint8_t mem_buf[MAX_PACKET_LENGTH];

    uint8_t *registers;

    target_ulong addr, len;



#ifdef DEBUG_GDB

    printf("command='%s'\n", line_buf);

#endif

    p = line_buf;

    ch = *p++;

    switch(ch) {

    case '?':

        /* TODO: Make this return the correct value for user-mode.  */

        snprintf(buf, sizeof(buf), "T%02xthread:%02x;", GDB_SIGNAL_TRAP,

                 cpu_index(ENV_GET_CPU(s->c_cpu)));

        put_packet(s, buf);

        /* Remove all the breakpoints when this query is issued,

         * because gdb is doing and initial connect and the state

         * should be cleaned up.

         */

        gdb_breakpoint_remove_all();

        break;

    case 'c':

        if (*p != '\0') {

            addr = strtoull(p, (char **)&p, 16);

            gdb_set_cpu_pc(s, addr);

        }

        s->signal = 0;

        gdb_continue(s);

	return RS_IDLE;

    case 'C':

        s->signal = gdb_signal_to_target (strtoul(p, (char **)&p, 16));

        if (s->signal == -1)

            s->signal = 0;

        gdb_continue(s);

        return RS_IDLE;

    case 'v':

        if (strncmp(p, "Cont", 4) == 0) {

            int res_signal, res_thread;



            p += 4;

            if (*p == '?') {

                put_packet(s, "vCont;c;C;s;S");

                break;

            }

            res = 0;

            res_signal = 0;

            res_thread = 0;

            while (*p) {

                int action, signal;



                if (*p++ != ';') {

                    res = 0;

                    break;

                }

                action = *p++;

                signal = 0;

                if (action == 'C' || action == 'S') {

                    signal = strtoul(p, (char **)&p, 16);

                } else if (action != 'c' && action != 's') {

                    res = 0;

                    break;

                }

                thread = 0;

                if (*p == ':') {

                    thread = strtoull(p+1, (char **)&p, 16);

                }

                action = tolower(action);

                if (res == 0 || (res == 'c' && action == 's')) {

                    res = action;

                    res_signal = signal;

                    res_thread = thread;

                }

            }

            if (res) {

                if (res_thread != -1 && res_thread != 0) {

                    env = find_cpu(res_thread);

                    if (env == NULL) {

                        put_packet(s, "E22");

                        break;

                    }

                    s->c_cpu = env;

                }

                if (res == 's') {

                    cpu_single_step(s->c_cpu, sstep_flags);

                }

                s->signal = res_signal;

                gdb_continue(s);

                return RS_IDLE;

            }

            break;

        } else {

            goto unknown_command;

        }

    case 'k':

#ifdef CONFIG_USER_ONLY

        /* Kill the target */

        fprintf(stderr, "\nQEMU: Terminated via GDBstub\n");

        exit(0);

#endif

    case 'D':

        /* Detach packet */

        gdb_breakpoint_remove_all();

        gdb_syscall_mode = GDB_SYS_DISABLED;

        gdb_continue(s);

        put_packet(s, "OK");

        break;

    case 's':

        if (*p != '\0') {

            addr = strtoull(p, (char **)&p, 16);

            gdb_set_cpu_pc(s, addr);

        }

        cpu_single_step(s->c_cpu, sstep_flags);

        gdb_continue(s);

	return RS_IDLE;

    case 'F':

        {

            target_ulong ret;

            target_ulong err;



            ret = strtoull(p, (char **)&p, 16);

            if (*p == ',') {

                p++;

                err = strtoull(p, (char **)&p, 16);

            } else {

                err = 0;

            }

            if (*p == ',')

                p++;

            type = *p;

            if (s->current_syscall_cb) {

                s->current_syscall_cb(s->c_cpu, ret, err);

                s->current_syscall_cb = NULL;

            }

            if (type == 'C') {

                put_packet(s, "T02");

            } else {

                gdb_continue(s);

            }

        }

        break;

    case 'g':

        cpu_synchronize_state(ENV_GET_CPU(s->g_cpu));

        env = s->g_cpu;

        len = 0;

        for (addr = 0; addr < num_g_regs; addr++) {

            reg_size = gdb_read_register(s->g_cpu, mem_buf + len, addr);

            len += reg_size;

        }

        memtohex(buf, mem_buf, len);

        put_packet(s, buf);

        break;

    case 'G':

        cpu_synchronize_state(ENV_GET_CPU(s->g_cpu));

        env = s->g_cpu;

        registers = mem_buf;

        len = strlen(p) / 2;

        hextomem((uint8_t *)registers, p, len);

        for (addr = 0; addr < num_g_regs && len > 0; addr++) {

            reg_size = gdb_write_register(s->g_cpu, registers, addr);

            len -= reg_size;

            registers += reg_size;

        }

        put_packet(s, "OK");

        break;

    case 'm':

        addr = strtoull(p, (char **)&p, 16);

        if (*p == ',')

            p++;

        len = strtoull(p, NULL, 16);

        if (target_memory_rw_debug(s->g_cpu, addr, mem_buf, len, 0) != 0) {

            put_packet (s, "E14");

        } else {

            memtohex(buf, mem_buf, len);

            put_packet(s, buf);

        }

        break;

    case 'M':

        addr = strtoull(p, (char **)&p, 16);

        if (*p == ',')

            p++;

        len = strtoull(p, (char **)&p, 16);

        if (*p == ':')

            p++;

        hextomem(mem_buf, p, len);

        if (target_memory_rw_debug(s->g_cpu, addr, mem_buf, len, 1) != 0) {

            put_packet(s, "E14");

        } else {

            put_packet(s, "OK");

        }

        break;

    case 'p':

        /* Older gdb are really dumb, and don't use 'g' if 'p' is avaialable.

           This works, but can be very slow.  Anything new enough to

           understand XML also knows how to use this properly.  */

        if (!gdb_has_xml)

            goto unknown_command;

        addr = strtoull(p, (char **)&p, 16);

        reg_size = gdb_read_register(s->g_cpu, mem_buf, addr);

        if (reg_size) {

            memtohex(buf, mem_buf, reg_size);

            put_packet(s, buf);

        } else {

            put_packet(s, "E14");

        }

        break;

    case 'P':

        if (!gdb_has_xml)

            goto unknown_command;

        addr = strtoull(p, (char **)&p, 16);

        if (*p == '=')

            p++;

        reg_size = strlen(p) / 2;

        hextomem(mem_buf, p, reg_size);

        gdb_write_register(s->g_cpu, mem_buf, addr);

        put_packet(s, "OK");

        break;

    case 'Z':

    case 'z':

        type = strtoul(p, (char **)&p, 16);

        if (*p == ',')

            p++;

        addr = strtoull(p, (char **)&p, 16);

        if (*p == ',')

            p++;

        len = strtoull(p, (char **)&p, 16);

        if (ch == 'Z')

            res = gdb_breakpoint_insert(addr, len, type);

        else

            res = gdb_breakpoint_remove(addr, len, type);

        if (res >= 0)

             put_packet(s, "OK");

        else if (res == -ENOSYS)

            put_packet(s, "");

        else

            put_packet(s, "E22");

        break;

    case 'H':

        type = *p++;

        thread = strtoull(p, (char **)&p, 16);

        if (thread == -1 || thread == 0) {

            put_packet(s, "OK");

            break;

        }

        env = find_cpu(thread);

        if (env == NULL) {

            put_packet(s, "E22");

            break;

        }

        switch (type) {

        case 'c':

            s->c_cpu = env;

            put_packet(s, "OK");

            break;

        case 'g':

            s->g_cpu = env;

            put_packet(s, "OK");

            break;

        default:

             put_packet(s, "E22");

             break;

        }

        break;

    case 'T':

        thread = strtoull(p, (char **)&p, 16);

        env = find_cpu(thread);



        if (env != NULL) {

            put_packet(s, "OK");

        } else {

            put_packet(s, "E22");

        }

        break;

    case 'q':

    case 'Q':

        /* parse any 'q' packets here */

        if (!strcmp(p,"qemu.sstepbits")) {

            /* Query Breakpoint bit definitions */

            snprintf(buf, sizeof(buf), "ENABLE=%x,NOIRQ=%x,NOTIMER=%x",

                     SSTEP_ENABLE,

                     SSTEP_NOIRQ,

                     SSTEP_NOTIMER);

            put_packet(s, buf);

            break;

        } else if (strncmp(p,"qemu.sstep",10) == 0) {

            /* Display or change the sstep_flags */

            p += 10;

            if (*p != '=') {

                /* Display current setting */

                snprintf(buf, sizeof(buf), "0x%x", sstep_flags);

                put_packet(s, buf);

                break;

            }

            p++;

            type = strtoul(p, (char **)&p, 16);

            sstep_flags = type;

            put_packet(s, "OK");

            break;

        } else if (strcmp(p,"C") == 0) {

            /* "Current thread" remains vague in the spec, so always return

             *  the first CPU (gdb returns the first thread). */

            put_packet(s, "QC1");

            break;

        } else if (strcmp(p,"fThreadInfo") == 0) {

            s->query_cpu = first_cpu->env_ptr;

            goto report_cpuinfo;

        } else if (strcmp(p,"sThreadInfo") == 0) {

        report_cpuinfo:

            if (s->query_cpu) {

                snprintf(buf, sizeof(buf), "m%x",

                         cpu_index(ENV_GET_CPU(s->query_cpu)));

                put_packet(s, buf);

                s->query_cpu = ENV_GET_CPU(s->query_cpu)->next_cpu->env_ptr;

            } else

                put_packet(s, "l");

            break;

        } else if (strncmp(p,"ThreadExtraInfo,", 16) == 0) {

            thread = strtoull(p+16, (char **)&p, 16);

            env = find_cpu(thread);

            if (env != NULL) {

                CPUState *cpu = ENV_GET_CPU(env);

                cpu_synchronize_state(cpu);

                len = snprintf((char *)mem_buf, sizeof(mem_buf),

                               "CPU#%d [%s]", cpu->cpu_index,

                               cpu->halted ? "halted " : "running");

                memtohex(buf, mem_buf, len);

                put_packet(s, buf);

            }

            break;

        }

#ifdef CONFIG_USER_ONLY

        else if (strncmp(p, "Offsets", 7) == 0) {

            TaskState *ts = s->c_cpu->opaque;



            snprintf(buf, sizeof(buf),

                     "Text=" TARGET_ABI_FMT_lx ";Data=" TARGET_ABI_FMT_lx

                     ";Bss=" TARGET_ABI_FMT_lx,

                     ts->info->code_offset,

                     ts->info->data_offset,

                     ts->info->data_offset);

            put_packet(s, buf);

            break;

        }

#else /* !CONFIG_USER_ONLY */

        else if (strncmp(p, "Rcmd,", 5) == 0) {

            int len = strlen(p + 5);



            if ((len % 2) != 0) {

                put_packet(s, "E01");

                break;

            }

            hextomem(mem_buf, p + 5, len);

            len = len / 2;

            mem_buf[len++] = 0;

            qemu_chr_be_write(s->mon_chr, mem_buf, len);

            put_packet(s, "OK");

            break;

        }

#endif /* !CONFIG_USER_ONLY */

        if (strncmp(p, "Supported", 9) == 0) {

            snprintf(buf, sizeof(buf), "PacketSize=%x", MAX_PACKET_LENGTH);

#ifdef GDB_CORE_XML

            pstrcat(buf, sizeof(buf), ";qXfer:features:read+");

#endif

            put_packet(s, buf);

            break;

        }

#ifdef GDB_CORE_XML

        if (strncmp(p, "Xfer:features:read:", 19) == 0) {

            const char *xml;

            target_ulong total_len;



            gdb_has_xml = 1;

            p += 19;

            xml = get_feature_xml(p, &p);

            if (!xml) {

                snprintf(buf, sizeof(buf), "E00");

                put_packet(s, buf);

                break;

            }



            if (*p == ':')

                p++;

            addr = strtoul(p, (char **)&p, 16);

            if (*p == ',')

                p++;

            len = strtoul(p, (char **)&p, 16);



            total_len = strlen(xml);

            if (addr > total_len) {

                snprintf(buf, sizeof(buf), "E00");

                put_packet(s, buf);

                break;

            }

            if (len > (MAX_PACKET_LENGTH - 5) / 2)

                len = (MAX_PACKET_LENGTH - 5) / 2;

            if (len < total_len - addr) {

                buf[0] = 'm';

                len = memtox(buf + 1, xml + addr, len);

            } else {

                buf[0] = 'l';

                len = memtox(buf + 1, xml + addr, total_len - addr);

            }

            put_packet_binary(s, buf, len + 1);

            break;

        }

#endif

        /* Unrecognised 'q' command.  */

        goto unknown_command;



    default:

    unknown_command:

        /* put empty packet */

        buf[0] = '\0';

        put_packet(s, buf);

        break;

    }

    return RS_IDLE;

}

static int gdb_handle_packet(GDBState *s, const char *line_buf)

{

    CPUArchState *env;

    const char *p;

    uint32_t thread;

    int ch, reg_size, type, res;

    char buf[MAX_PACKET_LENGTH];

    uint8_t mem_buf[MAX_PACKET_LENGTH];

    uint8_t *registers;

    target_ulong addr, len;



#ifdef DEBUG_GDB

    printf("command='%s'\n", line_buf);

#endif

    p = line_buf;

    ch = *p++;

    switch(ch) {

    case '?':

        

        snprintf(buf, sizeof(buf), "T%02xthread:%02x;", GDB_SIGNAL_TRAP,

                 cpu_index(ENV_GET_CPU(s->c_cpu)));

        put_packet(s, buf);

        







        gdb_breakpoint_remove_all();

        break;

    case 'c':

        if (*p != '\0') {

            addr = strtoull(p, (char **)&p, 16);

            gdb_set_cpu_pc(s, addr);

        }

        s->signal = 0;

        gdb_continue(s);

	return RS_IDLE;

    case 'C':

        s->signal = gdb_signal_to_target (strtoul(p, (char **)&p, 16));

        if (s->signal == -1)

            s->signal = 0;

        gdb_continue(s);

        return RS_IDLE;

    case 'v':

        if (strncmp(p, "Cont", 4) == 0) {

            int res_signal, res_thread;



            p += 4;

            if (*p == '?') {

                put_packet(s, "vCont;c;C;s;S");

                break;

            }

            res = 0;

            res_signal = 0;

            res_thread = 0;

            while (*p) {

                int action, signal;



                if (*p++ != ';') {

                    res = 0;

                    break;

                }

                action = *p++;

                signal = 0;

                if (action == 'C' || action == 'S') {

                    signal = strtoul(p, (char **)&p, 16);

                } else if (action != 'c' && action != 's') {

                    res = 0;

                    break;

                }

                thread = 0;

                if (*p == ':') {

                    thread = strtoull(p+1, (char **)&p, 16);

                }

                action = tolower(action);

                if (res == 0 || (res == 'c' && action == 's')) {

                    res = action;

                    res_signal = signal;

                    res_thread = thread;

                }

            }

            if (res) {

                if (res_thread != -1 && res_thread != 0) {

                    env = find_cpu(res_thread);

                    if (env == NULL) {

                        put_packet(s, "E22");

                        break;

                    }

                    s->c_cpu = env;

                }

                if (res == 's') {

                    cpu_single_step(s->c_cpu, sstep_flags);

                }

                s->signal = res_signal;

                gdb_continue(s);

                return RS_IDLE;

            }

            break;

        } else {

            goto unknown_command;

        }

    case 'k':

#ifdef CONFIG_USER_ONLY

        

        fprintf(stderr, "\nQEMU: Terminated via GDBstub\n");

        exit(0);

#endif

    case 'D':

        

        gdb_breakpoint_remove_all();

        gdb_syscall_mode = GDB_SYS_DISABLED;

        gdb_continue(s);

        put_packet(s, "OK");

        break;

    case 's':

        if (*p != '\0') {

            addr = strtoull(p, (char **)&p, 16);

            gdb_set_cpu_pc(s, addr);

        }

        cpu_single_step(s->c_cpu, sstep_flags);

        gdb_continue(s);

	return RS_IDLE;

    case 'F':

        {

            target_ulong ret;

            target_ulong err;



            ret = strtoull(p, (char **)&p, 16);

            if (*p == ',') {

                p++;

                err = strtoull(p, (char **)&p, 16);

            } else {

                err = 0;

            }

            if (*p == ',')

                p++;

            type = *p;

            if (s->current_syscall_cb) {

                s->current_syscall_cb(s->c_cpu, ret, err);

                s->current_syscall_cb = NULL;

            }

            if (type == 'C') {

                put_packet(s, "T02");

            } else {

                gdb_continue(s);

            }

        }

        break;

    case 'g':

        cpu_synchronize_state(ENV_GET_CPU(s->g_cpu));

        env = s->g_cpu;

        len = 0;

        for (addr = 0; addr < num_g_regs; addr++) {

            reg_size = gdb_read_register(s->g_cpu, mem_buf + len, addr);

            len += reg_size;

        }

        memtohex(buf, mem_buf, len);

        put_packet(s, buf);

        break;

    case 'G':

        cpu_synchronize_state(ENV_GET_CPU(s->g_cpu));

        env = s->g_cpu;

        registers = mem_buf;

        len = strlen(p) / 2;

        hextomem((uint8_t *)registers, p, len);

        for (addr = 0; addr < num_g_regs && len > 0; addr++) {

            reg_size = gdb_write_register(s->g_cpu, registers, addr);

            len -= reg_size;

            registers += reg_size;

        }

        put_packet(s, "OK");

        break;

    case 'm':

        addr = strtoull(p, (char **)&p, 16);

        if (*p == ',')

            p++;

        len = strtoull(p, NULL, 16);

        if (target_memory_rw_debug(s->g_cpu, addr, mem_buf, len, 0) != 0) {

            put_packet (s, "E14");

        } else {

            memtohex(buf, mem_buf, len);

            put_packet(s, buf);

        }

        break;

    case 'M':

        addr = strtoull(p, (char **)&p, 16);

        if (*p == ',')

            p++;

        len = strtoull(p, (char **)&p, 16);

        if (*p == ':')

            p++;

        hextomem(mem_buf, p, len);

        if (target_memory_rw_debug(s->g_cpu, addr, mem_buf, len, 1) != 0) {

            put_packet(s, "E14");

        } else {

            put_packet(s, "OK");

        }

        break;

    case 'p':

        





        if (!gdb_has_xml)

            goto unknown_command;

        addr = strtoull(p, (char **)&p, 16);

        reg_size = gdb_read_register(s->g_cpu, mem_buf, addr);

        if (reg_size) {

            memtohex(buf, mem_buf, reg_size);

            put_packet(s, buf);

        } else {

            put_packet(s, "E14");

        }

        break;

    case 'P':

        if (!gdb_has_xml)

            goto unknown_command;

        addr = strtoull(p, (char **)&p, 16);

        if (*p == '=')

            p++;

        reg_size = strlen(p) / 2;

        hextomem(mem_buf, p, reg_size);

        gdb_write_register(s->g_cpu, mem_buf, addr);

        put_packet(s, "OK");

        break;

    case 'Z':

    case 'z':

        type = strtoul(p, (char **)&p, 16);

        if (*p == ',')

            p++;

        addr = strtoull(p, (char **)&p, 16);

        if (*p == ',')

            p++;

        len = strtoull(p, (char **)&p, 16);

        if (ch == 'Z')

            res = gdb_breakpoint_insert(addr, len, type);

        else

            res = gdb_breakpoint_remove(addr, len, type);

        if (res >= 0)

             put_packet(s, "OK");

        else if (res == -ENOSYS)

            put_packet(s, "");

        else

            put_packet(s, "E22");

        break;

    case 'H':

        type = *p++;

        thread = strtoull(p, (char **)&p, 16);

        if (thread == -1 || thread == 0) {

            put_packet(s, "OK");

            break;

        }

        env = find_cpu(thread);

        if (env == NULL) {

            put_packet(s, "E22");

            break;

        }

        switch (type) {

        case 'c':

            s->c_cpu = env;

            put_packet(s, "OK");

            break;

        case 'g':

            s->g_cpu = env;

            put_packet(s, "OK");

            break;

        default:

             put_packet(s, "E22");

             break;

        }

        break;

    case 'T':

        thread = strtoull(p, (char **)&p, 16);

        env = find_cpu(thread);



        if (env != NULL) {

            put_packet(s, "OK");

        } else {

            put_packet(s, "E22");

        }

        break;

    case 'q':

    case 'Q':

        

        if (!strcmp(p,"qemu.sstepbits")) {

            

            snprintf(buf, sizeof(buf), "ENABLE=%x,NOIRQ=%x,NOTIMER=%x",

                     SSTEP_ENABLE,

                     SSTEP_NOIRQ,

                     SSTEP_NOTIMER);

            put_packet(s, buf);

            break;

        } else if (strncmp(p,"qemu.sstep",10) == 0) {

            

            p += 10;

            if (*p != '=') {

                

                snprintf(buf, sizeof(buf), "0x%x", sstep_flags);

                put_packet(s, buf);

                break;

            }

            p++;

            type = strtoul(p, (char **)&p, 16);

            sstep_flags = type;

            put_packet(s, "OK");

            break;

        } else if (strcmp(p,"C") == 0) {

            



            put_packet(s, "QC1");

            break;

        } else if (strcmp(p,"fThreadInfo") == 0) {

            s->query_cpu = first_cpu->env_ptr;

            goto report_cpuinfo;

        } else if (strcmp(p,"sThreadInfo") == 0) {

        report_cpuinfo:

            if (s->query_cpu) {

                snprintf(buf, sizeof(buf), "m%x",

                         cpu_index(ENV_GET_CPU(s->query_cpu)));

                put_packet(s, buf);

                s->query_cpu = ENV_GET_CPU(s->query_cpu)->next_cpu->env_ptr;

            } else

                put_packet(s, "l");

            break;

        } else if (strncmp(p,"ThreadExtraInfo,", 16) == 0) {

            thread = strtoull(p+16, (char **)&p, 16);

            env = find_cpu(thread);

            if (env != NULL) {

                CPUState *cpu = ENV_GET_CPU(env);

                cpu_synchronize_state(cpu);

                len = snprintf((char *)mem_buf, sizeof(mem_buf),

                               "CPU#%d [%s]", cpu->cpu_index,

                               cpu->halted ? "halted " : "running");

                memtohex(buf, mem_buf, len);

                put_packet(s, buf);

            }

            break;

        }

#ifdef CONFIG_USER_ONLY

        else if (strncmp(p, "Offsets", 7) == 0) {

            TaskState *ts = s->c_cpu->opaque;



            snprintf(buf, sizeof(buf),

                     "Text=" TARGET_ABI_FMT_lx ";Data=" TARGET_ABI_FMT_lx

                     ";Bss=" TARGET_ABI_FMT_lx,

                     ts->info->code_offset,

                     ts->info->data_offset,

                     ts->info->data_offset);

            put_packet(s, buf);

            break;

        }

#else 

        else if (strncmp(p, "Rcmd,", 5) == 0) {

            int len = strlen(p + 5);



            if ((len % 2) != 0) {

                put_packet(s, "E01");

                break;

            }

            hextomem(mem_buf, p + 5, len);

            len = len / 2;

            mem_buf[len++] = 0;

            qemu_chr_be_write(s->mon_chr, mem_buf, len);

            put_packet(s, "OK");

            break;

        }

#endif 

        if (strncmp(p, "Supported", 9) == 0) {

            snprintf(buf, sizeof(buf), "PacketSize=%x", MAX_PACKET_LENGTH);

#ifdef GDB_CORE_XML

            pstrcat(buf, sizeof(buf), ";qXfer:features:read+");

#endif

            put_packet(s, buf);

            break;

        }

#ifdef GDB_CORE_XML

        if (strncmp(p, "Xfer:features:read:", 19) == 0) {

            const char *xml;

            target_ulong total_len;



            gdb_has_xml = 1;

            p += 19;

            xml = get_feature_xml(p, &p);

            if (!xml) {

                snprintf(buf, sizeof(buf), "E00");

                put_packet(s, buf);

                break;

            }



            if (*p == ':')

                p++;

            addr = strtoul(p, (char **)&p, 16);

            if (*p == ',')

                p++;

            len = strtoul(p, (char **)&p, 16);



            total_len = strlen(xml);

            if (addr > total_len) {

                snprintf(buf, sizeof(buf), "E00");

                put_packet(s, buf);

                break;

            }

            if (len > (MAX_PACKET_LENGTH - 5) / 2)

                len = (MAX_PACKET_LENGTH - 5) / 2;

            if (len < total_len - addr) {

                buf[0] = 'm';

                len = memtox(buf + 1, xml + addr, len);

            } else {

                buf[0] = 'l';

                len = memtox(buf + 1, xml + addr, total_len - addr);

            }

            put_packet_binary(s, buf, len + 1);

            break;

        }

#endif

        

        goto unknown_command;



    default:

    unknown_command:

        

        buf[0] = '\0';

        put_packet(s, buf);

        break;

    }

    return RS_IDLE;

}

            s->query_cpu = first_cpu->env_ptr;                 snprintf(buf, sizeof(buf), "m%x",                          cpu_index(ENV_GET_CPU(s->query_cpu)));                 s->query_cpu = ENV_GET_CPU(s->query_cpu)->next_cpu->env_ptr;
static int FUNC_0(GDBState *VAR_0, const char *VAR_1)

{

    CPUArchState *env;

    const char *VAR_2;

    uint32_t thread;

    int VAR_3, VAR_4, VAR_5, VAR_6;

    char VAR_7[MAX_PACKET_LENGTH];

    uint8_t mem_buf[MAX_PACKET_LENGTH];

    uint8_t *registers;

    target_ulong addr, VAR_12;



#ifdef DEBUG_GDB

    printf("command='%VAR_0'\n", VAR_1);

#endif

    VAR_2 = VAR_1;

    VAR_3 = *VAR_2++;

    switch(VAR_3) {

    case '?':

        

        snprintf(VAR_7, sizeof(VAR_7), "T%02xthread:%02x;", GDB_SIGNAL_TRAP,

                 cpu_index(ENV_GET_CPU(VAR_0->c_cpu)));

        put_packet(VAR_0, VAR_7);

        







        gdb_breakpoint_remove_all();

        break;

    case 'c':

        if (*VAR_2 != '\0') {

            addr = strtoull(VAR_2, (char **)&VAR_2, 16);

            gdb_set_cpu_pc(VAR_0, addr);

        }

        VAR_0->VAR_11 = 0;

        gdb_continue(VAR_0);

	return RS_IDLE;

    case 'C':

        VAR_0->VAR_11 = gdb_signal_to_target (strtoul(VAR_2, (char **)&VAR_2, 16));

        if (VAR_0->VAR_11 == -1)

            VAR_0->VAR_11 = 0;

        gdb_continue(VAR_0);

        return RS_IDLE;

    case 'v':

        if (strncmp(VAR_2, "Cont", 4) == 0) {

            int VAR_8, VAR_9;



            VAR_2 += 4;

            if (*VAR_2 == '?') {

                put_packet(VAR_0, "vCont;c;C;VAR_0;S");

                break;

            }

            VAR_6 = 0;

            VAR_8 = 0;

            VAR_9 = 0;

            while (*VAR_2) {

                int VAR_10, VAR_11;



                if (*VAR_2++ != ';') {

                    VAR_6 = 0;

                    break;

                }

                VAR_10 = *VAR_2++;

                VAR_11 = 0;

                if (VAR_10 == 'C' || VAR_10 == 'S') {

                    VAR_11 = strtoul(VAR_2, (char **)&VAR_2, 16);

                } else if (VAR_10 != 'c' && VAR_10 != 'VAR_0') {

                    VAR_6 = 0;

                    break;

                }

                thread = 0;

                if (*VAR_2 == ':') {

                    thread = strtoull(VAR_2+1, (char **)&VAR_2, 16);

                }

                VAR_10 = tolower(VAR_10);

                if (VAR_6 == 0 || (VAR_6 == 'c' && VAR_10 == 'VAR_0')) {

                    VAR_6 = VAR_10;

                    VAR_8 = VAR_11;

                    VAR_9 = thread;

                }

            }

            if (VAR_6) {

                if (VAR_9 != -1 && VAR_9 != 0) {

                    env = find_cpu(VAR_9);

                    if (env == NULL) {

                        put_packet(VAR_0, "E22");

                        break;

                    }

                    VAR_0->c_cpu = env;

                }

                if (VAR_6 == 'VAR_0') {

                    cpu_single_step(VAR_0->c_cpu, sstep_flags);

                }

                VAR_0->VAR_11 = VAR_8;

                gdb_continue(VAR_0);

                return RS_IDLE;

            }

            break;

        } else {

            goto unknown_command;

        }

    case 'k':

#ifdef CONFIG_USER_ONLY

        

        fprintf(stderr, "\nQEMU: Terminated via GDBstub\n");

        exit(0);

#endif

    case 'D':

        

        gdb_breakpoint_remove_all();

        gdb_syscall_mode = GDB_SYS_DISABLED;

        gdb_continue(VAR_0);

        put_packet(VAR_0, "OK");

        break;

    case 'VAR_0':

        if (*VAR_2 != '\0') {

            addr = strtoull(VAR_2, (char **)&VAR_2, 16);

            gdb_set_cpu_pc(VAR_0, addr);

        }

        cpu_single_step(VAR_0->c_cpu, sstep_flags);

        gdb_continue(VAR_0);

	return RS_IDLE;

    case 'F':

        {

            target_ulong ret;

            target_ulong err;



            ret = strtoull(VAR_2, (char **)&VAR_2, 16);

            if (*VAR_2 == ',') {

                VAR_2++;

                err = strtoull(VAR_2, (char **)&VAR_2, 16);

            } else {

                err = 0;

            }

            if (*VAR_2 == ',')

                VAR_2++;

            VAR_5 = *VAR_2;

            if (VAR_0->current_syscall_cb) {

                VAR_0->current_syscall_cb(VAR_0->c_cpu, ret, err);

                VAR_0->current_syscall_cb = NULL;

            }

            if (VAR_5 == 'C') {

                put_packet(VAR_0, "T02");

            } else {

                gdb_continue(VAR_0);

            }

        }

        break;

    case 'g':

        cpu_synchronize_state(ENV_GET_CPU(VAR_0->g_cpu));

        env = VAR_0->g_cpu;

        VAR_12 = 0;

        for (addr = 0; addr < num_g_regs; addr++) {

            VAR_4 = gdb_read_register(VAR_0->g_cpu, mem_buf + VAR_12, addr);

            VAR_12 += VAR_4;

        }

        memtohex(VAR_7, mem_buf, VAR_12);

        put_packet(VAR_0, VAR_7);

        break;

    case 'G':

        cpu_synchronize_state(ENV_GET_CPU(VAR_0->g_cpu));

        env = VAR_0->g_cpu;

        registers = mem_buf;

        VAR_12 = strlen(VAR_2) / 2;

        hextomem((uint8_t *)registers, VAR_2, VAR_12);

        for (addr = 0; addr < num_g_regs && VAR_12 > 0; addr++) {

            VAR_4 = gdb_write_register(VAR_0->g_cpu, registers, addr);

            VAR_12 -= VAR_4;

            registers += VAR_4;

        }

        put_packet(VAR_0, "OK");

        break;

    case 'm':

        addr = strtoull(VAR_2, (char **)&VAR_2, 16);

        if (*VAR_2 == ',')

            VAR_2++;

        VAR_12 = strtoull(VAR_2, NULL, 16);

        if (target_memory_rw_debug(VAR_0->g_cpu, addr, mem_buf, VAR_12, 0) != 0) {

            put_packet (VAR_0, "E14");

        } else {

            memtohex(VAR_7, mem_buf, VAR_12);

            put_packet(VAR_0, VAR_7);

        }

        break;

    case 'M':

        addr = strtoull(VAR_2, (char **)&VAR_2, 16);

        if (*VAR_2 == ',')

            VAR_2++;

        VAR_12 = strtoull(VAR_2, (char **)&VAR_2, 16);

        if (*VAR_2 == ':')

            VAR_2++;

        hextomem(mem_buf, VAR_2, VAR_12);

        if (target_memory_rw_debug(VAR_0->g_cpu, addr, mem_buf, VAR_12, 1) != 0) {

            put_packet(VAR_0, "E14");

        } else {

            put_packet(VAR_0, "OK");

        }

        break;

    case 'VAR_2':

        





        if (!gdb_has_xml)

            goto unknown_command;

        addr = strtoull(VAR_2, (char **)&VAR_2, 16);

        VAR_4 = gdb_read_register(VAR_0->g_cpu, mem_buf, addr);

        if (VAR_4) {

            memtohex(VAR_7, mem_buf, VAR_4);

            put_packet(VAR_0, VAR_7);

        } else {

            put_packet(VAR_0, "E14");

        }

        break;

    case 'P':

        if (!gdb_has_xml)

            goto unknown_command;

        addr = strtoull(VAR_2, (char **)&VAR_2, 16);

        if (*VAR_2 == '=')

            VAR_2++;

        VAR_4 = strlen(VAR_2) / 2;

        hextomem(mem_buf, VAR_2, VAR_4);

        gdb_write_register(VAR_0->g_cpu, mem_buf, addr);

        put_packet(VAR_0, "OK");

        break;

    case 'Z':

    case 'z':

        VAR_5 = strtoul(VAR_2, (char **)&VAR_2, 16);

        if (*VAR_2 == ',')

            VAR_2++;

        addr = strtoull(VAR_2, (char **)&VAR_2, 16);

        if (*VAR_2 == ',')

            VAR_2++;

        VAR_12 = strtoull(VAR_2, (char **)&VAR_2, 16);

        if (VAR_3 == 'Z')

            VAR_6 = gdb_breakpoint_insert(addr, VAR_12, VAR_5);

        else

            VAR_6 = gdb_breakpoint_remove(addr, VAR_12, VAR_5);

        if (VAR_6 >= 0)

             put_packet(VAR_0, "OK");

        else if (VAR_6 == -ENOSYS)

            put_packet(VAR_0, "");

        else

            put_packet(VAR_0, "E22");

        break;

    case 'H':

        VAR_5 = *VAR_2++;

        thread = strtoull(VAR_2, (char **)&VAR_2, 16);

        if (thread == -1 || thread == 0) {

            put_packet(VAR_0, "OK");

            break;

        }

        env = find_cpu(thread);

        if (env == NULL) {

            put_packet(VAR_0, "E22");

            break;

        }

        switch (VAR_5) {

        case 'c':

            VAR_0->c_cpu = env;

            put_packet(VAR_0, "OK");

            break;

        case 'g':

            VAR_0->g_cpu = env;

            put_packet(VAR_0, "OK");

            break;

        default:

             put_packet(VAR_0, "E22");

             break;

        }

        break;

    case 'T':

        thread = strtoull(VAR_2, (char **)&VAR_2, 16);

        env = find_cpu(thread);



        if (env != NULL) {

            put_packet(VAR_0, "OK");

        } else {

            put_packet(VAR_0, "E22");

        }

        break;

    case 'q':

    case 'Q':

        

        if (!strcmp(VAR_2,"qemu.sstepbits")) {

            

            snprintf(VAR_7, sizeof(VAR_7), "ENABLE=%x,NOIRQ=%x,NOTIMER=%x",

                     SSTEP_ENABLE,

                     SSTEP_NOIRQ,

                     SSTEP_NOTIMER);

            put_packet(VAR_0, VAR_7);

            break;

        } else if (strncmp(VAR_2,"qemu.sstep",10) == 0) {

            

            VAR_2 += 10;

            if (*VAR_2 != '=') {

                

                snprintf(VAR_7, sizeof(VAR_7), "0x%x", sstep_flags);

                put_packet(VAR_0, VAR_7);

                break;

            }

            VAR_2++;

            VAR_5 = strtoul(VAR_2, (char **)&VAR_2, 16);

            sstep_flags = VAR_5;

            put_packet(VAR_0, "OK");

            break;

        } else if (strcmp(VAR_2,"C") == 0) {

            



            put_packet(VAR_0, "QC1");

            break;

        } else if (strcmp(VAR_2,"fThreadInfo") == 0) {

            VAR_0->query_cpu = first_cpu->env_ptr;

            goto report_cpuinfo;

        } else if (strcmp(VAR_2,"sThreadInfo") == 0) {

        report_cpuinfo:

            if (VAR_0->query_cpu) {

                snprintf(VAR_7, sizeof(VAR_7), "m%x",

                         cpu_index(ENV_GET_CPU(VAR_0->query_cpu)));

                put_packet(VAR_0, VAR_7);

                VAR_0->query_cpu = ENV_GET_CPU(VAR_0->query_cpu)->next_cpu->env_ptr;

            } else

                put_packet(VAR_0, "l");

            break;

        } else if (strncmp(VAR_2,"ThreadExtraInfo,", 16) == 0) {

            thread = strtoull(VAR_2+16, (char **)&VAR_2, 16);

            env = find_cpu(thread);

            if (env != NULL) {

                CPUState *cpu = ENV_GET_CPU(env);

                cpu_synchronize_state(cpu);

                VAR_12 = snprintf((char *)mem_buf, sizeof(mem_buf),

                               "CPU#%d [%VAR_0]", cpu->cpu_index,

                               cpu->halted ? "halted " : "running");

                memtohex(VAR_7, mem_buf, VAR_12);

                put_packet(VAR_0, VAR_7);

            }

            break;

        }

#ifdef CONFIG_USER_ONLY

        else if (strncmp(VAR_2, "Offsets", 7) == 0) {

            TaskState *ts = VAR_0->c_cpu->opaque;



            snprintf(VAR_7, sizeof(VAR_7),

                     "Text=" TARGET_ABI_FMT_lx ";Data=" TARGET_ABI_FMT_lx

                     ";Bss=" TARGET_ABI_FMT_lx,

                     ts->info->code_offset,

                     ts->info->data_offset,

                     ts->info->data_offset);

            put_packet(VAR_0, VAR_7);

            break;

        }

#else 

        else if (strncmp(VAR_2, "Rcmd,", 5) == 0) {

            int VAR_12 = strlen(VAR_2 + 5);



            if ((VAR_12 % 2) != 0) {

                put_packet(VAR_0, "E01");

                break;

            }

            hextomem(mem_buf, VAR_2 + 5, VAR_12);

            VAR_12 = VAR_12 / 2;

            mem_buf[VAR_12++] = 0;

            qemu_chr_be_write(VAR_0->mon_chr, mem_buf, VAR_12);

            put_packet(VAR_0, "OK");

            break;

        }

#endif 

        if (strncmp(VAR_2, "Supported", 9) == 0) {

            snprintf(VAR_7, sizeof(VAR_7), "PacketSize=%x", MAX_PACKET_LENGTH);

#ifdef GDB_CORE_XML

            pstrcat(VAR_7, sizeof(VAR_7), ";qXfer:features:read+");

#endif

            put_packet(VAR_0, VAR_7);

            break;

        }

#ifdef GDB_CORE_XML

        if (strncmp(VAR_2, "Xfer:features:read:", 19) == 0) {

            const char *xml;

            target_ulong total_len;



            gdb_has_xml = 1;

            VAR_2 += 19;

            xml = get_feature_xml(VAR_2, &VAR_2);

            if (!xml) {

                snprintf(VAR_7, sizeof(VAR_7), "E00");

                put_packet(VAR_0, VAR_7);

                break;

            }



            if (*VAR_2 == ':')

                VAR_2++;

            addr = strtoul(VAR_2, (char **)&VAR_2, 16);

            if (*VAR_2 == ',')

                VAR_2++;

            VAR_12 = strtoul(VAR_2, (char **)&VAR_2, 16);



            total_len = strlen(xml);

            if (addr > total_len) {

                snprintf(VAR_7, sizeof(VAR_7), "E00");

                put_packet(VAR_0, VAR_7);

                break;

            }

            if (VAR_12 > (MAX_PACKET_LENGTH - 5) / 2)

                VAR_12 = (MAX_PACKET_LENGTH - 5) / 2;

            if (VAR_12 < total_len - addr) {

                VAR_7[0] = 'm';

                VAR_12 = memtox(VAR_7 + 1, xml + addr, VAR_12);

            } else {

                VAR_7[0] = 'l';

                VAR_12 = memtox(VAR_7 + 1, xml + addr, total_len - addr);

            }

            put_packet_binary(VAR_0, VAR_7, VAR_12 + 1);

            break;

        }

#endif

        

        goto unknown_command;



    default:

    unknown_command:

        

        VAR_7[0] = '\0';

        put_packet(VAR_0, VAR_7);

        break;

    }

    return RS_IDLE;

}

static int FUNC_0(GDBState *VAR_0, const char *VAR_1)
{ CPUArchState *env; const char *VAR_2; uint32_t thread; int VAR_3, VAR_4, VAR_5, VAR_6; char VAR_7[MAX_PACKET_LENGTH]; uint8_t mem_buf[MAX_PACKET_LENGTH]; uint8_t *registers; target_ulong addr, VAR_12; #ifdef DEBUG_GDB
printf("command='%VAR_0'\n", VAR_1); #endif
VAR_2 = VAR_1; VAR_3 = *VAR_2++; switch(VAR_3) { case '?':
snprintf(VAR_7, sizeof(VAR_7), "T%02xthread:%02x;", GDB_SIGNAL_TRAP, cpu_index(ENV_GET_CPU(VAR_0->c_cpu))); put_packet(VAR_0, VAR_7); gdb_breakpoint_remove_all(); break; case 'c':
if (*VAR_2 != '\0') { addr = strtoull(VAR_2, (char **)&VAR_2, 16); gdb_set_cpu_pc(VAR_0, addr); } VAR_0->VAR_11 = 0; gdb_continue(VAR_0); return RS_IDLE; case 'C':
VAR_0->VAR_11 = gdb_signal_to_target (strtoul(VAR_2, (char **)&VAR_2, 16)); if (VAR_0->VAR_11 == -1)
VAR_0->VAR_11 = 0; gdb_continue(VAR_0); return RS_IDLE; case 'v':
if (strncmp(VAR_2, "Cont", 4) == 0) { int VAR_8, VAR_9; VAR_2 += 4; if (*VAR_2 == '?') { put_packet(VAR_0, "vCont;c;C;VAR_0;S"); break; } VAR_6 = 0; VAR_8 = 0; VAR_9 = 0; while (*VAR_2) { int VAR_10, VAR_11; if (*VAR_2++ != ';') { VAR_6 = 0; break; } VAR_10 = *VAR_2++; VAR_11 = 0; if (VAR_10 == 'C' || VAR_10 == 'S') { VAR_11 = strtoul(VAR_2, (char **)&VAR_2, 16); } else if (VAR_10 != 'c' && VAR_10 != 'VAR_0') { VAR_6 = 0; break; } thread = 0; if (*VAR_2 == ':') { thread = strtoull(VAR_2+1, (char **)&VAR_2, 16); } VAR_10 = tolower(VAR_10); if (VAR_6 == 0 || (VAR_6 == 'c' && VAR_10 == 'VAR_0')) { VAR_6 = VAR_10; VAR_8 = VAR_11; VAR_9 = thread; } } if (VAR_6) { if (VAR_9 != -1 && VAR_9 != 0) { env = find_cpu(VAR_9); if (env == NULL) { put_packet(VAR_0, "E22"); break; } VAR_0->c_cpu = env; } if (VAR_6 == 'VAR_0') { cpu_single_step(VAR_0->c_cpu, sstep_flags); } VAR_0->VAR_11 = VAR_8; gdb_continue(VAR_0); return RS_IDLE; } break; } else { goto unknown_command; } case 'k':
#ifdef CONFIG_USER_ONLY
fprintf(stderr, "\nQEMU: Terminated via GDBstub\n"); exit(0); #endif
case 'D':
gdb_breakpoint_remove_all(); gdb_syscall_mode = GDB_SYS_DISABLED; gdb_continue(VAR_0); put_packet(VAR_0, "OK"); break; case 'VAR_0':
if (*VAR_2 != '\0') { addr = strtoull(VAR_2, (char **)&VAR_2, 16); gdb_set_cpu_pc(VAR_0, addr); } cpu_single_step(VAR_0->c_cpu, sstep_flags); gdb_continue(VAR_0); return RS_IDLE; case 'F':
{ target_ulong ret; target_ulong err; ret = strtoull(VAR_2, (char **)&VAR_2, 16); if (*VAR_2 == ',') { VAR_2++; err = strtoull(VAR_2, (char **)&VAR_2, 16); } else { err = 0; } if (*VAR_2 == ',')
VAR_2++; VAR_5 = *VAR_2; if (VAR_0->current_syscall_cb) { VAR_0->current_syscall_cb(VAR_0->c_cpu, ret, err); VAR_0->current_syscall_cb = NULL; } if (VAR_5 == 'C') { put_packet(VAR_0, "T02"); } else { gdb_continue(VAR_0); } } break; case 'g':
cpu_synchronize_state(ENV_GET_CPU(VAR_0->g_cpu)); env = VAR_0->g_cpu; VAR_12 = 0; for (addr = 0; addr < num_g_regs; addr++) { VAR_4 = gdb_read_register(VAR_0->g_cpu, mem_buf + VAR_12, addr); VAR_12 += VAR_4; } memtohex(VAR_7, mem_buf, VAR_12); put_packet(VAR_0, VAR_7); break; case 'G':
cpu_synchronize_state(ENV_GET_CPU(VAR_0->g_cpu)); env = VAR_0->g_cpu; registers = mem_buf; VAR_12 = strlen(VAR_2) / 2; hextomem((uint8_t *)registers, VAR_2, VAR_12); for (addr = 0; addr < num_g_regs && VAR_12 > 0; addr++) { VAR_4 = gdb_write_register(VAR_0->g_cpu, registers, addr); VAR_12 -= VAR_4; registers += VAR_4; } put_packet(VAR_0, "OK"); break; case 'm':
addr = strtoull(VAR_2, (char **)&VAR_2, 16); if (*VAR_2 == ',')
VAR_2++; VAR_12 = strtoull(VAR_2, NULL, 16); if (target_memory_rw_debug(VAR_0->g_cpu, addr, mem_buf, VAR_12, 0) != 0) { put_packet (VAR_0, "E14"); } else { memtohex(VAR_7, mem_buf, VAR_12); put_packet(VAR_0, VAR_7); } break; case 'M':
addr = strtoull(VAR_2, (char **)&VAR_2, 16); if (*VAR_2 == ',')
VAR_2++; VAR_12 = strtoull(VAR_2, (char **)&VAR_2, 16); if (*VAR_2 == ':')
VAR_2++; hextomem(mem_buf, VAR_2, VAR_12); if (target_memory_rw_debug(VAR_0->g_cpu, addr, mem_buf, VAR_12, 1) != 0) { put_packet(VAR_0, "E14"); } else { put_packet(VAR_0, "OK"); } break; case 'VAR_2':
if (!gdb_has_xml)
goto unknown_command; addr = strtoull(VAR_2, (char **)&VAR_2, 16); VAR_4 = gdb_read_register(VAR_0->g_cpu, mem_buf, addr); if (VAR_4) { memtohex(VAR_7, mem_buf, VAR_4); put_packet(VAR_0, VAR_7); } else { put_packet(VAR_0, "E14"); } break; case 'P':
if (!gdb_has_xml)
goto unknown_command; addr = strtoull(VAR_2, (char **)&VAR_2, 16); if (*VAR_2 == '=')
VAR_2++; VAR_4 = strlen(VAR_2) / 2; hextomem(mem_buf, VAR_2, VAR_4); gdb_write_register(VAR_0->g_cpu, mem_buf, addr); put_packet(VAR_0, "OK"); break; case 'Z':
case 'z':
VAR_5 = strtoul(VAR_2, (char **)&VAR_2, 16); if (*VAR_2 == ',')
VAR_2++; addr = strtoull(VAR_2, (char **)&VAR_2, 16); if (*VAR_2 == ',')
VAR_2++; VAR_12 = strtoull(VAR_2, (char **)&VAR_2, 16); if (VAR_3 == 'Z')
VAR_6 = gdb_breakpoint_insert(addr, VAR_12, VAR_5); else
VAR_6 = gdb_breakpoint_remove(addr, VAR_12, VAR_5); if (VAR_6 >= 0)
put_packet(VAR_0, "OK"); else if (VAR_6 == -ENOSYS)
put_packet(VAR_0, ""); else
put_packet(VAR_0, "E22"); break; case 'H':
VAR_5 = *VAR_2++; thread = strtoull(VAR_2, (char **)&VAR_2, 16); if (thread == -1 || thread == 0) { put_packet(VAR_0, "OK"); break; } env = find_cpu(thread); if (env == NULL) { put_packet(VAR_0, "E22"); break; } switch (VAR_5) { case 'c':
VAR_0->c_cpu = env; put_packet(VAR_0, "OK"); break; case 'g':
VAR_0->g_cpu = env; put_packet(VAR_0, "OK"); break; default:
put_packet(VAR_0, "E22"); break; } break; case 'T':
thread = strtoull(VAR_2, (char **)&VAR_2, 16); env = find_cpu(thread); if (env != NULL) { put_packet(VAR_0, "OK"); } else { put_packet(VAR_0, "E22"); } break; case 'q':
case 'Q':
if (!strcmp(VAR_2,"qemu.sstepbits")) { snprintf(VAR_7, sizeof(VAR_7), "ENABLE=%x,NOIRQ=%x,NOTIMER=%x",
SSTEP_ENABLE,
SSTEP_NOIRQ,
SSTEP_NOTIMER); put_packet(VAR_0, VAR_7); break; } else if (strncmp(VAR_2,"qemu.sstep",10) == 0) { VAR_2 += 10; if (*VAR_2 != '=') { snprintf(VAR_7, sizeof(VAR_7), "0x%x", sstep_flags); put_packet(VAR_0, VAR_7); break; } VAR_2++; VAR_5 = strtoul(VAR_2, (char **)&VAR_2, 16); sstep_flags = VAR_5; put_packet(VAR_0, "OK"); break; } else if (strcmp(VAR_2,"C") == 0) { put_packet(VAR_0, "QC1"); break; } else if (strcmp(VAR_2,"fThreadInfo") == 0) { VAR_0->query_cpu = first_cpu->env_ptr; goto report_cpuinfo; } else if (strcmp(VAR_2,"sThreadInfo") == 0) { report_cpuinfo:
if (VAR_0->query_cpu) { snprintf(VAR_7, sizeof(VAR_7), "m%x",
cpu_index(ENV_GET_CPU(VAR_0->query_cpu))); put_packet(VAR_0, VAR_7); VAR_0->query_cpu = ENV_GET_CPU(VAR_0->query_cpu)->next_cpu->env_ptr; } else put_packet(VAR_0, "l"); break; } else if (strncmp(VAR_2,"ThreadExtraInfo,", 16) == 0) { thread = strtoull(VAR_2+16, (char **)&VAR_2, 16); env = find_cpu(thread); if (env != NULL) { CPUState *cpu = ENV_GET_CPU(env); cpu_synchronize_state(cpu); VAR_12 = snprintf((char *)mem_buf, sizeof(mem_buf),
"CPU#%d [%VAR_0]", cpu->cpu_index,
cpu->halted ? "halted " : "running"); memtohex(VAR_7, mem_buf, VAR_12); put_packet(VAR_0, VAR_7); } break; } #ifdef CONFIG_USER_ONLY
else if (strncmp(VAR_2, "Offsets", 7) == 0) { TaskState *ts = VAR_0->c_cpu->opaque; snprintf(VAR_7, sizeof(VAR_7),
"Text=" TARGET_ABI_FMT_lx ";Data=" TARGET_ABI_FMT_lx ";Bss=" TARGET_ABI_FMT_lx, ts->info->code_offset,
ts->info->data_offset,
ts->info->data_offset); put_packet(VAR_0, VAR_7); break; } #else
else if (strncmp(VAR_2, "Rcmd,", 5) == 0) { int VAR_12 = strlen(VAR_2 + 5); if ((VAR_12 % 2) != 0) { put_packet(VAR_0, "E01"); break; } hextomem(mem_buf, VAR_2 + 5, VAR_12); VAR_12 = VAR_12 / 2; mem_buf[VAR_12++] = 0; qemu_chr_be_write(VAR_0->mon_chr, mem_buf, VAR_12); put_packet(VAR_0, "OK"); break; } #endif
if (strncmp(VAR_2, "Supported", 9) == 0) { snprintf(VAR_7, sizeof(VAR_7), "PacketSize=%x", MAX_PACKET_LENGTH); #ifdef GDB_CORE_XML
pstrcat(VAR_7, sizeof(VAR_7), ";qXfer:features:read+"); #endif
put_packet(VAR_0, VAR_7); break; } #ifdef GDB_CORE_XML
if (strncmp(VAR_2, "Xfer:features:read:", 19) == 0) { const char *xml; target_ulong total_len; gdb_has_xml = 1; VAR_2 += 19; xml = get_feature_xml(VAR_2, &VAR_2); if (!xml) { snprintf(VAR_7, sizeof(VAR_7), "E00"); put_packet(VAR_0, VAR_7); break; } if (*VAR_2 == ':')
VAR_2++; addr = strtoul(VAR_2, (char **)&VAR_2, 16); if (*VAR_2 == ',')
VAR_2++; VAR_12 = strtoul(VAR_2, (char **)&VAR_2, 16); total_len = strlen(xml); if (addr > total_len) { snprintf(VAR_7, sizeof(VAR_7), "E00"); put_packet(VAR_0, VAR_7); break; } if (VAR_12 > (MAX_PACKET_LENGTH - 5) / 2)
VAR_12 = (MAX_PACKET_LENGTH - 5) / 2; if (VAR_12 < total_len - addr) { VAR_7[0] = 'm'; VAR_12 = memtox(VAR_7 + 1, xml + addr, VAR_12); } else { VAR_7[0] = 'l'; VAR_12 = memtox(VAR_7 + 1, xml + addr, total_len - addr); } put_packet_binary(VAR_0, VAR_7, VAR_12 + 1); break; } #endif
goto unknown_command; default:
unknown_command:
VAR_7[0] = '\0'; put_packet(VAR_0, VAR_7); break; } return RS_IDLE; }