From patchwork Tue Nov 6 11:05:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luc Michel X-Patchwork-Id: 993606 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=greensocs.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=greensocs.com header.i=@greensocs.com header.b="5uvu83pN"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="RkYW08bu"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="RkYW08bu"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42q6GB2pNbz9sDL for ; Tue, 6 Nov 2018 22:07:46 +1100 (AEDT) Received: from localhost ([::1]:40301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJzCx-0006sa-Kw for incoming@patchwork.ozlabs.org; Tue, 06 Nov 2018 06:07:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48951) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJzBk-0006QO-Vo for qemu-devel@nongnu.org; Tue, 06 Nov 2018 06:06:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJzBf-0000w2-6Q for qemu-devel@nongnu.org; Tue, 06 Nov 2018 06:06:28 -0500 Received: from greensocs.com ([193.104.36.180]:46712) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJzBW-0000os-E2; Tue, 06 Nov 2018 06:06:14 -0500 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id 205235C024F; Tue, 6 Nov 2018 12:06:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1541502374; bh=cYsacuZtqAvOWvrLvVMrJK7AgZ/b9/60aGrfdT4mrnA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=5uvu83pNvwqwXLqFYuEuz4ZRm1FMtekwLX0P8c38TxXXg/mapDaydRmGMx2Qui1kX yDf6+ZFWgkxODSj7Al9RCo9YRC7/B/Cp+lUaWcN1SZL8UwnMpRTzqX0TWJMOjqJzjc YLrFXYxUW8oQsbLQhLtg4WkLgagANBzrWhTp/UuA= 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=RkYW08bu; dkim=pass (1024-bit key) header.d=greensocs.com header.b=RkYW08bu 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 7a56G-qZrFSW; Tue, 6 Nov 2018 12:06:13 +0100 (CET) Received: by greensocs.com (Postfix, from userid 998) id 3C9F95C027D; Tue, 6 Nov 2018 12:06:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1541502369; bh=cYsacuZtqAvOWvrLvVMrJK7AgZ/b9/60aGrfdT4mrnA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RkYW08buA5LqMJXtU447Ey6RafdaomH+arLEZIAZDP5wyykpp4jFjT2FfVusarawC 0QgzMYNIKiDi8xU+ZVBHDc+/VYI0htegvArnkBKINE3XN2zpAOQmIG3U5jMuJen/WQ 8pe8fEzGRvbxHK5mHNBE8eyQnUFX+Lk2Uxy8lMhc= 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 C55CB5C0276; Tue, 6 Nov 2018 12:06:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1541502369; bh=cYsacuZtqAvOWvrLvVMrJK7AgZ/b9/60aGrfdT4mrnA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RkYW08buA5LqMJXtU447Ey6RafdaomH+arLEZIAZDP5wyykpp4jFjT2FfVusarawC 0QgzMYNIKiDi8xU+ZVBHDc+/VYI0htegvArnkBKINE3XN2zpAOQmIG3U5jMuJen/WQ 8pe8fEzGRvbxHK5mHNBE8eyQnUFX+Lk2Uxy8lMhc= From: Luc Michel To: qemu-devel@nongnu.org Date: Tue, 6 Nov 2018 12:05:42 +0100 Message-Id: <20181106110548.4209-11-luc.michel@greensocs.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181106110548.4209-1-luc.michel@greensocs.com> References: <20181106110548.4209-1-luc.michel@greensocs.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 193.104.36.180 Subject: [Qemu-devel] [PATCH v4 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" '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 | 60 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index decf56c610..bd4895ac0a 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1039,24 +1039,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) { @@ -1331,13 +1346,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_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);