[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 34/52] gdbstub: Implement deatch (D pkt) with new inf
From: |
Alex Bennée |
Subject: |
[Qemu-devel] [PULL 34/52] gdbstub: Implement deatch (D pkt) with new infra |
Date: |
Fri, 7 Jun 2019 10:05:33 +0100 |
From: Jon Doron <address@hidden>
Signed-off-by: Jon Doron <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Alex Bennée <address@hidden>
Signed-off-by: Alex Bennée <address@hidden>
diff --git a/gdbstub.c b/gdbstub.c
index 09fe5a4b99..120e52f5d2 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -1413,11 +1413,6 @@ static inline int startswith(const char *string, const
char *pattern)
return !strncmp(string, pattern, strlen(pattern));
}
-static int process_string_cmd(
- GDBState *s, void *user_ctx, const char *data,
- const GdbCmdParseEntry *cmds, int num_cmds)
- __attribute__((unused));
-
static int process_string_cmd(GDBState *s, void *user_ctx, const char *data,
const GdbCmdParseEntry *cmds, int num_cmds)
{
@@ -1463,6 +1458,55 @@ static int process_string_cmd(GDBState *s, void
*user_ctx, const char *data,
return -1;
}
+static void run_cmd_parser(GDBState *s, const char *data,
+ const GdbCmdParseEntry *cmd)
+{
+ if (!data) {
+ return;
+ }
+
+ /* In case there was an error during the command parsing we must
+ * send a NULL packet to indicate the command is not supported */
+ if (process_string_cmd(s, NULL, data, cmd, 1)) {
+ put_packet(s, "");
+ }
+}
+
+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;
@@ -1477,6 +1521,7 @@ static int gdb_handle_packet(GDBState *s, const char
*line_buf)
uint8_t *registers;
target_ulong addr, len;
GDBThreadIdKind thread_kind;
+ const GdbCmdParseEntry *cmd_parser = NULL;
trace_gdbstub_io_command(line_buf);
@@ -1577,42 +1622,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 const GdbCmdParseEntry detach_cmd_desc = {
+ .handler = handle_detach,
+ .cmd = "D",
+ .cmd_startswith = 1,
+ .schema = "?.l0"
+ };
+ cmd_parser = &detach_cmd_desc;
}
- put_packet(s, "OK");
break;
case 's':
if (*p != '\0') {
@@ -1985,6 +2003,9 @@ static int gdb_handle_packet(GDBState *s, const char
*line_buf)
put_packet(s, buf);
break;
}
+
+ run_cmd_parser(s, line_buf, cmd_parser);
+
return RS_IDLE;
}
--
2.20.1
- [Qemu-devel] [PULL 44/52] gdbstub: Implement write all registers (G pkt) with new infra, (continued)
- [Qemu-devel] [PULL 44/52] gdbstub: Implement write all registers (G pkt) with new infra, Alex Bennée, 2019/06/07
- [Qemu-devel] [PULL 50/52] gdbstub: Implement target halted (? pkt) with new infra, Alex Bennée, 2019/06/07
- [Qemu-devel] [PULL 28/52] tests/tcg: better detect truncated reads, Alex Bennée, 2019/06/07
- [Qemu-devel] [PULL 46/52] gdbstub: Implement file io (F pkt) with new infra, Alex Bennée, 2019/06/07
- [Qemu-devel] [PULL 33/52] gdbstub: Add infrastructure to parse cmd packets, Alex Bennée, 2019/06/07
- [Qemu-devel] [PULL 47/52] gdbstub: Implement step (s pkt) with new infra, Alex Bennée, 2019/06/07
- [Qemu-devel] [PULL 41/52] gdbstub: Implement get register (p pkt) with new infra, Alex Bennée, 2019/06/07
- [Qemu-devel] [PULL 35/52] gdbstub: Implement thread_alive (T pkt) with new infra, Alex Bennée, 2019/06/07
- [Qemu-devel] [PULL 37/52] gdbstub: Implement continue with signal (C pkt) with new infra, Alex Bennée, 2019/06/07
- [Qemu-devel] [PULL 16/52] tests/vm: run test builds on snapshot, Alex Bennée, 2019/06/07
- [Qemu-devel] [PULL 34/52] gdbstub: Implement deatch (D pkt) with new infra,
Alex Bennée <=
- [Qemu-devel] [PULL 21/52] tests/vm: openbsd autoinstall, using serial console, Alex Bennée, 2019/06/07
- [Qemu-devel] [PULL 22/52] tests/vm: freebsd autoinstall, using serial console, Alex Bennée, 2019/06/07
- [Qemu-devel] [PULL 14/52] tests/vm: send proxy environment variables over ssh, Alex Bennée, 2019/06/07
- [Qemu-devel] [PULL 31/52] MAINTAINERS: put myself forward for gdbstub, Alex Bennée, 2019/06/07
- [Qemu-devel] [PULL 19/52] tests/vm: add DEBUG=1 to help text, Alex Bennée, 2019/06/07
- [Qemu-devel] [PULL 39/52] gdbstub: Implement breakpoint commands (Z/z pkt) with new infra, Alex Bennée, 2019/06/07
- [Qemu-devel] [PULL 52/52] gdbstub: Implement qemu physical memory mode, Alex Bennée, 2019/06/07
- [Qemu-devel] [PULL 12/52] scripts: use git archive in archive-source, Alex Bennée, 2019/06/07
- [Qemu-devel] [PULL 48/52] gdbstub: Implement v commands with new infra, Alex Bennée, 2019/06/07
- [Qemu-devel] [PULL 49/52] gdbstub: Implement generic set/query (Q/q pkt) with new infra, Alex Bennée, 2019/06/07