Commit 3a9651d6 authored by Jon Doron's avatar Jon Doron Committed by Alex Bennée
Browse files

gdbstub: Implement set_thread (H pkt) with new infra



Signed-off-by: default avatarJon Doron <arilou@gmail.com>
Reviewed-by: default avatarAlex Bennée <alex.bennee@linaro.org>
Message-Id: <20190529064148.19856-7-arilou@gmail.com>
Signed-off-by: default avatarAlex Bennée <alex.bennee@linaro.org>
parent ccc47d5d
Loading
Loading
Loading
Loading
+53 −30
Original line number Diff line number Diff line
@@ -1564,6 +1564,51 @@ static void handle_cont_with_sig(GdbCmdContext *gdb_ctx, void *user_ctx)
    gdb_continue(gdb_ctx->s);
}

static void handle_set_thread(GdbCmdContext *gdb_ctx, void *user_ctx)
{
    CPUState *cpu;

    if (gdb_ctx->num_params != 2) {
        put_packet(gdb_ctx->s, "E22");
        return;
    }

    if (gdb_ctx->params[1].thread_id.kind == GDB_READ_THREAD_ERR) {
        put_packet(gdb_ctx->s, "E22");
        return;
    }

    if (gdb_ctx->params[1].thread_id.kind != GDB_ONE_THREAD) {
        put_packet(gdb_ctx->s, "OK");
        return;
    }

    cpu = gdb_get_cpu(gdb_ctx->s, gdb_ctx->params[1].thread_id.pid,
                      gdb_ctx->params[1].thread_id.tid);
    if (!cpu) {
        put_packet(gdb_ctx->s, "E22");
        return;
    }

    /*
     * Note: This command is deprecated and modern gdb's will be using the
     *       vCont command instead.
     */
    switch (gdb_ctx->params[0].opcode) {
    case 'c':
        gdb_ctx->s->c_cpu = cpu;
        put_packet(gdb_ctx->s, "OK");
        break;
    case 'g':
        gdb_ctx->s->g_cpu = cpu;
        put_packet(gdb_ctx->s, "OK");
        break;
    default:
        put_packet(gdb_ctx->s, "E22");
        break;
    }
}

static int gdb_handle_packet(GDBState *s, const char *line_buf)
{
    CPUState *cpu;
@@ -1577,7 +1622,6 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)
    char thread_id[16];
    uint8_t *registers;
    target_ulong addr, len;
    GDBThreadIdKind thread_kind;
    const GdbCmdParseEntry *cmd_parser = NULL;

    trace_gdbstub_io_command(line_buf);
@@ -1840,35 +1884,14 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)
            put_packet(s, "E22");
        break;
    case 'H':
        type = *p++;

        thread_kind = read_thread_id(p, &p, &pid, &tid);
        if (thread_kind == GDB_READ_THREAD_ERR) {
            put_packet(s, "E22");
            break;
        }

        if (thread_kind != GDB_ONE_THREAD) {
            put_packet(s, "OK");
            break;
        }
        cpu = gdb_get_cpu(s, pid, tid);
        if (cpu == NULL) {
            put_packet(s, "E22");
            break;
        }
        switch (type) {
        case 'c':
            s->c_cpu = cpu;
            put_packet(s, "OK");
            break;
        case 'g':
            s->g_cpu = cpu;
            put_packet(s, "OK");
            break;
        default:
             put_packet(s, "E22");
             break;
        {
            static const GdbCmdParseEntry set_thread_cmd_desc = {
                .handler = handle_set_thread,
                .cmd = "H",
                .cmd_startswith = 1,
                .schema = "o.t0"
            };
            cmd_parser = &set_thread_cmd_desc;
        }
        break;
    case 'T':