From patchwork Mon Sep 25 14:48:43 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: 726035 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2436763wrm; Mon, 25 Sep 2023 08:00:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHHN8HDR/XtFjCLCHuArBmO+mExgEreOmf0DJhJQjNy0wLlm0cfVktcbyEkI2kEG98MI/D+ X-Received: by 2002:a25:d491:0:b0:d1a:955f:304d with SMTP id m139-20020a25d491000000b00d1a955f304dmr6257191ybf.64.1695654043314; Mon, 25 Sep 2023 08:00:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695654043; cv=none; d=google.com; s=arc-20160816; b=nbsHf2617Nq0iw2hW+RpwCX0XeMc1hMDpXJ+QHylab9qlHtB/82jiFUMY06WsS5cZu +vK/dxH1nCZjINLKMR+sKLljLKGSwx2idGj3E6LRSD90gasK5Clzi5+cqcHDQ6APmf0F vKK0RNoNrhpjYIOgwcCgfx4KDwNkmw4s2sKTPSB0r0WTsPuVmxFZyb7KQ7MbM2OZx+A7 Q6m5cclkGqYWYKk6LRi4tWOKbajHM5S+ETBNYZOqlj7eYulnGLTwRei2xFMSKVR6CDuf PhGGep0NeHA/qbsbOXySbO3ZaIhvgdHmQyuqJUzLGD8bw1lcUf02RqGF50//+Ga+4Vtw IAJA== 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=51IOq6TYaNyuJXGEkqG0oju+dqewQYpgGsGyKSLbnRk=; fh=mlkRjkvEMCBvV2NmkuZ9E+MTYOKspqfxSPvD1d2xG14=; b=iduYWiRVY5h1Bm/N8FiLfYivTbvnGgvBiUCxcyJZcSO8cL1LWlWOho0Hz3otob9G8D 6A15i5URuaJ0kxaf3wgUln6lK12OojTFt8/tkoEQFIdI254fswioRFybyFBD/OWvmxJa PNqimednp8tRjweLHCk8l93bWGKJi26Pjd46ksulaRWOARJoVxe6OSfBU1vfrg9XBEJ9 TaM8CoWHNVnIG6sDc5oTMBjwiulUh9INWwISHONobiTRiWadf8vcpPzIYwbneXL9xSrw /jqp1zkJXGFJp76GXm861lgealIVJH9hWcYMiZ7iYJ/hLg9Odx8M4DCMSYWkcW+mtMVZ gOdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lUIDmU+G; 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 b2-20020a0cb3c2000000b0065af2065e52si3575733qvf.345.2023.09.25.08.00.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Sep 2023 08:00:43 -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=lUIDmU+G; 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 1qkn3R-0000Vv-P6; Mon, 25 Sep 2023 10:59:21 -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 1qkn3A-0008TD-Sy for qemu-devel@nongnu.org; Mon, 25 Sep 2023 10:59:08 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qkn2u-0002Hk-RO for qemu-devel@nongnu.org; Mon, 25 Sep 2023 10:59:04 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-405524e6740so43653445e9.1 for ; Mon, 25 Sep 2023 07:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695653927; x=1696258727; 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=51IOq6TYaNyuJXGEkqG0oju+dqewQYpgGsGyKSLbnRk=; b=lUIDmU+GOfcrYZYDX+buNryfjYWavL2LwSgtGANiwd4IZNkpII6H7YV4vPoezdsgK8 mgQL/bBYlcW5SHLdUGEj4lHcVKnBHfZC1b7EkftrUkkexzxRaIRPVKn8i8BLcGxYoXG+ LbpJvqflIDvcwmcOxpT5+s3tB79Lb0A92nfPA5+TiXmYteVeGtc260yT3wAw+gIk/h1w WDRO3ZV/bTh5K9DhNoFFfd+8ejdULoGnTeDRNe9Cb+fLb+/TVlfjMrU0KZrP2ziOt5Ux +4xOg2YIaiWMeSAb6MvGCOv4P8lyfFwXQRyFsAO48RHSyqtZAbUz7Kv0z3fYk9qL6EdU JqMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695653927; x=1696258727; 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=51IOq6TYaNyuJXGEkqG0oju+dqewQYpgGsGyKSLbnRk=; b=Abm4hxLia8ck5QMuYfZ/DSIcY5TrrIZppGTtuDZ/HZT7px0dZ7zyAg4MzFMJBN+cQp n6e+gHvupXgj4HP6Dsh4RVds5Sic3TIm11sGXl/F4mPclr9c4SsuRnsXmsAHEqPTQWCD AHU7fK6GHXSpSVm2F0HXgHK7hSO7Y1c4cwJswqz+ibpqirXikBRD7ldXsaUxz5dAOPNL xcTjKxtfbmp/6fDuZ7MQVzs/KDIo/3q3mANuYxqiV7DLSeN/buRXB+DVfCaVicYscIr4 zU69NseiX+tMywbPHQbjSGiZG/J1I1B6MONXUWaOoDs1l8ONhsazp5uwIqQ+wQq3I2QV WrCQ== X-Gm-Message-State: AOJu0YwEZg10by1io+jZJAcO6BrtfTpFf6A6mDEC38puP7+f5GUZaacW BdQspcgkxXFuBT3efxIsV3q+xw== X-Received: by 2002:adf:f404:0:b0:31f:eb88:e3c8 with SMTP id g4-20020adff404000000b0031feb88e3c8mr6204375wro.32.1695653927087; Mon, 25 Sep 2023 07:58:47 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id s13-20020a5d424d000000b0031753073abcsm12017142wrr.36.2023.09.25.07.58.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 07:58:45 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 7CEA01FFBE; Mon, 25 Sep 2023 15:48:57 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Alistair Francis , =?utf-8?q?C=C3=A9dric_Le_Go?= =?utf-8?q?ater?= , Marcin Juszkiewicz , John Snow , libvir-list@redhat.com, =?utf-8?q?Marc-Andr?= =?utf-8?q?=C3=A9_Lureau?= , qemu-s390x@nongnu.org, Song Gao , Daniel Henrique Barboza , Marcel Apfelbaum , Bastian Koppelmann , Liu Zhiwei , Weiwei Li , Nicholas Piggin , Radoslaw Biernacki , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost , Cleber Rosa , Paolo Bonzini , Mahmoud Mandour , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Thomas Huth , Wainer dos Santos Moschetta , Richard Henderson , Bin Meng , Alexandre Iooss , Xiaojuan Yang , qemu-ppc@nongnu.org, David Hildenbrand , =?utf-8?q?Alex_Benn=C3=A9e?= , Yanan Wang , Peter Maydell , qemu-riscv@nongnu.org, qemu-arm@nongnu.org, Palmer Dabbelt , Ilya Leoshkevich , Laurent Vivier , Yoshinori Sato , Leif Lindholm , Beraldo Leal , Akihiko Odaki Subject: [PATCH 20/31] gdbstub: Replace gdb_regs with an array Date: Mon, 25 Sep 2023 15:48:43 +0100 Message-Id: <20230925144854.1872513-21-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230925144854.1872513-1-alex.bennee@linaro.org> References: <20230925144854.1872513-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32b.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=unavailable 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 Message-Id: <20230912224107.29669-13-akihiko.odaki@daynix.com> [AJB: fixed a checkpatch violation] Signed-off-by: Alex Bennée --- include/hw/core/cpu.h | 2 +- gdbstub/gdbstub.c | 35 +++++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 5ae479a961..0338640e3d 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -364,7 +364,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 177dce9ba2..a041b1c0aa 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', "