@@ -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 */
@@ -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;
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(-)