From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 4CGGA7eCMmD/QwAAWB0awg (envelope-from ) for ; Sun, 21 Feb 2021 10:56:39 -0500 Received: by simark.ca (Postfix, from userid 112) id E60EA1EF7C; Sun, 21 Feb 2021 10:56:38 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 3D3661EF64 for ; Sun, 21 Feb 2021 10:56:38 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7D271384B011; Sun, 21 Feb 2021 15:56:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7D271384B011 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1613922997; bh=P1YzJFTVcOSBDkmsF0LBJDhccWDdkvYxAwo67k9iQ+w=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=FWNFuitZlGE2KpZg2b4iJpbwOYeU75mml9HpoxDNAQd8EA2iDtUPpqe7WLzhwqjtl I94Tvg4baQX/r3AJjkf6rt19Zc1vyBHXmtAetUWJf4j+6JKfriqB200pE8r/omnaPE rZ+9+/7C2fOvPeY4wVtcFLIhL1LOpk9ib/4e1kx4= Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id F399B3857C50 for ; Sun, 21 Feb 2021 15:56:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F399B3857C50 X-ASG-Debug-ID: 1613922992-0c856e6cd5a690e0001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id UvVb4irpJ8LoF3ir (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 21 Feb 2021 10:56:32 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.localdomain (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) by smtp.ebox.ca (Postfix) with ESMTP id 2F096441B21; Sun, 21 Feb 2021 10:56:32 -0500 (EST) X-Barracuda-RBL-IP: 192.222.157.6 X-Barracuda-Effective-Source-IP: 192-222-157-6.qc.cable.ebox.net[192.222.157.6] X-Barracuda-Apparent-Source-IP: 192.222.157.6 To: gdb-patches@sourceware.org Subject: [PATCH 2/2] gdb: add asserts in thread code Date: Sun, 21 Feb 2021 10:56:30 -0500 X-ASG-Orig-Subj: [PATCH 2/2] gdb: add asserts in thread code Message-Id: <20210221155630.3026942-2-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210221155630.3026942-1-simon.marchi@polymtl.ca> References: <20210221155630.3026942-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1613922992 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 1851 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.88051 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Cc: Libor Bukata Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" Unlike the previous patch, I don't propose that we take this patch into gdb-10-branch. This patch adds two asserts, prompted by investigating and fixing the bug fixed by the previous patch. The assert in find_thread_ptid would have caught the original issue before the segfault (I think it's slightly more use friendly). The assert in add_thread_silent would have made it clear that the solution proposed in [1] isn't the right one. The solution ended up passing nullptr as a target to add_thread. We don't want that, because add_thread_silent uses it to look up the inferior to which to add the thread. If the target is nullptr, we could find an inferior with the same pid, but belonging to an unrelated target. So we always want a non-nullptr target in add_thread_silent. gdb/ChangeLog: * thread.c (add_thread_silent): Add assert. (find_thread_ptid): Add assert. [1] https://sourceware.org/pipermail/gdb-patches/2021-February/176202.html Change-Id: Ie593ee45c5eb02235e8e9fbcda612d48ce883852 --- gdb/thread.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gdb/thread.c b/gdb/thread.c index 821070672171..3e7d6e14bf74 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -246,6 +246,8 @@ new_thread (struct inferior *inf, ptid_t ptid) struct thread_info * add_thread_silent (process_stratum_target *targ, ptid_t ptid) { + gdb_assert (targ != nullptr); + inferior *inf = find_inferior_ptid (targ, ptid); /* We may have an old thread with the same id in the thread list. @@ -535,6 +537,8 @@ find_thread_ptid (process_stratum_target *targ, ptid_t ptid) struct thread_info * find_thread_ptid (inferior *inf, ptid_t ptid) { + gdb_assert (inf != nullptr); + for (thread_info *tp : inf->non_exited_threads ()) if (tp->ptid == ptid) return tp; -- 2.30.1