From patchwork Fri Feb 23 16:21:47 2024 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: 775161 Delivered-To: patch@linaro.org Received: by 2002:adf:a356:0:b0:33b:4db1:f5b3 with SMTP id d22csp439190wrb; Fri, 23 Feb 2024 08:47:12 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCU2CDErHhsN+eRdOfy6jbkh41EQ/1lp3aob1/sasqrbbTiKnZnZBU903MTLrmHPGkeO+nB6GN39/OlA3vlqZkXs X-Google-Smtp-Source: AGHT+IFhJJ9cBu82Ne1POms7StmtpuFDalIwnLKPeCRIEUVEo9ALT3sh3Nnqli42Ni6Iu+J00HJ5 X-Received: by 2002:a05:620a:1124:b0:787:3abd:f41f with SMTP id p4-20020a05620a112400b007873abdf41fmr663322qkk.24.1708706832246; Fri, 23 Feb 2024 08:47:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708706832; cv=none; d=google.com; s=arc-20160816; b=j/qgBI8UgDWoVKC4BxcvFhip2xei0UxhMHTKyq+2c3LQcJ1QDqQVewylj1/YbZ9KXV BhCDSMV+zo6cwGhUM/lO2tcn02pAuYQJWRWM7yZVN1hM0nBo2DFlRjr/8h9++8OCNJJs dyoIEjSJU5I//nuYs7LpFrv3eKhiWCOm6bhsu3nGilNcEEYnuYzfPSZ2qp4eW2ASmXqq yTXJ2sohxffk1l4zvI+mX9qB2VVqP4qusTI+CkVnyQ2EF9McrHD8JVKKVxU0aJoFDpxN ys84PuhJOJj0i2nbOAbgw5knTcMVHQn4Vf7aZ1sTzav5d3xcBPJkuvaIxdNpXAO1r54r PtDA== 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=BKaOfkzsaddgrw5PBxNyKChRzqPSwV94abl+cum6jxg=; fh=2IXDtwkhE3u9iDHwRQ543d03t9X1toYDqf9u6DZTCZM=; b=BjLkWdO8lwoLawEC4XskHKklU/rXV5Ut0poPE4V+XeGjI8EO9qdKNo/xHIdfig6SU2 vJ+rCmlzLJlxDbi+G9mZvsg+d8G5AAD+XuyQkKlhcTWJj2dbPMqKHKnM5i41e40VpDzd tfKSgLNE3fiBUZNHzXaa3FUIKZrop2zr+2WJovGdaQhUUAT3a1DrcIFpuECnEybOEKSg orEFfuvIf3CBWUKRCyeOipIR4DaunnqVmCxmC4L8XDkdrgYzp9Zz0A+UXNfXLe9ziU2T ZLZPZPckjR/1jtwXML/52CNkAPBxMd26zvqgyEj5xAMymENiXKGv/tWx7Nj39vGqWwbz OZAg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L2bTo2Yb; 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 x8-20020ae9e648000000b00787330d0232si15088975qkl.485.2024.02.23.08.47.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 23 Feb 2024 08:47:12 -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=L2bTo2Yb; 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 1rdYfD-00081B-16; Fri, 23 Feb 2024 11:44:43 -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 1rdYJx-0004I3-KW for qemu-devel@nongnu.org; Fri, 23 Feb 2024 11:22:45 -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 1rdYJU-00068U-Dw for qemu-devel@nongnu.org; Fri, 23 Feb 2024 11:22:45 -0500 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-33d9d43a1eeso734423f8f.2 for ; Fri, 23 Feb 2024 08:22:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708705335; x=1709310135; 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=BKaOfkzsaddgrw5PBxNyKChRzqPSwV94abl+cum6jxg=; b=L2bTo2YbW7yXedVeTbueWofDLdJQhGv/kmhXDF5/S6+NtMyUR1YKurCj0Shav8iFuS gDoG4hvvbCAeiPR0HiHX/MWQ5OU9UwLak/EqH3ACKoV4btMXNd6CZEne69hdEOHG8Ewd q51My5x58ejEOVseGKxff05Q6PPXlCTcnsN6x7s/7sum0OXTw8xWI2MLVGxud03UNMSu Ghzi+XWUhmEpxTo92UNnw6MgPylQPML+q7EDR64pHRO/JBaaMxJjZfSR5lp+RTkB1hUY ELYpOww3KGa2bdWPc2m79poMuTSJdd5sWBUmfCM0QCneqLwduv+nQfHonR2A+qm7+KWy eWIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708705335; x=1709310135; 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=BKaOfkzsaddgrw5PBxNyKChRzqPSwV94abl+cum6jxg=; b=Apdb/nf6diiSJ9MZVr+rh1s05/1q8ZeIwb9u27Ol+9J6fPNMoQQ6o+xf1rC5YZmcjT 6Ti9r4oC+9l7ygSoGsqT3E8jMJPEdH0jG98p2A/YrwZHMZPHN7ciYoZEahDMDYJW4M6M sTntT+9fElN3O0R++M26hU1kAxslGPlfOc9CCH2EBo4PfBCLB2Up3ZgTBO6vSH77AGeP nqM48el8JKi0I7xF6kiJF50Etfv3VcPIKHKkeKiALNjcDfg9s2JFVEiQ9e/5hwEc6jd7 sqpbGnacAE2iTXrm2TihwzwYqeSKzac1g5+R0FLtQAZ2lfKjDbvZjWzRALLk/8Y70ZmV fMYw== X-Gm-Message-State: AOJu0YwU+a7NZbcdYoRdMPKqUSzLQykml/0s7NuNbN02kLDO1Wg8T36Z 7p8i/wkHqp9wEicN/LE4y8lxWZP05q6CCclwg1EEQemI0iXtF6Nm9zq/6Ogz85I= X-Received: by 2002:a05:6000:c91:b0:33d:96c7:ae3d with SMTP id dp17-20020a0560000c9100b0033d96c7ae3dmr168900wrb.16.1708705334967; Fri, 23 Feb 2024 08:22:14 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id f5-20020adff985000000b0033d5aee2ff1sm3226494wrr.97.2024.02.23.08.22.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 08:22:11 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id B9B075F92E; Fri, 23 Feb 2024 16:22:03 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Song Gao , qemu-s390x@nongnu.org, Liu Zhiwei , Pierrick Bouvier , Thomas Huth , Daniel Henrique Barboza , Bin Meng , Yanan Wang , Laurent Vivier , qemu-ppc@nongnu.org, David Hildenbrand , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Ilya Leoshkevich , Cleber Rosa , Nicholas Piggin , Marcel Apfelbaum , Eduardo Habkost , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= , Alexandre Iooss , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Daniel Henrique Barboza , qemu-arm@nongnu.org, qemu-riscv@nongnu.org, Palmer Dabbelt , Mahmoud Mandour , John Snow , Weiwei Li , Alistair Francis , Yoshinori Sato , Brian Cain , Paolo Bonzini , "Edgar E. Iglesias" , Michael Rolnik , Akihiko Odaki Subject: [PATCH v2 12/27] gdbstub: Add members to identify registers to GDBFeature Date: Fri, 23 Feb 2024 16:21:47 +0000 Message-Id: <20240223162202.1936541-13-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240223162202.1936541-1-alex.bennee@linaro.org> References: <20240223162202.1936541-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=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 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 Message-Id: <20240103173349.398526-36-alex.bennee@linaro.org> Message-Id: <20231213-gdb-v17-10-777047380591@daynix.com> Signed-off-by: Alex Bennée --- 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 82a8afa237f..da9ddfe54c5 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 f766ee277a0..a55b5e6581a 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 546e8692d17..be7a02cd903 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 e04d6b2df7f..807af0e685c 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')