diff mbox series

[v9,09/27] gdbstub: Implement set register (P pkt) with new infra

Message ID 20190502081554.5521-10-arilou@gmail.com (mailing list archive)
State New, archived
Headers show
Series gdbstub: Refactor command packets handler | expand

Commit Message

Jon Doron May 2, 2019, 8:15 a.m. UTC
Signed-off-by: Jon Doron <arilou@gmail.com>
---
 gdbstub.c | 39 ++++++++++++++++++++++++++++++---------
 1 file changed, 30 insertions(+), 9 deletions(-)

Comments

Alex Bennée May 15, 2019, 12:14 p.m. UTC | #1
Jon Doron <arilou@gmail.com> writes:

> Signed-off-by: Jon Doron <arilou@gmail.com>
> ---
>  gdbstub.c | 39 ++++++++++++++++++++++++++++++---------
>  1 file changed, 30 insertions(+), 9 deletions(-)
>
> diff --git a/gdbstub.c b/gdbstub.c
> index b42425b24c..10e3f12a68 100644
> --- a/gdbstub.c
> +++ b/gdbstub.c
> @@ -1634,6 +1634,27 @@ static void handle_remove_bp(GdbCmdContext *gdb_ctx, void *user_ctx)
>      put_packet(gdb_ctx->s, "E22");
>  }
>
> +static void handle_set_reg(GdbCmdContext *gdb_ctx, void *user_ctx)
> +{
> +    int reg_size;
> +
> +    if (!gdb_has_xml) {
> +        put_packet(gdb_ctx->s, "");
> +        return;
> +    }
> +
> +    if (gdb_ctx->num_params < 2) {

!= 2?

> +        put_packet(gdb_ctx->s, "");
> +        return;
> +    }

I don't understand what these null put_packets have been added for.
Should we not report an E code on failure?

> +
> +    reg_size = strlen(gdb_ctx->params[1].data) / 2;
> +    hextomem(gdb_ctx->mem_buf, gdb_ctx->params[1].data, reg_size);
> +    gdb_write_register(gdb_ctx->s->g_cpu, gdb_ctx->mem_buf,
> +                       gdb_ctx->params[0].val_ull);
> +    put_packet(gdb_ctx->s, "OK");
> +}
> +
>  static int gdb_handle_packet(GDBState *s, const char *line_buf)
>  {
>      CPUState *cpu;
> @@ -1878,15 +1899,15 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)
>          }
>          break;
>      case 'P':
> -        if (!gdb_has_xml)
> -            goto unknown_command;
> -        addr = strtoull(p, (char **)&p, 16);
> -        if (*p == '=')
> -            p++;
> -        reg_size = strlen(p) / 2;
> -        hextomem(mem_buf, p, reg_size);
> -        gdb_write_register(s->g_cpu, mem_buf, addr);
> -        put_packet(s, "OK");
> +        {
> +            static const GdbCmdParseEntry set_reg_cmd_desc = {
> +                .handler = handle_set_reg,
> +                .cmd = "P",
> +                .cmd_startswith = 1,
> +                .schema = "L?s0"
> +            };
> +            cmd_parser = &set_reg_cmd_desc;
> +        }
>          break;
>      case 'Z':
>          {


--
Alex Bennée
Jon Doron May 19, 2019, 10:32 a.m. UTC | #2
You are right but I was under the impression you want the patches to
have the exact same logic of the original code, that why i kept
adding those null packets and the parameter checks to be < N rather than !=

Now that I understand you prefer to fix the implementation ill review
all the patches and add error replays accordingly

-- Jon.

On Wed, May 15, 2019 at 3:14 PM Alex Bennée <alex.bennee@linaro.org> wrote:
>
>
> Jon Doron <arilou@gmail.com> writes:
>
> > Signed-off-by: Jon Doron <arilou@gmail.com>
> > ---
> >  gdbstub.c | 39 ++++++++++++++++++++++++++++++---------
> >  1 file changed, 30 insertions(+), 9 deletions(-)
> >
> > diff --git a/gdbstub.c b/gdbstub.c
> > index b42425b24c..10e3f12a68 100644
> > --- a/gdbstub.c
> > +++ b/gdbstub.c
> > @@ -1634,6 +1634,27 @@ static void handle_remove_bp(GdbCmdContext *gdb_ctx, void *user_ctx)
> >      put_packet(gdb_ctx->s, "E22");
> >  }
> >
> > +static void handle_set_reg(GdbCmdContext *gdb_ctx, void *user_ctx)
> > +{
> > +    int reg_size;
> > +
> > +    if (!gdb_has_xml) {
> > +        put_packet(gdb_ctx->s, "");
> > +        return;
> > +    }
> > +
> > +    if (gdb_ctx->num_params < 2) {
>
> != 2?
>
> > +        put_packet(gdb_ctx->s, "");
> > +        return;
> > +    }
>
> I don't understand what these null put_packets have been added for.
> Should we not report an E code on failure?
>
> > +
> > +    reg_size = strlen(gdb_ctx->params[1].data) / 2;
> > +    hextomem(gdb_ctx->mem_buf, gdb_ctx->params[1].data, reg_size);
> > +    gdb_write_register(gdb_ctx->s->g_cpu, gdb_ctx->mem_buf,
> > +                       gdb_ctx->params[0].val_ull);
> > +    put_packet(gdb_ctx->s, "OK");
> > +}
> > +
> >  static int gdb_handle_packet(GDBState *s, const char *line_buf)
> >  {
> >      CPUState *cpu;
> > @@ -1878,15 +1899,15 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)
> >          }
> >          break;
> >      case 'P':
> > -        if (!gdb_has_xml)
> > -            goto unknown_command;
> > -        addr = strtoull(p, (char **)&p, 16);
> > -        if (*p == '=')
> > -            p++;
> > -        reg_size = strlen(p) / 2;
> > -        hextomem(mem_buf, p, reg_size);
> > -        gdb_write_register(s->g_cpu, mem_buf, addr);
> > -        put_packet(s, "OK");
> > +        {
> > +            static const GdbCmdParseEntry set_reg_cmd_desc = {
> > +                .handler = handle_set_reg,
> > +                .cmd = "P",
> > +                .cmd_startswith = 1,
> > +                .schema = "L?s0"
> > +            };
> > +            cmd_parser = &set_reg_cmd_desc;
> > +        }
> >          break;
> >      case 'Z':
> >          {
>
>
> --
> Alex Bennée
diff mbox series

Patch

diff --git a/gdbstub.c b/gdbstub.c
index b42425b24c..10e3f12a68 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1634,6 +1634,27 @@  static void handle_remove_bp(GdbCmdContext *gdb_ctx, void *user_ctx)
     put_packet(gdb_ctx->s, "E22");
 }
 
