From nobody Mon Sep 16 20:07:05 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 ARC-Seal: i=1; a=rsa-sha256; t=1694851583; cv=none; d=zohomail.com; s=zohoarc; b=n2p1zYvwgmnlhO4DSi5UhdcKhPF+LOXNuQzw9mwukcQ7N+zU50Pirw64q/Yiwnq0na8YjRMQ4UfcnN76rb1x+Vj1L3fTW8GLPzrEVmF/Mr452BT8g3cdJXnq7pX6leVHZGsy/XL/aMkkc0jPGrDjXoFmTgrjCJ29A7EH1JmlZNo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694851583; 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=Umo2QdFmj6fXPFRoTffyd5nTftLEatYAZUP0DZd0IXk=; b=f5vmbzB/kBF7XT1OSyMPGm9qsJyUOhJ0WE8RVK9F9XE06Aoa55mgc8QhgAyX8Da7QdDopveUrk42jvXCTT3kg7MwcazuiPRRVSPeEhHbLLOgCbr2GucnjbgRNy0x3N4zuGwN3QGbVaJdTvBwGmrRih2hYn1bkrhquvZmG7v1HAQ= 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 169485158362851.84172171224657; Sat, 16 Sep 2023 01:06:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qhQGX-0003RN-CC; Sat, 16 Sep 2023 04:02:57 -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 1qhQGQ-0003Ki-F8 for qemu-devel@nongnu.org; Sat, 16 Sep 2023 04:02:50 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qhQGN-00062W-5R for qemu-devel@nongnu.org; Sat, 16 Sep 2023 04:02:50 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-68fac16ee5fso2662006b3a.1 for ; Sat, 16 Sep 2023 01:02:46 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id z21-20020aa791d5000000b0068a46cd4120sm4029484pfa.199.2023.09.16.01.02.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 01:02:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1694851366; x=1695456166; 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=Umo2QdFmj6fXPFRoTffyd5nTftLEatYAZUP0DZd0IXk=; b=0sGQIMw+ST65Pj6IzGxdrIMVZ1ZnntXsANHNvit1+7yOr8Q3oHFb5/SOb/fGh0jDL3 3tsqiOrXvz0BZYY6HNelZZFzXg6CysyrLSn+Pb9ZmlgWFxMiVubFRdaN9hWnIfBIcbJa Y0tURQnOZxwPAqZYVYlC/h8hw4uKRaU/CLMHhnMAQcNRX7wg5MOyd9F5O+8deG5iiDxc PmRPBm+EwnHCuvRSElJJdO0+a1FNfy//LF0nOMucS2Cyoa8JecJdp8s7PLLOjuQBZGfG birYB3hKFRDCyZVBpnkxWrw8YK6uQUmoUPE17Mr2QbY2ir6M8Ih4L/kdFTLVNoueLa5V L/Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694851366; x=1695456166; 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=Umo2QdFmj6fXPFRoTffyd5nTftLEatYAZUP0DZd0IXk=; b=jCrmvC5GBb0Sm1cm0S+fW1ymRgE/9gLG4oTvO90QJYg9bhpJqugn+EAYfNhip6/JTo oIEorqY/GFn0OBGDFpESunTic8BvcIXcuwGWYGmtQHa/C8Yjju6RXpIFhb/578fThurM 5iGEuaE2BGAzx11OtiVvZPuZf6vDzE5gRXGQzziWM+hLGYTyN+gjeuUP0qgecAcayH/W Q+utFJokRSLVed0X+D9GwLWR1q0vMA+rBHp0iORZHikaMg6xuiWuXkADn1COEWguyvvt c9hQQh7JQXGNXwmgBLP4oOSy1yFQOPnhKKRscxflIVeIMAMjmqSD4vB0TTA9k/fCR2em DRRw== X-Gm-Message-State: AOJu0YwNSZH+EWWPY6rKcHGfVXwJbv6cBAz3rKRES9K5AVTQ5IqXrDP3 IAL1xfiRUxr80wnUPi0XbZnQOMcbhGrI63YY/Vk= X-Google-Smtp-Source: AGHT+IGRPojV2g8gKZjK340BKV/u64XhdIAbxKAGwh1Y0UMGK9nzVlRZAyJSbkPbRKTG7uxYDyGetA== X-Received: by 2002:a05:6a21:3e09:b0:153:5dd1:219f with SMTP id bk9-20020a056a213e0900b001535dd1219fmr3681374pzc.31.1694851365954; Sat, 16 Sep 2023 01:02:45 -0700 (PDT) From: Akihiko Odaki To: Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mikhail Tyutin , Aleksandr Anenkov , qemu-devel@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Akihiko Odaki Subject: [PATCH v8 10/19] gdbstub: Simplify XML lookup Date: Sat, 16 Sep 2023 17:01:27 +0900 Message-ID: <20230916080149.129989-11-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230916080149.129989-1-akihiko.odaki@daynix.com> References: <20230916080149.129989-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::42d; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42d.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: 1694851585356100002 Content-Type: text/plain; charset="utf-8" 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 --- include/exec/gdbstub.h | 2 + gdbstub/gdbstub.c | 85 +++++++++++++++++++++++------------------- hw/core/cpu-common.c | 5 ++- 3 files changed, 52 insertions(+), 40 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 38b8db29f7..67f363132e 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -26,6 +26,8 @@ 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 +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 fb9f56bd4a..c2afdf20c2 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,10 +380,6 @@ static const char *get_feature_xml(const char *p, cons= t 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)); 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( @@ -398,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 @@ -527,39 +514,61 @@ static int gdb_write_register(CPUState *cpu, uint8_t = *mem_buf, int 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) +{ + guint i =3D cpu->gdb_regs->len; + GDBRegisterState *s; + + g_array_set_size(cpu->gdb_regs, i + 1); + s =3D &g_array_index(cpu->gdb_regs, GDBRegisterState, i); + s->base_reg =3D base_reg; + s->get_reg =3D get_reg; + s->set_reg =3D set_reg; + s->feature =3D feature; +} + +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; - } - } else { - cpu->gdb_regs =3D g_array_new(false, false, sizeof(GDBRegisterStat= e)); - i =3D 0; + 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; } =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 ced66c2b34..88a1d186a6 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" @@ -223,11 +224,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 doesn't have configurable SMP topology */ /* the default value is changed by qemu_init_vcpu() for softmmu */ cpu->nr_cores =3D 1; @@ -247,6 +247,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.42.0