Received: from eggs.gnu.org ([209.51.188.92]:43979) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJIzN-0004qG-6D for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:35:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hJIrv-0000M7-2X for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:27:28 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:40932) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hJIru-0000Kf-SI for qemu-devel@nongnu.org; Wed, 24 Apr 2019 10:27:27 -0400 Received: by mail-wr1-x444.google.com with SMTP id h4so25449651wre.7 for ; Wed, 24 Apr 2019 07:27:26 -0700 (PDT) From: arilou@gmail.com Date: Wed, 24 Apr 2019 17:26:56 +0300 Message-Id: <20190424142714.28460-2-arilou@gmail.com> In-Reply-To: <20190424142714.28460-1-arilou@gmail.com> References: <20190424142714.28460-1-arilou@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH v3 02/20] gdbstub: Implement deatch (D pkt) with new infra List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Jon Doron From: Jon Doron Signed-otff-by: Jon Doron --- 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') { -- 2.20.1