From patchwork Sat Sep 1 12:46:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luc Michel X-Patchwork-Id: 10584749 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DE127174C for ; Sat, 1 Sep 2018 13:01:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAA922A576 for ; Sat, 1 Sep 2018 13:01:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCFFC2A589; Sat, 1 Sep 2018 13:01:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 296332A576 for ; Sat, 1 Sep 2018 13:01:27 +0000 (UTC) Received: from localhost ([::1]:37129 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fw5Wp-0003sr-1q for patchwork-qemu-devel@patchwork.kernel.org; Sat, 01 Sep 2018 09:01:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35641) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fw5JZ-00068M-5u for qemu-devel@nongnu.org; Sat, 01 Sep 2018 08:47:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fw5JY-0007y9-6i for qemu-devel@nongnu.org; Sat, 01 Sep 2018 08:47:45 -0400 Received: from greensocs.com ([193.104.36.180]:40638) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fw5JQ-0007kG-Q3; Sat, 01 Sep 2018 08:47:37 -0400 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id 021CF521ABB; Sat, 1 Sep 2018 14:47:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1535806030; bh=U7y+z5X4f9EQxSzlOdGa0ZG0HeuqrrIUt9MwzUb7h4U=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DySiNmK21+iTbx5wpRYICPysJC8g6XFp9Dm00FE4xvRaHvW1khwHJP6OdBn/gUpVl yXMW/e61KjcrStGiiaUnw/3rn+IkYsEtwd4xdaKLbS1wGgaUMmIRTn6HkTrypk8elf Z41C2iAljUIwgCUyRPHdXzBbjhjaAK2M8Tg4nCaQ= X-Virus-Scanned: amavisd-new at greensocs.com Authentication-Results: gs-01.greensocs.com (amavisd-new); dkim=pass (1024-bit key) header.d=greensocs.com header.b=GSxCpWW0; dkim=pass (1024-bit key) header.d=greensocs.com header.b=MlM0jRIH Received: from greensocs.com ([127.0.0.1]) by localhost (gs-01.greensocs.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xiPcfbqhMoO3; Sat, 1 Sep 2018 14:47:09 +0200 (CEST) Received: by greensocs.com (Postfix, from userid 998) id 19B8D521AAA; Sat, 1 Sep 2018 14:47:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1535806029; bh=U7y+z5X4f9EQxSzlOdGa0ZG0HeuqrrIUt9MwzUb7h4U=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GSxCpWW0MlgFXy8OO+3eCtyt+jorz/E4EXtKC8OGEdhS3yOnxj/dArtQgW7gqjBpS FgaYarLLPziSW48QuyoOcDOKUIQ0p8oweQlvxYmal0hAqz7tMV8p4sCGqyo2DFeAJ0 Wn3xO3PkDBAYOEu+L6QcJwFMP5JPPW8OyOdozuYw= Received: from michell-laptop.home.lmichel.fr (LFbn-LYO-1-488-36.w2-7.abo.wanadoo.fr [2.7.77.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: luc.michel@greensocs.com) by greensocs.com (Postfix) with ESMTPSA id 3D31F521AB0; Sat, 1 Sep 2018 14:47:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1535806028; bh=U7y+z5X4f9EQxSzlOdGa0ZG0HeuqrrIUt9MwzUb7h4U=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MlM0jRIHHOPlPez4Nd3/gangVsXx8AxWRNp/f6gvSms1ZYVsY2ULq/17BCb4w3qhv ghXzTmhIIFlJL00GoTEOVoiVOyXhbA7km5Asqu4kVOYwbE+JZRRnRTWEpkq4tcB1ZX gzLmhNNmgzjYaTJat4FXoG3ZAsHVUOrYmtcLJXE0= From: Luc Michel To: qemu-devel@nongnu.org Date: Sat, 1 Sep 2018 14:46:33 +0200 Message-Id: <20180901124639.19735-10-luc.michel@greensocs.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180901124639.19735-1-luc.michel@greensocs.com> References: <20180901124639.19735-1-luc.michel@greensocs.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 193.104.36.180 Subject: [Qemu-devel] [PATCH 09/15] gdbstub: add multiprocess support to 'D' packets X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , alistair@alistair23.me, mark.burton@greensocs.com, saipava@xilinx.com, edgari@xilinx.com, qemu-arm@nongnu.org, Luc Michel Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 'D' packets are used by GDB to detach from a process. In multiprocess mode, the PID to detach from is sent in the request. Signed-off-by: Luc Michel Reviewed-by: Philippe Mathieu-Daudé --- gdbstub.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 4ccd1153ce..af8864e251 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1025,24 +1025,39 @@ static int gdb_breakpoint_remove(target_ulong addr, target_ulong len, int type) default: return -ENOSYS; } } +static inline void gdb_cpu_breakpoint_remove_all(CPUState *cpu) +{ + cpu_breakpoint_remove_all(cpu, BP_GDB); +#ifndef CONFIG_USER_ONLY + cpu_watchpoint_remove_all(cpu, BP_GDB); +#endif +} + +static void gdb_process_breakpoint_remove_all(const GDBState *s, GDBProcess *p) +{ + CPUState *cpu = get_first_cpu_in_process(s, p); + + while (cpu) { + gdb_cpu_breakpoint_remove_all(cpu); + cpu = gdb_next_cpu_in_process(s, cpu); + } +} + static void gdb_breakpoint_remove_all(void) { CPUState *cpu; if (kvm_enabled()) { kvm_remove_all_breakpoints(gdbserver_state->c_cpu); return; } CPU_FOREACH(cpu) { - cpu_breakpoint_remove_all(cpu, BP_GDB); -#ifndef CONFIG_USER_ONLY - cpu_watchpoint_remove_all(cpu, BP_GDB); -#endif + gdb_cpu_breakpoint_remove_all(cpu); } } static void gdb_set_cpu_pc(GDBState *s, target_ulong pc) { @@ -1318,13 +1333,39 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) /* Kill the target */ error_report("QEMU: Terminated via GDBstub"); exit(0); case 'D': /* Detach packet */ - gdb_breakpoint_remove_all(); - gdb_syscall_mode = GDB_SYS_DISABLED; - gdb_continue(s); + pid = 1; + + if (s->multiprocess) { + unsigned long lpid; + if (*p != ';') { + put_packet(s, "E22"); + break; + } + qemu_strtoul(p + 1, &p, 16, &lpid); + 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_cpu(s); + } + + if (pid == gdb_get_cpu_pid(s, s->g_cpu)) { + s->g_cpu = gdb_first_cpu(s); + } + + if (s->c_cpu == NULL) { + /* No more process attached */ + gdb_syscall_mode = GDB_SYS_DISABLED; + gdb_continue(s); + } put_packet(s, "OK"); break; case 's': if (*p != '\0') { addr = strtoull(p, (char **)&p, 16);