From nobody Fri Nov 1 07:26:03 2024 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1709045364; cv=none; d=zohomail.com; s=zohoarc; b=CddS0z6DDNx7PRIqvijFjz6plrwEMouy6ea5PjyM6lS98tZ4UWWa+2CPzsU8rTLNkodVmdVqpAdpfDhJbl0o0d5BeuEdrAadLkrEcATTLMatjgL8FjFFe+Pj1pDLQKqom3fcuDL5cwQUE3qiUgIY+v96zUJKDG9mvHI6deTpoqA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709045364; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hxDVqDXi3LGJSJYkq05RZi8ehgH06PAsi/NzuX8UMrA=; b=mz/xpCqUD1tELbij61kpI4vd230S79AOKKXVmPWMfAgJ6ZGnP5JqTWDJRpkayd2MXt3bvulQeqA6j+Hj2vsCJ6i8klBXbx1f4JJWB9c0Qa0gI/mrfu1sDOEbSGs+aX60mmAoiYVui/Eqf1w1dxACi1RI1BWVM/ucRIAzJgXHNsc= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709045364982480.6845241767701; Tue, 27 Feb 2024 06:49:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1reygx-0005zc-1F; Tue, 27 Feb 2024 09:44:23 -0500 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 1reygv-0005vM-Da for qemu-devel@nongnu.org; Tue, 27 Feb 2024 09:44:21 -0500 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reygL-00020O-Eq for qemu-devel@nongnu.org; Tue, 27 Feb 2024 09:44:21 -0500 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-33de4d3483eso1130487f8f.3 for ; Tue, 27 Feb 2024 06:43:44 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id d14-20020a5d538e000000b0033d4deb2356sm11489452wrv.56.2024.02.27.06.43.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 06:43:40 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 88BCC5F90B; Tue, 27 Feb 2024 14:43:36 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709045022; x=1709649822; 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=hxDVqDXi3LGJSJYkq05RZi8ehgH06PAsi/NzuX8UMrA=; b=ugwl+HgRfQh7bL7L0lBDQyRpjUE7qomkfF2LbCJ2wNetpEq3uCSPNdW8xm1PFnhIlV lYWUVM2fcYU5Zt9qUq/HlGsnfYrpJtQ2cVnOePVRFJFgDuq56R2Uv/uTP6tkJChc3+Qr 8ydTCcSX4uW1+D/Bz08yA3yNJTOwxNOfsBRxc0vk1i6n6esykdw7JCvVeezoZ6Ha2AQa Lnf6RWeGWzVbLUJghezzJ/ssWQidMJ96/ticvh8dUtWQvqYxsNQeL0z+2Ci7vxqNSWSq 4ruIt8yzTU0xmXx9M0Okt3PtDvZvNx1nK9cztSyP671LMRb6KZtnlyY44ejNMg3jCsMg YBnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709045022; x=1709649822; 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=hxDVqDXi3LGJSJYkq05RZi8ehgH06PAsi/NzuX8UMrA=; b=Ozs35ryfs37hRdPRye3OY/WxvGwcMYfXp+u/b5T3QxR4BRrI3CFkpJ4ichMQ82R36R gQQ0fpuo0Letm7m1De57EL3toGJvQgd48GOd7xKdjNqa0FetSRZE+XBITk1RP3OIHqR2 Ci+XS2Yau76CgagXVZhODm4q87da/jfx7LbLVmaD+Hcs7jgbqKPwu6L1IU5lK+GEzsXA AGQr0YkbtRyBTIqHAlhv1GOk0M9ASPdbZddQfzpnMhYXkio1j7RKT4w+A15mV4IT5viJ DvkvXxDSxz+enKomywkR4Qb7tLvm9wHqchyjQOUzd1s1uPDVqnYJ9wbasthwOZbWlELQ AdlQ== X-Gm-Message-State: AOJu0YxZidwozrO6BWRSPJtqLnOAmRSFZXy088i/Du895M87bi+znomD eOVkSLgroyCQXPBFtrJSnJcsA/+0rLYX1A6ot6cDiHqCVHr13XINI4l85OC3oiE= X-Google-Smtp-Source: AGHT+IEacG6jW3pkVUqXRpBiljitqFwKN4RhVp1BxiQrkK9uyPw+9aYn2eOY4WuGvU4uG/rtrDLgXA== X-Received: by 2002:adf:ef87:0:b0:33d:a011:ae42 with SMTP id d7-20020adfef87000000b0033da011ae42mr6990698wro.38.1709045022399; Tue, 27 Feb 2024 06:43:42 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-ppc@nongnu.org, Yoshinori Sato , qemu-arm@nongnu.org, Liu Zhiwei , Michael Rolnik , Yanan Wang , Eduardo Habkost , Wainer dos Santos Moschetta , Beraldo Leal , Cleber Rosa , David Hildenbrand , Paolo Bonzini , Peter Maydell , Song Gao , Daniel Henrique Barboza , Laurent Vivier , Warner Losh , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Ilya Leoshkevich , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , qemu-s390x@nongnu.org, Kyle Evans , Brad Smith , Nicholas Piggin , "Edgar E. Iglesias" , Pierrick Bouvier , John Snow , Alistair Francis , Richard Henderson , Brian Cain , Thomas Huth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-riscv@nongnu.org, Bin Meng , Daniel Henrique Barboza , Weiwei Li , Marcel Apfelbaum , Palmer Dabbelt , Mahmoud Mandour , Akihiko Odaki Subject: [PATCH v4 11/29] gdbstub: Simplify XML lookup Date: Tue, 27 Feb 2024 14:43:17 +0000 Message-Id: <20240227144335.1196131-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240227144335.1196131-1-alex.bennee@linaro.org> References: <20240227144335.1196131-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: pass client-ip=2a00:1450:4864:20::433; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x433.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, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1709045366725100003 From: Akihiko Odaki Now we know all instances of GDBFeature that is used in CPU so we can traverse them to find XML. This removes the need for a CPU-specific lookup function for dynamic XMLs. Signed-off-by: Akihiko Odaki Reviewed-by: Alex Benn=C3=A9e Message-Id: <20240103173349.398526-33-alex.bennee@linaro.org> Message-Id: <20231213-gdb-v17-7-777047380591@daynix.com> Signed-off-by: Alex Benn=C3=A9e --- include/exec/gdbstub.h | 6 +++ gdbstub/gdbstub.c | 118 +++++++++++++++++++++-------------------- hw/core/cpu-common.c | 5 +- 3 files changed, 69 insertions(+), 60 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index bcaab1bc750..82a8afa237f 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -27,6 +27,12 @@ typedef struct GDBFeatureBuilder { typedef int (*gdb_get_reg_cb)(CPUState *cpu, GByteArray *buf, int reg); typedef int (*gdb_set_reg_cb)(CPUState *cpu, uint8_t *buf, int reg); =20 +/** + * gdb_init_cpu(): Initialize the CPU for gdbstub. + * @cpu: The CPU to be initialized. + */ +void gdb_init_cpu(CPUState *cpu); + /** * gdb_register_coprocessor() - register a supplemental set of registers * @cpu - the CPU associated with registers diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 486ceb52d2e..d573f808d2e 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -352,6 +352,7 @@ static const char *get_feature_xml(const char *p, const= char **newp, { CPUState *cpu =3D gdb_get_first_cpu_in_process(process); CPUClass *cc =3D CPU_GET_CLASS(cpu); + GDBRegisterState *r; size_t len; =20 /* @@ -365,7 +366,6 @@ static const char *get_feature_xml(const char *p, const= char **newp, /* Is it the main target xml? */ if (strncmp(p, "target.xml", len) =3D=3D 0) { if (!process->target_xml) { - GDBRegisterState *r; g_autoptr(GPtrArray) xml =3D g_ptr_array_new_with_free_func(g_= free); =20 g_ptr_array_add( @@ -380,18 +380,12 @@ static const char *get_feature_xml(const char *p, con= st char **newp, g_markup_printf_escaped("%s", cc->gdb_arch_name(cpu))); } - g_ptr_array_add( - xml, - g_markup_printf_escaped("", - cc->gdb_core_xml_file)); - if (cpu->gdb_regs) { - 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("", - r->feature->xmlname)); - } + 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("", + r->feature->xmlname)); } g_ptr_array_add(xml, g_strdup("")); g_ptr_array_add(xml, NULL); @@ -400,20 +394,11 @@ static const char *get_feature_xml(const char *p, con= st char **newp, } return process->target_xml; } - /* Is it dynamically generated by the target? */ - if (cc->gdb_get_dynamic_xml) { - g_autofree char *xmlname =3D g_strndup(p, len); - const char *xml =3D cc->gdb_get_dynamic_xml(cpu, xmlname); - if (xml) { - return xml; - } - } - /* Is it one of the encoded gdb-xml/ files? */ - for (int i =3D 0; gdb_static_features[i].xmlname; i++) { - const char *name =3D gdb_static_features[i].xmlname; - if ((strncmp(name, p, len) =3D=3D 0) && - strlen(name) =3D=3D len) { - return gdb_static_features[i].xml; + /* Is it one of the features? */ + for (guint i =3D 0; i < cpu->gdb_regs->len; i++) { + r =3D &g_array_index(cpu->gdb_regs, GDBRegisterState, i); + if (strncmp(p, r->feature->xmlname, len) =3D=3D 0) { + return r->feature->xml; } } =20 @@ -508,12 +493,10 @@ static int gdb_read_register(CPUState *cpu, GByteArra= y *buf, int reg) return cc->gdb_read_register(cpu, buf, reg); } =20 - if (cpu->gdb_regs) { - 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->feature->nu= m_regs) { - return r->get_reg(cpu, buf, reg - r->base_reg); - } + 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->feature->num_re= gs) { + return r->get_reg(cpu, buf, reg - r->base_reg); } } return 0; @@ -528,51 +511,70 @@ static int gdb_write_register(CPUState *cpu, uint8_t = *mem_buf, int reg) return cc->gdb_write_register(cpu, mem_buf, reg); } =20 - if (cpu->gdb_regs) { - 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->feature->nu= m_regs) { - return r->set_reg(cpu, mem_buf, reg - r->base_reg); - } + 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->feature->num_re= gs) { + return r->set_reg(cpu, mem_buf, reg - r->base_reg); } } return 0; } =20 +static void gdb_register_feature(CPUState *cpu, int base_reg, + gdb_get_reg_cb get_reg, gdb_set_reg_cb se= t_reg, + const GDBFeature *feature) +{ + GDBRegisterState s =3D { + .base_reg =3D base_reg, + .get_reg =3D get_reg, + .set_reg =3D set_reg, + .feature =3D feature + }; + + g_array_append_val(cpu->gdb_regs, s); +} + +void gdb_init_cpu(CPUState *cpu) +{ + CPUClass *cc =3D CPU_GET_CLASS(cpu); + const GDBFeature *feature; + + cpu->gdb_regs =3D g_array_new(false, false, sizeof(GDBRegisterState)); + + if (cc->gdb_core_xml_file) { + feature =3D gdb_find_static_feature(cc->gdb_core_xml_file); + gdb_register_feature(cpu, 0, + cc->gdb_read_register, cc->gdb_write_register, + feature); + } + + cpu->gdb_num_regs =3D cpu->gdb_num_g_regs =3D cc->gdb_num_core_regs; +} + void gdb_register_coprocessor(CPUState *cpu, gdb_get_reg_cb get_reg, gdb_set_reg_cb set_r= eg, const GDBFeature *feature, int g_pos) { GDBRegisterState *s; guint i; + int base_reg =3D cpu->gdb_num_regs; =20 - 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 (s->feature =3D=3D feature) { - return; - } + for (i =3D 0; i < cpu->gdb_regs->len; i++) { + /* Check for duplicates. */ + s =3D &g_array_index(cpu->gdb_regs, GDBRegisterState, i); + if (s->feature =3D=3D feature) { + return; } - } else { - cpu->gdb_regs =3D g_array_new(false, false, sizeof(GDBRegisterStat= e)); - i =3D 0; } =20 - 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->get_reg =3D get_reg; - s->set_reg =3D set_reg; - s->feature =3D feature; + gdb_register_feature(cpu, base_reg, get_reg, set_reg, feature); =20 /* Add to end of list. */ cpu->gdb_num_regs +=3D feature->num_regs; if (g_pos) { - if (g_pos !=3D s->base_reg) { + if (g_pos !=3D base_reg) { error_report("Error: Bad gdb register numbering for '%s', " - "expected %d got %d", feature->xml, - g_pos, s->base_reg); + "expected %d got %d", feature->xml, g_pos, base_r= eg); } else { cpu->gdb_num_g_regs =3D cpu->gdb_num_regs; } diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index 67db07741d7..fe16d0d9df8 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -27,6 +27,7 @@ #include "qemu/main-loop.h" #include "exec/log.h" #include "exec/cpu-common.h" +#include "exec/gdbstub.h" #include "qemu/error-report.h" #include "qemu/qemu-print.h" #include "sysemu/tcg.h" @@ -240,11 +241,10 @@ static void cpu_common_unrealizefn(DeviceState *dev) static void cpu_common_initfn(Object *obj) { CPUState *cpu =3D CPU(obj); - CPUClass *cc =3D CPU_GET_CLASS(obj); =20 + gdb_init_cpu(cpu); cpu->cpu_index =3D UNASSIGNED_CPU_INDEX; cpu->cluster_index =3D UNASSIGNED_CLUSTER_INDEX; - cpu->gdb_num_regs =3D cpu->gdb_num_g_regs =3D cc->gdb_num_core_regs; /* user-mode doesn't have configurable SMP topology */ /* the default value is changed by qemu_init_vcpu() for system-mode */ cpu->nr_cores =3D 1; @@ -264,6 +264,7 @@ static void cpu_common_finalize(Object *obj) { CPUState *cpu =3D CPU(obj); =20 + g_array_free(cpu->gdb_regs, TRUE); qemu_lockcnt_destroy(&cpu->in_ioctl_lock); qemu_mutex_destroy(&cpu->work_mutex); } --=20 2.39.2