From nobody Mon Feb 9 11:51:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1620398668; cv=none; d=zohomail.com; s=zohoarc; b=JolSc4gIfxAi2mivAW+elAnkaUzcXT478PHvluATupM6GNulH4GMPUi8LsWHRCFV0qwN+QWJ1bGWiq90Wxh7HvRv7J9bO79AaGEsYatCtDcmJTb8jugXEXpf2wY+5zl7+JreFpq4ABMbRI16ahjp8nHyQZiJtq7YL/Tex5mLNEw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620398668; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=kLWd0gsOs/zJbnWSmwYcEDNmDuRZ+yJPcTXC6c2hf6w=; b=OWw/OsjMW+WUNsEiBSx6vUMlP0GVZw6Yk25PjuLPAT6cbDM+B3OZ//Sw4Op3P92EgQATjodSqifDshrAwgD9kpkpzgXYinxxuJJdkYsuUynGubhVc854xH9Sq6208TEEpftFohKOkDHBps2aWZ7usBWFhuCzoV9uw6KNskCt4ew= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1620398668460205.25354973533945; Fri, 7 May 2021 07:44:28 -0700 (PDT) Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-488-rzGL-EiKPAOZb4zH5LtrFw-1; Fri, 07 May 2021 10:44:22 -0400 Received: by mail-wr1-f72.google.com with SMTP id 65-20020adf82c70000b0290107593a42c3so3701238wrc.5 for ; Fri, 07 May 2021 07:44:21 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (astrasbourg-652-1-219-60.w90-40.abo.wanadoo.fr. [90.40.114.60]) by smtp.gmail.com with ESMTPSA id f11sm13853458wmq.41.2021.05.07.07.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 07:44:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620398666; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kLWd0gsOs/zJbnWSmwYcEDNmDuRZ+yJPcTXC6c2hf6w=; b=MFrzvjTXwYIckGvZ1IpCmpikzdFw6zgtcpQueFv8JUypgROa8mrJp9l8xvpVujuTlOaLdd 0I+pYXJHoE0y6iFct2zeDJxCHAW+APb+5nfkWpPssSq1OK3J71PvnX1/cb8tY46waCs7p7 0LkrgpUaFttpAkSf1/qi2qP9YrHI7eo= X-MC-Unique: rzGL-EiKPAOZb4zH5LtrFw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kLWd0gsOs/zJbnWSmwYcEDNmDuRZ+yJPcTXC6c2hf6w=; b=ar5lUhq1hIMzztOT5h8KQm7PRDTXxshNbE3YOdK6EbtlDtotZc0WRUPn6F4+GotrzT mB5m7X0wa7sTOFacSaNCrpcQqj7Q6bmcvRYdTWFUFaM39c+w0QHnSwX86y+iePhl3ZKq gBxez6GIO9KYSMs0cIYGcdOky+zcQ8NWg18FAHk+lIvU9RL59xbA1/MOxiDUIEMxI9K5 DKHNhNf5jPEXjVZAXrOwM6WwzzlSWzWvP2v1hkWrBTPD81DprdHbA9DfWzOFH7sWCf6n hroWd/TSzRRaAg84sYu3tXaKujc3sSlB+IzLOwIyF/OPHoLVnb0uyOfV5cDmAPC31b49 emxg== X-Gm-Message-State: AOAM530ZrJKeFuQwWJu5FX2++g6IZXiJ+0/ReMNa/IZ7ZtNtz8HGxoZv apJu/qw5gscm6M3XGj+6yq72ztS51FhySaluV3qSg6x0kia04vIcCHf1Dfoan9hY/kFF2iYHXB+ L0G1gmGKa8DjwOw== X-Received: by 2002:a05:600c:284:: with SMTP id 4mr10237628wmk.88.1620398660595; Fri, 07 May 2021 07:44:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAOOvRCHRw9pYpzgMzgqmnnpC9HZrmREjC7M9ldlWU6MI2H0ObL9x1a/PosyHMj8fhzWACXw== X-Received: by 2002:a05:600c:284:: with SMTP id 4mr10237606wmk.88.1620398660291; Fri, 07 May 2021 07:44:20 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Paolo Bonzini , qemu-ppc@nongnu.org, Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Gerd Hoffmann , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v3 13/17] gdbstub: Replace GdbCmdContext with plain g_array() Date: Fri, 7 May 2021 16:43:11 +0200 Message-Id: <20210507144315.1994337-14-philmd@redhat.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210507144315.1994337-1-philmd@redhat.com> References: <20210507144315.1994337-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) From: Alex Benn=C3=A9e Instead of jumping through hoops let glib deal with both tracking the number of elements and auto freeing the memory once we are done. This allows is to drop the usage of ALLOCA(3) which the man-page mentions its "use is discouraged". Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20210506160741.9841-1-alex.bennee@linaro.org> Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- gdbstub.c | 314 +++++++++++++++++++++++++----------------------------- 1 file changed, 146 insertions(+), 168 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 83d47c67325..5e9e8e3e006 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1338,6 +1338,8 @@ typedef union GdbCmdVariant { } thread_id; } GdbCmdVariant; =20 +#define get_param(p, i) (&g_array_index(p, GdbCmdVariant, i)) + static const char *cmd_next_param(const char *param, const char delimiter) { static const char all_delimiters[] =3D ",;:=3D"; @@ -1363,54 +1365,46 @@ static const char *cmd_next_param(const char *param= , const char delimiter) } =20 static int cmd_parse_params(const char *data, const char *schema, - GdbCmdVariant *params, int *num_params) + GArray *params) { - int curr_param; const char *curr_schema, *curr_data; =20 - *num_params =3D 0; - - if (!schema) { - return 0; - } + g_assert(schema); + g_assert(params->len =3D=3D 0); =20 curr_schema =3D schema; - curr_param =3D 0; curr_data =3D data; while (curr_schema[0] && curr_schema[1] && *curr_data) { + GdbCmdVariant this_param; + switch (curr_schema[0]) { case 'l': if (qemu_strtoul(curr_data, &curr_data, 16, - ¶ms[curr_param].val_ul)) { + &this_param.val_ul)) { return -EINVAL; } - curr_param++; curr_data =3D cmd_next_param(curr_data, curr_schema[1]); break; case 'L': if (qemu_strtou64(curr_data, &curr_data, 16, - (uint64_t *)¶ms[curr_param].val_ull)) { + (uint64_t *)&this_param.val_ull)) { return -EINVAL; } - curr_param++; curr_data =3D cmd_next_param(curr_data, curr_schema[1]); break; case 's': - params[curr_param].data =3D curr_data; - curr_param++; + this_param.data =3D curr_data; curr_data =3D cmd_next_param(curr_data, curr_schema[1]); break; case 'o': - params[curr_param].opcode =3D *(uint8_t *)curr_data; - curr_param++; + this_param.opcode =3D *(uint8_t *)curr_data; curr_data =3D cmd_next_param(curr_data, curr_schema[1]); break; case 't': - params[curr_param].thread_id.kind =3D + this_param.thread_id.kind =3D read_thread_id(curr_data, &curr_data, - ¶ms[curr_param].thread_id.pid, - ¶ms[curr_param].thread_id.tid); - curr_param++; + &this_param.thread_id.pid, + &this_param.thread_id.tid); curr_data =3D cmd_next_param(curr_data, curr_schema[1]); break; case '?': @@ -1419,19 +1413,14 @@ static int cmd_parse_params(const char *data, const= char *schema, default: return -EINVAL; } + g_array_append_val(params, this_param); curr_schema +=3D 2; } =20 - *num_params =3D curr_param; return 0; } =20 -typedef struct GdbCmdContext { - GdbCmdVariant *params; - int num_params; -} GdbCmdContext; - -typedef void (*GdbCmdHandler)(GdbCmdContext *gdb_ctx, void *user_ctx); +typedef void (*GdbCmdHandler)(GArray *params, void *user_ctx); =20 /* * cmd_startswith -> cmd is compared using startswith @@ -1471,8 +1460,8 @@ static inline int startswith(const char *string, cons= t char *pattern) static int process_string_cmd(void *user_ctx, const char *data, const GdbCmdParseEntry *cmds, int num_cmds) { - int i, schema_len, max_num_params =3D 0; - GdbCmdContext gdb_ctx; + int i; + g_autoptr(GArray) params =3D g_array_new(false, true, sizeof(GdbCmdVar= iant)); =20 if (!cmds) { return -1; @@ -1488,24 +1477,13 @@ static int process_string_cmd(void *user_ctx, const= char *data, } =20 if (cmd->schema) { - schema_len =3D strlen(cmd->schema); - if (schema_len % 2) { - return -2; + if (cmd_parse_params(&data[strlen(cmd->cmd)], + cmd->schema, params)) { + return -1; } - - max_num_params =3D schema_len / 2; } =20 - gdb_ctx.params =3D - (GdbCmdVariant *)alloca(sizeof(*gdb_ctx.params) * max_num_para= ms); - memset(gdb_ctx.params, 0, sizeof(*gdb_ctx.params) * max_num_params= ); - - if (cmd_parse_params(&data[strlen(cmd->cmd)], cmd->schema, - gdb_ctx.params, &gdb_ctx.num_params)) { - return -1; - } - - cmd->handler(&gdb_ctx, user_ctx); + cmd->handler(params, user_ctx); return 0; } =20 @@ -1528,18 +1506,18 @@ static void run_cmd_parser(const char *data, const = GdbCmdParseEntry *cmd) } } =20 -static void handle_detach(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_detach(GArray *params, void *user_ctx) { GDBProcess *process; uint32_t pid =3D 1; =20 if (gdbserver_state.multiprocess) { - if (!gdb_ctx->num_params) { + if (!params->len) { put_packet("E22"); return; } =20 - pid =3D gdb_ctx->params[0].val_ul; + pid =3D get_param(params, 0)->val_ul; } =20 process =3D gdb_get_process(pid); @@ -1562,22 +1540,22 @@ static void handle_detach(GdbCmdContext *gdb_ctx, v= oid *user_ctx) put_packet("OK"); } =20 -static void handle_thread_alive(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_thread_alive(GArray *params, void *user_ctx) { CPUState *cpu; =20 - if (!gdb_ctx->num_params) { + if (!params->len) { put_packet("E22"); return; } =20 - if (gdb_ctx->params[0].thread_id.kind =3D=3D GDB_READ_THREAD_ERR) { + if (get_param(params, 0)->thread_id.kind =3D=3D GDB_READ_THREAD_ERR) { put_packet("E22"); return; } =20 - cpu =3D gdb_get_cpu(gdb_ctx->params[0].thread_id.pid, - gdb_ctx->params[0].thread_id.tid); + cpu =3D gdb_get_cpu(get_param(params, 0)->thread_id.pid, + get_param(params, 0)->thread_id.tid); if (!cpu) { put_packet("E22"); return; @@ -1586,17 +1564,17 @@ static void handle_thread_alive(GdbCmdContext *gdb_= ctx, void *user_ctx) put_packet("OK"); } =20 -static void handle_continue(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_continue(GArray *params, void *user_ctx) { - if (gdb_ctx->num_params) { - gdb_set_cpu_pc(gdb_ctx->params[0].val_ull); + if (params->len) { + gdb_set_cpu_pc(get_param(params, 0)->val_ull); } =20 gdbserver_state.signal =3D 0; gdb_continue(); } =20 -static void handle_cont_with_sig(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_cont_with_sig(GArray *params, void *user_ctx) { unsigned long signal =3D 0; =20 @@ -1604,8 +1582,8 @@ static void handle_cont_with_sig(GdbCmdContext *gdb_c= tx, void *user_ctx) * Note: C sig;[addr] is currently unsupported and we simply * omit the addr parameter */ - if (gdb_ctx->num_params) { - signal =3D gdb_ctx->params[0].val_ul; + if (params->len) { + signal =3D get_param(params, 0)->val_ul; } =20 gdbserver_state.signal =3D gdb_signal_to_target(signal); @@ -1615,27 +1593,27 @@ static void handle_cont_with_sig(GdbCmdContext *gdb= _ctx, void *user_ctx) gdb_continue(); } =20 -static void handle_set_thread(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_set_thread(GArray *params, void *user_ctx) { CPUState *cpu; =20 - if (gdb_ctx->num_params !=3D 2) { + if (params->len !=3D 2) { put_packet("E22"); return; } =20 - if (gdb_ctx->params[1].thread_id.kind =3D=3D GDB_READ_THREAD_ERR) { + if (get_param(params, 1)->thread_id.kind =3D=3D GDB_READ_THREAD_ERR) { put_packet("E22"); return; } =20 - if (gdb_ctx->params[1].thread_id.kind !=3D GDB_ONE_THREAD) { + if (get_param(params, 1)->thread_id.kind !=3D GDB_ONE_THREAD) { put_packet("OK"); return; } =20 - cpu =3D gdb_get_cpu(gdb_ctx->params[1].thread_id.pid, - gdb_ctx->params[1].thread_id.tid); + cpu =3D gdb_get_cpu(get_param(params, 1)->thread_id.pid, + get_param(params, 1)->thread_id.tid); if (!cpu) { put_packet("E22"); return; @@ -1645,7 +1623,7 @@ static void handle_set_thread(GdbCmdContext *gdb_ctx,= void *user_ctx) * Note: This command is deprecated and modern gdb's will be using the * vCont command instead. */ - switch (gdb_ctx->params[0].opcode) { + switch (get_param(params, 0)->opcode) { case 'c': gdbserver_state.c_cpu =3D cpu; put_packet("OK"); @@ -1660,18 +1638,18 @@ static void handle_set_thread(GdbCmdContext *gdb_ct= x, void *user_ctx) } } =20 -static void handle_insert_bp(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_insert_bp(GArray *params, void *user_ctx) { int res; =20 - if (gdb_ctx->num_params !=3D 3) { + if (params->len !=3D 3) { put_packet("E22"); return; } =20 - res =3D gdb_breakpoint_insert(gdb_ctx->params[0].val_ul, - gdb_ctx->params[1].val_ull, - gdb_ctx->params[2].val_ull); + res =3D gdb_breakpoint_insert(get_param(params, 0)->val_ul, + get_param(params, 1)->val_ull, + get_param(params, 2)->val_ull); if (res >=3D 0) { put_packet("OK"); return; @@ -1683,18 +1661,18 @@ static void handle_insert_bp(GdbCmdContext *gdb_ctx= , void *user_ctx) put_packet("E22"); } =20 -static void handle_remove_bp(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_remove_bp(GArray *params, void *user_ctx) { int res; =20 - if (gdb_ctx->num_params !=3D 3) { + if (params->len !=3D 3) { put_packet("E22"); return; } =20 - res =3D gdb_breakpoint_remove(gdb_ctx->params[0].val_ul, - gdb_ctx->params[1].val_ull, - gdb_ctx->params[2].val_ull); + res =3D gdb_breakpoint_remove(get_param(params, 0)->val_ul, + get_param(params, 1)->val_ull, + get_param(params, 2)->val_ull); if (res >=3D 0) { put_packet("OK"); return; @@ -1717,7 +1695,7 @@ static void handle_remove_bp(GdbCmdContext *gdb_ctx, = void *user_ctx) * the remote gdb to fallback to older methods. */ =20 -static void handle_set_reg(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_set_reg(GArray *params, void *user_ctx) { int reg_size; =20 @@ -1726,19 +1704,19 @@ static void handle_set_reg(GdbCmdContext *gdb_ctx, = void *user_ctx) return; } =20 - if (gdb_ctx->num_params !=3D 2) { + if (params->len !=3D 2) { put_packet("E22"); return; } =20 - reg_size =3D strlen(gdb_ctx->params[1].data) / 2; - hextomem(gdbserver_state.mem_buf, gdb_ctx->params[1].data, reg_size); + reg_size =3D strlen(get_param(params, 1)->data) / 2; + hextomem(gdbserver_state.mem_buf, get_param(params, 1)->data, reg_size= ); gdb_write_register(gdbserver_state.g_cpu, gdbserver_state.mem_buf->dat= a, - gdb_ctx->params[0].val_ull); + get_param(params, 0)->val_ull); put_packet("OK"); } =20 -static void handle_get_reg(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_get_reg(GArray *params, void *user_ctx) { int reg_size; =20 @@ -1747,14 +1725,14 @@ static void handle_get_reg(GdbCmdContext *gdb_ctx, = void *user_ctx) return; } =20 - if (!gdb_ctx->num_params) { + if (!params->len) { put_packet("E14"); return; } =20 reg_size =3D gdb_read_register(gdbserver_state.g_cpu, gdbserver_state.mem_buf, - gdb_ctx->params[0].val_ull); + get_param(params, 0)->val_ull); if (!reg_size) { put_packet("E14"); return; @@ -1766,22 +1744,22 @@ static void handle_get_reg(GdbCmdContext *gdb_ctx, = void *user_ctx) put_strbuf(); } =20 -static void handle_write_mem(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_write_mem(GArray *params, void *user_ctx) { - if (gdb_ctx->num_params !=3D 3) { + if (params->len !=3D 3) { put_packet("E22"); return; } =20 /* hextomem() reads 2*len bytes */ - if (gdb_ctx->params[1].val_ull > strlen(gdb_ctx->params[2].data) / 2) { + if (get_param(params, 1)->val_ull > strlen(get_param(params, 2)->data)= / 2) { put_packet("E22"); return; } =20 - hextomem(gdbserver_state.mem_buf, gdb_ctx->params[2].data, - gdb_ctx->params[1].val_ull); - if (target_memory_rw_debug(gdbserver_state.g_cpu, gdb_ctx->params[0].v= al_ull, + hextomem(gdbserver_state.mem_buf, get_param(params, 2)->data, + get_param(params, 1)->val_ull); + if (target_memory_rw_debug(gdbserver_state.g_cpu, get_param(params, 0)= ->val_ull, gdbserver_state.mem_buf->data, gdbserver_state.mem_buf->len, true)) { put_packet("E14"); @@ -1791,22 +1769,22 @@ static void handle_write_mem(GdbCmdContext *gdb_ctx= , void *user_ctx) put_packet("OK"); } =20 -static void handle_read_mem(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_read_mem(GArray *params, void *user_ctx) { - if (gdb_ctx->num_params !=3D 2) { + if (params->len !=3D 2) { put_packet("E22"); return; } =20 /* memtohex() doubles the required space */ - if (gdb_ctx->params[1].val_ull > MAX_PACKET_LENGTH / 2) { + if (get_param(params, 1)->val_ull > MAX_PACKET_LENGTH / 2) { put_packet("E22"); return; } =20 - g_byte_array_set_size(gdbserver_state.mem_buf, gdb_ctx->params[1].val_= ull); + g_byte_array_set_size(gdbserver_state.mem_buf, get_param(params, 1)->v= al_ull); =20 - if (target_memory_rw_debug(gdbserver_state.g_cpu, gdb_ctx->params[0].v= al_ull, + if (target_memory_rw_debug(gdbserver_state.g_cpu, get_param(params, 0)= ->val_ull, gdbserver_state.mem_buf->data, gdbserver_state.mem_buf->len, false)) { put_packet("E14"); @@ -1818,19 +1796,19 @@ static void handle_read_mem(GdbCmdContext *gdb_ctx,= void *user_ctx) put_strbuf(); } =20 -static void handle_write_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_write_all_regs(GArray *params, void *user_ctx) { target_ulong addr, len; uint8_t *registers; int reg_size; =20 - if (!gdb_ctx->num_params) { + if (!params->len) { return; } =20 cpu_synchronize_state(gdbserver_state.g_cpu); - len =3D strlen(gdb_ctx->params[0].data) / 2; - hextomem(gdbserver_state.mem_buf, gdb_ctx->params[0].data, len); + len =3D strlen(get_param(params, 0)->data) / 2; + hextomem(gdbserver_state.mem_buf, get_param(params, 0)->data, len); registers =3D gdbserver_state.mem_buf->data; for (addr =3D 0; addr < gdbserver_state.g_cpu->gdb_num_g_regs && len >= 0; addr++) { @@ -1841,7 +1819,7 @@ static void handle_write_all_regs(GdbCmdContext *gdb_= ctx, void *user_ctx) put_packet("OK"); } =20 -static void handle_read_all_regs(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_read_all_regs(GArray *params, void *user_ctx) { target_ulong addr, len; =20 @@ -1859,14 +1837,14 @@ static void handle_read_all_regs(GdbCmdContext *gdb= _ctx, void *user_ctx) put_strbuf(); } =20 -static void handle_file_io(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_file_io(GArray *params, void *user_ctx) { - if (gdb_ctx->num_params >=3D 1 && gdbserver_state.current_syscall_cb) { + if (params->len >=3D 1 && gdbserver_state.current_syscall_cb) { target_ulong ret, err; =20 - ret =3D (target_ulong)gdb_ctx->params[0].val_ull; - if (gdb_ctx->num_params >=3D 2) { - err =3D (target_ulong)gdb_ctx->params[1].val_ull; + ret =3D (target_ulong)get_param(params, 0)->val_ull; + if (params->len >=3D 2) { + err =3D (target_ulong)get_param(params, 1)->val_ull; } else { err =3D 0; } @@ -1874,7 +1852,7 @@ static void handle_file_io(GdbCmdContext *gdb_ctx, vo= id *user_ctx) gdbserver_state.current_syscall_cb =3D NULL; } =20 - if (gdb_ctx->num_params >=3D 3 && gdb_ctx->params[2].opcode =3D=3D (ui= nt8_t)'C') { + if (params->len >=3D 3 && get_param(params, 2)->opcode =3D=3D (uint8_t= )'C') { put_packet("T02"); return; } @@ -1882,23 +1860,23 @@ static void handle_file_io(GdbCmdContext *gdb_ctx, = void *user_ctx) gdb_continue(); } =20 -static void handle_step(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_step(GArray *params, void *user_ctx) { - if (gdb_ctx->num_params) { - gdb_set_cpu_pc((target_ulong)gdb_ctx->params[0].val_ull); + if (params->len) { + gdb_set_cpu_pc((target_ulong)get_param(params, 0)->val_ull); } =20 cpu_single_step(gdbserver_state.c_cpu, get_sstep_flags()); gdb_continue(); } =20 -static void handle_backward(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_backward(GArray *params, void *user_ctx) { if (replay_mode !=3D REPLAY_MODE_PLAY) { put_packet("E22"); } - if (gdb_ctx->num_params =3D=3D 1) { - switch (gdb_ctx->params[0].opcode) { + if (params->len =3D=3D 1) { + switch (get_param(params, 0)->opcode) { case 's': if (replay_reverse_step()) { gdb_continue(); @@ -1920,20 +1898,20 @@ static void handle_backward(GdbCmdContext *gdb_ctx,= void *user_ctx) put_packet(""); } =20 -static void handle_v_cont_query(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_v_cont_query(GArray *params, void *user_ctx) { put_packet("vCont;c;C;s;S"); } =20 -static void handle_v_cont(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_v_cont(GArray *params, void *user_ctx) { int res; =20 - if (!gdb_ctx->num_params) { + if (!params->len) { return; } =20 - res =3D gdb_handle_vcont(gdb_ctx->params[0].data); + res =3D gdb_handle_vcont(get_param(params, 0)->data); if ((res =3D=3D -EINVAL) || (res =3D=3D -ERANGE)) { put_packet("E22"); } else if (res) { @@ -1941,17 +1919,17 @@ static void handle_v_cont(GdbCmdContext *gdb_ctx, v= oid *user_ctx) } } =20 -static void handle_v_attach(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_v_attach(GArray *params, void *user_ctx) { GDBProcess *process; CPUState *cpu; =20 g_string_assign(gdbserver_state.str_buf, "E22"); - if (!gdb_ctx->num_params) { + if (!params->len) { goto cleanup; } =20 - process =3D gdb_get_process(gdb_ctx->params[0].val_ul); + process =3D gdb_get_process(get_param(params, 0)->val_ul); if (!process) { goto cleanup; } @@ -1972,7 +1950,7 @@ cleanup: put_strbuf(); } =20 -static void handle_v_kill(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_v_kill(GArray *params, void *user_ctx) { /* Kill the target */ put_packet("OK"); @@ -2007,43 +1985,43 @@ static const GdbCmdParseEntry gdb_v_commands_table[= ] =3D { }, }; =20 -static void handle_v_commands(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_v_commands(GArray *params, void *user_ctx) { - if (!gdb_ctx->num_params) { + if (!params->len) { return; } =20 - if (process_string_cmd(NULL, gdb_ctx->params[0].data, + if (process_string_cmd(NULL, get_param(params, 0)->data, gdb_v_commands_table, ARRAY_SIZE(gdb_v_commands_table))) { put_packet(""); } } =20 -static void handle_query_qemu_sstepbits(GdbCmdContext *gdb_ctx, void *user= _ctx) +static void handle_query_qemu_sstepbits(GArray *params, void *user_ctx) { g_string_printf(gdbserver_state.str_buf, "ENABLE=3D%x,NOIRQ=3D%x,NOTIM= ER=3D%x", SSTEP_ENABLE, SSTEP_NOIRQ, SSTEP_NOTIMER); put_strbuf(); } =20 -static void handle_set_qemu_sstep(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_set_qemu_sstep(GArray *params, void *user_ctx) { - if (!gdb_ctx->num_params) { + if (!params->len) { return; } =20 - sstep_flags =3D gdb_ctx->params[0].val_ul; + sstep_flags =3D get_param(params, 0)->val_ul; put_packet("OK"); } =20 -static void handle_query_qemu_sstep(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_query_qemu_sstep(GArray *params, void *user_ctx) { g_string_printf(gdbserver_state.str_buf, "0x%x", sstep_flags); put_strbuf(); } =20 -static void handle_query_curr_tid(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_query_curr_tid(GArray *params, void *user_ctx) { CPUState *cpu; GDBProcess *process; @@ -2060,7 +2038,7 @@ static void handle_query_curr_tid(GdbCmdContext *gdb_= ctx, void *user_ctx) put_strbuf(); } =20 -static void handle_query_threads(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_query_threads(GArray *params, void *user_ctx) { if (!gdbserver_state.query_cpu) { put_packet("l"); @@ -2073,25 +2051,25 @@ static void handle_query_threads(GdbCmdContext *gdb= _ctx, void *user_ctx) gdbserver_state.query_cpu =3D gdb_next_attached_cpu(gdbserver_state.qu= ery_cpu); } =20 -static void handle_query_first_threads(GdbCmdContext *gdb_ctx, void *user_= ctx) +static void handle_query_first_threads(GArray *params, void *user_ctx) { gdbserver_state.query_cpu =3D gdb_first_attached_cpu(); - handle_query_threads(gdb_ctx, user_ctx); + handle_query_threads(params, user_ctx); } =20 -static void handle_query_thread_extra(GdbCmdContext *gdb_ctx, void *user_c= tx) +static void handle_query_thread_extra(GArray *params, void *user_ctx) { g_autoptr(GString) rs =3D g_string_new(NULL); CPUState *cpu; =20 - if (!gdb_ctx->num_params || - gdb_ctx->params[0].thread_id.kind =3D=3D GDB_READ_THREAD_ERR) { + if (!params->len || + get_param(params, 0)->thread_id.kind =3D=3D GDB_READ_THREAD_ERR) { put_packet("E22"); return; } =20 - cpu =3D gdb_get_cpu(gdb_ctx->params[0].thread_id.pid, - gdb_ctx->params[0].thread_id.tid); + cpu =3D gdb_get_cpu(get_param(params, 0)->thread_id.pid, + get_param(params, 0)->thread_id.tid); if (!cpu) { return; } @@ -2116,7 +2094,7 @@ static void handle_query_thread_extra(GdbCmdContext *= gdb_ctx, void *user_ctx) } =20 #ifdef CONFIG_USER_ONLY -static void handle_query_offsets(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_query_offsets(GArray *params, void *user_ctx) { TaskState *ts; =20 @@ -2131,17 +2109,17 @@ static void handle_query_offsets(GdbCmdContext *gdb= _ctx, void *user_ctx) put_strbuf(); } #else -static void handle_query_rcmd(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_query_rcmd(GArray *params, void *user_ctx) { const guint8 zero =3D 0; int len; =20 - if (!gdb_ctx->num_params) { + if (!params->len) { put_packet("E22"); return; } =20 - len =3D strlen(gdb_ctx->params[0].data); + len =3D strlen(get_param(params, 0)->data); if (len % 2) { put_packet("E01"); return; @@ -2149,7 +2127,7 @@ static void handle_query_rcmd(GdbCmdContext *gdb_ctx,= void *user_ctx) =20 g_assert(gdbserver_state.mem_buf->len =3D=3D 0); len =3D len / 2; - hextomem(gdbserver_state.mem_buf, gdb_ctx->params[0].data, len); + hextomem(gdbserver_state.mem_buf, get_param(params, 0)->data, len); g_byte_array_append(gdbserver_state.mem_buf, &zero, 1); qemu_chr_be_write(gdbserver_state.mon_chr, gdbserver_state.mem_buf->da= ta, gdbserver_state.mem_buf->len); @@ -2157,7 +2135,7 @@ static void handle_query_rcmd(GdbCmdContext *gdb_ctx,= void *user_ctx) } #endif =20 -static void handle_query_supported(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_query_supported(GArray *params, void *user_ctx) { CPUClass *cc; =20 @@ -2178,8 +2156,8 @@ static void handle_query_supported(GdbCmdContext *gdb= _ctx, void *user_ctx) } #endif =20 - if (gdb_ctx->num_params && - strstr(gdb_ctx->params[0].data, "multiprocess+")) { + if (params->len && + strstr(get_param(params, 0)->data, "multiprocess+")) { gdbserver_state.multiprocess =3D true; } =20 @@ -2187,7 +2165,7 @@ static void handle_query_supported(GdbCmdContext *gdb= _ctx, void *user_ctx) put_strbuf(); } =20 -static void handle_query_xfer_features(GdbCmdContext *gdb_ctx, void *user_= ctx) +static void handle_query_xfer_features(GArray *params, void *user_ctx) { GDBProcess *process; CPUClass *cc; @@ -2195,7 +2173,7 @@ static void handle_query_xfer_features(GdbCmdContext = *gdb_ctx, void *user_ctx) const char *xml; const char *p; =20 - if (gdb_ctx->num_params < 3) { + if (params->len < 3) { put_packet("E22"); return; } @@ -2208,15 +2186,15 @@ static void handle_query_xfer_features(GdbCmdContex= t *gdb_ctx, void *user_ctx) } =20 gdb_has_xml =3D true; - p =3D gdb_ctx->params[0].data; + p =3D get_param(params, 0)->data; xml =3D get_feature_xml(p, &p, process); if (!xml) { put_packet("E00"); return; } =20 - addr =3D gdb_ctx->params[1].val_ul; - len =3D gdb_ctx->params[2].val_ul; + addr =3D get_param(params, 1)->val_ul; + len =3D get_param(params, 2)->val_ul; total_len =3D strlen(xml); if (addr > total_len) { put_packet("E00"); @@ -2240,18 +2218,18 @@ static void handle_query_xfer_features(GdbCmdContex= t *gdb_ctx, void *user_ctx) } =20 #if defined(CONFIG_USER_ONLY) && defined(CONFIG_LINUX_USER) -static void handle_query_xfer_auxv(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_query_xfer_auxv(GArray *params, void *user_ctx) { TaskState *ts; unsigned long offset, len, saved_auxv, auxv_len; =20 - if (gdb_ctx->num_params < 2) { + if (params->len < 2) { put_packet("E22"); return; } =20 - offset =3D gdb_ctx->params[0].val_ul; - len =3D gdb_ctx->params[1].val_ul; + offset =3D get_param(params, 0)->val_ul; + len =3D get_param(params, 1)->val_ul; ts =3D gdbserver_state.c_cpu->opaque; saved_auxv =3D ts->info->saved_auxv; auxv_len =3D ts->info->auxv_len; @@ -2286,12 +2264,12 @@ static void handle_query_xfer_auxv(GdbCmdContext *g= db_ctx, void *user_ctx) } #endif =20 -static void handle_query_attached(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_query_attached(GArray *params, void *user_ctx) { put_packet(GDB_ATTACHED); } =20 -static void handle_query_qemu_supported(GdbCmdContext *gdb_ctx, void *user= _ctx) +static void handle_query_qemu_supported(GArray *params, void *user_ctx) { g_string_printf(gdbserver_state.str_buf, "sstepbits;sstep"); #ifndef CONFIG_USER_ONLY @@ -2301,21 +2279,21 @@ static void handle_query_qemu_supported(GdbCmdConte= xt *gdb_ctx, void *user_ctx) } =20 #ifndef CONFIG_USER_ONLY -static void handle_query_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx, +static void handle_query_qemu_phy_mem_mode(GArray *params, void *user_ctx) { g_string_printf(gdbserver_state.str_buf, "%d", phy_memory_mode); put_strbuf(); } =20 -static void handle_set_qemu_phy_mem_mode(GdbCmdContext *gdb_ctx, void *use= r_ctx) +static void handle_set_qemu_phy_mem_mode(GArray *params, void *user_ctx) { - if (!gdb_ctx->num_params) { + if (!params->len) { put_packet("E22"); return; } =20 - if (!gdb_ctx->params[0].val_ul) { + if (!get_param(params, 0)->val_ul) { phy_memory_mode =3D 0; } else { phy_memory_mode =3D 1; @@ -2438,45 +2416,45 @@ static const GdbCmdParseEntry gdb_gen_set_table[] = =3D { #endif }; =20 -static void handle_gen_query(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_gen_query(GArray *params, void *user_ctx) { - if (!gdb_ctx->num_params) { + if (!params->len) { return; } =20 - if (!process_string_cmd(NULL, gdb_ctx->params[0].data, + if (!process_string_cmd(NULL, get_param(params, 0)->data, gdb_gen_query_set_common_table, ARRAY_SIZE(gdb_gen_query_set_common_table))) { return; } =20 - if (process_string_cmd(NULL, gdb_ctx->params[0].data, + if (process_string_cmd(NULL, get_param(params, 0)->data, gdb_gen_query_table, ARRAY_SIZE(gdb_gen_query_table))) { put_packet(""); } } =20 -static void handle_gen_set(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_gen_set(GArray *params, void *user_ctx) { - if (!gdb_ctx->num_params) { + if (!params->len) { return; } =20 - if (!process_string_cmd(NULL, gdb_ctx->params[0].data, + if (!process_string_cmd(NULL, get_param(params, 0)->data, gdb_gen_query_set_common_table, ARRAY_SIZE(gdb_gen_query_set_common_table))) { return; } =20 - if (process_string_cmd(NULL, gdb_ctx->params[0].data, + if (process_string_cmd(NULL, get_param(params, 0)->data, gdb_gen_set_table, ARRAY_SIZE(gdb_gen_set_table))) { put_packet(""); } } =20 -static void handle_target_halt(GdbCmdContext *gdb_ctx, void *user_ctx) +static void handle_target_halt(GArray *params, void *user_ctx) { g_string_printf(gdbserver_state.str_buf, "T%02xthread:", GDB_SIGNAL_TR= AP); gdb_append_thread_id(gdbserver_state.c_cpu, gdbserver_state.str_buf); --=20 2.26.3