From patchwork Mon Nov 6 18:51:00 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: 741433 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp1255713wrr; Mon, 6 Nov 2023 10:54:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IFZZn5Z4r+DXKxbMHTVzyNhnGllfGEVIfTEnKjKVJqgCK0lPpqnH03S2An2RK63Tb4UF5De X-Received: by 2002:a05:6214:242a:b0:66d:3c8b:5f44 with SMTP id gy10-20020a056214242a00b0066d3c8b5f44mr41818872qvb.27.1699296844652; Mon, 06 Nov 2023 10:54:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699296844; cv=none; d=google.com; s=arc-20160816; b=kgHss1D2Fwqlfr+Vj0LhFB3shOW5SlrBCQv3kmdtpnwbo4Wa3GhFDaDEqDfNGV8CLx O7zSEODWDmqdR5ohTzFPyWtMiwzy7SN09FHDEY6ELvbT9gNgCd3hIKpYidrtNv9T5so5 DxFtw2Z3Ysfd5YhsDKazZI7ptNAQ/UNSygjr1NplHYeRmPOl99qy8kI6xBJTdGGqzyeL wAbdhxh09YOr8/LcAO1HJMUYD/d2q9Zjyii82YqwUWVw99JojJOaXs3kssUVFA7n3A/t 5trLji8jJcda9uK8O/4rIW5St0iR8lUpna7ZowN4JNgTGR0tAG1K7Xqr28dRNfu9dww/ dGlQ== 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=yl+xLH6GlZSHRHLCyoxTrOuqj2ZDEe6hXJbkzkboBr8=; fh=QpeTAvHhnTko3wrHMxWRvx4UcZ87hia2zOY3VJVcfak=; b=raoUtjWhW3IJJSxkxCljLoHxanOtYQxPPw7RvOM9RNorCiaCTAGB0xZXqrBNHQohKI IL9rQNTmbPCUr64+UYXW1QDF9FfRQHYTNC5Kk0UVZXauh8cdXJSONJdnkPYHTXEpAWOE oE5CxpimUtfaLxrY+v7juUaeRxc9a3CLrm0DFQva7XzeRMZZwiwF2OJFsWQgj+MhwXr/ atsYAZC08fnoZ3tr23L/E8HaVjLvYlpqr3n6JurCWt2iFCXiHyPALu6v91XjdeeLjVC6 YWijIvGmFxkJx7URHzyapunmPMrxjTaZByu91V5/st7DDVCR6wjcAjRzHdpN723/6RJJ 7ejg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="HTWe0w/E"; 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 q3-20020a0cfa03000000b0066d1790f92dsi6074855qvn.211.2023.11.06.10.54.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 Nov 2023 10:54:04 -0800 (PST) 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="HTWe0w/E"; 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 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) 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-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) 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) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Peter Maydell , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Laurent Vivier , =?utf-8?q?Alex_Benn=C3=A9e?= , Mahmoud Mandour , Cleber Rosa , Wainer dos Santos Moschetta , Paolo Bonzini , Thomas Huth , Beraldo Leal , Alexandre Iooss , John Snow , =?utf-8?q?Daniel_P=2E_Berrang=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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée 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; +typedef struct GDBFeatureBuilder { + GDBFeature *feature; + GPtrArray *xml; + int base_reg; +} GDBFeatureBuilder; + /* 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); +/** + * 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 *feature, + 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 NULL. + */ +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, const char **newp, return NULL; } +void gdb_feature_builder_init(GDBFeatureBuilder *builder, GDBFeature *feature, + const char *name, const char *xmlname, + int base_reg) +{ + char *header = g_markup_printf_escaped( + "" + "" + "", + name); + + builder->feature = feature; + builder->xml = g_ptr_array_new(); + g_ptr_array_add(builder->xml, header); + builder->base_reg = base_reg; + feature->xmlname = xmlname; + feature->num_regs = 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 = 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 = g_strjoinv(NULL, (void *)builder->xml->pdata); + + for (guint i = 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;