From nobody Thu Nov 6 00:38:34 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538395455572244.370742961004; Mon, 1 Oct 2018 05:04:15 -0700 (PDT) Received: from localhost ([::1]:37832 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g6wvu-0000r4-9O for importer@patchew.org; Mon, 01 Oct 2018 08:04:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g6wpT-0002RF-B0 for qemu-devel@nongnu.org; Mon, 01 Oct 2018 07:57:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g6wpQ-0005nt-LH for qemu-devel@nongnu.org; Mon, 01 Oct 2018 07:57:35 -0400 Received: from greensocs.com ([193.104.36.180]:40040) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g6wpG-0005SR-2s; Mon, 01 Oct 2018 07:57:26 -0400 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id C20E0511C74; Mon, 1 Oct 2018 13:57:08 +0200 (CEST) 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 EhjVCXGYCR9b; Mon, 1 Oct 2018 13:57:08 +0200 (CEST) Received: by greensocs.com (Postfix, from userid 998) id E0D47511C65; Mon, 1 Oct 2018 13:57:06 +0200 (CEST) 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 84613511C69; Mon, 1 Oct 2018 13:57:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1538395028; bh=CZDV+nwNooxk+V+II5p/pzKlDVhCtkeY4U7VPDETTBM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=D3ecuqbHWKf8D+1LPrpBLuxE2C8OAmjaAavOYp3wA8LBNcv7x4Vw2KQQxLy6q0ZzO HArFRVlG7vwOdEAaYwKTH7aJPIqQHxM3SyMYmtY9bQ3sq5Udrr0vB2SFOSpmbPqyfz B4C8ds1vukWGc2FCPu/NEGoVT6qOILsCSBs/8lV0= 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=N6pDGiDj; dkim=pass (1024-bit key) header.d=greensocs.com header.b=N6pDGiDj DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1538395026; bh=CZDV+nwNooxk+V+II5p/pzKlDVhCtkeY4U7VPDETTBM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=N6pDGiDjsemAxATb7juswwz8L8QbZ4LFP7faEfJ5/4CU+vViYshtPyJfK0mlWLU2V AU5VEDqum+9/3AfitV8aZAaWjHmCyTBHiLT+XZVD74ilXEANskw1BqZyqaBFkqtMrK LqmaCBSnKoAllOBpOqnVWR3QpAwPbPuyFAsQJSRY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1538395026; bh=CZDV+nwNooxk+V+II5p/pzKlDVhCtkeY4U7VPDETTBM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=N6pDGiDjsemAxATb7juswwz8L8QbZ4LFP7faEfJ5/4CU+vViYshtPyJfK0mlWLU2V AU5VEDqum+9/3AfitV8aZAaWjHmCyTBHiLT+XZVD74ilXEANskw1BqZyqaBFkqtMrK LqmaCBSnKoAllOBpOqnVWR3QpAwPbPuyFAsQJSRY= From: Luc Michel To: qemu-devel@nongnu.org Date: Mon, 1 Oct 2018 13:56:51 +0200 Message-Id: <20181001115704.701-3-luc.michel@greensocs.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181001115704.701-1-luc.michel@greensocs.com> References: <20181001115704.701-1-luc.michel@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 193.104.36.180 Subject: [Qemu-devel] [PATCH v2 02/15] 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 , alistair@alistair23.me, mark.burton@greensocs.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , saipava@xilinx.com, edgari@xilinx.com, qemu-arm@nongnu.org, Luc Michel Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (found 2 invalid signatures) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The gdb_get_cpu_pid() function does the PID lookup for the given CPU. It checks if the CPU is in a QOM container named after the GDB_CPU_GROUP_NAME macro. If found, it returns the correponding PID, which is the group ID plus one (group IDs start at 0, GDB PIDs at 1). When the CPU is not a child of such a container, PID 1 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 it in the reply to a '?' request. Signed-off-by: Luc Michel Reviewed-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- gdbstub.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 5c86218f49..ac9d540fda 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -640,10 +640,37 @@ static int memtox(char *buf, const char *mem, int len) } } return p - buf; } =20 +static uint32_t gdb_get_cpu_pid(const GDBState *s, CPUState *cpu) +{ + gchar *path; + gchar *cont; + const char *left; + unsigned long pid; + + if (!s->multiprocess || (s->process_num =3D=3D 1)) { + return 1; + } + + path =3D object_get_canonical_path(OBJECT(cpu)); + cont =3D g_strrstr(path, "/" GDB_CPU_GROUP_NAME "["); + + if (cont =3D=3D NULL) { + return 1; + } + + cont +=3D strlen("/" GDB_CPU_GROUP_NAME "["); + + if (qemu_strtoul(cont, &left, 10, &pid)) { + return 1; + } + + return pid + 1; +} + static const char *get_feature_xml(const char *p, const char **newp, CPUClass *cc) { size_t len; int i; @@ -909,10 +936,23 @@ static CPUState *find_cpu(uint32_t thread_id) } =20 return NULL; } =20 +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 separato= r) { unsigned int query_len =3D strlen(query); =20 return strncmp(p, query, query_len) =3D=3D 0 && @@ -1020,22 +1060,23 @@ static int gdb_handle_packet(GDBState *s, const cha= r *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; =20 trace_gdbstub_io_command(line_buf); =20 p =3D line_buf; ch =3D *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_i= d))); 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. */ --=20 2.19.0