From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.freebsd.org (mx2.freebsd.org [96.47.72.81]) by sourceware.org (Postfix) with ESMTPS id CCEDA3858D35 for ; Wed, 8 Jul 2020 00:20:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CCEDA3858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=jhb@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [96.47.72.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx2.freebsd.org (Postfix) with ESMTPS id 6FAAC97545; Wed, 8 Jul 2020 00:20:22 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4B1g1f1ZS9z4HTw; Wed, 8 Jul 2020 00:20:22 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from John-Baldwins-MacBook-Pro-274.local (unknown [IPv6:2601:648:8203:2990:98ed:1435:28a2:b475]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id AFC701222A; Wed, 8 Jul 2020 00:20:21 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Subject: Re: [PATCH 00/28] Decouple inferior_ptid/inferior_thread(); dup ptids in thread list (PR/25412) To: Pedro Alves , gdb-patches@sourceware.org References: <20200414175434.8047-1-palves@redhat.com> <935bd7c8-f107-f2d1-ade2-f6259dc1297c@FreeBSD.org> <1000f354-aa00-9cf3-7417-57b2efe59216@palves.net> From: John Baldwin Autocrypt: addr=jhb@FreeBSD.org; keydata= mQGiBETQ+XcRBADMFybiq69u+fJRy/0wzqTNS8jFfWaBTs5/OfcV7wWezVmf9sgwn8TW0Dk0 c9MBl0pz+H01dA2ZSGZ5fXlmFIsee1WEzqeJzpiwd/pejPgSzXB9ijbLHZ2/E0jhGBcVy5Yo /Tw5+U/+laeYKu2xb0XPvM0zMNls1ah5OnP9a6Ql6wCgupaoMySb7DXm2LHD1Z9jTsHcAQMD /1jzh2BoHriy/Q2s4KzzjVp/mQO5DSm2z14BvbQRcXU48oAosHA1u3Wrov6LfPY+0U1tG47X 1BGfnQH+rNAaH0livoSBQ0IPI/8WfIW7ub4qV6HYwWKVqkDkqwcpmGNDbz3gfaDht6nsie5Z pcuCcul4M9CW7Md6zzyvktjnbz61BADGDCopfZC4of0Z3Ka0u8Wik6UJOuqShBt1WcFS8ya1 oB4rc4tXfSHyMF63aPUBMxHR5DXeH+EO2edoSwViDMqWk1jTnYza51rbGY+pebLQOVOxAY7k do5Ordl3wklBPMVEPWoZ61SdbcjhHVwaC5zfiskcxj5wwXd2E9qYlBqRg7QeSm9obiBCYWxk d2luIDxqaGJARnJlZUJTRC5vcmc+iGAEExECACAFAkTQ+awCGwMGCwkIBwMCBBUCCAMEFgID AQIeAQIXgAAKCRBy3lIGd+N/BI6RAJ9S97fvbME+3hxzE3JUyUZ6vTewDACdE1stFuSfqMvM jomvZdYxIYyTUpC5Ag0ERND5ghAIAPwsO0B7BL+bz8sLlLoQktGxXwXQfS5cInvL17Dsgnr3 1AKa94j9EnXQyPEj7u0d+LmEe6CGEGDh1OcGFTMVrof2ZzkSy4+FkZwMKJpTiqeaShMh+Goj XlwIMDxyADYvBIg3eN5YdFKaPQpfgSqhT+7El7w+wSZZD8pPQuLAnie5iz9C8iKy4/cMSOrH YUK/tO+Nhw8Jjlw94Ik0T80iEhI2t+XBVjwdfjbq3HrJ0ehqdBwukyeJRYKmbn298KOFQVHO EVbHA4rF/37jzaMadK43FgJ0SAhPPF5l4l89z5oPu0b/+5e2inA3b8J3iGZxywjM+Csq1tqz hltEc7Q+E08AAwUIAL+15XH8bPbjNJdVyg2CMl10JNW2wWg2Q6qdljeaRqeR6zFus7EZTwtX sNzs5bP8y51PSUDJbeiy2RNCNKWFMndM22TZnk3GNG45nQd4OwYK0RZVrikalmJY5Q6m7Z16 4yrZgIXFdKj2t8F+x613/SJW1lIr9/bDp4U9tw0V1g3l2dFtD3p3ZrQ3hpoDtoK70ioIAjjH aIXIAcm3FGZFXy503DOA0KaTWwvOVdYCFLm3zWuSOmrX/GsEc7ovasOWwjPn878qVjbUKWwx Q4QkF4OhUV9zPtf9tDSAZ3x7QSwoKbCoRCZ/xbyTUPyQ1VvNy/mYrBcYlzHodsaqUDjHuW+I SQQYEQIACQUCRND5ggIbDAAKCRBy3lIGd+N/BCO8AJ9j1dWVQWxw/YdTbEyrRKOY8YZNwwCf afMAg8QvmOWnHx3wl8WslCaXaE8= Message-ID: Date: Tue, 7 Jul 2020 17:19:20 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <1000f354-aa00-9cf3-7417-57b2efe59216@palves.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org 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: , X-List-Received-Date: Wed, 08 Jul 2020 00:20:24 -0000 On 7/7/20 4:53 PM, Pedro Alves wrote: > On 7/8/20 12:16 AM, John Baldwin wrote: >> This appears to have broken native debugging on FreeBSD for me in that >> when I run a process to completion it triggers an assertion failure: >> >> (gdb) r >> Starting program: /bin/echo >> >> Child process unexpectedly missing: No child processes. >> /home/john/work/git/gdb/gdb/inferior.c:293: internal-error: struct inferior *find_inferior_pid(process_stratum_target *, int): Assertion `pid != 0' failed. >> >> I tracked this down to this code in inf_ptrace::wait(): >> >> /* Ignore terminated detached child processes. */ >> if (!WIFSTOPPED (status) && pid != inferior_ptid.pid ()) >> pid = -1; >> >> At this point, inferior_ptid() is all zeroes and the process >> has reported a non-stopped exit status (WIFEXITED) so this >> ignores the exit event and loops back around to call waitpid() >> again which then fails with ECHILD. >> >> Looks like we always clear the inferior thread (and thus >> inferior_ptid) in do_target_wait_1: >> >> /* We know that we are looking for an event in the target of inferior >> INF, but we don't know which thread the event might come from. As >> such we want to make sure that INFERIOR_PTID is reset so that none of >> the wait code relies on it - doing so is always a mistake. */ >> switch_to_inferior_no_thread (inf); >> >> Commenting out the check in inf_ptrace::wait() "fixes" the issue for >> me on FreeBSD, but I'm not sure that is the right fix. > > linux-nat.c has something logic, here in linux_nat_filter_event: > > /* Make sure we don't report an event for the exit of an LWP not in > our list, i.e. not part of the current process. This can happen > if we detach from a program we originally forked and then it > exits. */ > if (!WIFSTOPPED (status) && !lp) > return NULL; > > For inf-ptrace.c, the right fix should be something around this: > > diff --git c/gdb/inf-ptrace.c w/gdb/inf-ptrace.c > index d25d226abb..ae0b0f7ff0 100644 > --- c/gdb/inf-ptrace.c > +++ w/gdb/inf-ptrace.c > @@ -347,7 +347,7 @@ inf_ptrace_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus, > } > > /* Ignore terminated detached child processes. */ > - if (!WIFSTOPPED (status) && pid != inferior_ptid.pid ()) > + if (!WIFSTOPPED (status) && find_inferior_pid (this, pid) == nullptr) > pid = -1; > } > while (pid == -1); Yes, this works. I hadn't found that function and was thinking of writing it from scratch, but this is better of course. > The inferior_ptid reference in the error path above that code, where it > reads: > > "Claim it exited with unknown signal" > > is also wrong. I'm not sure what to do about that one. > Not clear if that path can really happen. linux-nat.c calls > perror_with_name in some places if waitpid returns -1, > and in the main waitpid call, just assumes that error -1 never > happens... It happened for me in this case since wait failed with -1 when we discarded the exit info incorrectly. I can change it to return null_ptid which would match what it does now, or perhaps we could just add an assertion here rather than relying on the null_ptid tripping over another assertion later? >> Here you can see that the last call to fbsd_resume() used the ptid from >> inferior 1 instead of inferior 2, and inferior 1 didn't discard it's >> pending SIGTRAP but instead was killed by it.) > "set debug infrun 1" will probably reveal what is happening. Yes, I have some more details on this in my other followup where infrun debugging was very helpful, though I realize I failed to include any of the infrun debug output. -- John Baldwin