[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v7 13/18] gdbstub: Expose functions to read registers
From: |
Akihiko Odaki |
Subject: |
[PATCH v7 13/18] gdbstub: Expose functions to read registers |
Date: |
Tue, 12 Sep 2023 16:11:59 +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 | 5 +++++
gdbstub/gdbstub.c | 50 +++++++++++++++++++++++++++++++++++++++++-
2 files changed, 54 insertions(+), 1 deletion(-)
diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h
index 340ab35d74..e6ba2a2886 100644
--- a/include/exec/gdbstub.h
+++ b/include/exec/gdbstub.h
@@ -69,6 +69,11 @@ void gdb_feature_builder_end(const GDBFeatureBuilder
*builder);
const GDBFeature *gdb_find_static_feature(const char *xmlname);
+int gdb_find_feature(CPUState *cpu, const char *name);
+int gdb_find_feature_register(CPUState *cpu, int feature, const char *name);
+
+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 60faae8b2b..fc780ae6fe 100644
--- a/gdbstub/gdbstub.c
+++ b/gdbstub/gdbstub.c
@@ -492,7 +492,55 @@ 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)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+ GDBRegisterState *r;
+
+ if (!cc->gdb_core_feature) {
+ return -1;
+ }
+
+ if (!strcmp(name, cc->gdb_core_feature->name)) {
+ return 0;
+ }
+
+ 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 + 1;
+ }
+ }
+
+ return -1;
+}
+
+int gdb_find_feature_register(CPUState *cpu, int feature, const char *name)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+ const GDBFeature *p;
+ int base_reg;
+
+ if (feature) {
+ GDBRegisterState *r =
+ &g_array_index(cpu->gdb_regs, GDBRegisterState, feature - 1);
+ p = r->feature;
+ base_reg = r->base_reg;
+ } else {
+ p = cc->gdb_core_feature;
+ base_reg = 0;
+ }
+
+ for (int i = 0; i < p->num_regs; i++) {
+ if (p->regs[i] && !strcmp(name, p->regs[i])) {
+ return base_reg + i;
+ }
+ }
+
+ return -1;
+}
+
+int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg)
{
CPUClass *cc = CPU_GET_CLASS(cpu);
CPUArchState *env = cpu->env_ptr;
--
2.42.0
- [PATCH v7 04/18] gdbstub: Introduce GDBFeatureBuilder, (continued)
- [PATCH v7 04/18] gdbstub: Introduce GDBFeatureBuilder, Akihiko Odaki, 2023/09/12
- [PATCH v7 03/18] hw/core/cpu: Replace gdb_core_xml_file with gdb_core_feature, Akihiko Odaki, 2023/09/12
- [PATCH v7 05/18] target/arm: Use GDBFeature for dynamic XML, Akihiko Odaki, 2023/09/12
- [PATCH v7 06/18] target/ppc: Use GDBFeature for dynamic XML, Akihiko Odaki, 2023/09/12
- [PATCH v7 07/18] target/riscv: Use GDBFeature for dynamic XML, Akihiko Odaki, 2023/09/12
- [PATCH v7 08/18] gdbstub: Use GDBFeature for gdb_register_coprocessor, Akihiko Odaki, 2023/09/12
- [PATCH v7 09/18] gdbstub: Use GDBFeature for GDBRegisterState, Akihiko Odaki, 2023/09/12
- [PATCH v7 10/18] gdbstub: Simplify XML lookup, Akihiko Odaki, 2023/09/12
- [PATCH v7 11/18] hw/core/cpu: Remove gdb_get_dynamic_xml member, Akihiko Odaki, 2023/09/12
- [PATCH v7 12/18] gdbstub: Add members to identify registers to GDBFeature, Akihiko Odaki, 2023/09/12
- [PATCH v7 13/18] gdbstub: Expose functions to read registers,
Akihiko Odaki <=
- [PATCH v7 14/18] cpu: Call plugin hooks only when ready, Akihiko Odaki, 2023/09/12
- [PATCH v7 15/18] plugins: Allow to read registers, Akihiko Odaki, 2023/09/12
- [PATCH v7 16/18] contrib/plugins: Allow to log registers, Akihiko Odaki, 2023/09/12
- [PATCH v7 17/18] plugins: Support C++, Akihiko Odaki, 2023/09/12
- [PATCH v7 18/18] contrib/plugins: Add cc plugin, Akihiko Odaki, 2023/09/12