From patchwork Wed Oct 11 10:33:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 731935 Delivered-To: patch@linaro.org Received: by 2002:a5d:54d1:0:b0:31d:da82:a3b4 with SMTP id x17csp326070wrv; Wed, 11 Oct 2023 03:35:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFqBJ5SCqih1KXORWpItryQ8CJgGA/FaMbLWM5Wyom5kZC52sr+Gd+aqKznb69LIIF7+IeQ X-Received: by 2002:a05:6808:2b0a:b0:3af:e45d:a0ee with SMTP id fe10-20020a0568082b0a00b003afe45da0eemr8499572oib.31.1697020518754; Wed, 11 Oct 2023 03:35:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697020518; cv=none; d=google.com; s=arc-20160816; b=0WHB54+mYtmi3nDmhnhSbi9ZD8rLNFN09TKBuXQx0Jz/fCA+gIXvrb5j7xp1Nfi2ow o7eJ5PSpaUrCaXiqYA/6di+xJABP465kk4kaZuwK1klp3/miPTo+TsQd+PMi6NMldfuR r5y0U8nPW4s5sO/9z8J26kuthN/JeZ3PBlkKHsJd104zYrhxVtJWzSl8tMJ1BySzZZBM HiDC1Z9/AbGGxVMhrfqdniox5cq5fNePZjNwxsc7OJpWgVn7b1+r8HOlAO30EEqeNqKp aSAasDtrMiC7Gjfhq4rW+iUzwrSUB6a8jWNXL8Yl2TTMBqMWj0iDO7tXM0J2emaAQrR/ vXZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Z+7nP3IGdaoip82hIlnEMfS+fdM67SWVcyUnWsux9qo=; fh=w08Nh9X7fSYg7tpzwkfMI5SwivQ42t+PxlOtJWYRP1U=; b=FN2brY0AM34y+sYDkaVRf9w1nUyDnewD5rAohcSVjWqquyKuIRSiEnHgEmHE6cJG4m NRepPHgrrqHOLKAPdlF11YvRbgUsMWVRttEfBNozxrtasfy/iUQIdzaZX78E/GWT69iJ 5dpL7NWAksaqsqC5L8o3YTlbRJwqu7hlpDuImhOfuTnrWSlHCEhyiNLf3aKQASwsUr2B kdrbkZwsfs1gyGKBwJ3tExUM5BUQ8UWWF8SPxm5rIMWy/CDp6WsltErLiVG+taGoz0XX BCSPbai9dc/mTRmL2DaNlYr6nbRpj6UHLJ7MqLSYbYBCBtQvfSAXanLHZjGBOrHbvNyY Xhpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YZE3CG1J; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t2-20020a05622a180200b00419629d080fsi8912146qtc.386.2023.10.11.03.35.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Oct 2023 03:35:18 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YZE3CG1J; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqWXG-0001YI-Qw; Wed, 11 Oct 2023 06:33:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqWXB-0001OP-3w for qemu-devel@nongnu.org; Wed, 11 Oct 2023 06:33:47 -0400 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qqWX7-0005H0-3g for qemu-devel@nongnu.org; Wed, 11 Oct 2023 06:33:44 -0400 Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-503397ee920so8441233e87.1 for ; Wed, 11 Oct 2023 03:33:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697020419; x=1697625219; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Z+7nP3IGdaoip82hIlnEMfS+fdM67SWVcyUnWsux9qo=; b=YZE3CG1JnDa3kGpb+AytELYa5LUtwS9AqcFgHVg5CDW8YyRpbjsVeOffb1TgCQ0jw/ 8Mb8HeNpDllPYn6hwRA96Fk5swYzNeA8hDhVmp8VVgqwNhR4KXHnFGKkRfvFBBTj1XuJ FBNlthE704UQ4Wb5sJdyOth+99ljg8aPruVZz3s8SgNIomIBudIDE138NQN19LVEwTtW OkMLVd/DlFQ1mxGT0IiOw/SDIWeBlsVpDLK5XsJJczNv3KPTeiBc1YHNAxPJJMuoBWq9 Hm03JsASGUH7c+mlAspCJcV7JCrtV01+0avntRvfMetMXcok0aXQMsvm4RBqnW86D38L wa2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697020419; x=1697625219; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z+7nP3IGdaoip82hIlnEMfS+fdM67SWVcyUnWsux9qo=; b=fMmXUemp5Sa+0Wr6ob7HOh/ClD09GVmq+I9Oa2cLNQRsn8Y6vddzA1h6Cj/lyJ7iZP u04WNsCRx4AwEa4yJWy/zmOlk024Z2FxfNIAtRx0aw+8WnyBfOh1T2/dQlINtvNwWEbQ VLJpwpYMfEik7iMArtRZhn4xJKoFtoLSvULnq2+f3xGQA4V/zG57QaAy7aKxRddRK/YP RQCtwXpQkvrKlH6M2c4W9T3GNCDBfjMy9r17Klgv9Wj3Jq/ACqRJuPFkDbn9h0ToE8di C+fwVSUTuObCQBtHcy2bc3HMlEq1/OwD47GXvFQVS3ZDXCx/G48O0+HjimNSugvSBKVc t59w== X-Gm-Message-State: AOJu0YxG18/ya8teRn2Gb950XRoxNg3vfVzoG9mFVR+7FIP/DVL0Vniy tcv7vkjjYN7HYQk0lv49LoKRXw== X-Received: by 2002:a05:6512:ea5:b0:4f8:77db:1d9e with SMTP id bi37-20020a0565120ea500b004f877db1d9emr25721739lfb.12.1697020418927; Wed, 11 Oct 2023 03:33:38 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id 12-20020a05600c024c00b0040531f5c51asm16622591wmj.5.2023.10.11.03.33.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 03:33:35 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 426131FFCB; Wed, 11 Oct 2023 11:33:32 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Alistair Francis , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang Subject: [PULL 19/25] gdbstub: Replace gdb_regs with an array Date: Wed, 11 Oct 2023 11:33:23 +0100 Message-Id: <20231011103329.670525-20-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231011103329.670525-1-alex.bennee@linaro.org> References: <20231011103329.670525-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::131; envelope-from=alex.bennee@linaro.org; helo=mail-lf1-x131.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Akihiko Odaki An array is a more appropriate data structure than a list for gdb_regs since it is initialized only with append operation and read-only after initialization. Signed-off-by: Akihiko Odaki Reviewed-by: Alistair Francis Message-Id: <20230912224107.29669-13-akihiko.odaki@daynix.com> [AJB: fixed a checkpatch violation] Signed-off-by: Alex Bennée Message-Id: <20231009164104.369749-20-alex.bennee@linaro.org> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 7b8347ed5a..3968369554 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -502,7 +502,7 @@ struct CPUState { CPUJumpCache *tb_jmp_cache; - struct GDBRegisterState *gdb_regs; + GArray *gdb_regs; int gdb_num_regs; int gdb_num_g_regs; QTAILQ_ENTRY(CPUState) node; diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 62608a5389..b1532118d1 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -51,7 +51,6 @@ typedef struct GDBRegisterState { gdb_get_reg_cb get_reg; gdb_set_reg_cb set_reg; const char *xml; - struct GDBRegisterState *next; } GDBRegisterState; GDBState gdbserver_state; @@ -386,7 +385,8 @@ static const char *get_feature_xml(const char *p, const char **newp, xml, g_markup_printf_escaped("", cc->gdb_core_xml_file)); - for (r = cpu->gdb_regs; r; r = r->next) { + for (guint i = 0; i < cpu->gdb_regs->len; i++) { + r = &g_array_index(cpu->gdb_regs, GDBRegisterState, i); g_ptr_array_add( xml, g_markup_printf_escaped("", @@ -430,7 +430,8 @@ static int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg) return cc->gdb_read_register(cpu, buf, reg); } - for (r = cpu->gdb_regs; r; r = r->next) { + for (guint i = 0; i < cpu->gdb_regs->len; i++) { + r = &g_array_index(cpu->gdb_regs, GDBRegisterState, i); if (r->base_reg <= reg && reg < r->base_reg + r->num_regs) { return r->get_reg(env, buf, reg - r->base_reg); } @@ -448,7 +449,8 @@ static int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg) return cc->gdb_write_register(cpu, mem_buf, reg); } - for (r = cpu->gdb_regs; r; r = r->next) { + for (guint i = 0; i < cpu->gdb_regs->len; i++) { + r = &g_array_index(cpu->gdb_regs, GDBRegisterState, i); if (r->base_reg <= reg && reg < r->base_reg + r->num_regs) { return r->set_reg(env, mem_buf, reg - r->base_reg); } @@ -461,17 +463,23 @@ void gdb_register_coprocessor(CPUState *cpu, int num_regs, const char *xml, int g_pos) { GDBRegisterState *s; - GDBRegisterState **p; - - p = &cpu->gdb_regs; - while (*p) { - /* Check for duplicates. */ - if (strcmp((*p)->xml, xml) == 0) - return; - p = &(*p)->next; + guint i; + + if (cpu->gdb_regs) { + for (i = 0; i < cpu->gdb_regs->len; i++) { + /* Check for duplicates. */ + s = &g_array_index(cpu->gdb_regs, GDBRegisterState, i); + if (strcmp(s->xml, xml) == 0) { + return; + } + } + } else { + cpu->gdb_regs = g_array_new(false, false, sizeof(GDBRegisterState)); + i = 0; } - s = g_new0(GDBRegisterState, 1); + g_array_set_size(cpu->gdb_regs, i + 1); + s = &g_array_index(cpu->gdb_regs, GDBRegisterState, i); s->base_reg = cpu->gdb_num_regs; s->num_regs = num_regs; s->get_reg = get_reg; @@ -480,7 +488,6 @@ void gdb_register_coprocessor(CPUState *cpu, /* Add to end of list. */ cpu->gdb_num_regs += num_regs; - *p = s; if (g_pos) { if (g_pos != s->base_reg) { error_report("Error: Bad gdb register numbering for '%s', "