From nobody Fri Nov 7 10:16:23 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547906518912658.6510503605055; Sat, 19 Jan 2019 06:01:58 -0800 (PST) Received: from localhost ([127.0.0.1]:56266 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkrC9-0003pA-Bv for importer@patchew.org; Sat, 19 Jan 2019 09:01:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36807) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkrAq-0003G7-LJ for qemu-devel@nongnu.org; Sat, 19 Jan 2019 09:00:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkrAp-0000n9-7b for qemu-devel@nongnu.org; Sat, 19 Jan 2019 09:00:36 -0500 Received: from greensocs.com ([193.104.36.180]:35888) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkrAo-0000cN-I2 for qemu-devel@nongnu.org; Sat, 19 Jan 2019 09:00:35 -0500 Received: from localhost (localhost [127.0.0.1]) by greensocs.com (Postfix) with ESMTP id 4E9D564140C; Sat, 19 Jan 2019 15:00:09 +0100 (CET) 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 idoTwVHadE6T; Sat, 19 Jan 2019 15:00:08 +0100 (CET) Received: by greensocs.com (Postfix, from userid 998) id 46013441979; Sat, 19 Jan 2019 15:00:08 +0100 (CET) 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 78F6864140C; Sat, 19 Jan 2019 15:00:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1547906409; bh=xSobmz1nhUClHRO8H4Da793zVakZBsatbY2SETjr18Y=; h=From:To:Cc:Subject:Date; b=lbfzUC8z8uD997DxNjgGrDnGVpi/VtQj8eTm1kKvq9PVqMT7WZ45UMJVU+xmltugy SLq9GFRAN/YVKet9pviWLL4L735iHXt/LFPGpXkPy9gDE9GPQwfK220q1EKHbZkttg N8ucUwpqVOuvLqpzjOXGcTTaVa+kUZm7/svl6n7M= 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=LSjkLsKO; dkim=pass (1024-bit key) header.d=greensocs.com header.b=J8YWYJL6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1547906408; bh=xSobmz1nhUClHRO8H4Da793zVakZBsatbY2SETjr18Y=; h=From:To:Cc:Subject:Date; b=LSjkLsKOTe/g4UFIsmjrkACNkv5iC0U/F+Lwem2IQ48aq1Lk5izAZ/KUTQ/9CHQk9 ImgDGYu0zGvYYihGz2ZwzVvp0LB4ck6tA5NeAYomzprsoMRx9+BxtGkb1N6hBTAZ2f 1/gy8oddY98hsTwdDUTsv1NXL60khQnh7pCZnKZ8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=greensocs.com; s=mail; t=1547906407; bh=xSobmz1nhUClHRO8H4Da793zVakZBsatbY2SETjr18Y=; h=From:To:Cc:Subject:Date; b=J8YWYJL6eLMzL6q6iqoKEUIRJdh5KvC3DvWSNXKNCZ05EOOOZfK4bUIYZ13N4L6Oa Ay+hVf0McQV/VmQLmATJwBa8O8YG3Xu5aDWTWXXijN9FSpIvNDxLHA90BCz3PHXLo/ baiTQzMISlzNS3kBLkX2VlH31bx2cT5KTnM/ccqM= From: Luc Michel To: qemu-devel@nongnu.org Date: Sat, 19 Jan 2019 15:00:00 +0100 Message-Id: <20190119140000.11767-1-luc.michel@greensocs.com> X-Mailer: git-send-email 2.20.1 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] gdbstub: fix gdb_get_cpu(s, pid, tid) when pid and/or tid are 0 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: "Edgar E . Iglesias" , Peter Maydell , mark.burton@greensocs.com, Alistair Francis , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Luc Michel Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (found 3 invalid signatures) Content-Type: text/plain; charset="utf-8" a TID or PID value means "any thread" (resp. "any process"). This commit fixes the different combinations when at least one value is 0. When both are 0, the function now returns the first attached CPU, instead of the CPU with TID 1, which is not necessarily attached or even existent. When PID is specified but TID is 0, the function returns the first CPU in the process, or NULL if the process does not exist or is not attached. In other cases, it returns the corresponding CPU, while ignoring the PID check when PID is 0. Reported-by: Peter Maydell Signed-off-by: Luc Michel Reviewed-by: Peter Maydell --- gdbstub.c | 72 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index bfc7afb509..d4cc6ecf99 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -754,39 +754,10 @@ static CPUState *gdb_next_cpu_in_process(const GDBSta= te *s, CPUState *cpu) } =20 return cpu; } =20 -static CPUState *gdb_get_cpu(const GDBState *s, uint32_t pid, uint32_t tid) -{ - GDBProcess *process; - CPUState *cpu; - - if (!tid) { - /* 0 means any thread, we take the first one */ - tid =3D 1; - } - - cpu =3D find_cpu(tid); - - if (cpu =3D=3D NULL) { - return NULL; - } - - process =3D gdb_get_cpu_process(s, cpu); - - if (process->pid !=3D pid) { - return NULL; - } - - if (!process->attached) { - return NULL; - } - - return cpu; -} - /* Return the cpu following @cpu, while ignoring unattached processes. */ static CPUState *gdb_next_attached_cpu(const GDBState *s, CPUState *cpu) { cpu =3D CPU_NEXT(cpu); =20 @@ -812,10 +783,53 @@ static CPUState *gdb_first_attached_cpu(const GDBStat= e *s) } =20 return cpu; } =20 +static CPUState *gdb_get_cpu(const GDBState *s, uint32_t pid, uint32_t tid) +{ + GDBProcess *process; + CPUState *cpu; + + if (!pid && !tid) { + /* 0 means any process/thread, we take the first attached one */ + return gdb_first_attached_cpu(s); + } else if (pid && !tid) { + /* any thread in a specific process */ + process =3D gdb_get_process(s, pid); + + if (process =3D=3D NULL) { + return NULL; + } + + if (!process->attached) { + return NULL; + } + + return get_first_cpu_in_process(s, process); + } else { + /* a specific thread */ + cpu =3D find_cpu(tid); + + if (cpu =3D=3D NULL) { + return NULL; + } + + process =3D gdb_get_cpu_process(s, cpu); + + if (pid && process->pid !=3D pid) { + return NULL; + } + + if (!process->attached) { + return NULL; + } + + return cpu; + } +} + static const char *get_feature_xml(const GDBState *s, const char *p, const char **newp, GDBProcess *process) { size_t len; int i; --=20 2.20.1