From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>,
"Akihiko Odaki" <akihiko.odaki@daynix.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PULL 16/22] gdbstub: expose api to find registers
Date: Tue, 16 Jan 2024 10:48:03 +0000 [thread overview]
Message-ID: <20240116104809.250076-17-alex.bennee@linaro.org> (raw)
In-Reply-To: <20240116104809.250076-1-alex.bennee@linaro.org>
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 <akihiko.odaki@daynix.com>
Message-Id: <20240103173349.398526-38-alex.bennee@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
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);
+/**
+ * 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);
/* 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();
}
-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 = 0; i < cpu->gdb_regs->len; i++) {
+ r = &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 = &g_array_index(cpu->gdb_regs, GDBRegisterState, feature);
+
+ for (int i = 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 = 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 = 0; f < cpu->gdb_regs->len; f++) {
+ GDBRegisterState *r = &g_array_index(cpu->gdb_regs, GDBRegisterState, f);
+ for (int i = 0; i < r->feature->num_regs; i++) {
+ const char *name = r->feature->regs[i];
+ GDBRegDesc desc = {
+ 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 = CPU_GET_CLASS(cpu);
GDBRegisterState *r;
--
2.39.2
next prev parent reply other threads:[~2024-01-16 10:49 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-16 10:47 [PULL 00/22] gdb cleanups and tcg plugin register access Alex Bennée
2024-01-16 10:47 ` [PULL 01/22] hw/riscv: Use misa_mxl instead of misa_mxl_max Alex Bennée
2024-01-16 10:47 ` [PULL 02/22] target/riscv: Remove misa_mxl validation Alex Bennée
2024-01-16 10:47 ` [PULL 03/22] target/riscv: Move misa_mxl_max to class Alex Bennée
2024-01-16 10:47 ` [PULL 04/22] target/riscv: Validate misa_mxl_max only once Alex Bennée
2024-01-16 10:47 ` [PULL 05/22] target/arm: Use GDBFeature for dynamic XML Alex Bennée
2024-01-16 10:47 ` [PULL 06/22] target/ppc: " Alex Bennée
2024-01-16 10:47 ` [PULL 07/22] target/riscv: " Alex Bennée
2024-01-16 10:47 ` [PULL 08/22] gdbstub: Use GDBFeature for gdb_register_coprocessor Alex Bennée
2024-01-16 10:47 ` [PULL 09/22] gdbstub: Use GDBFeature for GDBRegisterState Alex Bennée
2024-01-16 10:47 ` [PULL 10/22] gdbstub: Change gdb_get_reg_cb and gdb_set_reg_cb Alex Bennée
2024-01-16 10:47 ` [PULL 11/22] gdbstub: Simplify XML lookup Alex Bennée
2024-01-16 10:47 ` [PULL 12/22] gdbstub: Infer number of core registers from XML Alex Bennée
2024-01-16 10:48 ` [PULL 13/22] hw/core/cpu: Remove gdb_get_dynamic_xml member Alex Bennée
2024-01-16 10:48 ` [PULL 14/22] gdbstub: Add members to identify registers to GDBFeature Alex Bennée
2024-01-16 10:48 ` [PULL 15/22] plugins: Use different helpers when reading registers Alex Bennée
2024-01-16 10:48 ` Alex Bennée [this message]
2024-01-17 7:50 ` [PULL 16/22] gdbstub: expose api to find registers Akihiko Odaki
2024-01-17 15:24 ` Alex Bennée
2024-01-16 10:48 ` [PULL 17/22] plugins: add an API to read registers Alex Bennée
2024-01-17 9:09 ` Akihiko Odaki
2024-01-18 11:38 ` Alex Bennée
2024-01-21 14:36 ` Akihiko Odaki
2024-01-22 9:53 ` Alex Bennée
2024-01-16 10:48 ` [PULL 18/22] contrib/plugins: fix imatch Alex Bennée
2024-01-16 10:48 ` [PULL 19/22] contrib/plugins: extend execlog to track register changes Alex Bennée
2024-01-16 10:48 ` [PULL 20/22] contrib/plugins: optimise the register value tracking Alex Bennée
2024-01-16 10:48 ` [PULL 21/22] docs/devel: lift example and plugin API sections up Alex Bennée
2024-01-16 10:48 ` [PULL 22/22] docs/devel: document some plugin assumptions Alex Bennée
2024-01-18 10:13 ` [PULL 00/22] gdb cleanups and tcg plugin register access Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240116104809.250076-17-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=akihiko.odaki@daynix.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).