From nobody Wed Feb 11 00:36:52 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1694502003; cv=none; d=zohomail.com; s=zohoarc; b=X1rQRxul/z7q4hsasda5f+1TuRsLNDUnwhrHxfAd9Rud3VGP/bqcts7xELztPjirzR8V1YBFHccVJtNEpMd+ZmXvBbGJmmAQcoldjp0/BZVpbfxA0kT6EYprMZMqAZuYJl+XN4zTSu+17JBw461zC4c4yAWI2FvR/M79dmqCbgo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694502003; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject; bh=YR6f2ljT/PkMnpwGwuqVmtD8rXDReW0mqLVfL5y4OQE=; b=J6sj95jWXg8dkJH9Y7vnHUWiC7pJ5O2p2gadiP3FwubElFMC59YtFB0cYX6gm8uudbtPtZ2ldmzwiroPNrRBJ9dfJdQgHsJYgEASrlzPUOcAl5EHIA+kPncVSQ6N1fU/qkVZZuxP/uNPniUIQx0Xpfh9NfXvqiQfZ6xgQmChCow= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694502003932641.856160051296; Tue, 12 Sep 2023 00:00:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qfxMS-00018J-5m; Tue, 12 Sep 2023 02:59:00 -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 1qfxMM-0000ul-Oh for qemu-devel@nongnu.org; Tue, 12 Sep 2023 02:58:55 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qfxMK-0007as-FN for qemu-devel@nongnu.org; Tue, 12 Sep 2023 02:58:54 -0400 Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-273d10d3df3so3305444a91.3 for ; Mon, 11 Sep 2023 23:58:50 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id i8-20020a17090a2ac800b002696aeb72e5sm9315058pjg.2.2023.09.11.23.58.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 23:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1694501929; x=1695106729; 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=YR6f2ljT/PkMnpwGwuqVmtD8rXDReW0mqLVfL5y4OQE=; b=OM+of/Y48FEkCqJOufpI9t1/OzCNnJdKc3O13Eqc3MP++EFysxbREvC0onTvkP8HEk 1Zra+OC+fUy1+faCeFIXigP56MQ3HvGBxZXB0PL855XPJYidwbpMErzbt3oXaqY3QCRQ fR5Ytlzomxdbale4OKwLYI/bL9ea/i6d4A1kSFOqyR2hkRQZFcW8ZjHI0Q3WefSZ5F1H ryN2/fgehZjn1LfySy0liPd/4JjCd/s1f7fNmanzEhORKLxY/CY/hqq9s7D2qVTr7ymC j9zoqSdHTVTQpsDRyIOjLf79qNzF8W9RidZOAUW2k6qNUXf87w+LlGzwaakQ5FBepj3r VhCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694501929; x=1695106729; 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=YR6f2ljT/PkMnpwGwuqVmtD8rXDReW0mqLVfL5y4OQE=; b=SCuK62SxWyM/cRl8HFfNq4bVjN0zglLlNg0u9EcQ8dm/8dxKyHC8iKApENk9aka0BF VUEXJdlCfL7mDKXnXMxnSwjqxpyvj/KnMlOy69HdKItVxtviCFTjmCcO3zc1y3DR2YPf mUHd49r+lOU3DDK83dvNIGv9VmOUsP6VSGHMuHNjJFCeh7PrM3vpvfbKIiJ34ZNDqUXp 7ojZhfwgZQ4A6+EdIv2KWUlPCVoCAbdu0XZaNOnMHO8jPfnZNiCjbB/+YABBPzQZhpiR WsCPudq0vwIY/Kq6skoXPGfQQZJ4adIe44Q4FUP67isbT5IldZOoFyDO74c7izwtcikc ZY6w== X-Gm-Message-State: AOJu0YxhXJLJJjV09fBNcp7gtq/Lzuz+DaIFqR8uktx2Qhv7LC4oaNE2 aT9WVjfZfEXTHQeFbCJKsPUEhA== X-Google-Smtp-Source: AGHT+IF9TOgQPUhoOgxLskBgRqjhDi4h3eqOseqbEVO+VnHesztNvq+S0N4PgK4b1DJ9DyTzhXr8Jw== X-Received: by 2002:a17:90b:1488:b0:268:ac99:4bb4 with SMTP id js8-20020a17090b148800b00268ac994bb4mr9709232pjb.46.1694501929190; Mon, 11 Sep 2023 23:58:49 -0700 (PDT) From: Akihiko Odaki To: Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mikhail Tyutin , Aleksandr Anenkov , qemu-devel@nongnu.org, Akihiko Odaki , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang Subject: [PATCH v2 11/11] gdbstub: Replace gdb_regs with an array Date: Tue, 12 Sep 2023 15:58:06 +0900 Message-ID: <20230912065811.27796-12-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230912065811.27796-1-akihiko.odaki@daynix.com> References: <20230912065811.27796-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::1034; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x1034.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1694502005137100001 Content-Type: text/plain; charset="utf-8" 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 --- include/hw/core/cpu.h | 2 +- gdbstub/gdbstub.c | 34 ++++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 4f5c7eb04e..c84c631242 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -375,7 +375,7 @@ struct CPUState { =20 CPUJumpCache *tb_jmp_cache; =20 - 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 177dce9ba2..9810d15278 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; =20 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 =3D cpu->gdb_regs; r; r =3D r->next) { + for (guint i =3D 0; i < cpu->gdb_regs->len; i++) { + r =3D &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); } =20 - for (r =3D cpu->gdb_regs; r; r =3D r->next) { + for (guint i =3D 0; i < cpu->gdb_regs->len; i++) { + r =3D &g_array_index(cpu->gdb_regs, GDBRegisterState, i); if (r->base_reg <=3D 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 *m= em_buf, int reg) return cc->gdb_write_register(cpu, mem_buf, reg); } =20 - for (r =3D cpu->gdb_regs; r; r =3D r->next) { + for (guint i =3D 0; i < cpu->gdb_regs->len; i++) { + r =3D &g_array_index(cpu->gdb_regs, GDBRegisterState, i); if (r->base_reg <=3D reg && reg < r->base_reg + r->num_regs) { return r->set_reg(env, mem_buf, reg - r->base_reg); } @@ -461,17 +463,22 @@ void gdb_register_coprocessor(CPUState *cpu, int num_regs, const char *xml, int g_pos) { GDBRegisterState *s; - GDBRegisterState **p; - - p =3D &cpu->gdb_regs; - while (*p) { - /* Check for duplicates. */ - if (strcmp((*p)->xml, xml) =3D=3D 0) - return; - p =3D &(*p)->next; + guint i; + + if (cpu->gdb_regs) { + for (i =3D 0; i < cpu->gdb_regs->len; i++) { + /* Check for duplicates. */ + s =3D &g_array_index(cpu->gdb_regs, GDBRegisterState, i); + if (strcmp(s->xml, xml) =3D=3D 0) + return; + } + } else { + cpu->gdb_regs =3D g_array_new(false, false, sizeof(GDBRegisterStat= e)); + i =3D 0; } =20 - s =3D g_new0(GDBRegisterState, 1); + g_array_set_size(cpu->gdb_regs, i + 1); + s =3D &g_array_index(cpu->gdb_regs, GDBRegisterState, i); s->base_reg =3D cpu->gdb_num_regs; s->num_regs =3D num_regs; s->get_reg =3D get_reg; @@ -480,7 +487,6 @@ void gdb_register_coprocessor(CPUState *cpu, =20 /* Add to end of list. */ cpu->gdb_num_regs +=3D num_regs; - *p =3D s; if (g_pos) { if (g_pos !=3D s->base_reg) { error_report("Error: Bad gdb register numbering for '%s', " --=20 2.42.0