From nobody Sat Jun 29 05:20:12 2024 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; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548699872880534.4486505102946; Mon, 28 Jan 2019 10:24:32 -0800 (PST) Received: from localhost ([127.0.0.1]:36542 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBa6-0004hf-QC for importer@patchew.org; Mon, 28 Jan 2019 13:24:26 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBN3-0002Zq-Sz for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:10:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goBN1-0008Dy-QY for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:10:57 -0500 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:35825) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goBN1-0008BL-Jf for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:10:55 -0500 Received: by mail-wm1-x341.google.com with SMTP id t200so15071697wmt.0 for ; Mon, 28 Jan 2019 10:10:55 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id b18sm97910681wrw.83.2019.01.28.10.10.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 10:10:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=g1+1iU25RO4b9+GWllKtnX6ssOKxW8r9jeqFWVW6jf4=; b=Fqv6oFNV1U7huHW9yy1c4MYzG7K1oAoxgfFjMq+eSPt9giWVIzE4mRHU5VGnSe+O8H AB2sPSfEjlfOY7IoiN6Xp/Y/v808KHnwOVbLOr/CDXT2mngWrb3tbeozTtakb2qyHDPN 1p9J+iIZZgU/Vu77i5XD9zjeWnxzmTD/t/onA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g1+1iU25RO4b9+GWllKtnX6ssOKxW8r9jeqFWVW6jf4=; b=PsaQ4dhMcOc6JWxJ0MQI9YqdJQu2xm0QO3eQ54zYgO680braxJNqB+lpD+po/S+zzY rnpQqim1c8F/P9YoCr5l0rlX97ToiSZDWvNf28SvL47FGorB5svdpgml+4pVjXfHK+Y/ 5Uo1UBPJ0vdKc8wBuDY/Y9nIyP1Cq8t1wrHSYcFvEcLqHdTp9cJkWMOH+Lw7kZ9QZ8JK BtW5ATBNnaI/95unGHCzGtor25s03puTKORc29x2GWkCEITOxcNWVuIHdZAzXeWiYxkW oQI6IY/Od1Ew/9nG5Kwpr4NmrgRT5E0bqaeNrSUBR0i2q3yrK4MOBw5uFJ6PZD+nezAP J/zw== X-Gm-Message-State: AJcUukfxgya/iMSor82yByaKe/UzV5FQms9MxqE6Vwzt1qMLGDOxlCRG WLGigQs5sPCVX6wsZA6J2PzJUB76gNt9SQ== X-Google-Smtp-Source: ALg8bN5XZEZ+By56A802omDXr7kaLhPs2Ge+b8g4oFWO6i2ZePTugbkX89/m056HHXu3ErqqSD+UlQ== X-Received: by 2002:a1c:9806:: with SMTP id a6mr17773164wme.114.1548699053877; Mon, 28 Jan 2019 10:10:53 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2019 18:10:24 +0000 Message-Id: <20190128181047.20781-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190128181047.20781-1-peter.maydell@linaro.org> References: <20190128181047.20781-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::341 Subject: [Qemu-devel] [PULL 03/26] 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Luc Michel 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 Message-id: 20190119140000.11767-1-luc.michel@greensocs.com Signed-off-by: Peter Maydell --- gdbstub.c | 72 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index bfc7afb5096..d4cc6ecf99b 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -756,35 +756,6 @@ static CPUState *gdb_next_cpu_in_process(const GDBStat= e *s, CPUState *cpu) 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) { @@ -814,6 +785,49 @@ static CPUState *gdb_first_attached_cpu(const GDBState= *s) 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) { --=20 2.20.1