From patchwork Tue Nov 7 14:23:41 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: 741888 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp1646947wrr; Tue, 7 Nov 2023 06:24:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IHH7gmfEsjRI3SxehB9HvvwX+GCBXaw6nUGX72+KLRsaiFg2LLl34T8dWTHUvgshBRzyc2t X-Received: by 2002:a05:600c:198a:b0:402:98cd:a3e9 with SMTP id t10-20020a05600c198a00b0040298cda3e9mr2720960wmq.32.1699367079351; Tue, 07 Nov 2023 06:24:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699367079; cv=none; d=google.com; s=arc-20160816; b=mmbMK+3J2NegBzgcPq7tHNQXrU/6PYIaLyY6wQQniMblW7DG4CYO7nE33VL82v0x1l 2xPEbhsLNveLKcXdRhfJvrr5i/ToChIyuj8Y8aO1eoU8uF4iZyf32SlvjtYQ2Wfsy0Ca 2ZLFLdoZ9yNxMMaYapnw85Mm5OjqNZzACXz/4QkqpZtj+X1K3rcl57LLFBknlddiXInH OAtt9r2BbIVpNRPHTGDSIPbfqkD8HpTmPr9IgJmE5NmxFWljCD6VAI2Y96NmZWcOMCgi epFaM6W/S9b1uoOXYCz2T3VxTk1Hqz4seFTFCX5nEx4tU0+27Aiau7C8Lic2FKKdtpht rCaQ== 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=suLqpGfBVG7ThOgluqJcKn5BkWpm3J+H+wT05/2ihKs=; fh=g0aVkQyE8KKcu7z02J31mxvBAmOhMETLQweDnrZ+tYA=; b=dlUtP2hK5PypWnA4eYdpm8dmUp2UWdmLXXLqXTZ54G1kS+gHH4z/BzfKekbyCf8SW/ xclIyWUIvwOMwcmZ5XXzI5dOZoW/nWCpICprjzoQLPeOEMPcvMBXndJjtnRChY8vl2vW l9nc+noIp+GKIGYYHi+OY9GgUI2ignXnthP5frCplJYofzHOzztBznYS6WZHrXxcOfnI T3ixHB7zmBkQBOfRgaVL8wVLViKi20iMz8++DIqZMXt56Crf6vX9QlREs4aISu4jtyqz 5ViHkNAA6L3w1TkMp+oIdm4eBbxYVKplMRdEc5K+bIUiUSSj5CSGofgOoFAegonMf5On wshA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Cznd68PX; 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 e18-20020a05600c4e5200b004053fe477d0si8560321wmq.76.2023.11.07.06.24.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Nov 2023 06:24:39 -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=Cznd68PX; 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 1r0N0D-0004Lh-Vp; Tue, 07 Nov 2023 09:24:26 -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 1r0Mzw-0004EP-HI for qemu-devel@nongnu.org; Tue, 07 Nov 2023 09:24:09 -0500 Received: from mail-wr1-x42d.google.com ([2a00:1450: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 1r0Mzu-0007Zy-CT for qemu-devel@nongnu.org; Tue, 07 Nov 2023 09:24:07 -0500 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-32fe1a29010so368037f8f.0 for ; Tue, 07 Nov 2023 06:24:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699367044; x=1699971844; 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=suLqpGfBVG7ThOgluqJcKn5BkWpm3J+H+wT05/2ihKs=; b=Cznd68PXxEL7z4536zKvT++fj9n8RO6iWRMHjidE7WuRnTqtUPEVavj9lOoWigUi4d ggrzbvs4wLpDgtGXSTlSewi0YJB8G6gTsNghbvhHqqj686i9/xBDF9SKlT0i8L9JXLN8 30VzxIJ8I5hJTuai6qp/RCVc/M8K4BZO467yrfZDa0gOewfWjnZJdTp7nUVKkZkzzkbV yCvpPoF+3LPUEiIa2nVXYWcbjBc9SfbJWP7L28F+VBsj/jS/btUINid9eFeZsYbHVKQw LUQzWp6Lx4fnZrWo7GvfSlWjjyizaCBW5FseF6Ooq4lYJ4KMNeoMz7lyARfmGxsj72Un tEzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699367044; x=1699971844; 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=suLqpGfBVG7ThOgluqJcKn5BkWpm3J+H+wT05/2ihKs=; b=AX3C7GHxUp03dLEYjiKWaC1VQEgonp33Syo14DCtRtdGv3IZ+7Ws8OxHjaWyJA/eRs Nfa26oRJ/yB6TpvDCbRcN3mS9HKjmdDANEBt4KJysIxfSR7BvxItZTLbP8Mstb8MrvVs BuFXcwXMcHMfEzFmJT/C3XL9Ff8sQyL6NYlny+Yywt5uKEe6pJd7JQHe3eOx6liKND32 xVfc+ihAdKhJ5/2r2/pf6fDXDsrzBGCTQPkc7xCJn8Hh0h+XKHrkvZa8f85XHtJWLvam 76raY6caqdzr12KsiA/ATaj5russlp2KUbRTu1pfGw/gtjbrI3eKqTi2T4M1Qe/0hlF2 upUg== X-Gm-Message-State: AOJu0Yy9ijaxiYfURrZ33I2gEtzxnV4C2Hkc9aXTJMtcB161Tlv4XyW7 j4RU/QeoYJGkShGfEl/fCJ9IMtHbZmvWm9+xHbjwTw== X-Received: by 2002:a5d:6051:0:b0:32d:a4c4:f700 with SMTP id j17-20020a5d6051000000b0032da4c4f700mr22864163wrt.38.1699367043779; Tue, 07 Nov 2023 06:24:03 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id l2-20020a5d4bc2000000b0032da319a27asm2497290wrt.9.2023.11.07.06.23.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Nov 2023 06:23:58 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 82E4765760; Tue, 7 Nov 2023 14:23:55 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Richard Henderson , =?utf-8?q?Alex_Benn=C3=A9?= =?utf-8?q?e?= , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= Subject: [PULL 10/23] gdbstub: Introduce GDBFeatureBuilder Date: Tue, 7 Nov 2023 14:23:41 +0000 Message-Id: <20231107142354.3151266-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231107142354.3151266-1-alex.bennee@linaro.org> References: <20231107142354.3151266-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42d.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=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+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: <20231106185112.2755262-11-alex.bennee@linaro.org> 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;