From nobody Tue Feb 10 09:45:06 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=1693717727; cv=none; d=zohomail.com; s=zohoarc; b=HCZpSD5LNZjXgaokAewMS7sXqjhl1w/DFjHIA2v71rPuvXh4+CE7fYZP/A+5B613Q0lexGzWcOt9C/Lh9fT8+PThBq0AeyXSmAu21AWY4VDdLLP5daWxIXymDuRf1v1kiqsKihLCMasy7Vm88QUat23DIfVSgv78Ft2Xx6dz1eQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693717727; 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=dWldEFnlW9A80gzZPMkU/3+GIni4xAZTiT/tj+RWSzA=; b=FCYVBY5aU9X6IHfXy/Bqm8Pp8S9B73ZJDD/N1iL3xsUNXw9WsU6C1PXdGkmIVTDUe/02NdfAKFYKzgnb/DtYT0CLX3YMnIDH83E9brQ8e5kCw0w+L7JpAqkLiCIpVdSKzPgDebrqbgcRam8CQgkpPmYZz0amWOWoW0m9x3oMrjI= 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 169371772729220.59918562175858; Sat, 2 Sep 2023 22:08:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qcfHL-0002hp-9H; Sun, 03 Sep 2023 01:04:07 -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 1qcfHE-0002gJ-Iu for qemu-devel@nongnu.org; Sun, 03 Sep 2023 01:04:01 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qcfHC-0001gQ-8r for qemu-devel@nongnu.org; Sun, 03 Sep 2023 01:04:00 -0400 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-565334377d0so301200a12.2 for ; Sat, 02 Sep 2023 22:03:57 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id l11-20020a170902f68b00b001b8af7f632asm5324835plg.176.2023.09.02.22.03.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Sep 2023 22:03:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1693717436; x=1694322236; 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=dWldEFnlW9A80gzZPMkU/3+GIni4xAZTiT/tj+RWSzA=; b=TKADRALTXPmBl/Phv3jNSeWVkLehmqr14MvD0kXhR/H2yfgzwP+14M6sfj1azpCMOu lhaG6/1eZZo6LBJfGFa3D3KL5RETgX7pH6tsq389whjehL93NN/Mw+0a6FTbG3wUULrv YT8mpGsrCFbcdnMMubpIsXe3M9NtpOW8m4+MIFsUeWw2DmHQjD1/FSyWMJx0hFFos5DR hpPLADpXeIV0CMn0pIqjAd5iBz9Hcop7FLKpdxhkKx57PTa/CPATEGFg0xSJ+ozzPbW3 5IXWO3Jq9v/zRNqLGQd7J7SML0cMSGxRD2Hd9yMwdcS503c7HVmBAg1sI6emVZpeyArg ufsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693717436; x=1694322236; 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=dWldEFnlW9A80gzZPMkU/3+GIni4xAZTiT/tj+RWSzA=; b=d1C02noFm2qLs+JBTS5hZAlB4Gu0nlxasFoBSUokZg5MPeByI/0NS4NaLyX+rCX18W RZh5GanbkUI9UjRTyy00+WC4vaOmeD4RVTj/7mZrUnufumEgXhfq7n51c8Ue6eyyMHxj LlIKmecrrVJiRRNTIJ6gMxC3wN+5AnNcgIT1qe3U5R3QqQLMil0f7gGiRV6IZezjw6wr CXhosHdnU3H+oEBlTptPcny1SI573NPHmhr5vz21iMZQXUZfNhYECfrmMNCln45AhRzd Y77EzwpMT4d2BbG/Uvbx1bkLNyWXoax6AORWt3y7p+/VgBE7rQhQvessvxdjPGfhcjTx yAdw== X-Gm-Message-State: AOJu0YxFCjewJFTyoyMUf8CDz9K4BWCpCSSvAqBEVs7n6/uKswoa2oHe blSZcSUlq4R6NQ/Pz/RSW+nGxQ== X-Google-Smtp-Source: AGHT+IFy+4xBtsIRcra8EsBa0BzPg5coemriiM3MA4ufaqN35EEOg8PG/8KZ51uZ0595Lb3W+M4BJQ== X-Received: by 2002:a17:902:be05:b0:1bb:c06e:647a with SMTP id r5-20020a170902be0500b001bbc06e647amr7712676pls.53.1693717436674; Sat, 02 Sep 2023 22:03:56 -0700 (PDT) From: Akihiko Odaki To: Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mikhail Tyutin , Aleksandr Anenkov , qemu-devel@nongnu.org, Akihiko Odaki , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v6 04/18] gdbstub: Introduce GDBFeatureBuilder Date: Sun, 3 Sep 2023 14:03:12 +0900 Message-ID: <20230903050338.35256-5-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230903050338.35256-1-akihiko.odaki@daynix.com> References: <20230903050338.35256-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::532; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x532.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: 1693717728016100001 Content-Type: text/plain; charset="utf-8" GDBFeatureBuilder unifies the logic to generate dynamic GDBFeature. Signed-off-by: Akihiko Odaki Reviewed-by: Richard Henderson --- include/exec/gdbstub.h | 20 ++++++++++++++ gdbstub/gdbstub.c | 59 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 3091e7a706..1ea2631c24 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -16,6 +16,11 @@ typedef struct GDBFeature { int num_regs; } GDBFeature; =20 +typedef struct GDBFeatureBuilder { + GDBFeature *feature; + GPtrArray *xml; +} GDBFeatureBuilder; + =20 /* Get or set a register. Returns the size of the register. */ typedef int (*gdb_get_reg_cb)(CPUArchState *env, GByteArray *buf, int reg); @@ -34,6 +39,21 @@ void gdb_register_coprocessor(CPUState *cpu, */ int gdbserver_start(const char *port_or_device); =20 +void gdb_feature_builder_init(GDBFeatureBuilder *builder, GDBFeature *feat= ure, + const char *name, const char *xmlname); + +void gdb_feature_builder_append_tag(const GDBFeatureBuilder *builder, + const char *format, ...) + G_GNUC_PRINTF(2, 3); + +int gdb_feature_builder_append_reg(const GDBFeatureBuilder *builder, + const char *name, + int bitsize, + const char *type, + const char *group); + +void gdb_feature_builder_end(const GDBFeatureBuilder *builder); + const GDBFeature *gdb_find_static_feature(const char *xmlname); =20 void gdb_set_stop_cpu(CPUState *cpu); diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 34ef45c94a..6b530f1e1e 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -414,6 +414,65 @@ static const char *get_feature_xml(const char *p, cons= t char **newp, return name ? gdb_static_features[i].xml : NULL; } =20 +void gdb_feature_builder_init(GDBFeatureBuilder *builder, GDBFeature *feat= ure, + const char *name, const char *xmlname) +{ + char *header =3D g_markup_printf_escaped( + "" + "" + "", + name); + + builder->feature =3D feature; + builder->xml =3D g_ptr_array_new(); + g_ptr_array_add(builder->xml, header); + feature->xmlname =3D xmlname; + feature->num_regs =3D 0; +} + +void gdb_feature_builder_append_tag(const GDBFeatureBuilder *builder, + const char *format, ...) +{ + va_list ap; + va_start(ap, format); + g_ptr_array_add(builder->xml, g_markup_vprintf_escaped(format, ap)); + va_end(ap); +} + +int gdb_feature_builder_append_reg(const GDBFeatureBuilder *builder, + const char *name, + int bitsize, + const char *type, + const char *group) +{ + if (group) { + gdb_feature_builder_append_tag( + builder, + "", + name, bitsize, type, group); + } else { + gdb_feature_builder_append_tag( + builder, "", + name, bitsize, type); + } + + return builder->feature->num_regs++; +} + +void gdb_feature_builder_end(const GDBFeatureBuilder *builder) +{ + g_ptr_array_add(builder->xml, (void *)""); + g_ptr_array_add(builder->xml, NULL); + + builder->feature->xml =3D g_strjoinv(NULL, (void *)builder->xml->pdata= ); + + for (guint i =3D 0; i < builder->xml->len - 2; i++) { + g_free(g_ptr_array_index(builder->xml, i)); + } + + g_ptr_array_free(builder->xml, TRUE); +} + const GDBFeature *gdb_find_static_feature(const char *xmlname) { const GDBFeature *feature; --=20 2.42.0