From patchwork Fri Dec 7 09:01:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luc Michel X-Patchwork-Id: 10717703 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 2A1FD13BB for ; Fri, 7 Dec 2018 09:11:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18A9F2DB52 for ; Fri, 7 Dec 2018 09:11:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0CB2E2E8BF; Fri, 7 Dec 2018 09:11:15 +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.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 C29EF2DB52 for ; Fri, 7 Dec 2018 09:11:13 +0000 (UTC) Received: from localhost ([::1]:44893 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gVCAC-0008Op-QK for patchwork-qemu-devel@patchwork.kernel.org; Fri, 07 Dec 2018 04:11:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57589) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gVC1a-00089q-02 for qemu-devel@nongnu.org; Fri, 07 Dec 2018 04:02:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gVC1Z-0005fj-4p for qemu-devel@nongnu.org; Fri, 07 Dec 2018 04:02:17 -0500 Received: from greensocs.com ([193.104.36.180]:52246) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gVC1V-0005Rs-A7; Fri, 07 Dec 2018 04:02:13 -0500 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id 2E513480036; Fri, 7 Dec 2018 10:01:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1544173311; bh=fTLojJdToljvuaXR6Y5DUo7NPRDCtUsKLEk8/1L5s4k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=qGMnhw3V5VbeAJJgjH5w8UfEdINWNpVwVvARFFIzY3Wrd+bFrnDl2oOdSZkGK9uiH CCXG3t+GFhrh8l2Ii02514xSH2bgwV8pXUnaLQgz3HimhUlXGdZStAgml9JmUfXMgX C5rd6N+9VXHyzEWEE5B82q70Z7SYi10SckIx9NyM= 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=LAFz6sz5; dkim=pass (1024-bit key) header.d=greensocs.com header.b=LAFz6sz5 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 o7Yf1L6AME2X; Fri, 7 Dec 2018 10:01:50 +0100 (CET) Received: by greensocs.com (Postfix, from userid 998) id 698F1480038; Fri, 7 Dec 2018 10:01:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1544173305; bh=fTLojJdToljvuaXR6Y5DUo7NPRDCtUsKLEk8/1L5s4k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=LAFz6sz5j9L5LiIpDtvvLm/kCN6LE6VMYsr3OApcGA8feVzeGVdxXGTfMaTp3T/Nx 851WSxpwV26fvRq+Y4sLJSghf7p0ZynC9m/l6vfqMBTBLTYG3F0X1ahwykVcffGJgc yuPAQ7E+AbRL2CJrzmDBvZviXzhDMaVQLv5/u4ts= Received: from michell-laptop.home.lmichel.fr (lfbn-1-8165-82.w90-112.abo.wanadoo.fr [90.112.74.82]) (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 0328C480011; Fri, 7 Dec 2018 10:01:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1544173305; bh=fTLojJdToljvuaXR6Y5DUo7NPRDCtUsKLEk8/1L5s4k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=LAFz6sz5j9L5LiIpDtvvLm/kCN6LE6VMYsr3OApcGA8feVzeGVdxXGTfMaTp3T/Nx 851WSxpwV26fvRq+Y4sLJSghf7p0ZynC9m/l6vfqMBTBLTYG3F0X1ahwykVcffGJgc yuPAQ7E+AbRL2CJrzmDBvZviXzhDMaVQLv5/u4ts= From: Luc Michel To: qemu-devel@nongnu.org Date: Fri, 7 Dec 2018 10:01:28 +0100 Message-Id: <20181207090135.7651-11-luc.michel@greensocs.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181207090135.7651-1-luc.michel@greensocs.com> References: <20181207090135.7651-1-luc.michel@greensocs.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 193.104.36.180 Subject: [Qemu-devel] [PATCH v8 10/16] 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 , Eduardo Habkost , alistair@alistair23.me, mark.burton@greensocs.com, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , 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é Reviewed-by: Edgar E. Iglesias Acked-by: Alistair Francis --- gdbstub.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 4645d59d8c..48c2571ebe 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1046,24 +1046,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) { @@ -1338,13 +1353,44 @@ 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; + } + + 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); + } put_packet(s, "OK"); break; case 's': if (*p != '\0') { addr = strtoull(p, (char **)&p, 16);