Message ID | 20190424142714.28460-2-arilou@gmail.com |
---|---|
State | New |
Headers | show |
Series | [v3,01/20] gdbstub: Add infrastructure to parse cmd packets | expand |
On 4/24/19 7:26 AM, arilou@gmail.com wrote: > + { > + static GdbCmdParseEntry deatch_cmd_desc = { static const. s/deatch/detach/. That'll require changes to patch 1, since process_string_cmd doesn't take a const GdbCmdParseEntry pointer. > + .handler = handle_detach, > + .cmd = "D", > + .cmd_startswith = 1, > + .schema = "?.l0" > + }; > + process_string_cmd(s, NULL, line_buf, &deatch_cmd_desc, 1); process_string_cmd returns errors, which you make no attempt to handle here. Should the errors returns in fact be asserts? r~
arilou@gmail.com writes: > From: Jon Doron <arilou@gmail.com> > > Signed-otff-by: Jon Doron <arilou@gmail.com> mini typo... (btw you can either create a editor shortcut for adding s-o-b tags or use --signoff while re-basing) Otherwise: Reviewed-by: Alex Bennée <alex.bennee@linaro.org> > --- > gdbstub.c | 82 +++++++++++++++++++++++++++++-------------------------- > 1 file changed, 43 insertions(+), 39 deletions(-) > > diff --git a/gdbstub.c b/gdbstub.c > index b5bd01b913..34e6722a8c 100644 > --- a/gdbstub.c > +++ b/gdbstub.c > @@ -1435,10 +1435,6 @@ static inline int startswith(const char *string, const char *pattern) > return !strncmp(string, pattern, strlen(pattern)); > } > > -__attribute__((unused)) static int process_string_cmd( > - GDBState *s, void *user_ctx, const char *data, > - GdbCmdParseEntry *cmds, int num_cmds); > - > static int process_string_cmd(GDBState *s, void *user_ctx, const char *data, > GdbCmdParseEntry *cmds, int num_cmds) > { > @@ -1483,6 +1479,41 @@ static int process_string_cmd(GDBState *s, void *user_ctx, const char *data, > return -1; > } > > +static void handle_detach(GdbCmdContext *gdb_ctx, void *user_ctx) > +{ > + GDBProcess *process; > + GDBState *s = gdb_ctx->s; > + uint32_t pid = 1; > + > + if (s->multiprocess) { > + if (!gdb_ctx->num_params) { > + put_packet(s, "E22"); > + return; > + } > + > + pid = gdb_ctx->params[0].val_ul; > + } > + > + process = gdb_get_process(s, pid); > + gdb_process_breakpoint_remove_all(s, process); > + process->attached = false; > + > + if (pid == gdb_get_cpu_pid(s, s->c_cpu)) { > + s->c_cpu = gdb_first_attached_cpu(s); > + } > + > + if (pid == gdb_get_cpu_pid(s, s->g_cpu)) { > + s->g_cpu = gdb_first_attached_cpu(s); > + } > + > + if (!s->c_cpu) { > + /* No more process attached */ > + gdb_syscall_mode = GDB_SYS_DISABLED; > + gdb_continue(s); > + } > + put_packet(s, "OK"); > +} > + > static int gdb_handle_packet(GDBState *s, const char *line_buf) > { > CPUState *cpu; > @@ -1597,42 +1628,15 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) > error_report("QEMU: Terminated via GDBstub"); > exit(0); > case 'D': > - /* Detach packet */ > - pid = 1; > - > - if (s->multiprocess) { > - unsigned long lpid; > - if (*p != ';') { > - put_packet(s, "E22"); > - break; > - } > - > - if (qemu_strtoul(p + 1, &p, 16, &lpid)) { > - put_packet(s, "E22"); > - break; > - } > - > - pid = lpid; > - } > - > - process = gdb_get_process(s, pid); > - gdb_process_breakpoint_remove_all(s, process); > - process->attached = false; > - > - if (pid == gdb_get_cpu_pid(s, s->c_cpu)) { > - s->c_cpu = gdb_first_attached_cpu(s); > - } > - > - if (pid == gdb_get_cpu_pid(s, s->g_cpu)) { > - s->g_cpu = gdb_first_attached_cpu(s); > - } > - > - if (s->c_cpu == NULL) { > - /* No more process attached */ > - gdb_syscall_mode = GDB_SYS_DISABLED; > - gdb_continue(s); > + { > + static GdbCmdParseEntry deatch_cmd_desc = { > + .handler = handle_detach, > + .cmd = "D", > + .cmd_startswith = 1, > + .schema = "?.l0" > + }; > + process_string_cmd(s, NULL, line_buf, &deatch_cmd_desc, 1); > } > - put_packet(s, "OK"); > break; > case 's': > if (*p != '\0') { -- Alex Bennée
diff --git a/gdbstub.c b/gdbstub.c index b5bd01b913..34e6722a8c 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1435,10 +1435,6 @@ static inline int startswith(const char *string, const char *pattern) return !strncmp(string, pattern, strlen(pattern)); } -__attribute__((unused)) static int process_string_cmd( - GDBState *s, void *user_ctx, const char *data, - GdbCmdParseEntry *cmds, int num_cmds); - static int process_string_cmd(GDBState *s, void *user_ctx, const char *data, GdbCmdParseEntry *cmds, int num_cmds) { @@ -1483,6 +1479,41 @@ static int process_string_cmd(GDBState *s, void *user_ctx, const char *data, return -1; } +static void handle_detach(GdbCmdContext *gdb_ctx, void *user_ctx) +{ + GDBProcess *process; + GDBState *s = gdb_ctx->s; + uint32_t pid = 1; + + if (s->multiprocess) { + if (!gdb_ctx->num_params) { + put_packet(s, "E22"); + return; + } + + pid = gdb_ctx->params[0].val_ul; + } + + process = gdb_get_process(s, pid); + gdb_process_breakpoint_remove_all(s, process); + process->attached = false; + + if (pid == gdb_get_cpu_pid(s, s->c_cpu)) { + s->c_cpu = gdb_first_attached_cpu(s); + } + + if (pid == gdb_get_cpu_pid(s, s->g_cpu)) { + s->g_cpu = gdb_first_attached_cpu(s); + } + + if (!s->c_cpu) { + /* No more process attached */ + gdb_syscall_mode = GDB_SYS_DISABLED; + gdb_continue(s); + } + put_packet(s, "OK"); +} + static int gdb_handle_packet(GDBState *s, const char *line_buf) { CPUState *cpu; @@ -1597,42 +1628,15 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) error_report("QEMU: Terminated via GDBstub"); exit(0); case 'D': - /* Detach packet */ - pid = 1; - - if (s->multiprocess) { - unsigned long lpid; - if (*p != ';') { - put_packet(s, "E22"); - break; - } - - if (qemu_strtoul(p + 1, &p, 16, &lpid)) { - put_packet(s, "E22"); - break; - } - - pid = lpid; - } - - process = gdb_get_process(s, pid); - gdb_process_breakpoint_remove_all(s, process); - process->attached = false; - - if (pid == gdb_get_cpu_pid(s, s->c_cpu)) { - s->c_cpu = gdb_first_attached_cpu(s); - } - - if (pid == gdb_get_cpu_pid(s, s->g_cpu)) { - s->g_cpu = gdb_first_attached_cpu(s); - } - - if (s->c_cpu == NULL) { - /* No more process attached */ - gdb_syscall_mode = GDB_SYS_DISABLED; - gdb_continue(s); + { + static GdbCmdParseEntry deatch_cmd_desc = { + .handler = handle_detach, + .cmd = "D", + .cmd_startswith = 1, + .schema = "?.l0" + }; + process_string_cmd(s, NULL, line_buf, &deatch_cmd_desc, 1); } - put_packet(s, "OK"); break; case 's': if (*p != '\0') {
From: Jon Doron <arilou@gmail.com> Signed-otff-by: Jon Doron <arilou@gmail.com> --- gdbstub.c | 82 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 39 deletions(-)