[PATCH v14 14/18] gdbstub: Expose functions to read registers

Akihiko Odaki posted 18 patches 2 years, 2 months ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, Alexandre Iooss <erdnaxe@crans.org>, Mahmoud Mandour <ma.mandourr@gmail.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Yanan Wang <wangyanan55@huawei.com>, John Snow <jsnow@redhat.com>, Cleber Rosa <crosa@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Michael Rolnik <mrolnik@gmail.com>, Brian Cain <bcain@quicinc.com>, Song Gao <gaosong@loongson.cn>, Laurent Vivier <laurent@vivier.eu>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Nicholas Piggin <npiggin@gmail.com>, Daniel Henrique Barboza <danielhb413@gmail.com>, "Cédric Le Goater" <clg@kaod.org>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Bin Meng <bin.meng@windriver.com>, Weiwei Li <liweiwei@iscas.ac.cn>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Yoshinori Sato <ysato@users.sourceforge.jp>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>, Thomas Huth <thuth@redhat.com>
There is a newer version of this series
[PATCH v14 14/18] gdbstub: Expose functions to read registers
Posted by Akihiko Odaki 2 years, 2 months ago
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      | 31 ++++++++++++++++++++++++++++++-
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h
index 346151d0f2..308b5c266a 100644
--- a/include/exec/gdbstub.h
+++ b/include/exec/gdbstub.h
@@ -74,6 +74,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 fade023559..0b64b93960 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.42.0
Re: [PATCH v14 14/18] gdbstub: Expose functions to read registers
Posted by Alex Bennée 2 years, 2 months ago
Akihiko Odaki <akihiko.odaki@daynix.com> writes:

> 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      | 31 ++++++++++++++++++++++++++++++-
>  2 files changed, 35 insertions(+), 1 deletion(-)
>
> diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h
> index 346151d0f2..308b5c266a 100644
> --- a/include/exec/gdbstub.h
> +++ b/include/exec/gdbstub.h
> @@ -74,6 +74,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);
> +

Can we try to add kdoc comments to the new external facing APIs please.
I should have mentioned that for previous cases as well.

>  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 fade023559..0b64b93960 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;


-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro