From patchwork Fri Oct 26 08:16:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Michel X-Patchwork-Id: 989502 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="VCXgaPL6"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="v2chrusj"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="2Zz+F0Y4"; 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 42hHYH0tXkz9s9h for ; Fri, 26 Oct 2018 19:42:11 +1100 (AEDT) Received: from localhost ([::1]:58874 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxh2-0006Su-LO for incoming@patchwork.ozlabs.org; Fri, 26 Oct 2018 04:42:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59989) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxUF-0000gN-W9 for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:28:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFxJE-0004pt-Lq for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:17:34 -0400 Received: from greensocs.com ([193.104.36.180]:45399) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxJ9-0004lQ-Jm; Fri, 26 Oct 2018 04:17:29 -0400 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id 135B9441B51; Fri, 26 Oct 2018 10:17:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541838; bh=FPZyVC5tVv7WdxRkgpQY4rs7Qz562EN5IzYD1va8ctA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=VCXgaPL6J26K7DWcPgz3zrwUzWftlUIfLVrm2lrRniGthevfZTh4Cv9B0b8fyhpSL 8sRHNzhpIJyhXRnGkxQV9P4tyRihnFPxq0XKbonD6uAVVqLkR2eCcJVGRlK2rFmDC5 1loqC0IzoXQ6bPMlxvn58mdfXQHbvexKSGfVwaN8= 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=v2chrusj; dkim=pass (1024-bit key) header.d=greensocs.com header.b=2Zz+F0Y4 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 4dOj2i8Wkzhi; Fri, 26 Oct 2018 10:17:12 +0200 (CEST) Received: by greensocs.com (Postfix, from userid 998) id 06B44441B44; Fri, 26 Oct 2018 10:17:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541832; bh=FPZyVC5tVv7WdxRkgpQY4rs7Qz562EN5IzYD1va8ctA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=v2chrusjq7+j20MYPahLseoT0uO21jAmycZnqy4KmyaqkvX7zrTCUnGH+uKJH7FA/ s3ZELv7t7hoxqYQaAm/T66ngby4A3SBDq8GGpzx5SsEa6qkTcYzD29Wbd6Q8DEomgw ICLroHqmHNkyvrGwgRrzok7MnUXcfVBNqbfAQ9Hc= 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 97110441B41; Fri, 26 Oct 2018 10:17:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541831; bh=FPZyVC5tVv7WdxRkgpQY4rs7Qz562EN5IzYD1va8ctA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=2Zz+F0Y4DKzjR4bR9uWKkKkEyIEL+N3BIahz/3TaH1iYyDpBLo0oiZqaE6HrSZe/B Avl+yqAbo/Wp6oaY9k30kD7glUMrX6GxFHl8RZmI3DTkNRyCeaC0unpmP3rZb2YoAU 9ia++TLqNJujMj+IwNmFf13G2oYQXxspioiIHW64= From: Luc Michel To: qemu-devel@nongnu.org Date: Fri, 26 Oct 2018 10:16:38 +0200 Message-Id: <20181026081653.24602-2-luc.michel@greensocs.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181026081653.24602-1-luc.michel@greensocs.com> References: <20181026081653.24602-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 v3 01/16] hw/cpu: introduce CPU clusters 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" This commit adds the cpu-cluster type. It aims at gathering CPUs from the same cluster in a machine. For now it only has a `cluster-id` property. Signed-off-by: Luc Michel Reviewed-by: Alistair Francis --- include/hw/cpu/cluster.h | 38 +++++++++++++++++++++++++++++++ hw/cpu/cluster.c | 49 ++++++++++++++++++++++++++++++++++++++++ hw/cpu/Makefile.objs | 2 +- 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 include/hw/cpu/cluster.h create mode 100644 hw/cpu/cluster.c diff --git a/include/hw/cpu/cluster.h b/include/hw/cpu/cluster.h new file mode 100644 index 0000000000..f233a47a4a --- /dev/null +++ b/include/hw/cpu/cluster.h @@ -0,0 +1,38 @@ +/* + * QEMU CPU cluster + * + * Copyright (c) 2018 GreenSocs SAS + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see + * + */ +#ifndef QEMU_HW_CPU_CLUSTER_H +#define QEMU_HW_CPU_CLUSTER_H + +#include "qemu/osdep.h" +#include "hw/qdev.h" + +#define TYPE_CPU_CLUSTER "cpu-cluster" +#define CPU_CLUSTER(obj) \ + OBJECT_CHECK(CPUClusterState, (obj), TYPE_CPU_CLUSTER) + +typedef struct CPUClusterState { + /*< private >*/ + DeviceState parent_obj; + + /*< public >*/ + uint32_t cluster_id; +} CPUClusterState; + +#endif diff --git a/hw/cpu/cluster.c b/hw/cpu/cluster.c new file mode 100644 index 0000000000..11121e6f26 --- /dev/null +++ b/hw/cpu/cluster.c @@ -0,0 +1,49 @@ +/* + * QEMU CPU cluster + * + * Copyright (c) 2018 GreenSocs SAS + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see + * + */ + +#include "hw/cpu/cluster.h" +#include "qapi/error.h" +#include "qemu/module.h" + +static Property cpu_cluster_properties[] = { + DEFINE_PROP_UINT32("cluster-id", CPUClusterState, cluster_id, 0), + DEFINE_PROP_END_OF_LIST() +}; + +static void cpu_cluster_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + dc->props = cpu_cluster_properties; +} + +static const TypeInfo cpu_cluster_type_info = { + .name = TYPE_CPU_CLUSTER, + .parent = TYPE_DEVICE, + .instance_size = sizeof(CPUClusterState), + .class_init = cpu_cluster_class_init, +}; + +static void cpu_cluster_register_types(void) +{ + type_register_static(&cpu_cluster_type_info); +} + +type_init(cpu_cluster_register_types) diff --git a/hw/cpu/Makefile.objs b/hw/cpu/Makefile.objs index cd52d20b65..8db9e8a7b3 100644 --- a/hw/cpu/Makefile.objs +++ b/hw/cpu/Makefile.objs @@ -1,5 +1,5 @@ obj-$(CONFIG_ARM11MPCORE) += arm11mpcore.o obj-$(CONFIG_REALVIEW) += realview_mpcore.o obj-$(CONFIG_A9MPCORE) += a9mpcore.o obj-$(CONFIG_A15MPCORE) += a15mpcore.o -common-obj-y += core.o +common-obj-y += core.o cluster.o From patchwork Fri Oct 26 08:16:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Michel X-Patchwork-Id: 989500 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="ovUCefj6"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="pLZu8LMw"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="pLZu8LMw"; 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 42hHTx2mvMz9s9h for ; Fri, 26 Oct 2018 19:39:17 +1100 (AEDT) Received: from localhost ([::1]:58858 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxeE-0003y0-U6 for incoming@patchwork.ozlabs.org; Fri, 26 Oct 2018 04:39:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60010) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxUI-0000gX-De for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:29:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFxJD-0004oZ-Js for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:17:33 -0400 Received: from greensocs.com ([193.104.36.180]:45300) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxJ7-0004hc-Uu; Fri, 26 Oct 2018 04:17:26 -0400 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id 43BDA441B41; Fri, 26 Oct 2018 10:17:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541833; bh=scAeeVUfiTBPeUG7BQf+uaQpfj0tR1sNl+CRKI8s5z4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ovUCefj6d9PIItgvl4j6FmxhFy8yfP56++oLV+fTswumOybax39M0qXmboIHXzWqm I0PI7h6G6CK/THiqHg13mXSWXEAXz8g0Q88p8REvnNPg0gq/XhIaCFU3V8qC0wIk/C tF2UGKAtu80DpwRqFIyxOPyCG+nUKMO+ppfq0Ug4= 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=pLZu8LMw; dkim=pass (1024-bit key) header.d=greensocs.com header.b=pLZu8LMw 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 le96QaU4gNHj; Fri, 26 Oct 2018 10:17:12 +0200 (CEST) Received: by greensocs.com (Postfix, from userid 998) id 6F16B441B47; Fri, 26 Oct 2018 10:17:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541832; bh=scAeeVUfiTBPeUG7BQf+uaQpfj0tR1sNl+CRKI8s5z4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=pLZu8LMwLViZG4fWBeenF7n2WA9d6gWAPtMPAzQ06nZrhlN0I+v69uX2riH9rssjJ KLQnBu0mcZImHesptI0aG7wmN3Pf+AUg7UYBmgRJPA/Ul5LesFhabmQ6a1hme9IAqI AzOQGF9LYpm2KLxLcNwUm0paWjKgaJilbpV63BcM= 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 0ABC8441B41; Fri, 26 Oct 2018 10:17:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541832; bh=scAeeVUfiTBPeUG7BQf+uaQpfj0tR1sNl+CRKI8s5z4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=pLZu8LMwLViZG4fWBeenF7n2WA9d6gWAPtMPAzQ06nZrhlN0I+v69uX2riH9rssjJ KLQnBu0mcZImHesptI0aG7wmN3Pf+AUg7UYBmgRJPA/Ul5LesFhabmQ6a1hme9IAqI AzOQGF9LYpm2KLxLcNwUm0paWjKgaJilbpV63BcM= From: Luc Michel To: qemu-devel@nongnu.org Date: Fri, 26 Oct 2018 10:16:39 +0200 Message-Id: <20181026081653.24602-3-luc.michel@greensocs.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181026081653.24602-1-luc.michel@greensocs.com> References: <20181026081653.24602-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 v3 02/16] gdbstub: introduce GDB processes 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" Add a structure GDBProcess that represent processes from the GDB semantic point of view. CPUs can be split into different processes, by grouping them under different cpu-cluster objects. Each occurrence of a cpu-cluster object implies the existence of the corresponding process in the GDB stub. The GDB process ID is derived from the corresponding cluster ID as follows: GDB PID = cluster ID + 1 This is because PIDs -1 and 0 are reserved in GDB and cannot be used by processes. When no such container are found, all the CPUs are put in a unique GDB process (create_unique_process()). This is also the case when compiled in user mode, where multi-processes do not make much sense for now. Signed-off-by: Luc Michel Acked-by: Alistair Francis --- gdbstub.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/gdbstub.c b/gdbstub.c index c4e4f9f082..096ac8e99c 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -27,10 +27,11 @@ #include "monitor/monitor.h" #include "chardev/char.h" #include "chardev/char-fe.h" #include "sysemu/sysemu.h" #include "exec/gdbstub.h" +#include "hw/cpu/cluster.h" #endif #define MAX_PACKET_LENGTH 4096 #include "qemu/sockets.h" @@ -294,10 +295,15 @@ typedef struct GDBRegisterState { gdb_reg_cb set_reg; const char *xml; struct GDBRegisterState *next; } GDBRegisterState; +typedef struct GDBProcess { + uint32_t pid; + bool attached; +} GDBProcess; + enum RSState { RS_INACTIVE, RS_IDLE, RS_GETLINE, RS_GETLINE_ESC, @@ -322,10 +328,13 @@ typedef struct GDBState { int running_state; #else CharBackend chr; Chardev *mon_chr; #endif + bool multiprocess; + GDBProcess *processes; + int process_num; char syscall_buf[256]; gdb_syscall_complete_cb current_syscall_cb; } GDBState; /* By default use no IRQs and no timers while single stepping so as to @@ -1749,10 +1758,24 @@ void gdb_exit(CPUArchState *env, int code) #ifndef CONFIG_USER_ONLY qemu_chr_fe_deinit(&s->chr, true); #endif } +/* + * Create a unique process containing all the CPUs. + */ +static void create_unique_process(GDBState *s) +{ + GDBProcess *process; + + s->processes = g_malloc0(sizeof(GDBProcess)); + s->process_num = 1; + process = &s->processes[0]; + + process->pid = 1; +} + #ifdef CONFIG_USER_ONLY int gdb_handlesig(CPUState *cpu, int sig) { GDBState *s; @@ -1846,10 +1869,11 @@ static bool gdb_accept(void) } s = g_malloc0(sizeof(GDBState)); s->c_cpu = first_cpu; s->g_cpu = first_cpu; + create_unique_process(s); s->fd = fd; gdb_has_xml = false; gdbserver_state = s; return true; @@ -2002,10 +2026,57 @@ static const TypeInfo char_gdb_type_info = { .name = TYPE_CHARDEV_GDB, .parent = TYPE_CHARDEV, .class_init = char_gdb_class_init, }; +static int find_cpu_clusters(Object *child, void *opaque) +{ + if (object_dynamic_cast(child, TYPE_CPU_CLUSTER)) { + GDBState *s = (GDBState *) opaque; + CPUClusterState *cluster = CPU_CLUSTER(child); + + s->processes = g_renew(GDBProcess, s->processes, ++s->process_num); + + GDBProcess *process = &s->processes[s->process_num - 1]; + + /* GDB process IDs -1 and 0 are reserved */ + process->pid = cluster->cluster_id + 1; + process->attached = false; + return 0; + } + + return object_child_foreach(child, find_cpu_clusters, opaque); +} + +static int pid_order(const void *a, const void *b) +{ + GDBProcess *pa = (GDBProcess *) a; + GDBProcess *pb = (GDBProcess *) b; + + return pa->pid - pb->pid; +} + +static void create_processes(GDBState *s) +{ + object_child_foreach(object_get_root(), find_cpu_clusters, s); + + if (!s->processes) { + /* No CPU cluster specified by the machine */ + create_unique_process(s); + } else { + /* Sort by PID */ + qsort(s->processes, s->process_num, sizeof(s->processes[0]), pid_order); + } +} + +static void cleanup_processes(GDBState *s) +{ + g_free(s->processes); + s->process_num = 0; + s->processes = NULL; +} + int gdbserver_start(const char *device) { trace_gdbstub_op_start(device); GDBState *s; @@ -2058,15 +2129,19 @@ int gdbserver_start(const char *device) NULL, &error_abort); monitor_init(mon_chr, 0); } else { qemu_chr_fe_deinit(&s->chr, true); mon_chr = s->mon_chr; + cleanup_processes(s); memset(s, 0, sizeof(GDBState)); s->mon_chr = mon_chr; } s->c_cpu = first_cpu; s->g_cpu = first_cpu; + + create_processes(s); + if (chr) { qemu_chr_fe_init(&s->chr, chr, &error_abort); qemu_chr_fe_set_handlers(&s->chr, gdb_chr_can_receive, gdb_chr_receive, gdb_chr_event, NULL, NULL, NULL, true); } From patchwork Fri Oct 26 08:16:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Michel X-Patchwork-Id: 989509 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="KVFunOic"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="RtSEkmRT"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="auAzIix1"; 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 42hHjj0MNFz9sBZ for ; Fri, 26 Oct 2018 19:49:27 +1100 (AEDT) Received: from localhost ([::1]:58928 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxo4-0005sS-6H for incoming@patchwork.ozlabs.org; Fri, 26 Oct 2018 04:49:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60010) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxUL-0000gX-08 for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:29:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFxJD-0004oe-MX for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:17:33 -0400 Received: from greensocs.com ([193.104.36.180]:45299) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxJ7-0004hd-Uq; Fri, 26 Oct 2018 04:17:26 -0400 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id 3F8D7441B4A; Fri, 26 Oct 2018 10:17:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541834; bh=H9ZOA3Y55LXnxzE0O/GI2JMr62WKwOXtlHrOSEZjWQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KVFunOicAaKMYU9DbNcu9IAVp7AKBXbOMVfNTKYVuyUDh4/4QUKv5mhUQ+G7395gu p4rr0R+ypA216I7iRtQoUt570VRPxYV3l6p7HyUuek1qTjV9XbxouF98SqmMLRPOYb 4HgWGEE5w4DEu6g0v/XLYWf4WqivF3vdpHW9pSEI= 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=RtSEkmRT; dkim=pass (1024-bit key) header.d=greensocs.com header.b=auAzIix1 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 0gIv1EPlpdYl; Fri, 26 Oct 2018 10:17:13 +0200 (CEST) Received: by greensocs.com (Postfix, from userid 998) id 033B4441B48; Fri, 26 Oct 2018 10:17:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541833; bh=H9ZOA3Y55LXnxzE0O/GI2JMr62WKwOXtlHrOSEZjWQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RtSEkmRTZ4WcNt63lPjd6ESn8/Sat38vk37emxW7z2sQVxAB/zgw3U9PSHJcBOmWN lIvp2WNJSSEfivY0dm/HBChQkHx2HD10n/5mQlcE7XlLFos7QJaKSZNbIAl+h6Iw4q 54xTyAtg33dFKrq3MxfogDcUkRDblyTA9WmLXKQA= 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 75997441B41; Fri, 26 Oct 2018 10:17:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541832; bh=H9ZOA3Y55LXnxzE0O/GI2JMr62WKwOXtlHrOSEZjWQ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=auAzIix1+YJfQzGW45WHy+eptMQVI5QIcnOf0jJrOtumhjP0Hmvwjx3EOsGkWtt44 NgpRJHWLrS634Hiof7ngx00uKz765SioMD/ndGTQlTfVf7ifpQ209tJstoZHQWlfom SqucS2QWb+Yj4ZtBR3WyxOoiGMOMcIqwt9mkiaQY= From: Luc Michel To: qemu-devel@nongnu.org Date: Fri, 26 Oct 2018 10:16:40 +0200 Message-Id: <20181026081653.24602-4-luc.michel@greensocs.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181026081653.24602-1-luc.michel@greensocs.com> References: <20181026081653.24602-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 v3 03/16] gdbstub: add multiprocess support to '?' 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" The gdb_get_cpu_pid() function does the PID lookup for the given CPU. It checks if the CPU is a direct child of a CPU cluster. If it is, the returned PID is the cluster ID plus one (cluster IDs start at 0, GDB PIDs at 1). When the CPU is not a child of such a container, the PID of the first process is returned. The gdb_fmt_thread_id() function generates the string to be used to identify a given thread, in a response packet for the peer. This function supports generating thread IDs when multiprocess mode is enabled (in the form `p.'). Use them in the reply to a '?' request. Signed-off-by: Luc Michel Acked-by: Alistair Francis --- gdbstub.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 096ac8e99c..9ca743a4c6 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -638,10 +638,49 @@ static int memtox(char *buf, const char *mem, int len) } } return p - buf; } +static uint32_t gdb_get_cpu_pid(const GDBState *s, CPUState *cpu) +{ +#ifndef CONFIG_USER_ONLY + gchar *path, *name; + Object *obj; + CPUClusterState *cluster; + uint32_t ret; + + path = object_get_canonical_path(OBJECT(cpu)); + name = object_get_canonical_path_component(OBJECT(cpu)); + + if (path == NULL) { + ret = s->processes[0].pid; + goto out; + } + + path[strlen(path) - strlen(name) - 1] = '\0'; + + obj = object_resolve_path_type(path, TYPE_CPU_CLUSTER, NULL); + + if (obj == NULL) { + ret = s->processes[0].pid; + goto out; + } + + cluster = CPU_CLUSTER(obj); + ret = cluster->cluster_id + 1; + +out: + g_free(name); + g_free(path); + + return ret; + +#else + return s->processes[0].pid; +#endif +} + static const char *get_feature_xml(const char *p, const char **newp, CPUClass *cc) { size_t len; int i; @@ -907,10 +946,23 @@ static CPUState *find_cpu(uint32_t thread_id) } return NULL; } +static char *gdb_fmt_thread_id(const GDBState *s, CPUState *cpu, + char *buf, size_t buf_size) +{ + if (s->multiprocess) { + snprintf(buf, buf_size, "p%02x.%02x", + gdb_get_cpu_pid(s, cpu), cpu_gdb_index(cpu)); + } else { + snprintf(buf, buf_size, "%02x", cpu_gdb_index(cpu)); + } + + return buf; +} + static int is_query_packet(const char *p, const char *query, char separator) { unsigned int query_len = strlen(query); return strncmp(p, query, query_len) == 0 && @@ -1018,22 +1070,23 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) const char *p; uint32_t thread; int ch, reg_size, type, res; uint8_t mem_buf[MAX_PACKET_LENGTH]; char buf[sizeof(mem_buf) + 1 /* trailing NUL */]; + char thread_id[16]; uint8_t *registers; target_ulong addr, len; trace_gdbstub_io_command(line_buf); p = line_buf; ch = *p++; switch(ch) { case '?': /* TODO: Make this return the correct value for user-mode. */ - snprintf(buf, sizeof(buf), "T%02xthread:%02x;", GDB_SIGNAL_TRAP, - cpu_gdb_index(s->c_cpu)); + snprintf(buf, sizeof(buf), "T%02xthread:%s;", GDB_SIGNAL_TRAP, + gdb_fmt_thread_id(s, s->c_cpu, thread_id, sizeof(thread_id))); put_packet(s, buf); /* Remove all the breakpoints when this query is issued, * because gdb is doing and initial connect and the state * should be cleaned up. */ From patchwork Fri Oct 26 08:16:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luc Michel X-Patchwork-Id: 989494 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="7ViYDlRe"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="DImW7CMD"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="DImW7CMD"; 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 42hHMN2fyqz9sDC for ; Fri, 26 Oct 2018 19:33:36 +1100 (AEDT) Received: from localhost ([::1]:58822 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxYj-0006Ii-QE for incoming@patchwork.ozlabs.org; Fri, 26 Oct 2018 04:33:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60010) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxUG-0000gX-OM for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:28:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFxJD-0004oP-IP for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:17:33 -0400 Received: from greensocs.com ([193.104.36.180]:45294) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxJ7-0004ha-Ut; Fri, 26 Oct 2018 04:17:26 -0400 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id 222EE441B4B; Fri, 26 Oct 2018 10:17:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541835; bh=kfi+4rwqBfiuRZUcgcD1QABcY/trccxb8GYquvbc9rM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=7ViYDlRegu95dN6BLg4/YfPyUlhkKQIMe0wYL0DP41rZb6+JrSU08kTFFqGLeD8jg H0roqUDecwJDQNwA4deHFb1pOg0N0HtJu87kUM1gMqNBX9MEh0mvaT9DCZUXOJfobj x0TcJnOHW6bRmD66g89zNG5/bgFRDzpn4b0s6Ayk= 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=DImW7CMD; dkim=pass (1024-bit key) header.d=greensocs.com header.b=DImW7CMD 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 WtV8_2muA85O; Fri, 26 Oct 2018 10:17:14 +0200 (CEST) Received: by greensocs.com (Postfix, from userid 998) id 8FCD2441B45; Fri, 26 Oct 2018 10:17:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541833; bh=kfi+4rwqBfiuRZUcgcD1QABcY/trccxb8GYquvbc9rM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DImW7CMDpJSTtcDFtAmkfzTFPNwagzeg0gNtBoJ/rvvAVRfFsccXJH284V5ECwdX6 B8wt9I7/LHGvJq7YTNlyr0wwDMnqZXNsTGse3R7neKwLkNzLGF2j3oKfNhloyYAq3l USD7ghDcQbkia/DpJBAokG73hvyqExI0ib/l7pm8= 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 E86F4441B42; Fri, 26 Oct 2018 10:17:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541833; bh=kfi+4rwqBfiuRZUcgcD1QABcY/trccxb8GYquvbc9rM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DImW7CMDpJSTtcDFtAmkfzTFPNwagzeg0gNtBoJ/rvvAVRfFsccXJH284V5ECwdX6 B8wt9I7/LHGvJq7YTNlyr0wwDMnqZXNsTGse3R7neKwLkNzLGF2j3oKfNhloyYAq3l USD7ghDcQbkia/DpJBAokG73hvyqExI0ib/l7pm8= From: Luc Michel To: qemu-devel@nongnu.org Date: Fri, 26 Oct 2018 10:16:41 +0200 Message-Id: <20181026081653.24602-5-luc.michel@greensocs.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181026081653.24602-1-luc.michel@greensocs.com> References: <20181026081653.24602-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 v3 04/16] gdbstub: add multiprocess support to 'H' and 'T' 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" Add a couple of helper functions to cope with GDB threads and processes. The gdb_get_process() function looks for a process given a pid. The gdb_get_cpu() function returns the CPU corresponding to the (pid, tid) pair given as parameters. The read_thread_id() function parses the thread-id sent by the peer. This function supports the multiprocess extension thread-id syntax. The return value specifies if the parsing failed, or if a special case was encountered (all processes or all threads). Use them in 'H' and 'T' packets handling to support the multiprocess extension. Signed-off-by: Luc Michel Reviewed-by: Philippe Mathieu-Daudé --- gdbstub.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 134 insertions(+), 18 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 9ca743a4c6..c437af7aca 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -677,10 +677,73 @@ out: #else return s->processes[0].pid; #endif } +static GDBProcess *gdb_get_process(const GDBState *s, uint32_t pid) +{ + int i; + + if (!pid) { + /* 0 means any process, we take the first one */ + return &s->processes[0]; + } + + for (i = 0; i < s->process_num; i++) { + if (s->processes[i].pid == pid) { + return &s->processes[i]; + } + } + + return NULL; +} + +static GDBProcess *gdb_get_cpu_process(const GDBState *s, CPUState *cpu) +{ + return gdb_get_process(s, gdb_get_cpu_pid(s, cpu)); +} + +static CPUState *find_cpu(uint32_t thread_id) +{ + CPUState *cpu; + + CPU_FOREACH(cpu) { + if (cpu_gdb_index(cpu) == thread_id) { + return cpu; + } + } + + return NULL; +} + +static CPUState *gdb_get_cpu(const GDBState *s, uint32_t pid, uint32_t tid) +{ + GDBProcess *process; + CPUState *cpu = find_cpu(tid); + + if (!tid) { + /* 0 means any thread, we take the first one */ + tid = 1; + } + + if (cpu == NULL) { + return NULL; + } + + process = gdb_get_cpu_process(s, cpu); + + if (process->pid != pid) { + return NULL; + } + + if (!process->attached) { + return NULL; + } + + return cpu; +} + static const char *get_feature_xml(const char *p, const char **newp, CPUClass *cc) { size_t len; int i; @@ -933,23 +996,10 @@ static void gdb_set_cpu_pc(GDBState *s, target_ulong pc) cpu_synchronize_state(cpu); cpu_set_pc(cpu, pc); } -static CPUState *find_cpu(uint32_t thread_id) -{ - CPUState *cpu; - - CPU_FOREACH(cpu) { - if (cpu_gdb_index(cpu) == thread_id) { - return cpu; - } - } - - return NULL; -} - static char *gdb_fmt_thread_id(const GDBState *s, CPUState *cpu, char *buf, size_t buf_size) { if (s->multiprocess) { snprintf(buf, buf_size, "p%02x.%02x", @@ -959,10 +1009,64 @@ static char *gdb_fmt_thread_id(const GDBState *s, CPUState *cpu, } return buf; } +typedef enum GDBThreadIdKind { + GDB_ONE_THREAD = 0, + GDB_ALL_THREADS, /* One process, all threads */ + GDB_ALL_PROCESSES, + GDB_READ_THREAD_ERR +} GDBThreadIdKind; + +static GDBThreadIdKind read_thread_id(const char *buf, const char **end_buf, + uint32_t *pid, uint32_t *tid) +{ + unsigned long p, t; + int ret; + + if (*buf == 'p') { + buf++; + ret = qemu_strtoul(buf, &buf, 16, &p); + + if (ret) { + return GDB_READ_THREAD_ERR; + } + + /* Skip '.' */ + buf++; + } else { + p = 1; + } + + ret = qemu_strtoul(buf, &buf, 16, &t); + + if (ret) { + return GDB_READ_THREAD_ERR; + } + + *end_buf = buf; + + if (p == -1) { + return GDB_ALL_PROCESSES; + } + + if (pid) { + *pid = p; + } + + if (t == -1) { + return GDB_ALL_THREADS; + } + + if (tid) { + *tid = t; + } + + return GDB_ONE_THREAD; +} + static int is_query_packet(const char *p, const char *query, char separator) { unsigned int query_len = strlen(query); return strncmp(p, query, query_len) == 0 && @@ -1067,16 +1171,18 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) { CPUState *cpu; CPUClass *cc; const char *p; uint32_t thread; + uint32_t pid, tid; int ch, reg_size, type, res; uint8_t mem_buf[MAX_PACKET_LENGTH]; char buf[sizeof(mem_buf) + 1 /* trailing NUL */]; char thread_id[16]; uint8_t *registers; target_ulong addr, len; + GDBThreadIdKind thread_kind; trace_gdbstub_io_command(line_buf); p = line_buf; ch = *p++; @@ -1280,16 +1386,22 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) else put_packet(s, "E22"); break; case 'H': type = *p++; - thread = strtoull(p, (char **)&p, 16); - if (thread == -1 || thread == 0) { + + thread_kind = read_thread_id(p, &p, &pid, &tid); + if (thread_kind == GDB_READ_THREAD_ERR) { + put_packet(s, "E22"); + break; + } + + if (thread_kind != GDB_ONE_THREAD) { put_packet(s, "OK"); break; } - cpu = find_cpu(thread); + cpu = gdb_get_cpu(s, pid, tid); if (cpu == NULL) { put_packet(s, "E22"); break; } switch (type) { @@ -1305,12 +1417,16 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) put_packet(s, "E22"); break; } break; case 'T': - thread = strtoull(p, (char **)&p, 16); - cpu = find_cpu(thread); + thread_kind = read_thread_id(p, &p, &pid, &tid); + if (thread_kind == GDB_READ_THREAD_ERR) { + put_packet(s, "E22"); + break; + } + cpu = gdb_get_cpu(s, pid, tid); if (cpu != NULL) { put_packet(s, "OK"); } else { put_packet(s, "E22"); From patchwork Fri Oct 26 08:16: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: 989503 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="Pn1w3Xgn"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="ZcG29Jd2"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="gT6miJT7"; 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 42hHYJ2C8sz9sBZ for ; Fri, 26 Oct 2018 19:42:12 +1100 (AEDT) Received: from localhost ([::1]:58875 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxh3-0006UB-Rt for incoming@patchwork.ozlabs.org; Fri, 26 Oct 2018 04:42:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59989) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxUL-0000gN-0x for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:29:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFxJD-0004ok-OF for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:17:33 -0400 Received: from greensocs.com ([193.104.36.180]:45295) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxJ7-0004hZ-Um; Fri, 26 Oct 2018 04:17:26 -0400 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id F384E441B4D; Fri, 26 Oct 2018 10:17:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541836; bh=nBv+pEnI6n0XuM/9Ux9lAAB28PeFXmf8egJR1vkQ/WM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Pn1w3XgnR+2eHCPga75qkfyGheccxH0AbYtIRE70oYi95PyGsx3RbpQk4kgm0A+Bq 5JQ3AePX1sufmUkiPpDmPbzZ7M+SLmPEtQHjOCxlLH0mT6obtslqf7FJIV5cK8wMW8 QoIk1xaYUKPBLeivGi53MNpXUN4UqELyRM6U7SQU= 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=ZcG29Jd2; dkim=pass (1024-bit key) header.d=greensocs.com header.b=gT6miJT7 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 AY5pT2dCRQ4z; Fri, 26 Oct 2018 10:17:15 +0200 (CEST) Received: by greensocs.com (Postfix, from userid 998) id 1DC3E441B49; Fri, 26 Oct 2018 10:17:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541834; bh=nBv+pEnI6n0XuM/9Ux9lAAB28PeFXmf8egJR1vkQ/WM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZcG29Jd23wHph5UdSFU5ol/LFoANMcwrrpf1LCb+gtlKc5089DMzKGeTkKnoCQHWI RjDrwA3iM1CrTVey6VnO4u6+9FvQnyO/LD9YANf1Ji+s+VHlMzpawOIidCFDnliNld V/X5pj91R54M8KuFkvxq59FK84DK/+17HYssQx+c= 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 96C7A441B42; Fri, 26 Oct 2018 10:17:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541833; bh=nBv+pEnI6n0XuM/9Ux9lAAB28PeFXmf8egJR1vkQ/WM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gT6miJT7HfUFsMS23XBktbOqVnuyu/DlNv21vyKaD5jXXNdNvoFdjc0ydZUnerzk3 UxN4Ko+4K3GxQljxkYRJeSLsv//2t55SlDI5fWDXFZ2QE/OGF8RKDJvSZn6R+heqRN lh5dJVLrloDJGbAICCwpEhHhN0ku60IWgnY8hxx0= From: Luc Michel To: qemu-devel@nongnu.org Date: Fri, 26 Oct 2018 10:16:42 +0200 Message-Id: <20181026081653.24602-6-luc.michel@greensocs.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181026081653.24602-1-luc.michel@greensocs.com> References: <20181026081653.24602-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 v3 05/16] gdbstub: add multiprocess support to vCont 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" Add the gdb_first_cpu() and gdb_next_cpu() to iterate over all the CPUs in currently attached processes. Add the gdb_first_cpu_in_process() and gdb_next_cpu_in_process() to iterate over CPUs of a given process. Use them to add multiprocess extension support to vCont packets. Signed-off-by: Luc Michel Reviewed-by: Philippe Mathieu-Daudé --- gdbstub.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 102 insertions(+), 15 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index c437af7aca..d1ec245d1d 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -713,10 +713,40 @@ static CPUState *find_cpu(uint32_t thread_id) } return NULL; } +static CPUState *get_first_cpu_in_process(const GDBState *s, + GDBProcess *process) +{ + CPUState *cpu; + + CPU_FOREACH(cpu) { + if (gdb_get_cpu_pid(s, cpu) == process->pid) { + return cpu; + } + } + + return NULL; +} + +static CPUState *gdb_next_cpu_in_process(const GDBState *s, CPUState *cpu) +{ + uint32_t pid = gdb_get_cpu_pid(s, cpu); + cpu = CPU_NEXT(cpu); + + while (cpu) { + if (gdb_get_cpu_pid(s, cpu) == pid) { + break; + } + + cpu = CPU_NEXT(cpu); + } + + return cpu; +} + static CPUState *gdb_get_cpu(const GDBState *s, uint32_t pid, uint32_t tid) { GDBProcess *process; CPUState *cpu = find_cpu(tid); @@ -740,10 +770,41 @@ static CPUState *gdb_get_cpu(const GDBState *s, uint32_t pid, uint32_t tid) } return cpu; } +/* Return the cpu following @cpu, while ignoring + * unattached processes. + */ +static CPUState *gdb_next_cpu(const GDBState *s, CPUState *cpu) +{ + cpu = CPU_NEXT(cpu); + + while (cpu) { + if (gdb_get_cpu_process(s, cpu)->attached) { + break; + } + + cpu = CPU_NEXT(cpu); + } + + return cpu; +} + +/* Return the first attached cpu */ +static CPUState *gdb_first_cpu(const GDBState *s) +{ + CPUState *cpu = first_cpu; + GDBProcess *process = gdb_get_cpu_process(s, cpu); + + if (!process->attached) { + return gdb_next_cpu(s, cpu); + } + + return cpu; +} + static const char *get_feature_xml(const char *p, const char **newp, CPUClass *cc) { size_t len; int i; @@ -1078,14 +1139,16 @@ static int is_query_packet(const char *p, const char *query, char separator) * returns -ENOTSUP if a command is unsupported, -EINVAL or -ERANGE if there is * a format error, 0 on success. */ static int gdb_handle_vcont(GDBState *s, const char *p) { - int res, idx, signal = 0; + int res, signal = 0; char cur_action; char *newstates; unsigned long tmp; + uint32_t pid, tid; + GDBProcess *process; CPUState *cpu; #ifdef CONFIG_USER_ONLY int max_cpus = 1; /* global variable max_cpus exists only in system mode */ CPU_FOREACH(cpu) { @@ -1124,29 +1187,52 @@ static int gdb_handle_vcont(GDBState *s, const char *p) } else if (cur_action != 'c' && cur_action != 's') { /* unknown/invalid/unsupported command */ res = -ENOTSUP; goto out; } - /* thread specification. special values: (none), -1 = all; 0 = any */ - if ((p[0] == ':' && p[1] == '-' && p[2] == '1') || (p[0] != ':')) { - if (*p == ':') { - p += 3; - } - for (idx = 0; idx < max_cpus; idx++) { - if (newstates[idx] == 1) { - newstates[idx] = cur_action; + + if (*p++ != ':') { + res = -ENOTSUP; + goto out; + } + + switch (read_thread_id(p, &p, &pid, &tid)) { + case GDB_READ_THREAD_ERR: + res = -EINVAL; + goto out; + + case GDB_ALL_PROCESSES: + cpu = gdb_first_cpu(s); + while (cpu) { + if (newstates[cpu->cpu_index] == 1) { + newstates[cpu->cpu_index] = cur_action; } + + cpu = gdb_next_cpu(s, cpu); } - } else if (*p == ':') { - p++; - res = qemu_strtoul(p, &p, 16, &tmp); - if (res) { + break; + + case GDB_ALL_THREADS: + process = gdb_get_process(s, pid); + + if (!process->attached) { + res = -EINVAL; goto out; } - /* 0 means any thread, so we pick the first valid CPU */ - cpu = tmp ? find_cpu(tmp) : first_cpu; + cpu = get_first_cpu_in_process(s, process); + while (cpu) { + if (newstates[cpu->cpu_index] == 1) { + newstates[cpu->cpu_index] = cur_action; + } + + cpu = gdb_next_cpu_in_process(s, cpu); + } + break; + + case GDB_ONE_THREAD: + cpu = gdb_get_cpu(s, pid, tid); /* invalid CPU/thread specified */ if (!cpu) { res = -EINVAL; goto out; @@ -1154,10 +1240,11 @@ static int gdb_handle_vcont(GDBState *s, const char *p) /* only use if no previous match occourred */ if (newstates[cpu->cpu_index] == 1) { newstates[cpu->cpu_index] = cur_action; } + break; } } s->signal = signal; gdb_continue_partial(s, newstates); From patchwork Fri Oct 26 08:16:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luc Michel X-Patchwork-Id: 989506 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="5Kocbv/p"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="U3rZqD+F"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="U3rZqD+F"; 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 42hHbs10RLz9s8F for ; Fri, 26 Oct 2018 19:44:23 +1100 (AEDT) Received: from localhost ([::1]:58884 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxjA-00015F-MB for incoming@patchwork.ozlabs.org; Fri, 26 Oct 2018 04:44:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59989) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxUH-0000gN-EA for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:29:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFxJE-0004pf-H4 for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:17:33 -0400 Received: from greensocs.com ([193.104.36.180]:45400) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxJ9-0004lP-H0; Fri, 26 Oct 2018 04:17:29 -0400 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id 10C58441B4F; Fri, 26 Oct 2018 10:17:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541837; bh=tEd2P0fg10cenqbv0sIZIp+ENwFNIB8g6Mf2Gz9V6yo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=5Kocbv/pl11xTrZ5EK4TjMC+Y5q4feTtmgEWTR1gLMIAY0YONP3UoqpnlyDcptq9/ o2ZUbT8qYFbfirrhKb03ZI8lJG7wpvGErU96mW8THmt5y6EKq5G0xxlLTIFDlxtmY3 RUG5UHpfGLaUs5ZVnJAn7DeeNz8R3bZGB5Vlswyk= 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=U3rZqD+F; dkim=pass (1024-bit key) header.d=greensocs.com header.b=U3rZqD+F 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 SW1zuAOR-HPq; Fri, 26 Oct 2018 10:17:16 +0200 (CEST) Received: by greensocs.com (Postfix, from userid 998) id A0559441B47; Fri, 26 Oct 2018 10:17:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541834; bh=tEd2P0fg10cenqbv0sIZIp+ENwFNIB8g6Mf2Gz9V6yo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=U3rZqD+F7OMmALIaJnM6+T4RLKr7CQYf1dKP+I+CKW44pN4qbo6Pv4qxkqyl8/N29 9+Qy/7hT5BvzoDbL7g184AxkZ/teCKu+Kik15pJv6V8TMHsn8j3EOLnMr1K8f1ByQO bRakPBpsZ1KwSf4DseiBS13Qn0BMSur6ArYV+UmQ= 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 2370A441B42; Fri, 26 Oct 2018 10:17:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541834; bh=tEd2P0fg10cenqbv0sIZIp+ENwFNIB8g6Mf2Gz9V6yo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=U3rZqD+F7OMmALIaJnM6+T4RLKr7CQYf1dKP+I+CKW44pN4qbo6Pv4qxkqyl8/N29 9+Qy/7hT5BvzoDbL7g184AxkZ/teCKu+Kik15pJv6V8TMHsn8j3EOLnMr1K8f1ByQO bRakPBpsZ1KwSf4DseiBS13Qn0BMSur6ArYV+UmQ= From: Luc Michel To: qemu-devel@nongnu.org Date: Fri, 26 Oct 2018 10:16:43 +0200 Message-Id: <20181026081653.24602-7-luc.michel@greensocs.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181026081653.24602-1-luc.michel@greensocs.com> References: <20181026081653.24602-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 v3 06/16] gdbstub: add multiprocess support to 'sC' 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" Change the sC packet handling to support the multiprocess extension. Instead of returning the first thread, we return the first thread of the current process. Signed-off-by: Luc Michel Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Alistair Francis --- gdbstub.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index d1ec245d1d..17fec8a41c 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1543,13 +1543,18 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) type = strtoul(p, (char **)&p, 16); sstep_flags = type; put_packet(s, "OK"); break; } else if (strcmp(p,"C") == 0) { - /* "Current thread" remains vague in the spec, so always return - * the first CPU (gdb returns the first thread). */ - put_packet(s, "QC1"); + /* "Current thread" remains vague in the spec, so always return the + * first thread of the current process (gdb returns the first + * thread). + */ + cpu = get_first_cpu_in_process(s, gdb_get_cpu_process(s, s->g_cpu)); + snprintf(buf, sizeof(buf), "QC%s", + gdb_fmt_thread_id(s, cpu, thread_id, sizeof(thread_id))); + put_packet(s, buf); break; } else if (strcmp(p,"fThreadInfo") == 0) { s->query_cpu = first_cpu; goto report_cpuinfo; } else if (strcmp(p,"sThreadInfo") == 0) { From patchwork Fri Oct 26 08:16:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luc Michel X-Patchwork-Id: 989501 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="Q8KUJf5R"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="1Vir/1de"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="1Vir/1de"; 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 42hHVf72hfz9s1c for ; Fri, 26 Oct 2018 19:39:54 +1100 (AEDT) Received: from localhost ([::1]:58860 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxeq-0004ZN-HF for incoming@patchwork.ozlabs.org; Fri, 26 Oct 2018 04:39:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59943) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxUH-0000LS-Ek for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:29:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFxJE-0004pY-Ew for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:17:33 -0400 Received: from greensocs.com ([193.104.36.180]:45402) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxJ9-0004lW-Id; Fri, 26 Oct 2018 04:17:29 -0400 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id 32F5B441B52; Fri, 26 Oct 2018 10:17:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541838; bh=+bywekg1op7l1Y73+cSyV1i54Evh+KgmouT9yYwL0DM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Q8KUJf5Rs8JX+2aenEIOIGHa1p4iMdCBQxaq3kaNcQV+2B+EFEsu0O5KbCQvIIafB QOBZR2nzCCRm+IRLzGYoPoU7rwDl6wS8/olAmscKcL5ff8SDWSQ9SAPh5WTQalEb/c 167MEFXGd6UfHjustLOil630fh4nAUpBbAahKEmY= 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=1Vir/1de; dkim=pass (1024-bit key) header.d=greensocs.com header.b=1Vir/1de 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 aQ72E5I5hsOF; Fri, 26 Oct 2018 10:17:17 +0200 (CEST) Received: by greensocs.com (Postfix, from userid 998) id 45027441B45; Fri, 26 Oct 2018 10:17:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541835; bh=+bywekg1op7l1Y73+cSyV1i54Evh+KgmouT9yYwL0DM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=1Vir/1dei0+bicrl/JcEIDsqgYpXUJT0qqJ8g8f6plDscZQtvV5Y1qhmOVh5qBOKm lN2IYupvoWYktAhPEoo61MpQfpRLBbRQ0NRo0e54md/UI6eoXcqxPsbBkpujuaUCnf +wqLcsj8ZLID1PEkCKu+zs0aL4no7h9MViXHF+Mk= 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 CC7C5441B42; Fri, 26 Oct 2018 10:17:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541835; bh=+bywekg1op7l1Y73+cSyV1i54Evh+KgmouT9yYwL0DM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=1Vir/1dei0+bicrl/JcEIDsqgYpXUJT0qqJ8g8f6plDscZQtvV5Y1qhmOVh5qBOKm lN2IYupvoWYktAhPEoo61MpQfpRLBbRQ0NRo0e54md/UI6eoXcqxPsbBkpujuaUCnf +wqLcsj8ZLID1PEkCKu+zs0aL4no7h9MViXHF+Mk= From: Luc Michel To: qemu-devel@nongnu.org Date: Fri, 26 Oct 2018 10:16:44 +0200 Message-Id: <20181026081653.24602-8-luc.michel@greensocs.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181026081653.24602-1-luc.michel@greensocs.com> References: <20181026081653.24602-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 v3 07/16] gdbstub: add multiprocess support to (f|s)ThreadInfo and ThreadExtraInfo 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" Change the thread info related packets handling to support multiprocess extension. Add the CPUs class name in the extra info to help differentiate them in multiprocess mode. Signed-off-by: Luc Michel Reviewed-by: Philippe Mathieu-Daudé --- gdbstub.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 17fec8a41c..b8aa4b34af 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1257,11 +1257,10 @@ out: static int gdb_handle_packet(GDBState *s, const char *line_buf) { CPUState *cpu; CPUClass *cc; const char *p; - uint32_t thread; uint32_t pid, tid; int ch, reg_size, type, res; uint8_t mem_buf[MAX_PACKET_LENGTH]; char buf[sizeof(mem_buf) + 1 /* trailing NUL */]; char thread_id[16]; @@ -1553,30 +1552,46 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) snprintf(buf, sizeof(buf), "QC%s", gdb_fmt_thread_id(s, cpu, thread_id, sizeof(thread_id))); put_packet(s, buf); break; } else if (strcmp(p,"fThreadInfo") == 0) { - s->query_cpu = first_cpu; + s->query_cpu = gdb_first_cpu(s); goto report_cpuinfo; } else if (strcmp(p,"sThreadInfo") == 0) { report_cpuinfo: if (s->query_cpu) { - snprintf(buf, sizeof(buf), "m%x", cpu_gdb_index(s->query_cpu)); + snprintf(buf, sizeof(buf), "m%s", + gdb_fmt_thread_id(s, s->query_cpu, + thread_id, sizeof(thread_id))); put_packet(s, buf); - s->query_cpu = CPU_NEXT(s->query_cpu); + s->query_cpu = gdb_next_cpu(s, s->query_cpu); } else put_packet(s, "l"); break; } else if (strncmp(p,"ThreadExtraInfo,", 16) == 0) { - thread = strtoull(p+16, (char **)&p, 16); - cpu = find_cpu(thread); + if (read_thread_id(p + 16, &p, &pid, &tid) == GDB_READ_THREAD_ERR) { + put_packet(s, "E22"); + break; + } + cpu = gdb_get_cpu(s, pid, tid); if (cpu != NULL) { cpu_synchronize_state(cpu); - /* memtohex() doubles the required space */ - len = snprintf((char *)mem_buf, sizeof(buf) / 2, - "CPU#%d [%s]", cpu->cpu_index, - cpu->halted ? "halted " : "running"); + + if (s->multiprocess && (s->process_num > 1)) { + /* Print the CPU model in multiprocess mode */ + ObjectClass *oc = object_get_class(OBJECT(cpu)); + const char *cpu_model = object_class_get_name(oc); + len = snprintf((char *)mem_buf, sizeof(buf) / 2, + "CPU#%d %s [%s]", cpu->cpu_index, + cpu_model, + cpu->halted ? "halted " : "running"); + } else { + /* memtohex() doubles the required space */ + len = snprintf((char *)mem_buf, sizeof(buf) / 2, + "CPU#%d [%s]", cpu->cpu_index, + cpu->halted ? "halted " : "running"); + } trace_gdbstub_op_extra_info((char *)mem_buf); memtohex(buf, mem_buf, len); put_packet(s, buf); } break; From patchwork Fri Oct 26 08:16:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luc Michel X-Patchwork-Id: 989499 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="BG2/C5D0"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="GC9sXizl"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="GC9sXizl"; 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 42hHTw3cJKz9s1c for ; Fri, 26 Oct 2018 19:39:15 +1100 (AEDT) Received: from localhost ([::1]:58857 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxeB-0003oE-PD for incoming@patchwork.ozlabs.org; Fri, 26 Oct 2018 04:39:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59943) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxUG-0000LS-2D for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:28:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFxJE-0004pl-Je for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:17:34 -0400 Received: from greensocs.com ([193.104.36.180]:45401) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxJ9-0004lX-JY; Fri, 26 Oct 2018 04:17:29 -0400 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id F17EF441B44; Fri, 26 Oct 2018 10:17:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541839; bh=LSwJYhzSHocGetfdRoWRaX8Ih1Bj93XsS34Ng7gxibw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BG2/C5D0Jtzwckl1pnX4q6GrMi6Vmxv3B9HEKLRpRw/POdE1njFUAqeFCH/PLMHcl +ElkIOm33UPb/P77gjp3h65WQWKgPrA5qgzwawL7NDW6cSQd9yzKhG5WxWkujz6uHp vfgSPiGYLB9gov8RGuZgm5AJbEc/SfJ0oyO0YA+Q= 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=GC9sXizl; dkim=pass (1024-bit key) header.d=greensocs.com header.b=GC9sXizl 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 uU7JU91vO0BO; Fri, 26 Oct 2018 10:17:18 +0200 (CEST) Received: by greensocs.com (Postfix, from userid 998) id A6E80441B42; Fri, 26 Oct 2018 10:17:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541835; bh=LSwJYhzSHocGetfdRoWRaX8Ih1Bj93XsS34Ng7gxibw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GC9sXizlsbWTDLX0hQez2W9IUcSdj7W8tLsbq5yYLGXu/Dhw2StOLKh5mDu8cGjdV y5zQG6bIWuZbrjeHQSKlPCv2JtkwsllSm8z7w3xJVYxmLCFcSjlhekfa5mJUYB/3zB MVo0dtgR37KUQga9ntskuHN1PdCfq1eBlvbWKeGM= 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 451F3441B48; Fri, 26 Oct 2018 10:17:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541835; bh=LSwJYhzSHocGetfdRoWRaX8Ih1Bj93XsS34Ng7gxibw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GC9sXizlsbWTDLX0hQez2W9IUcSdj7W8tLsbq5yYLGXu/Dhw2StOLKh5mDu8cGjdV y5zQG6bIWuZbrjeHQSKlPCv2JtkwsllSm8z7w3xJVYxmLCFcSjlhekfa5mJUYB/3zB MVo0dtgR37KUQga9ntskuHN1PdCfq1eBlvbWKeGM= From: Luc Michel To: qemu-devel@nongnu.org Date: Fri, 26 Oct 2018 10:16:45 +0200 Message-Id: <20181026081653.24602-9-luc.michel@greensocs.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181026081653.24602-1-luc.michel@greensocs.com> References: <20181026081653.24602-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 v3 08/16] gdbstub: add multiprocess support to Xfer:features:read: 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" Change the Xfer:features:read: packet handling to support the multiprocess extension. This packet is used to request the XML description of the CPU. In multiprocess mode, different descriptions can be sent for different processes. This function now takes the process to send the description for as a parameter, and use a buffer in the process structure to store the generated description. It takes the first CPU of the process to generate the description. Signed-off-by: Luc Michel Reviewed-by: Philippe Mathieu-Daudé --- gdbstub.c | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index b8aa4b34af..b7079eff4a 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -298,10 +298,12 @@ typedef struct GDBRegisterState { } GDBRegisterState; typedef struct GDBProcess { uint32_t pid; bool attached; + + char target_xml[1024]; } GDBProcess; enum RSState { RS_INACTIVE, RS_IDLE, @@ -801,55 +803,57 @@ static CPUState *gdb_first_cpu(const GDBState *s) } return cpu; } -static const char *get_feature_xml(const char *p, const char **newp, - CPUClass *cc) +static const char *get_feature_xml(const GDBState *s, const char *p, + const char **newp, GDBProcess *process) { size_t len; int i; const char *name; - static char target_xml[1024]; + CPUState *cpu = get_first_cpu_in_process(s, process); + CPUClass *cc = CPU_GET_CLASS(cpu); len = 0; while (p[len] && p[len] != ':') len++; *newp = p + len; name = NULL; if (strncmp(p, "target.xml", len) == 0) { + char *buf = process->target_xml; + const size_t buf_sz = sizeof(process->target_xml); + /* Generate the XML description for this CPU. */ - if (!target_xml[0]) { + if (!buf[0]) { GDBRegisterState *r; - CPUState *cpu = first_cpu; - pstrcat(target_xml, sizeof(target_xml), + pstrcat(buf, buf_sz, "" "" ""); if (cc->gdb_arch_name) { gchar *arch = cc->gdb_arch_name(cpu); - pstrcat(target_xml, sizeof(target_xml), ""); - pstrcat(target_xml, sizeof(target_xml), arch); - pstrcat(target_xml, sizeof(target_xml), ""); + pstrcat(buf, buf_sz, ""); + pstrcat(buf, buf_sz, arch); + pstrcat(buf, buf_sz, ""); g_free(arch); } - pstrcat(target_xml, sizeof(target_xml), "gdb_core_xml_file); - pstrcat(target_xml, sizeof(target_xml), "\"/>"); + pstrcat(buf, buf_sz, "gdb_core_xml_file); + pstrcat(buf, buf_sz, "\"/>"); for (r = cpu->gdb_regs; r; r = r->next) { - pstrcat(target_xml, sizeof(target_xml), "xml); - pstrcat(target_xml, sizeof(target_xml), "\"/>"); + pstrcat(buf, buf_sz, "xml); + pstrcat(buf, buf_sz, "\"/>"); } - pstrcat(target_xml, sizeof(target_xml), ""); + pstrcat(buf, buf_sz, ""); } - return target_xml; + return buf; } if (cc->gdb_get_dynamic_xml) { - CPUState *cpu = first_cpu; char *xmlname = g_strndup(p, len); const char *xml = cc->gdb_get_dynamic_xml(cpu, xmlname); g_free(xmlname); if (xml) { @@ -1255,10 +1259,11 @@ out: } static int gdb_handle_packet(GDBState *s, const char *line_buf) { CPUState *cpu; + GDBProcess *process; CPUClass *cc; const char *p; uint32_t pid, tid; int ch, reg_size, type, res; uint8_t mem_buf[MAX_PACKET_LENGTH]; @@ -1636,18 +1641,19 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) } if (strncmp(p, "Xfer:features:read:", 19) == 0) { const char *xml; target_ulong total_len; - cc = CPU_GET_CLASS(first_cpu); + process = gdb_get_cpu_process(s, s->g_cpu); + cc = CPU_GET_CLASS(s->g_cpu); if (cc->gdb_core_xml_file == NULL) { goto unknown_command; } gdb_has_xml = true; p += 19; - xml = get_feature_xml(p, &p, cc); + xml = get_feature_xml(s, p, &p, process); if (!xml) { snprintf(buf, sizeof(buf), "E00"); put_packet(s, buf); break; } @@ -2315,10 +2321,11 @@ static int find_cpu_clusters(Object *child, void *opaque) GDBProcess *process = &s->processes[s->process_num - 1]; /* GDB process IDs -1 and 0 are reserved */ process->pid = cluster->cluster_id + 1; process->attached = false; + process->target_xml[0] = '\0'; return 0; } return object_child_foreach(child, find_cpu_clusters, opaque); } From patchwork Fri Oct 26 08:16:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luc Michel X-Patchwork-Id: 989508 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="DmAtSqYh"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="dbjZynMp"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="dbjZynMp"; 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 42hHfS47FXz9s8F for ; Fri, 26 Oct 2018 19:46:40 +1100 (AEDT) Received: from localhost ([::1]:58915 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxlO-0002vP-7G for incoming@patchwork.ozlabs.org; Fri, 26 Oct 2018 04:46:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59943) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxUK-0000LS-Ur for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:29:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFxJE-0004pA-1G for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:17:33 -0400 Received: from greensocs.com ([193.104.36.180]:45407) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxJ9-0004lb-K5; Fri, 26 Oct 2018 04:17:29 -0400 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id 14E4C441B54; Fri, 26 Oct 2018 10:17:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541839; bh=Y3IS9iymOA/SZuoyxBm1kgEzXBvSr1gd1zJpQV1LzIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DmAtSqYhcl8iIev49JY49lXYg9wg3vTcuszyNVxjVm/oRWo6GKvRqBfJ4OSbKkG/h 4bq+NX1UfKTnE9N3AIItwTwISmuKLk+F4YxtoiNC3c0uhv4VRs5+7O47UIVklodUU6 xG0LvflXosfvnxxL7wA7GdlSn6X2iVxwghJ9/ZUk= 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=dbjZynMp; dkim=pass (1024-bit key) header.d=greensocs.com header.b=dbjZynMp 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 3LR76BUzPNUY; Fri, 26 Oct 2018 10:17:18 +0200 (CEST) Received: by greensocs.com (Postfix, from userid 998) id 371EC441B4E; Fri, 26 Oct 2018 10:17:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541836; bh=Y3IS9iymOA/SZuoyxBm1kgEzXBvSr1gd1zJpQV1LzIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dbjZynMp5U500DArADoGBMsr/OxVOlP2b2jNi1LUH2TLsV8VUdm07daNVTbY/hY+k dAX1tLlhGDgKr7IzK8oHhNJMqkMn++6SaDYG214z022zf905i6Kd3D9zmcJtkCUpf8 7s+NQLcrkpfr2kjk5MD7iZuSDaqSBYapQToCcggE= 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 ADCD4441B48; Fri, 26 Oct 2018 10:17:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541836; bh=Y3IS9iymOA/SZuoyxBm1kgEzXBvSr1gd1zJpQV1LzIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dbjZynMp5U500DArADoGBMsr/OxVOlP2b2jNi1LUH2TLsV8VUdm07daNVTbY/hY+k dAX1tLlhGDgKr7IzK8oHhNJMqkMn++6SaDYG214z022zf905i6Kd3D9zmcJtkCUpf8 7s+NQLcrkpfr2kjk5MD7iZuSDaqSBYapQToCcggE= From: Luc Michel To: qemu-devel@nongnu.org Date: Fri, 26 Oct 2018 10:16:46 +0200 Message-Id: <20181026081653.24602-10-luc.michel@greensocs.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181026081653.24602-1-luc.michel@greensocs.com> References: <20181026081653.24602-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 v3 09/16] gdbstub: add multiprocess support to gdb_vm_state_change() 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" Add support for multiprocess extension in gdb_vm_state_change() function. Signed-off-by: Luc Michel Reviewed-by: Philippe Mathieu-Daudé --- gdbstub.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index b7079eff4a..39b1766f28 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1710,10 +1710,11 @@ void gdb_set_stop_cpu(CPUState *cpu) static void gdb_vm_state_change(void *opaque, int running, RunState state) { GDBState *s = gdbserver_state; CPUState *cpu = s->c_cpu; char buf[256]; + char thread_id[16]; const char *type; int ret; if (running || s->state == RS_INACTIVE) { return; @@ -1721,10 +1722,18 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state) /* Is there a GDB syscall waiting to be sent? */ if (s->current_syscall_cb) { put_packet(s, s->syscall_buf); return; } + + if (cpu == NULL) { + /* No process attached */ + return; + } + + gdb_fmt_thread_id(s, cpu, thread_id, sizeof(thread_id)); + switch (state) { case RUN_STATE_DEBUG: if (cpu->watchpoint_hit) { switch (cpu->watchpoint_hit->flags & BP_MEM_ACCESS) { case BP_MEM_READ: @@ -1738,12 +1747,12 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state) break; } trace_gdbstub_hit_watchpoint(type, cpu_gdb_index(cpu), (target_ulong)cpu->watchpoint_hit->vaddr); snprintf(buf, sizeof(buf), - "T%02xthread:%02x;%swatch:" TARGET_FMT_lx ";", - GDB_SIGNAL_TRAP, cpu_gdb_index(cpu), type, + "T%02xthread:%s;%swatch:" TARGET_FMT_lx ";", + GDB_SIGNAL_TRAP, thread_id, type, (target_ulong)cpu->watchpoint_hit->vaddr); cpu->watchpoint_hit = NULL; goto send_packet; } else { trace_gdbstub_hit_break(); @@ -1781,11 +1790,11 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state) trace_gdbstub_hit_unknown(state); ret = GDB_SIGNAL_UNKNOWN; break; } gdb_set_stop_cpu(cpu); - snprintf(buf, sizeof(buf), "T%02xthread:%02x;", ret, cpu_gdb_index(cpu)); + snprintf(buf, sizeof(buf), "T%02xthread:%s;", ret, thread_id); send_packet: put_packet(s, buf); /* disable single step if it was enabled */ From patchwork Fri Oct 26 08:16:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luc Michel X-Patchwork-Id: 989492 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="rYHzEfAu"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="rfIB1kaN"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="rfIB1kaN"; 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 42hHGt6NpZz9sDC for ; Fri, 26 Oct 2018 19:29:42 +1100 (AEDT) Received: from localhost ([::1]:58797 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxUy-0002k5-Dd for incoming@patchwork.ozlabs.org; Fri, 26 Oct 2018 04:29:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59989) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxU8-0000gN-ID for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:28:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFxJY-0004yP-Hl for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:17:53 -0400 Received: from greensocs.com ([193.104.36.180]:45404) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxJT-0004lZ-NK; Fri, 26 Oct 2018 04:17:47 -0400 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id CF96E441B42; Fri, 26 Oct 2018 10:17:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541839; bh=ZJZ51gb/+0GYcqwnEU5qIkiweEdjBR4mN+0UW8TXl+s=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=rYHzEfAuk7/u/AvYFYc1pB0dCt1YqoDDq8Ad5RoVwc5uh+N5XwRRYczwtElFyA3ee XvNh3w/dpbZWteXc1rePrCrQ4Y2c7JHpfZrYsgZMbvXglhHkqerikOVgQOfm6zbIsQ Ic0iRy6fRAFdOZv8Djq8L/sIaxbZVgOcfdb8V+N4= 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=rfIB1kaN; dkim=pass (1024-bit key) header.d=greensocs.com header.b=rfIB1kaN 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 eR0hpdBfr9Xa; Fri, 26 Oct 2018 10:17:19 +0200 (CEST) Received: by greensocs.com (Postfix, from userid 998) id 9F46A441B48; Fri, 26 Oct 2018 10:17:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541836; bh=ZJZ51gb/+0GYcqwnEU5qIkiweEdjBR4mN+0UW8TXl+s=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=rfIB1kaN11HEzlIFO4e5rko3hlHaGoRo1d5v3X3cv4mRMzuIl4LMQCRXB8A/GzDyk M3eytmGrUWYoYqOzYuhlEwFG46TYmjF/HQ2XOSigpADIxIUEmZwOSVmENuE86VureK h+68MYvzMi0oMaCTnee04eCD+LQYaXLUhcfIEe/4= 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 30C0F441B49; Fri, 26 Oct 2018 10:17:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541836; bh=ZJZ51gb/+0GYcqwnEU5qIkiweEdjBR4mN+0UW8TXl+s=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=rfIB1kaN11HEzlIFO4e5rko3hlHaGoRo1d5v3X3cv4mRMzuIl4LMQCRXB8A/GzDyk M3eytmGrUWYoYqOzYuhlEwFG46TYmjF/HQ2XOSigpADIxIUEmZwOSVmENuE86VureK h+68MYvzMi0oMaCTnee04eCD+LQYaXLUhcfIEe/4= From: Luc Michel To: qemu-devel@nongnu.org Date: Fri, 26 Oct 2018 10:16:47 +0200 Message-Id: <20181026081653.24602-11-luc.michel@greensocs.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181026081653.24602-1-luc.michel@greensocs.com> References: <20181026081653.24602-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 v3 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 39b1766f28..4d8474204f 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1036,24 +1036,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) { @@ -1328,13 +1343,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); From patchwork Fri Oct 26 08:16:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Michel X-Patchwork-Id: 989493 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="Pjr9ZwzG"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="ZoAZPuG2"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="KM3huB0m"; 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 42hHLj70RZz9sDC for ; Fri, 26 Oct 2018 19:33:01 +1100 (AEDT) Received: from localhost ([::1]:58817 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxYB-0005M4-Hb for incoming@patchwork.ozlabs.org; Fri, 26 Oct 2018 04:32:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60010) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxUD-0000gX-Td for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:28:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFxJY-0004yU-IQ for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:17:53 -0400 Received: from greensocs.com ([193.104.36.180]:45405) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxJT-0004lY-Pc; Fri, 26 Oct 2018 04:17:48 -0400 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id DB1E5441B55; Fri, 26 Oct 2018 10:17:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541839; bh=9dQbVgz96/nsR5DpXYpQlUDTF/nsJCFo9CdyXS2rSHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Pjr9ZwzGkioo52c58otX4hwdYTAdVKwl0cu9yVTAxVwxiHAsf959waYRzu5Tnoc9B ruklDYVWAjO37TWEDe6zrTNKI8kZu2USqpa0tfWlkWpC76lccr8lhIkGBajKRgubFW 6N/sdFg05byt0rMQzo3KtdWqKsNZxDJzIFJ6tOvk= 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=ZoAZPuG2; dkim=pass (1024-bit key) header.d=greensocs.com header.b=KM3huB0m 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 lLYsbp3KA7LI; Fri, 26 Oct 2018 10:17:19 +0200 (CEST) Received: by greensocs.com (Postfix, from userid 998) id 92D5C441B50; Fri, 26 Oct 2018 10:17:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541837; bh=9dQbVgz96/nsR5DpXYpQlUDTF/nsJCFo9CdyXS2rSHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZoAZPuG2Y7W70aVBkJ67awPOtn7RBDeb1nWE5QS8Af+vdMXOvzPiDSZAMF9pDLYp3 yxI7SYREKMX1Mt3sXDTAZeKoD5MbnOmxVqAy25Q6y0frr0Ss6jsakFMxp+lTW4skTN SQc0nd3NacoV5VI3cyqY5gUIgrpR0/Jl+fpvgEsQ= 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 A7952441B49; Fri, 26 Oct 2018 10:17:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541836; bh=9dQbVgz96/nsR5DpXYpQlUDTF/nsJCFo9CdyXS2rSHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KM3huB0mpRKA600VRtIt/UQaMHvX+g8ITM/q1rPHOfY+3hsj2gdRg4i3slL1yW+wt BpYgIV2biKfsFxdzL+LRv7yDfc8mkL++dOXnZlkIBdNvMuwY8x3IbMbFbOMewl6PUL lD1IVUzp9vMZarci94leUFw/24gOh29tNiHX7x8g= From: Luc Michel To: qemu-devel@nongnu.org Date: Fri, 26 Oct 2018 10:16:48 +0200 Message-Id: <20181026081653.24602-12-luc.michel@greensocs.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181026081653.24602-1-luc.michel@greensocs.com> References: <20181026081653.24602-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 v3 11/16] gdbstub: add support for extended mode packet 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" Add support for the '!' extended mode packet. This is required for the multiprocess extension. Signed-off-by: Luc Michel --- gdbstub.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gdbstub.c b/gdbstub.c index 4d8474204f..9c239c1760 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1291,10 +1291,13 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) trace_gdbstub_io_command(line_buf); p = line_buf; ch = *p++; switch(ch) { + case '!': + put_packet(s, "OK"); + break; case '?': /* TODO: Make this return the correct value for user-mode. */ snprintf(buf, sizeof(buf), "T%02xthread:%s;", GDB_SIGNAL_TRAP, gdb_fmt_thread_id(s, s->c_cpu, thread_id, sizeof(thread_id))); put_packet(s, buf); From patchwork Fri Oct 26 08:16:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Michel X-Patchwork-Id: 989497 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="orY2G34F"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="EfzeOY0j"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="EfzeOY0j"; 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 42hHQR75Xcz9s3C for ; Fri, 26 Oct 2018 19:36:15 +1100 (AEDT) Received: from localhost ([::1]:58838 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxbJ-0000Xh-81 for incoming@patchwork.ozlabs.org; Fri, 26 Oct 2018 04:36:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59989) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxUD-0000gN-6b for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:28:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFxJY-0004y8-GF for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:17:53 -0400 Received: from greensocs.com ([193.104.36.180]:45406) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxJT-0004la-Ny; Fri, 26 Oct 2018 04:17:48 -0400 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id 9CFAA441B48; Fri, 26 Oct 2018 10:17:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541840; bh=L3lheXRjjCXYHVz6bZsvvaoBb9o5ZwPf2un7Fgcf6EM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=orY2G34F/yzysqdJR2OBUhO5bCBaSxZ6O823QP52IH/JktBgzNJQ9nWHv/MrjuJ6w NKpFwhOJugo1deeG5NZEbKjIhwSumLeof6Ywf7RNOsTVDarGs6HwMpr2AIRRrOanYy VXW6CLioO2C8BGYffKKnccLYWj1YCBu98QpzCQR8= 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=EfzeOY0j; dkim=pass (1024-bit key) header.d=greensocs.com header.b=EfzeOY0j 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 nZG5xloL_VVl; Fri, 26 Oct 2018 10:17:19 +0200 (CEST) Received: by greensocs.com (Postfix, from userid 998) id E05A0441B49; Fri, 26 Oct 2018 10:17:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541837; bh=L3lheXRjjCXYHVz6bZsvvaoBb9o5ZwPf2un7Fgcf6EM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=EfzeOY0jnDc07yxeRB0FJlZFSWDTFUU2zA2br+5zfiToyPlrxUeXheuZNeBXLFuRw j8itz+yTJ4sKgqnhCLjqAp8sh6kIeNyTOJzEcWIrGVNThecTDsrcYctnoqXVnSLSx4 dZ2I6hUNuzPShILzxz8yTRnJxQuxmyeSh283OtDA= 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 7C081441B47; Fri, 26 Oct 2018 10:17:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541837; bh=L3lheXRjjCXYHVz6bZsvvaoBb9o5ZwPf2un7Fgcf6EM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=EfzeOY0jnDc07yxeRB0FJlZFSWDTFUU2zA2br+5zfiToyPlrxUeXheuZNeBXLFuRw j8itz+yTJ4sKgqnhCLjqAp8sh6kIeNyTOJzEcWIrGVNThecTDsrcYctnoqXVnSLSx4 dZ2I6hUNuzPShILzxz8yTRnJxQuxmyeSh283OtDA= From: Luc Michel To: qemu-devel@nongnu.org Date: Fri, 26 Oct 2018 10:16:49 +0200 Message-Id: <20181026081653.24602-13-luc.michel@greensocs.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181026081653.24602-1-luc.michel@greensocs.com> References: <20181026081653.24602-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 v3 12/16] gdbstub: add support for vAttach 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" Add support for the vAttach packets. In multiprocess mode, GDB sends them to attach to additional processes. Signed-off-by: Luc Michel --- gdbstub.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/gdbstub.c b/gdbstub.c index 9c239c1760..e5eddd8e2b 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1337,10 +1337,45 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) break; } goto unknown_command; } break; + } else if (strncmp(p, "Attach;", 7) == 0) { + unsigned long pid; + + p += 7; + + if (qemu_strtoul(p, &p, 16, &pid)) { + put_packet(s, "E22"); + break; + } + + process = gdb_get_process(s, pid); + + if (process == NULL) { + put_packet(s, "E22"); + break; + } + + cpu = get_first_cpu_in_process(s, process); + + if (cpu == NULL) { + /* Refuse to attach an empty process */ + put_packet(s, "E22"); + break; + } + + process->attached = true; + + s->g_cpu = cpu; + s->c_cpu = cpu; + + snprintf(buf, sizeof(buf), "T%02xthread:%s;", GDB_SIGNAL_TRAP, + gdb_fmt_thread_id(s, cpu, thread_id, sizeof(thread_id))); + + put_packet(s, buf); + break; } else { goto unknown_command; } case 'k': /* Kill the target */ From patchwork Fri Oct 26 08:16:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Michel X-Patchwork-Id: 989498 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="Xjhu3rGQ"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="Lv9BWhGQ"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="Lv9BWhGQ"; 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 42hHR82tGyz9s3C for ; Fri, 26 Oct 2018 19:36:52 +1100 (AEDT) Received: from localhost ([::1]:58842 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxbt-000121-TN for incoming@patchwork.ozlabs.org; Fri, 26 Oct 2018 04:36:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60297) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxUI-0002m7-9l for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:29:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFxJE-0004pH-4I for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:17:33 -0400 Received: from greensocs.com ([193.104.36.180]:45409) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxJ9-0004lc-GG; Fri, 26 Oct 2018 04:17:29 -0400 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id C6EEB441B49; Fri, 26 Oct 2018 10:17:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541840; bh=BihBqIDZ9GGhR6yGrLTs+q1njikFDNZXrheaOwYcMtE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Xjhu3rGQyMvmw1AWFtMokInf+aKnKVZ2/j2+SW2PCWoEh0DLYx3p1OdKd9aD64o43 +qkJS4BPedxjUjW2fRlKNvUUdpiL8Lg5TR//7K0PMvhutnb/RHhuXd+iz4JxsOK0nl 4Fs9CYiS28BHMiBdrG0elQjIg3J78PrZ2cTWJ0Y0= 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=Lv9BWhGQ; dkim=pass (1024-bit key) header.d=greensocs.com header.b=Lv9BWhGQ 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 wCgoeseR5jE5; Fri, 26 Oct 2018 10:17:20 +0200 (CEST) Received: by greensocs.com (Postfix, from userid 998) id 68650441B45; Fri, 26 Oct 2018 10:17:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541838; bh=BihBqIDZ9GGhR6yGrLTs+q1njikFDNZXrheaOwYcMtE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Lv9BWhGQLK7ixObPInvQF6iAkzgVIPMmY6Myx6z+KTI8r90j7IXjSU2Nm3WVv7zON /+20HiVlX/bf3eYRdf1y8stEBc5APGQUc7UKhc00toe6Aux4nlCpZykQFMTUJzUUG0 3WyPHxnV/N6Mc+CUxf7KEU94g5FvZ0Ef1Py27qYM= 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 E4C7F441B47; Fri, 26 Oct 2018 10:17:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541838; bh=BihBqIDZ9GGhR6yGrLTs+q1njikFDNZXrheaOwYcMtE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Lv9BWhGQLK7ixObPInvQF6iAkzgVIPMmY6Myx6z+KTI8r90j7IXjSU2Nm3WVv7zON /+20HiVlX/bf3eYRdf1y8stEBc5APGQUc7UKhc00toe6Aux4nlCpZykQFMTUJzUUG0 3WyPHxnV/N6Mc+CUxf7KEU94g5FvZ0Ef1Py27qYM= From: Luc Michel To: qemu-devel@nongnu.org Date: Fri, 26 Oct 2018 10:16:50 +0200 Message-Id: <20181026081653.24602-14-luc.michel@greensocs.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181026081653.24602-1-luc.michel@greensocs.com> References: <20181026081653.24602-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 v3 13/16] gdbstub: processes initialization on new peer connection 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" When a new connection is established, we set the first process to be attached, and the others detached. The first CPU of the first process is selected as the current CPU. Signed-off-by: Luc Michel Reviewed-by: Alistair Francis --- gdbstub.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index e5eddd8e2b..b3461eff9e 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -2242,13 +2242,14 @@ static bool gdb_accept(void) close(fd); return false; } s = g_malloc0(sizeof(GDBState)); - s->c_cpu = first_cpu; - s->g_cpu = first_cpu; create_unique_process(s); + s->processes[0].attached = true; + s->c_cpu = gdb_first_cpu(s); + s->g_cpu = s->c_cpu; s->fd = fd; gdb_has_xml = false; gdbserver_state = s; return true; @@ -2330,12 +2331,23 @@ static void gdb_chr_receive(void *opaque, const uint8_t *buf, int size) } } static void gdb_chr_event(void *opaque, int event) { + int i; + GDBState *s = (GDBState *) opaque; + switch (event) { case CHR_EVENT_OPENED: + /* Start with first process attached, others detached */ + for (i = 0; i < s->process_num; i++) { + s->processes[i].attached = !i; + } + + s->c_cpu = gdb_first_cpu(s); + s->g_cpu = s->c_cpu; + vm_stop(RUN_STATE_PAUSED); gdb_has_xml = false; break; default: break; @@ -2509,19 +2521,17 @@ int gdbserver_start(const char *device) mon_chr = s->mon_chr; cleanup_processes(s); memset(s, 0, sizeof(GDBState)); s->mon_chr = mon_chr; } - s->c_cpu = first_cpu; - s->g_cpu = first_cpu; create_processes(s); if (chr) { qemu_chr_fe_init(&s->chr, chr, &error_abort); qemu_chr_fe_set_handlers(&s->chr, gdb_chr_can_receive, gdb_chr_receive, - gdb_chr_event, NULL, NULL, NULL, true); + gdb_chr_event, NULL, s, NULL, true); } s->state = chr ? RS_IDLE : RS_INACTIVE; s->mon_chr = mon_chr; s->current_syscall_cb = NULL; From patchwork Fri Oct 26 08:16:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Michel X-Patchwork-Id: 989496 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="iKZRF2jS"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="fSNzYhn8"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="fSNzYhn8"; 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 42hHPH5P9Vz9s3C for ; Fri, 26 Oct 2018 19:35:15 +1100 (AEDT) Received: from localhost ([::1]:58828 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxaL-0008As-9O for incoming@patchwork.ozlabs.org; Fri, 26 Oct 2018 04:35:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59943) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxUD-0000LS-5R for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:28:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFxJY-0004yZ-K0 for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:17:53 -0400 Received: from greensocs.com ([193.104.36.180]:45408) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxJT-0004ll-QZ; Fri, 26 Oct 2018 04:17:48 -0400 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id 74585441B45; Fri, 26 Oct 2018 10:17:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541841; bh=rD9a4K7ZyB7rSOPQ+3dwrMRt9gvBTShbRNlnFXihPlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=iKZRF2jSa8Dvgxj1HmbX0oro1Egggd2a+3KqU2pgP9qmZpcbr4ZqwqblK8/MgC9Nn DhyM81urJ+acT5Kd12uuEgYrAVdpzp83teFemZoH1rqya7uWqeqTDiZPEWQDE98lkt dzggl1vlgjroXkCuvlqy/yNAfenP6xKXMWyLfJ0U= 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=fSNzYhn8; dkim=pass (1024-bit key) header.d=greensocs.com header.b=fSNzYhn8 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 LXxh8FMbAaEE; Fri, 26 Oct 2018 10:17:20 +0200 (CEST) Received: by greensocs.com (Postfix, from userid 998) id D2A99441B53; Fri, 26 Oct 2018 10:17:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541838; bh=rD9a4K7ZyB7rSOPQ+3dwrMRt9gvBTShbRNlnFXihPlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fSNzYhn8i4NeRzAk1dRhJMCAMbpVdVUOgxqdxVEp4pxkK+eJjulSV6erlgN8g/C4A sthT7Myv315hH12Znv2FLq6FHKMQc+2ZNetkpFE3B6wrYJ22TuPcgaR2Ydd5xz3hdJ ighLMjOSdFXf/c1jshD/qh11iJxNy9Z5Z5S/6ikQ= 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 621B2441B44; Fri, 26 Oct 2018 10:17:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541838; bh=rD9a4K7ZyB7rSOPQ+3dwrMRt9gvBTShbRNlnFXihPlc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fSNzYhn8i4NeRzAk1dRhJMCAMbpVdVUOgxqdxVEp4pxkK+eJjulSV6erlgN8g/C4A sthT7Myv315hH12Znv2FLq6FHKMQc+2ZNetkpFE3B6wrYJ22TuPcgaR2Ydd5xz3hdJ ighLMjOSdFXf/c1jshD/qh11iJxNy9Z5Z5S/6ikQ= From: Luc Michel To: qemu-devel@nongnu.org Date: Fri, 26 Oct 2018 10:16:51 +0200 Message-Id: <20181026081653.24602-15-luc.michel@greensocs.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181026081653.24602-1-luc.michel@greensocs.com> References: <20181026081653.24602-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 v3 14/16] gdbstub: gdb_set_stop_cpu: ignore request when process is not attached 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" When gdb_set_stop_cpu() is called with a CPU associated to a process currently not attached by the GDB client, return without modifying the stop CPU. Otherwise, GDB get confused if it receives packets with a thread-id it does not know about. Signed-off-by: Luc Michel Acked-by: Alistair Francis --- gdbstub.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gdbstub.c b/gdbstub.c index b3461eff9e..09480df2bf 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1784,10 +1784,19 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) return RS_IDLE; } void gdb_set_stop_cpu(CPUState *cpu) { + GDBProcess *p = gdb_get_cpu_process(gdbserver_state, cpu); + + if (!p->attached) { + /* Having a stop CPU corresponding to a process that is not attached + * confuses GDB. So we ignore the request. + */ + return; + } + gdbserver_state->c_cpu = cpu; gdbserver_state->g_cpu = cpu; } #ifndef CONFIG_USER_ONLY From patchwork Fri Oct 26 08:16:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Michel X-Patchwork-Id: 989495 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="iE35CTiv"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="htkXR1t1"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="htkXR1t1"; 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 42hHP464VFz9s3C for ; Fri, 26 Oct 2018 19:35:04 +1100 (AEDT) Received: from localhost ([::1]:58825 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxaA-000817-8x for incoming@patchwork.ozlabs.org; Fri, 26 Oct 2018 04:35:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60010) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxU8-0000gX-JZ for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:28:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFxJY-0004y3-FR for qemu-devel@nongnu.org; Fri, 26 Oct 2018 04:17:53 -0400 Received: from greensocs.com ([193.104.36.180]:45407) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFxJW-0004lb-Ov; Fri, 26 Oct 2018 04:17:51 -0400 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id 63F95441B4C; Fri, 26 Oct 2018 10:17:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541842; bh=vDaD67RQ3c5X2pyk00EKbHlGZty38odwBUnpI9bYUZ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=iE35CTivZ6RF76dBikz7M0+R7/Z+AKRp8IHaxisgS8v/hMpXSiIJpti1TYPxe4LkY iPeZfKdTjBEpOQiGpeev1OYqWTGK9wnG/xEXvh3Fl5W8i28M2kConanJgQ5dVj+jzB s4Y6ZQD0lY4DdAtBLPqgVwXBXsyB2RrKWPbFVGNs= 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=htkXR1t1; dkim=pass (1024-bit key) header.d=greensocs.com header.b=htkXR1t1 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 ZFgPReZDztvv; Fri, 26 Oct 2018 10:17:21 +0200 (CEST) Received: by greensocs.com (Postfix, from userid 998) id C473E441B47; Fri, 26 Oct 2018 10:17:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541839; bh=vDaD67RQ3c5X2pyk00EKbHlGZty38odwBUnpI9bYUZ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=htkXR1t1O3Vl32T2v05gjVNzeQYnxvUpFmAhnUrBkVF4ni7IPxaTZqER+DX6CB+DT fP5JmPGhfggHrk28qnqWxIvKYA9v5T1CVBM1lJGaOaqxwKEgboKNDKitLT1t9Nai56 11B7qLGBIGydpAmmCkh+nJvFDLewtoIGHpth5nDg= 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 4D69F441B42; Fri, 26 Oct 2018 10:17:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1540541839; bh=vDaD67RQ3c5X2pyk00EKbHlGZty38odwBUnpI9bYUZ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=htkXR1t1O3Vl32T2v05gjVNzeQYnxvUpFmAhnUrBkVF4ni7IPxaTZqER+DX6CB+DT fP5JmPGhfggHrk28qnqWxIvKYA9v5T1CVBM1lJGaOaqxwKEgboKNDKitLT1t9Nai56 11B7qLGBIGydpAmmCkh+nJvFDLewtoIGHpth5nDg= From: Luc Michel To: qemu-devel@nongnu.org Date: Fri, 26 Oct 2018 10:16:53 +0200 Message-Id: <20181026081653.24602-17-luc.michel@greensocs.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181026081653.24602-1-luc.michel@greensocs.com> References: <20181026081653.24602-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 v3 16/16] arm/xlnx-zynqmp: put APUs and RPUs in separate CPU clusters 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" Create two separate CPU clusters for APUs and RPUs. Signed-off-by: Luc Michel --- include/hw/arm/xlnx-zynqmp.h | 3 +++ hw/arm/xlnx-zynqmp.c | 23 +++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/include/hw/arm/xlnx-zynqmp.h b/include/hw/arm/xlnx-zynqmp.h index 98f925ab84..591515c760 100644 --- a/include/hw/arm/xlnx-zynqmp.h +++ b/include/hw/arm/xlnx-zynqmp.h @@ -29,10 +29,11 @@ #include "hw/dma/xlnx_dpdma.h" #include "hw/dma/xlnx-zdma.h" #include "hw/display/xlnx_dp.h" #include "hw/intc/xlnx-zynqmp-ipi.h" #include "hw/timer/xlnx-zynqmp-rtc.h" +#include "hw/cpu/cluster.h" #define TYPE_XLNX_ZYNQMP "xlnx,zynqmp" #define XLNX_ZYNQMP(obj) OBJECT_CHECK(XlnxZynqMPState, (obj), \ TYPE_XLNX_ZYNQMP) @@ -75,10 +76,12 @@ typedef struct XlnxZynqMPState { /*< private >*/ DeviceState parent_obj; /*< public >*/ + CPUClusterState apu_cluster; + CPUClusterState rpu_cluster; ARMCPU apu_cpu[XLNX_ZYNQMP_NUM_APU_CPUS]; ARMCPU rpu_cpu[XLNX_ZYNQMP_NUM_RPU_CPUS]; GICState gic; MemoryRegion gic_mr[XLNX_ZYNQMP_GIC_REGIONS][XLNX_ZYNQMP_GIC_ALIASES]; diff --git a/hw/arm/xlnx-zynqmp.c b/hw/arm/xlnx-zynqmp.c index c195040350..7cc01f0b77 100644 --- a/hw/arm/xlnx-zynqmp.c +++ b/hw/arm/xlnx-zynqmp.c @@ -176,16 +176,23 @@ static void xlnx_zynqmp_create_rpu(XlnxZynqMPState *s, const char *boot_cpu, { Error *err = NULL; int i; int num_rpus = MIN(smp_cpus - XLNX_ZYNQMP_NUM_APU_CPUS, XLNX_ZYNQMP_NUM_RPU_CPUS); + object_initialize_child(OBJECT(s), "rpu-cluster", &s->rpu_cluster, + sizeof(s->rpu_cluster), TYPE_CPU_CLUSTER, + &error_abort, NULL); + + qdev_prop_set_uint32(DEVICE(&s->rpu_cluster), "cluster-id", 1); + qdev_init_nofail(DEVICE(&s->rpu_cluster)); + for (i = 0; i < num_rpus; i++) { char *name; object_initialize(&s->rpu_cpu[i], sizeof(s->rpu_cpu[i]), "cortex-r5f-" TYPE_ARM_CPU); - object_property_add_child(OBJECT(s), "rpu-cpu[*]", + object_property_add_child(OBJECT(&s->rpu_cluster), "rpu-cpu[*]", OBJECT(&s->rpu_cpu[i]), &error_abort); name = object_get_canonical_path_component(OBJECT(&s->rpu_cpu[i])); if (strcmp(name, boot_cpu)) { /* Secondary CPUs start in PSCI powered-down state */ @@ -211,14 +218,19 @@ static void xlnx_zynqmp_init(Object *obj) { XlnxZynqMPState *s = XLNX_ZYNQMP(obj); int i; int num_apus = MIN(smp_cpus, XLNX_ZYNQMP_NUM_APU_CPUS); + object_initialize_child(obj, "apu-cluster", &s->apu_cluster, + sizeof(s->apu_cluster), TYPE_CPU_CLUSTER, + &error_abort, NULL); + for (i = 0; i < num_apus; i++) { - object_initialize_child(obj, "apu-cpu[*]", &s->apu_cpu[i], - sizeof(s->apu_cpu[i]), - "cortex-a53-" TYPE_ARM_CPU, &error_abort, NULL); + object_initialize_child(OBJECT(&s->apu_cluster), "apu-cpu[*]", + &s->apu_cpu[i], sizeof(s->apu_cpu[i]), + "cortex-a53-" TYPE_ARM_CPU, &error_abort, + NULL); } sysbus_init_child_obj(obj, "gic", &s->gic, sizeof(s->gic), gic_class_name()); @@ -331,10 +343,13 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp) qdev_prop_set_uint32(DEVICE(&s->gic), "num-cpu", num_apus); qdev_prop_set_bit(DEVICE(&s->gic), "has-security-extensions", s->secure); qdev_prop_set_bit(DEVICE(&s->gic), "has-virtualization-extensions", s->virt); + qdev_prop_set_uint32(DEVICE(&s->apu_cluster), "cluster-id", 0); + qdev_init_nofail(DEVICE(&s->apu_cluster)); + /* Realize APUs before realizing the GIC. KVM requires this. */ for (i = 0; i < num_apus; i++) { char *name; object_property_set_int(OBJECT(&s->apu_cpu[i]), QEMU_PSCI_CONDUIT_SMC,