From patchwork Tue Apr 7 10:22:28 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 132751 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 438D44BA2E27 for ; Tue, 7 Apr 2026 10:23:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 438D44BA2E27 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aQJiz00l X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id D039C4BA2E0D for ; Tue, 7 Apr 2026 10:22:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D039C4BA2E0D Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D039C4BA2E0D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775557356; cv=none; b=uB3P3E3GUGEg8HxBoEKAhNY62xonQAGOri49NPPulL2/ukUSVH6wiQNo+rRh7+nFaWOzu8i+eFBjXlBLe+BdjZtNz8pJC/Eo371fbwcM1IwYVOA3wmUnBChsWomp92oHpyZVvZYYRdz9COhnye+w4mmrDjkNAfU+E8Zn7rMF3hU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775557356; c=relaxed/simple; bh=s9I47/PwYIG1ErgJSoDouPR5ueZPNztiG763BywneqE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=vTlpPy+2DnsFLpYEzJHF3Di6oSBuJmqEaCQ4jyZ5S4ylP28kK7tHfAaVdfrWlIEEaeM6j6LOuDQoekW7ilsXaqFujM9GUnD98PYX+Era0SVLb35PBtBzK6/sIDyq3VrT4ZIKw5PpXwIDAZXgrLR1pYi71CuiU1MkONRVmJ1xKGU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D039C4BA2E0D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1775557356; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iYhYgb5obz1Et6Jx8OuDFolaWIP4Wrfxp9ZRUZATo6I=; b=aQJiz00lQA8limsG+/QY5ulhn0pyi4LV6KpndLxscK/PD0W983yq4xOA6BpQOEduSdUHec i0vzQarc3QttWSe+9oMW7XtDT8Cf3+eyJV5ixlxypIU/Qml3qN17f56OYuqEqcDm5ZnsZt waoPSWGbWbE53t7smz08op8sxJqufTs= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-644-nn5C7zUlOkWdZvMytHL4wA-1; Tue, 07 Apr 2026 06:22:35 -0400 X-MC-Unique: nn5C7zUlOkWdZvMytHL4wA-1 X-Mimecast-MFC-AGG-ID: nn5C7zUlOkWdZvMytHL4wA_1775557354 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-43d0c06c232so4257763f8f.1 for ; Tue, 07 Apr 2026 03:22:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775557353; x=1776162153; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=iYhYgb5obz1Et6Jx8OuDFolaWIP4Wrfxp9ZRUZATo6I=; b=a4MTNjl5GeaOUwbFS+YSjM00UNdFLBdgcxx551qmc1PFP2cvXxwOpJV6+X7mCXxVhK TGANxVn9ujMvVfppulFjxHcOmUvf3Jwlv9rDDUcNI8rLIl5xDZPAKk3NxVNbIwbQVT8H MEHpIKy9Hv7AqzpgcDSX/CT3O+vzIPiTQS7cpf2KlE0auYC21JRDFxh7h4YxnFNTXNMS HXy/tdKEewKAbj3iV+I9Xd270xCWMpXIPyEzRwPmrKIA3MhdNi9qgwo6ChWilb0EnPEB PeU8gK2OEZUxBgT9JBsWSYxzKEIh41hVLkukKuY1LlOR0V9hhABKAGSpJOI4J2CJcNWY CQxA== X-Gm-Message-State: AOJu0YyhJm4Gl9v2jaKyl1EptPTH8huCQgHLt1ciHNolQHjGUHvLrT5H 7t/tiN3NocCIlsttakv3/uujmVf34S2iPhqLS47Y1e+Cg/xGlK7ds9LyNopsx4N73FfLNcwwVLn +9MdsvuY2pfb+2wKbK+V7La7L3LZHnkjUYX3+qCv0aIhzf291TbpAmPVZNmSwcGnFRs3WaAAiUl y5MFqyoZ2o31RASKRmN87yC9awby0cvtXEngGX6KGDZ1bEMGk= X-Gm-Gg: AeBDieukuTLdMldS6/qS+j9nQz4vpDYh7KB4NgzVfCknoWrarmekDxaUW+BbFPVII8C YbufD201lPJPKrPmtNA6Ac0P86/aFZPgtGEpFjAnF9fLMSOKatYKZF2Zlqdg4HNnuGS8YjwYxZn C/S19VuLtTchxRSPhTYsF4e1ACQteCHv4PEBNd5tY+S/G9iC7DBuGwe+WVXn6K8ee4oj3g1GSAU 557Tr4FMAhZD65sUiqitsoQ5uza5bRW/FSWFm2JzdQS/pNs6uPkdngU14bTNX7CSdLbblgbTePr KuxLeXgOpD/1QEc5ZT6hY4xifd+Htmr2/UCP8KQKdJ8yPbOOoR2cb8dI11s6RiXfr9nZHzPJzbc ueaMmMk319PU5r5Lq X-Received: by 2002:a5d:5f86:0:b0:43b:43d3:62ac with SMTP id ffacd0b85a97d-43d292a8a5amr25002206f8f.18.1775557353501; Tue, 07 Apr 2026 03:22:33 -0700 (PDT) X-Received: by 2002:a5d:5f86:0:b0:43b:43d3:62ac with SMTP id ffacd0b85a97d-43d292a8a5amr25002152f8f.18.1775557353025; Tue, 07 Apr 2026 03:22:33 -0700 (PDT) Received: from localhost ([31.111.84.232]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d1e2a6f5bsm44498829f8f.7.2026.04.07.03.22.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2026 03:22:32 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 2/3] gdb: add some asserts to thread_db_notice_clone Date: Tue, 7 Apr 2026 11:22:28 +0100 Message-Id: <2c5f44442eacd91020ce9058abf16442ecf3718a.1775557188.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: qBc3PXvLebS67Zikr2WeSKl4k4tsOF-QLzTrIht3kLA_1775557354 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org This commit adds some asserts to thread_db_notice_clone, and reorders some code. This is really just a refactor ahead of the next commit. The changes made here are: 1. Add an assert that STOPPED is not NULL. We pass STOPPED as the first argument to thread_from_lwp, which already assumes that the pointer is not NULL. If STOPPED was ever NULL then we would have hit a segfault in thread_from_lwp long ago. 2. Move the thread_from_lwp call relating to the PARENT thread before the call relating to the CHILD thread, and assert that the value we get back is STOPPED. The thread_from_lwp might also gather thread-db related information about PARENT, so the call is important, but even if PARENT cannot be managed via thread-db, the result we get back should always still be STOPPED (see record_thread for more details). Moving this call before the call relating to the CHILD thread makes the next commit cleaner. There should be no user visible changes after this commit as I believe both of the things being asserted have always been true. Reviewed-By: Keith Seitz --- gdb/linux-thread-db.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index cd25c55a898..1807352ed76 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -440,12 +440,17 @@ thread_db_notice_clone (ptid_t parent, ptid_t child) return false; thread_info *stopped = linux_target->find_thread (parent); - - thread_from_lwp (stopped, child); + gdb_assert (stopped != nullptr); /* If we do not know about the main thread's pthread info yet, this - would be a good time to find it. */ - thread_from_lwp (stopped, parent); + would be a good time to find it. This should return the same + thread_info as STOPPED, but a side effect of this call is that the + pthread/thread-db information might have been filled in if it was not + already known. */ + thread_info *parent_info = thread_from_lwp (stopped, parent); + gdb_assert (parent_info == stopped); + + thread_from_lwp (stopped, child); return true; }