[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 36/40] gdbstub: expose api to find registers
From: |
Alex Bennée |
Subject: |
[PATCH 36/40] gdbstub: expose api to find registers |
Date: |
Thu, 21 Dec 2023 10:38:14 +0000 |
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>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
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);
+/**
+ * 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
- [PATCH 08/40] qtest: bump npcm7xx_pwn-test timeout to 5 minutes, (continued)
- [PATCH 08/40] qtest: bump npcm7xx_pwn-test timeout to 5 minutes, Alex Bennée, 2023/12/21
- [PATCH 11/40] qtest: bump prom-env-test timeout to 6 minutes, Alex Bennée, 2023/12/21
- [PATCH 04/40] chardev: use bool for fe_is_open, Alex Bennée, 2023/12/21
- [PATCH 14/40] qtest: bump aspeed_smc-test timeout to 6 minutes, Alex Bennée, 2023/12/21
- [PATCH 13/40] qtest: bump qos-test timeout to 2 minutes, Alex Bennée, 2023/12/21
- [PATCH 12/40] qtest: bump boot-serial-test timeout to 3 minutes, Alex Bennée, 2023/12/21
- [PATCH 19/40] tests/fp: Bump fp-test-mulAdd test timeout to 3 minutes, Alex Bennée, 2023/12/21
- [PATCH 15/40] qtest: bump bios-table-test timeout to 9 minutes, Alex Bennée, 2023/12/21
- [PATCH 09/40] qtest: bump test-hmp timeout to 4 minutes, Alex Bennée, 2023/12/21
- [PATCH 39/40] contrib/plugins: extend execlog to track register changes, Alex Bennée, 2023/12/21
- [PATCH 36/40] gdbstub: expose api to find registers,
Alex Bennée <=
- [PATCH 37/40] plugins: add an API to read registers, Alex Bennée, 2023/12/21
- [PATCH 38/40] contrib/plugins: fix imatch, Alex Bennée, 2023/12/21
- [PATCH 40/40] contrib/plugins: optimise the register value tracking, Alex Bennée, 2023/12/21
- [PATCH 22/40] target/riscv: Remove misa_mxl validation, Alex Bennée, 2023/12/21
- [PATCH 23/40] target/riscv: Move misa_mxl_max to class, Alex Bennée, 2023/12/21
- [PATCH 25/40] target/arm: Use GDBFeature for dynamic XML, Alex Bennée, 2023/12/21
- [PATCH 27/40] target/riscv: Use GDBFeature for dynamic XML, Alex Bennée, 2023/12/21