From nobody Tue Feb 10 02:00:22 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1704304147; cv=none; d=zohomail.com; s=zohoarc; b=B76s6jSw50l5M1QFJ+O5Ze01v12PMGqlVzrg3hT80eBAnDeXp5Ch+H/FpcrsHS8i7Z6zzQZ6UlPfJN7sRmRFiO2uj3PmLjkx2bBlxCwXOI44A1n0PkXa5Dn/Mzy2E+HCKS/fF0di1dPQO8vf+psfugRwhU4fHexyln8ZrGOsrF4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704304147; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=s7b3xpykHeaHl4suIRJtcydNJ+7RVLNIDOZxUbbJygc=; b=gH1rKRsBFtzQ3pXsrVOYkza/SHQJxj0tHY3vSU24ZbtOO37imP3HLfoNwQ8eYJFcDZQoGsDmf/Nxou2w8Os6Avg0lPbIBS86Q4MxAjlPP/KXWj1wAPlaGlCsaK9ZyI8EQRqyeHOJKT5jG+6GKmExaVXqaRb0ZIgmKcNUzrpPnVs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704304146961541.4434329158506; Wed, 3 Jan 2024 09:49:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rL5DP-0007fH-IQ; Wed, 03 Jan 2024 12:39:39 -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 1rL5DB-0006Ys-Re for qemu-devel@nongnu.org; Wed, 03 Jan 2024 12:39:26 -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 1rL5Cx-0000fe-RY for qemu-devel@nongnu.org; Wed, 03 Jan 2024 12:39:24 -0500 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3367632ce7bso9142545f8f.2 for ; Wed, 03 Jan 2024 09:39:11 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id j18-20020a5d5652000000b00336ca349bdesm21896679wrw.47.2024.01.03.09.39.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 09:39:08 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 1FA005F9D3; Wed, 3 Jan 2024 17:33:53 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704303550; x=1704908350; 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=s7b3xpykHeaHl4suIRJtcydNJ+7RVLNIDOZxUbbJygc=; b=YzclKS91ROCiEUliPREbJ5vhRAlB73+Wjwf5IUCj09NEb4igPTjVwdzZtGqYJyNB0j pKngCV8XMGc+JaptJLXYKK5bfZ9EcjbIiza2IvHSZILsb9t8PUjGDnYYGfoWDntAQwy8 leW35p4ZsWi+18Ui7IF7BaxMSF18azdmtbT2FhYyjGNLTq9dXRBwKxH8eRrYWuREFdgt iTfKDQ6sxNCEIfvqPLaxXZztRpUBafpsmJXIhi3PjaqApHPscXEvhGfNOEcmTVWYvwCN 5WY2qMZX+NwIxFpC3l43/WT+S0zQUES/hc/kteddsPrrrTkVdG80dZrg6wlnf692WfyC 1Qcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704303550; x=1704908350; 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=s7b3xpykHeaHl4suIRJtcydNJ+7RVLNIDOZxUbbJygc=; b=IlIuhKZIX0ye5aLntQtt65MzicjHda5E9oaWShT3KijD0q4d5w6+TH5uJECagl7Y4h TLE10MYk7lr9SGHA+ym8ZTxqQ7SHBHJ/V/c6LIzH5nSAx5AOIa1nUG3PtF7r60nreKBC Ya1Td+XUQignLXKu/Brfgw9PyHD7W8oZB68091gxhQKj8l2xgbn4+PXOfcEWMRgr2+HD nF+vZrHusnkApKux8P3sjAoshm7ygMtp+4dsQfOh5hWzUDvR0qxMe55k08nz6d8hsXTN Nm2st89xwjZjlfsD0MupAHd4ByKzKeabunjEHedvV+CyTKmjX/TAZgIVRv5HaHtkiEn9 PNyw== X-Gm-Message-State: AOJu0YzAXqCIhyutvJspSbCRMQnMQ3tI/HBERnXWUSKYheNhferxG0p7 VZ90Kvh7jTvDAINMrhd8ye8lH4YxAUpO8Q== X-Google-Smtp-Source: AGHT+IFhVN5CUKKwTQpPFIkvofPSf4XwbYH6uuKyBdKo+vTtyQ3x8fc2E3p+z7+XbMrRJtLtJWYynA== X-Received: by 2002:a05:6000:1845:b0:337:39ee:2b85 with SMTP id c5-20020a056000184500b0033739ee2b85mr3828333wri.104.1704303550198; Wed, 03 Jan 2024 09:39:10 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Richard Henderson , Song Gao , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Aurelien Jarno , Yoshinori Sato , Yanan Wang , Bin Meng , Laurent Vivier , Michael Rolnik , Alexandre Iooss , David Woodhouse , Laurent Vivier , Paolo Bonzini , Brian Cain , Daniel Henrique Barboza , Beraldo Leal , Paul Durrant , Mahmoud Mandour , Thomas Huth , Liu Zhiwei , Cleber Rosa , kvm@vger.kernel.org, Peter Maydell , Wainer dos Santos Moschetta , =?UTF-8?q?Alex=20Benn=C3=A9e?= , qemu-arm@nongnu.org, Weiwei Li , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , John Snow , Daniel Henrique Barboza , Nicholas Piggin , Palmer Dabbelt , Marcel Apfelbaum , Ilya Leoshkevich , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , "Edgar E. Iglesias" , Eduardo Habkost , Pierrick Bouvier , qemu-riscv@nongnu.org, Alistair Francis , Akihiko Odaki Subject: [PATCH v2 37/43] gdbstub: expose api to find registers Date: Wed, 3 Jan 2024 17:33:43 +0000 Message-Id: <20240103173349.398526-38-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240103173349.398526-1-alex.bennee@linaro.org> References: <20240103173349.398526-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1704304147547100001 Expose an internal API to QEMU to return all the registers for a vCPU. The list containing the details required to called gdb_read_register(). Based-on: <20231025093128.33116-15-akihiko.odaki@daynix.com> Cc: Akihiko Odaki Signed-off-by: Alex Benn=C3=A9e --- v2 - just make gdb_get_register_list return everything for a vCPU vAJB: This principle difference is the find registers is a single call which can return a) multiple registers and b) is agnostic to the gdb feature. This is because I haven't so far found any duplicate registers in the system so I thing the regname by itself should be enough. However I do expose the gdb feature name in case the caller wants to do some additional filtering. --- include/exec/gdbstub.h | 47 +++++++++++++++++++++++++++++++++++ gdbstub/gdbstub.c | 56 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 102 insertions(+), 1 deletion(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index da9ddfe54c5..7bddea8259e 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -111,6 +111,53 @@ void gdb_feature_builder_end(const GDBFeatureBuilder *= builder); */ const GDBFeature *gdb_find_static_feature(const char *xmlname); =20 +/** + * gdb_find_feature() - Find a feature associated with a CPU. + * @cpu: The CPU associated with the feature. + * @name: The feature's name. + * + * Return: The feature's number. + */ +int gdb_find_feature(CPUState *cpu, const char *name); + +/** + * gdb_find_feature_register() - Find a register associated with a CPU. + * @cpu: The CPU associated with the register. + * @feature: The feature's number returned by gdb_find_feature(). + * @name: The register's name. + * + * Return: The register's number. + */ +int gdb_find_feature_register(CPUState *cpu, int feature, const char *name= ); + +/** + * gdb_read_register() - Read a register associated with a CPU. + * @cpu: The CPU associated with the register. + * @buf: The buffer that the read register will be appended to. + * @reg: The register's number returned by gdb_find_feature_register(). + * + * Return: The number of read bytes. + */ +int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); + +/** + * typedef GDBRegDesc - a register description from gdbstub + */ +typedef struct { + int gdb_reg; + const char *name; + const char *feature_name; +} GDBRegDesc; + +/** + * gdb_get_register_list() - Return list of all registers for CPU + * @cpu: The CPU being searched + * + * Returns a GArray of GDBRegDesc, caller frees array but not the + * const strings. + */ +GArray *gdb_get_register_list(CPUState *cpu); + void gdb_set_stop_cpu(CPUState *cpu); =20 /* in gdbstub-xml.c, generated by scripts/feature_to_c.py */ diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 420ab2a3766..b0230138246 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -490,7 +490,61 @@ const GDBFeature *gdb_find_static_feature(const char *= xmlname) g_assert_not_reached(); } =20 -static int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg) +int gdb_find_feature(CPUState *cpu, const char *name) +{ + GDBRegisterState *r; + + for (guint i =3D 0; i < cpu->gdb_regs->len; i++) { + r =3D &g_array_index(cpu->gdb_regs, GDBRegisterState, i); + if (!strcmp(name, r->feature->name)) { + return i; + } + } + + return -1; +} + +int gdb_find_feature_register(CPUState *cpu, int feature, const char *name) +{ + GDBRegisterState *r; + + r =3D &g_array_index(cpu->gdb_regs, GDBRegisterState, feature); + + for (int i =3D 0; i < r->feature->num_regs; i++) { + if (r->feature->regs[i] && !strcmp(name, r->feature->regs[i])) { + return r->base_reg + i; + } + } + + return -1; +} + +GArray *gdb_get_register_list(CPUState *cpu) +{ + GArray *results =3D g_array_new(true, true, sizeof(GDBRegDesc)); + + /* registers are only available once the CPU is initialised */ + if (!cpu->gdb_regs) { + return results; + } + + for (int f =3D 0; f < cpu->gdb_regs->len; f++) { + GDBRegisterState *r =3D &g_array_index(cpu->gdb_regs, GDBRegisterS= tate, f); + for (int i =3D 0; i < r->feature->num_regs; i++) { + const char *name =3D r->feature->regs[i]; + GDBRegDesc desc =3D { + r->base_reg + i, + name, + r->feature->name + }; + g_array_append_val(results, desc); + } + } + + return results; +} + +int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg) { CPUClass *cc =3D CPU_GET_CLASS(cpu); GDBRegisterState *r; --=20 2.39.2