From nobody Wed Nov 27 11:51:43 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=1699296843; cv=none; d=zohomail.com; s=zohoarc; b=ChDqYRCVbz4npwvnqStOajajQiunuUkyQ1ZDkHXUaDnPksjmkhsVGogDkuiTHC3twUhV2/l4/bP0W+HyNZSaod051TwHr0sHGYmfo90q0J4hDgluYPOnp8BrJoaAz6dOkV1582H39hZsbkN5SUxNs75gnVmamynUWXkxKv9IV20= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699296843; 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=yl+xLH6GlZSHRHLCyoxTrOuqj2ZDEe6hXJbkzkboBr8=; b=jdPSMcRrro/bI3pKRQLvxeomFXAFou7GeUadMNVoKMg7NtLA9z/MCSn8zmwvVUKB5gxyH5w/vp5MhtoL/SDdxbrw0SZ2fJsU4mQmjv4k9Yjv4ghqQlCr3lZBwD+bBxurxowV9jdqYOhcmLG8u6KCDitOGSJ9Gm7Y2cw2zEmhl6Q= 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 1699296843640859.9923580296739; Mon, 6 Nov 2023 10:54:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r04h2-0005y1-Iu; Mon, 06 Nov 2023 13:51:24 -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 1r04h0-0005tf-Ue for qemu-devel@nongnu.org; Mon, 06 Nov 2023 13:51:22 -0500 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r04gy-0000y3-7C for qemu-devel@nongnu.org; Mon, 06 Nov 2023 13:51:22 -0500 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40853c639abso35600355e9.0 for ; Mon, 06 Nov 2023 10:51:18 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a1-20020a05600c348100b003fe1fe56202sm13473409wmq.33.2023.11.06.10.51.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 10:51:15 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 5D8B16575D; Mon, 6 Nov 2023 18:51:13 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699296678; x=1699901478; 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=yl+xLH6GlZSHRHLCyoxTrOuqj2ZDEe6hXJbkzkboBr8=; b=HTWe0w/E2trBMfOvJhr/ke8uvchwLPtamqy9nvf35mCV/dm1WQi0paW0gMgcnk4une 6jdfufumiEIUqxtxrzbk6uiC72UD9X/UU3DNWNCkADJAdURYNge307/jvtGZ0l0Vb47B eUriogU549cRQ5x4I4i2B5jdfM7TXpMVt2o8V81FE2TJf8YnaiOujJ1aSqscLE+GWd9g 4NJvUJLfqZvBTTfUCbX8vML2VnyrBBI/miuP7Kc1FleKjJy2TNfZ939VZ1Ez6oxyaZqR iQgJ2KZAWYZirwGaLCVf0KCbkaPZo5ZVSDkncz2QLy1z0OkEV4ttDbCg9odcTM3RglFu RepQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699296678; x=1699901478; 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=yl+xLH6GlZSHRHLCyoxTrOuqj2ZDEe6hXJbkzkboBr8=; b=HL/fl9s1avpi04Hs2WK8tNHRSU7ObLFHKejeh743V7TT+ZkiHYLRpSEq1nENxB/ho4 drIAwrNbka41J5cNs3Q7+BYd4Y06Pp59+G/VOQjYGn9GJo6jdbSz2pnCApq8SkMouV9G 3aGGQeV+hBDuaMUSkhVl5U3vglqHLpkgKYcgr/lSwVj0TTpUXaDt8mFt4UpcsCqS4mct 9RmJSZCDwZ3LHcrwlSEqcPJ/URkK8JTqWQL/IFEjTUp1FxrFYoyb9bHVQzHKYqgF+pCh wUTtBMYePRIsaHHsY9ITpln67nVzTSadrHM8MpEglYfQRv5K6oUccx0yb77Ehso7AsJu Gcdg== X-Gm-Message-State: AOJu0YwMPps5bBN8obAC/pIGhvrA34sHg2h2Q/oRRBTKUkpev483bZOT 1z7BWOyn2L4g5zmBexhvtI44Nw== X-Google-Smtp-Source: AGHT+IERBH6Tyizby9keCoCx2ukmTB6iDLQK3sDLo4qV2eWqpzDVKR11jpLnnFabYoAkh6zNWXXr8g== X-Received: by 2002:a05:600c:6011:b0:409:5d7d:b266 with SMTP id az17-20020a05600c601100b004095d7db266mr451625wmb.14.1699296677708; Mon, 06 Nov 2023 10:51:17 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Peter Maydell , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Laurent Vivier , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Mahmoud Mandour , Cleber Rosa , Wainer dos Santos Moschetta , Paolo Bonzini , Thomas Huth , Beraldo Leal , Alexandre Iooss , John Snow , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Chris Wulff , Marek Vasut , Richard Henderson , Akihiko Odaki Subject: [PATCH 10/22] gdbstub: Introduce GDBFeatureBuilder Date: Mon, 6 Nov 2023 18:51:00 +0000 Message-Id: <20231106185112.2755262-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231106185112.2755262-1-alex.bennee@linaro.org> References: <20231106185112.2755262-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::334; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x334.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: 1699296844844100007 From: Akihiko Odaki GDBFeatureBuilder unifies the logic to generate dynamic GDBFeature. Signed-off-by: Akihiko Odaki Reviewed-by: Richard Henderson Message-Id: <20231025093128.33116-4-akihiko.odaki@daynix.com> Signed-off-by: Alex Benn=C3=A9e Message-Id: <20231103195956.1998255-11-alex.bennee@linaro.org> --- include/exec/gdbstub.h | 50 ++++++++++++++++++++++++++++++++ gdbstub/gdbstub.c | 65 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 7fe00506c7..d8a3c56fa2 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -16,6 +16,12 @@ typedef struct GDBFeature { int num_regs; } GDBFeature; =20 +typedef struct GDBFeatureBuilder { + GDBFeature *feature; + GPtrArray *xml; + int base_reg; +} 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); @@ -44,6 +50,50 @@ void gdb_register_coprocessor(CPUState *cpu, */ int gdbserver_start(const char *port_or_device); =20 +/** + * gdb_feature_builder_init() - Initialize GDBFeatureBuilder. + * @builder: The builder to be initialized. + * @feature: The feature to be filled. + * @name: The name of the feature. + * @xmlname: The name of the XML. + * @base_reg: The base number of the register ID. + */ +void gdb_feature_builder_init(GDBFeatureBuilder *builder, GDBFeature *feat= ure, + const char *name, const char *xmlname, + int base_reg); + +/** + * gdb_feature_builder_append_tag() - Append a tag. + * @builder: The builder. + * @format: The format of the tag. + * @...: The values to be formatted. + */ +void G_GNUC_PRINTF(2, 3) +gdb_feature_builder_append_tag(const GDBFeatureBuilder *builder, + const char *format, ...); + +/** + * gdb_feature_builder_append_reg() - Append a register. + * @builder: The builder. + * @name: The register's name; it must be unique within a CPU. + * @bitsize: The register's size, in bits. + * @regnum: The offset of the register's number in the feature. + * @type: The type of the register. + * @group: The register group to which this register belongs; it can be NU= LL. + */ +void gdb_feature_builder_append_reg(const GDBFeatureBuilder *builder, + const char *name, + int bitsize, + int regnum, + const char *type, + const char *group); + +/** + * gdb_feature_builder_end() - End building GDBFeature. + * @builder: The builder. + */ +void gdb_feature_builder_end(const GDBFeatureBuilder *builder); + /** * gdb_find_static_feature() - Find a static feature. * @xmlname: The name of the XML. diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index ae24c4848f..ebb912da1b 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -422,6 +422,71 @@ static const char *get_feature_xml(const char *p, cons= t char **newp, return NULL; } =20 +void gdb_feature_builder_init(GDBFeatureBuilder *builder, GDBFeature *feat= ure, + const char *name, const char *xmlname, + int base_reg) +{ + 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); + builder->base_reg =3D base_reg; + 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); +} + +void gdb_feature_builder_append_reg(const GDBFeatureBuilder *builder, + const char *name, + int bitsize, + int regnum, + const char *type, + const char *group) +{ + if (builder->feature->num_regs < regnum) { + builder->feature->num_regs =3D regnum; + } + + if (group) { + gdb_feature_builder_append_tag( + builder, + "", + name, bitsize, builder->base_reg + regnum, type, group); + } else { + gdb_feature_builder_append_tag( + builder, + "", + name, bitsize, builder->base_reg + regnum, type); + } +} + +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.39.2