From patchwork Fri Nov 23 09:17:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Michel X-Patchwork-Id: 1002203 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="3JdHeqUy"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="Hdx5UaMP"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=greensocs.com header.i=@greensocs.com header.b="OWWHhx9U"; 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 431W3S0yYhz9s7T for ; Fri, 23 Nov 2018 20:19:32 +1100 (AEDT) Received: from localhost ([::1]:51152 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gQ7cX-0000gd-DZ for incoming@patchwork.ozlabs.org; Fri, 23 Nov 2018 04:19:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57989) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gQ7b3-0007yS-Ey for qemu-devel@nongnu.org; Fri, 23 Nov 2018 04:17:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gQ7b1-0000m7-UM for qemu-devel@nongnu.org; Fri, 23 Nov 2018 04:17:57 -0500 Received: from greensocs.com ([193.104.36.180]:47023) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gQ7ar-0000Lj-2e; Fri, 23 Nov 2018 04:17:45 -0500 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id 61A055C025C; Fri, 23 Nov 2018 10:17:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1542964654; bh=KrQImGji4CDiFKtwmdt0cnVuILaxfZ+qg7f4LV2oAA0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=3JdHeqUybAsL0UWJ6XA/3g1BzzIym7R2cVbDABXh3ccIB2wPDRzd6flSr0FXsSrj9 YETIDAdZghEG3A1CJzd2CfcrDTMcluYz7U4p8u4ibq/OMXQRvHComOiCjMg/usOPYm O7egYQPO+f9tOfEkYZjVRI7rHtULI5BBIcrOdSOc= 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=Hdx5UaMP; dkim=pass (1024-bit key) header.d=greensocs.com header.b=OWWHhx9U 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 QDMe3M1pUPpD; Fri, 23 Nov 2018 10:17:33 +0100 (CET) Received: by greensocs.com (Postfix, from userid 998) id 0B13E5BD1A0; Fri, 23 Nov 2018 10:17:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1542964653; bh=KrQImGji4CDiFKtwmdt0cnVuILaxfZ+qg7f4LV2oAA0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Hdx5UaMPBtPYC342v2voJNW82zeU5xEakY63fT7+eX1AYX4K3G0254MCDZKi7AFTk KW0E1uaLSpdqGEC8kMKJvCKUCSB2CDGRSvfx74eD3G8djfovodUor6OLckU2ft/oD+ 22VJRvEy6qA6YIVpfcuIxJvjNUs26m64lOTjO+zY= 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 8E8105C0259; Fri, 23 Nov 2018 10:17:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1542964652; bh=KrQImGji4CDiFKtwmdt0cnVuILaxfZ+qg7f4LV2oAA0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OWWHhx9URe7We9BVC5xSR8gIKxWdWqKymgQ7zlz16HVNfedJOaSuR2YIA7TU4t7b0 6X/L3AoNc51SFRcHao5eX8oLG0L9gVejoDvLyufV8xAb3s1LIGmi9cvrVncUJEF9Yo XUo07hTLNmIMBp+Ltjgk1qTECWDPBx5jdt2D9GC0= From: Luc Michel To: qemu-devel@nongnu.org Date: Fri, 23 Nov 2018 10:17:16 +0100 Message-Id: <20181123091729.29921-4-luc.michel@greensocs.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181123091729.29921-1-luc.michel@greensocs.com> References: <20181123091729.29921-1-luc.michel@greensocs.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 193.104.36.180 Subject: [Qemu-devel] [PATCH v7 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 Reviewed-by: Edgar E. Iglesias --- gdbstub.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 26f5a7449a..4fbc05dfe3 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -638,10 +638,52 @@ 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; + } + + /* + * Retrieve the CPU parent path by removing the last '/' and the CPU name + * from the CPU canonical path. */ + 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 +949,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 +1073,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. */