From patchwork Fri Nov 3 19:59:37 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: 740710 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp8338wrr; Fri, 3 Nov 2023 13:02:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGi+V7pW2UmY8tvg9X1lH8TywrHRjXu+Fs0d3tf+aZmRSiv07w6fNTGWT4B0ugLcENL4nQ+ X-Received: by 2002:a05:620a:1a91:b0:778:8ce0:221a with SMTP id bl17-20020a05620a1a9100b007788ce0221amr25073042qkb.63.1699041765227; Fri, 03 Nov 2023 13:02:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699041765; cv=none; d=google.com; s=arc-20160816; b=s363olYvtZn4xZKTDaRmRWKUjvC3rVC7SXRKjnT9pFND4KVS+vif662b0LUvr41NNf H4pgUM1YoGrbJ5OxMvMGl55K2gFDkQZsIGjPyMSifOibcIJUxDCng3d+MTyxF8daJTRo V4hwDDPgLjFaYjWmuyz2ZK1190fv386Okgo+meywlCsaaaeZAEcZSW1XkJ/rGjgpzIgi 6X/f2chrzVnpOzZ1XNiHx/xB+xVax3azYgqCPAqPJheiH/txogF21c2fXJjlecg0jM3a 3S+iaf4l9pF4fVCcIoeEOYgJpP5ozajw2R8c7sOy0Gz1ZqTB/8LIKJCHdnCTQQdgdOQT tmGA== 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=xDHxhqQ2TRgZnPkoBNWcXo2iYA2BIDMte92mKl4hAgo=; fh=+DJyABPrPOszaX8covAxj8Yhupz9POTwrYeebio0HgM=; b=LhtZ1++OGqaorll+vYyqhctK/GfGjb7pGb4T9brHqtl1U3uoT2F7mxyNE63k5Ie9hB sixjFP6yHKNP9ilyNOuFpPWocKwuJKprDrG1jtv7VUD1rO9qpwTBCv9l7KsoeeuJGTmF JucU/KLoo5NNN/k9uZ0XEoXB7ikg6IFD3k5twTmirmZz3AAvJfkvPodHpANERwlC98UK w9lUWIGr5T/JZ6Ra1+PYRVW479djvlwo4tiE7jnyPyUVURoR8bASqqz9ph5divqhCirx 5OKk/TCTW5vjmwZhVTAezNMulIeJjL5Cl7uciOuDA1DG5Dq3ZPiyzwuEfVPNkfUE1xeN fosA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PATGqExd; 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 h6-20020a05620a400600b007680efd52bdsi2109313qko.368.2023.11.03.13.02.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 Nov 2023 13:02:45 -0700 (PDT) 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=PATGqExd; 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 1qz0Mm-00021e-Cq; Fri, 03 Nov 2023 16:02:04 -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 1qz0LA-0008ET-Cz for qemu-devel@nongnu.org; Fri, 03 Nov 2023 16:00:32 -0400 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qz0Kv-0005bV-Fz for qemu-devel@nongnu.org; Fri, 03 Nov 2023 16:00:23 -0400 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-5079f3f3d7aso3164441e87.1 for ; Fri, 03 Nov 2023 13:00:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699041608; x=1699646408; 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=xDHxhqQ2TRgZnPkoBNWcXo2iYA2BIDMte92mKl4hAgo=; b=PATGqExd/YclyT1IGLFHKhfMqpTJAQTZsxRtbw2iZo8mUpGukn/rjv0OtTk90vB8fi CAqj6un1VsoI6XLEHoC495Ej52mvj/32N/PZmt/Do6mPtfClQkzPgvo9u6xOxsDX/Z0h 4TjQm4hIqLVg0s5kHYeGA45VIgKVBn9VoxMdgCqv+MxNnUTJBujaIocmtiOmu/P9fwfr kvn571x86AIRIXbjkWgGu2+x4oKcVSOedegES59yDCai3KN3xQuXa4kFijwD7nAozOOE DcfzKH9KfREpLZSezj/qRF9dthRhvjRfyxSbvUst+z4Tx2YtuiZTI9SF9pPvxM4qcY6s 1FBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699041608; x=1699646408; 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=xDHxhqQ2TRgZnPkoBNWcXo2iYA2BIDMte92mKl4hAgo=; b=q2loOLwxFQL7bPJXxqnW6IllaDs1XYhQWkeB28cSyXi+OkiAqUweInzwO+tzyWkm5T +qHJCvW5N5exgBRb7Lw4Z6mDSrblfEfhkRv1n0IUjrXKujKURsdcNunHSsFHovE4s9bO tpe8oBr020adbmwq5wIKjKCWc4TJGEv0KuT7aDstBc4DiYkITeMdD28Z8JgIEccTVta7 ffkGKPbr0ropM5pjrXBLLx2Qv5zWAPu0aaICish6/Z06ksgobjNKv0192/rj6aLgpla0 Fumow3Mkp1GCulbl3OXofO4x/5B+gkRwsLDNx8mQd5wkW3EWp4RX1oqf3BGdGCFKJS79 +ahQ== X-Gm-Message-State: AOJu0YwZpqeXsdoYBewGIjXuTDmbIC2UCnG0TT+4bKNIM0U2VQwgGtPN 1sjS7MpS5SNFGUe5HBDf7xieWA== X-Received: by 2002:a05:6512:3f0f:b0:509:2b81:fc40 with SMTP id y15-20020a0565123f0f00b005092b81fc40mr12879285lfa.9.1699041607681; Fri, 03 Nov 2023 13:00:07 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id h17-20020adff4d1000000b0031c52e81490sm2624408wrp.72.2023.11.03.12.59.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 13:00:00 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id A551965740; Fri, 3 Nov 2023 19:59:57 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Peter Maydell , "Edgar E. Iglesias" , Song Gao , qemu-arm@nongnu.org, =?utf-8?q?Marc-Andr?= =?utf-8?q?=C3=A9_Lureau?= , Wainer dos Santos Moschetta , Weiwei Li , Marcel Apfelbaum , Ilya Leoshkevich , Daniel Henrique Barboza , Yanan Wang , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?C=C3=A9dri?= =?utf-8?q?c_Le_Goater?= , Paolo Bonzini , David Hildenbrand , Brian Cain , qemu-ppc@nongnu.org, Palmer Dabbelt , qemu-riscv@nongnu.org, Eduardo Habkost , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= , Alistair Francis , Liu Zhiwei , Cleber Rosa , qemu-s390x@nongnu.org, Laurent Vivier , Yoshinori Sato , Nicholas Piggin , Thomas Huth , John Snow , Alexandre Iooss , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Mahmoud Mandour , Daniel Henrique Barboza , Bin Meng , Beraldo Leal , Richard Henderson , Michael Rolnik , Akihiko Odaki Subject: [PATCH 10/29] gdbstub: Introduce GDBFeatureBuilder Date: Fri, 3 Nov 2023 19:59:37 +0000 Message-Id: <20231103195956.1998255-11-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231103195956.1998255-1-alex.bennee@linaro.org> References: <20231103195956.1998255-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12a; envelope-from=alex.bennee@linaro.org; helo=mail-lf1-x12a.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 --- 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;