[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v17 11/14] gdbstub: Expose functions to read registers
From: |
Akihiko Odaki |
Subject: |
[PATCH v17 11/14] gdbstub: Expose functions to read registers |
Date: |
Wed, 13 Dec 2023 15:41:10 +0900 |
gdb_find_feature() and gdb_find_feature_register() find registers.
gdb_read_register() actually reads registers.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
include/exec/gdbstub.h | 29 +++++++++++++++++++++++++++++
gdbstub/gdbstub.c | 31 ++++++++++++++++++++++++++++++-
2 files changed, 59 insertions(+), 1 deletion(-)
diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h
index da9ddfe54c5b..12336cb60064 100644
--- a/include/exec/gdbstub.h
+++ b/include/exec/gdbstub.h
@@ -111,6 +111,35 @@ 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);
+
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 420ab2a3766b..9db623f1f730 100644
--- a/gdbstub/gdbstub.c
+++ b/gdbstub/gdbstub.c
@@ -490,7 +490,36 @@ 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;
+}
+
+int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg)
{
CPUClass *cc = CPU_GET_CLASS(cpu);
GDBRegisterState *r;
--
2.43.0
- Re: [PATCH v17 04/14] gdbstub: Use GDBFeature for gdb_register_coprocessor, (continued)
- [PATCH v17 05/14] gdbstub: Use GDBFeature for GDBRegisterState, Akihiko Odaki, 2023/12/13
- [PATCH v17 06/14] gdbstub: Change gdb_get_reg_cb and gdb_set_reg_cb, Akihiko Odaki, 2023/12/13
- [PATCH v17 07/14] gdbstub: Simplify XML lookup, Akihiko Odaki, 2023/12/13
- [PATCH v17 08/14] gdbstub: Infer number of core registers from XML, Akihiko Odaki, 2023/12/13
- [PATCH v17 09/14] hw/core/cpu: Remove gdb_get_dynamic_xml member, Akihiko Odaki, 2023/12/13
- [PATCH v17 10/14] gdbstub: Add members to identify registers to GDBFeature, Akihiko Odaki, 2023/12/13
- [PATCH v17 11/14] gdbstub: Expose functions to read registers,
Akihiko Odaki <=
- [PATCH v17 12/14] plugins: Use different helpers when reading registers, Akihiko Odaki, 2023/12/13
- [PATCH v17 13/14] plugins: Allow to read registers, Akihiko Odaki, 2023/12/13
- [PATCH v17 14/14] contrib/plugins: Allow to log registers, Akihiko Odaki, 2023/12/13