+static void handle_set_reg(GdbCmdContext *gdb_ctx, void *user_ctx)
+{
+    int reg_size;
+
+    if (!gdb_has_xml) {
+        put_packet(gdb_ctx->s, "");
+        return;
+    }
+
+    if (gdb_ctx->num_params < 2) {
+        put_packet(gdb_ctx->s, "");
+        return;
+    }
+
+    reg_size = strlen(gdb_ctx->params[1].data) / 2;
+    hextomem(gdb_ctx->mem_buf, gdb_ctx->params[1].data, reg_size);
+    gdb_write_register(gdb_ctx->s->g_cpu, gdb_ctx->mem_buf,
+                       gdb_ctx->params[0].val_ull);
+    put_packet(gdb_ctx->s, "OK");
+}
+
 static int gdb_handle_packet(GDBState *s, const char *line_buf)
 {
     CPUState *cpu;
@@ -1878,15 +1899,15 @@  static int gdb_handle_packet(GDBState *s, const char *line_buf)
         }
         break;
     case 'P':
-        if (!gdb_has_xml)
-            goto unknown_command;
-        addr = strtoull(p, (char **)&p, 16);
-        if (*p == '=')
-            p++;
-        reg_size = strlen(p) / 2;
-        hextomem(mem_buf, p, reg_size);
-        gdb_write_register(s->g_cpu, mem_buf, addr);
-        put_packet(s, "OK");
+        {
+            static const GdbCmdParseEntry set_reg_cmd_desc = {
+                .handler = handle_set_reg,
+                .cmd = "P",
+                .cmd_startswith = 1,
+                .schema = "L?s0"
+            };
+            cmd_parser = &set_reg_cmd_desc;
+        }
         break;
     case 'Z':
         {