From patchwork Wed Dec 13 06:41:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1875484 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=rwkAAkLp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SqmDS46pjz20LT for ; Wed, 13 Dec 2023 17:44:24 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rDIxO-0001E7-CI; Wed, 13 Dec 2023 01:42:58 -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 1rDIxK-00016U-8E for qemu-devel@nongnu.org; Wed, 13 Dec 2023 01:42:55 -0500 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rDIxH-0005bI-4a for qemu-devel@nongnu.org; Wed, 13 Dec 2023 01:42:54 -0500 Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3b8b8372e30so4919839b6e.3 for ; Tue, 12 Dec 2023 22:42:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1702449770; x=1703054570; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=O7ILKFsi9ywq2Ox/zLkxDLDmYoxOoBk7KrvuMPbhQDQ=; b=rwkAAkLptrwlYG/kiX3DlbPqDZZO/WIp4fpTdbdDnqNGkUas1mKdxKBxduguR+HhJC BJWNm3hJriHdqIvEfe54cS+ugpsRHhQq2RIIsJSRNFPArdYw4901bGXBWsHi6At2ypRF xowqIZ0J0VFuf5T1P+qROQ52sv4wALsoeBHWbWpMmZR0tf2XK+UGXVtnJhfc90XXxkrH g20ZscrZsLX/GDPz6NAicJLFQT08OTK0Se+Yc/ljGIg908qU54I/1V0AyZD6Mb1HgiQb vYcpryrNhlvFJQn1Ech54jlFwFA8GYUkgk55UvlY4iw/I9ey/UzrJ6z1HDHcKTuupndZ Y0BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702449770; x=1703054570; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O7ILKFsi9ywq2Ox/zLkxDLDmYoxOoBk7KrvuMPbhQDQ=; b=UvWyN8BqZC+Bhn/oXGA8OxALW0QsJm1MT+hSYAJ2tqyA94sb5+4bm9h6fhfSoPEDiA iJk8VxiA5gpfIr5isMP+7hsGicIjKh90woi0hyfQgbTGEedjPodo4wSyo5ApyE4gyPNC uE8rowWshrbkdNkRNvFXfygrMjebcBXxzHc9cDfp/dwjxOinE0jOylUwmeMQ7r6dqkXz 6xQV9hwpxMFGvkCEJta8kfw1Fnveezx/01wIm/GhluNVKjVc/JjMIICZm3jTf+Acp9OX Kn8ZnEvmqAkpOVqERPuuQrJNBmIgZQgTgrtPs/qtm87QmOLDCk+LxLjEGnaz4y/hbMrQ NYng== X-Gm-Message-State: AOJu0Yytk7DrwRyDyJ2QqX/C1bcAn87HAmfy5GKnpQH/ogsah5ZT+o8X VUaH6tsUh/JRkSoa15ISRQEFDA== X-Google-Smtp-Source: AGHT+IHUJ7Q22Nuyc2efcKTlcrilmy5Waw8Mz2ngDq6p5F8FeZmi9VKxWxy8Xpi/geONyk1DGBQ4XQ== X-Received: by 2002:a05:6808:1a23:b0:3b9:db46:8eec with SMTP id bk35-20020a0568081a2300b003b9db468eecmr9404198oib.3.1702449769859; Tue, 12 Dec 2023 22:42:49 -0800 (PST) Received: from localhost ([157.82.205.15]) by smtp.gmail.com with UTF8SMTPSA id r9-20020a63ec49000000b005b9083b81f0sm9372900pgj.36.2023.12.12.22.42.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 12 Dec 2023 22:42:49 -0800 (PST) From: Akihiko Odaki Date: Wed, 13 Dec 2023 15:41:09 +0900 Subject: [PATCH v17 10/14] gdbstub: Add members to identify registers to GDBFeature MIME-Version: 1.0 Message-Id: <20231213-gdb-v17-10-777047380591@daynix.com> References: <20231213-gdb-v17-0-777047380591@daynix.com> In-Reply-To: <20231213-gdb-v17-0-777047380591@daynix.com> To: Peter Maydell , Nicholas Piggin , Daniel Henrique Barboza , =?utf-8?q?C=C3=A9dric_Le_?= =?utf-8?q?Goater?= , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= , Brian Cain , Song Gao , Laurent Vivier , "Edgar E. Iglesias" , Richard Henderson , David Hildenbrand , Ilya Leoshkevich , Thomas Huth , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Michael Rolnik , Paolo Bonzini , Yoshinori Sato , John Snow , Cleber Rosa , Alexandre Iooss , Mahmoud Mandour , Mikhail Tyutin , Aleksandr Anenkov Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, 20231213-riscv-v7-0-a760156a337f@daynix.com, Akihiko Odaki X-Mailer: b4 0.12.4 Received-SPF: none client-ip=2607:f8b0:4864:20::233; envelope-from=akihiko.odaki@daynix.com; helo=mail-oi1-x233.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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org These members will be used to help plugins to identify registers. The added members in instances of GDBFeature dynamically generated by CPUs will be filled in later changes. Signed-off-by: Akihiko Odaki --- include/exec/gdbstub.h | 3 +++ gdbstub/gdbstub.c | 12 +++++++++--- target/riscv/gdbstub.c | 4 +--- scripts/feature_to_c.py | 14 +++++++++++++- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 82a8afa237f0..da9ddfe54c5b 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -13,12 +13,15 @@ typedef struct GDBFeature { const char *xmlname; const char *xml; + const char *name; + const char * const *regs; int num_regs; } GDBFeature; typedef struct GDBFeatureBuilder { GDBFeature *feature; GPtrArray *xml; + GPtrArray *regs; int base_reg; } GDBFeatureBuilder; diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 801eba9a0b0b..420ab2a3766b 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -419,9 +419,10 @@ void gdb_feature_builder_init(GDBFeatureBuilder *builder, GDBFeature *feature, builder->feature = feature; builder->xml = g_ptr_array_new(); g_ptr_array_add(builder->xml, header); + builder->regs = g_ptr_array_new(); builder->base_reg = base_reg; feature->xmlname = xmlname; - feature->num_regs = 0; + feature->name = name; } void gdb_feature_builder_append_tag(const GDBFeatureBuilder *builder, @@ -440,10 +441,12 @@ void gdb_feature_builder_append_reg(const GDBFeatureBuilder *builder, const char *type, const char *group) { - if (builder->feature->num_regs < regnum) { - builder->feature->num_regs = regnum; + if (builder->regs->len <= regnum) { + g_ptr_array_set_size(builder->regs, regnum + 1); } + builder->regs->pdata[regnum] = (gpointer *)name; + if (group) { gdb_feature_builder_append_tag( builder, @@ -469,6 +472,9 @@ void gdb_feature_builder_end(const GDBFeatureBuilder *builder) } g_ptr_array_free(builder->xml, TRUE); + + builder->feature->num_regs = builder->regs->len; + builder->feature->regs = (void *)g_ptr_array_free(builder->regs, FALSE); } const GDBFeature *gdb_find_static_feature(const char *xmlname) diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c index 68d0fdc1fd6c..d9b52ffd09b6 100644 --- a/target/riscv/gdbstub.c +++ b/target/riscv/gdbstub.c @@ -266,11 +266,9 @@ static GDBFeature *riscv_gen_dynamic_csr_feature(CPUState *cs, int base_reg) } predicate = csr_ops[i].predicate; if (predicate && (predicate(env, i) == RISCV_EXCP_NONE)) { - g_autofree char *dynamic_name = NULL; name = csr_ops[i].name; if (!name) { - dynamic_name = g_strdup_printf("csr%03x", i); - name = dynamic_name; + name = g_strdup_printf("csr%03x", i); } gdb_feature_builder_append_reg(&builder, name, bitsize, i, diff --git a/scripts/feature_to_c.py b/scripts/feature_to_c.py index e04d6b2df7f7..807af0e685c3 100644 --- a/scripts/feature_to_c.py +++ b/scripts/feature_to_c.py @@ -50,7 +50,9 @@ def writeliteral(indent, bytes): sys.stderr.write(f'unexpected start tag: {element.tag}\n') exit(1) + feature_name = element.attrib['name'] regnum = 0 + regnames = [] regnums = [] tags = ['feature'] for event, element in events: @@ -67,6 +69,7 @@ def writeliteral(indent, bytes): if 'regnum' in element.attrib: regnum = int(element.attrib['regnum']) + regnames.append(element.attrib['name']) regnums.append(regnum) regnum += 1 @@ -85,6 +88,15 @@ def writeliteral(indent, bytes): writeliteral(8, bytes(os.path.basename(input), 'utf-8')) sys.stdout.write(',\n') writeliteral(8, read) - sys.stdout.write(f',\n {num_regs},\n }},\n') + sys.stdout.write(',\n') + writeliteral(8, bytes(feature_name, 'utf-8')) + sys.stdout.write(',\n (const char * const []) {\n') + + for index, regname in enumerate(regnames): + sys.stdout.write(f' [{regnums[index] - base_reg}] =\n') + writeliteral(16, bytes(regname, 'utf-8')) + sys.stdout.write(',\n') + + sys.stdout.write(f' }},\n {num_regs},\n }},\n') sys.stdout.write(' { NULL }\n};\n')