From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id wcewOnSCF2m7NAIAWB0awg (envelope-from ) for ; Fri, 14 Nov 2025 14:26:44 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=k/ZR1ttf; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id E8BC01E0B8; Fri, 14 Nov 2025 14:26:44 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 560591E04C for ; Fri, 14 Nov 2025 14:26:44 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EBEE03858D26 for ; Fri, 14 Nov 2025 19:26:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EBEE03858D26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1763148404; bh=o4Qmt420rapLxbCsDQ1uz2Sidtt6lJaBZs+Esdrc5K8=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=k/ZR1ttfgUsm6Gmg18ustoDXakiacdDBTsh+uCt+dlD56RBFQ1mG+1mUZV92TM6aN KWontuc7iJNu06pJ3h2P3vc+hSIYoy0cjpY9/npVfWmjddsQFJsXSTVSGwSoA8jUkA pAchaodiKNWZGv9M+5jOasW/i+4u1DXQVn8FRGS4= Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 0046A3858D20 for ; Fri, 14 Nov 2025 19:25:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0046A3858D20 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0046A3858D20 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1763148338; cv=none; b=LnYMH4t2wJNH6at/s8/WwiQAeTX3vY5hUYShgEelzpIQ96hG11W5bnHD6zunWQo6vYDRG54HirTD58AknEJn6hPaQaMv1lOwxM7YOwKskF1mXV1rzyGBMiyogFpPtkxUWEwIPDjcFBTVn5wKi9UZQ5YSlUDpbg4U0PMmfq1yhYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1763148338; c=relaxed/simple; bh=e5U8ZUCXMZ0cfS5lossmAv67RS2GZXrgb7Wp9gi9guw=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=opMMUJTQISBv5qn1jmwL53T2ulAkoN8ZMp11dxJ2bZVjEPATHA1yfuy+WdB2UifHBnqVGMUU3Pfoc74NvyC7eq3NXw9Zx6o66LMl3B4RF/JIBw954fYbb5+HLibMRTVLKX1A9olDCHMGD4A1yp+MBAOg1qPKeidOyscKGWH7B8c= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0046A3858D20 Received: by simark.ca (Postfix) id 7337F1E04C; Fri, 14 Nov 2025 14:25:37 -0500 (EST) Message-ID: Date: Fri, 14 Nov 2025 14:25:37 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: GDB 15/16 crashing in add_thread_silent() To: psmith@gnu.org, gdb@sourceware.org References: <78bf54fc9dfbb57d3434d8435e94b091e1fa6785.camel@gnu.org> Content-Language: en-US In-Reply-To: <78bf54fc9dfbb57d3434d8435e94b091e1fa6785.camel@gnu.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-BeenThere: gdb@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Simon Marchi via Gdb Reply-To: Simon Marchi Errors-To: gdb-bounces~public-inbox=simark.ca@sourceware.org Sender: "Gdb" On 2025-11-14 14:20, Paul Smith via Gdb wrote: > I investigated more and the problem is that GDB cannot determine the > PID of the core file. I checked the inferiors list and it looks > correct, but the ptid value passed into add_thread_silent() has a bad > PID: > > (gdb) fr 8 > #8 0x00000000013817cd in add_thread_silent (targ=0x3ed1ae0, ptid=...) > at gdb/thread.c:311 > warning: 311 gdb/thread.c: No such file or directory > (gdb) p ptid > $6 = { > m_pid = 1, > m_lwp = 0, > m_tid = 0 > } > > This is apparently because we entered this code in corelow.c: > > if (inferior_ptid == null_ptid) > { > /* Either we found no .reg/NN section, and hence we have a > non-threaded core (single-threaded, from gdb's perspective), > or for some reason add_to_thread_list couldn't determine > which was the "main" thread. The latter case shouldn't > usually happen, but we're dealing with input here, which can > always be broken in different ways. */ > thread_info *thread = first_thread_of_inferior (inf); > > if (thread == NULL) > thread = add_thread_silent (target, ptid_t (CORELOW_PID)); > > switch_to_thread (thread); > } > > It appears that add_thread_silent() doesn't work properly with > CORELOW_PID (1). > > Just to note, my program is decidedly NOT single-threaded; there are > 20+ active threads in it. > > I see that this (still in corelow.c:core_target_open()) returns the > correct PID: > > int pid = bfd_core_file_pid (current_program_space->core_bfd ()); > > so I think it's a bug that when we invoke add_thread_silent() above we > use CORELOW_PID instead of just pid. If your core is threaded, you shouldn't get to that fallback "if" at all. This is where GDB should add all your threads: /* Build up thread list from BFD sections, and possibly set the current thread to the .reg/NN section matching the .reg section. */ asection *reg_sect = bfd_get_section_by_name (current_program_space->core_bfd (), ".reg"); for (asection *sect : gdb_bfd_sections (current_program_space->core_bfd ())) add_to_thread_list (sect, reg_sect, inf); If this doesn't add any threads, then you need to dig to understand why BFD doesn't create the .reg pseudo sections. Simon