From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 63966 invoked by alias); 13 Jan 2017 01:27:53 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 63952 invoked by uid 89); 13 Jan 2017 01:27:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.6 required=5.0 tests=AWL,BAYES_50,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=sk:iterate, LWP, inferior_ptid, H*f:sk:c0b0268 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 13 Jan 2017 01:27:50 +0000 Received: from svr-orw-mbx-03.mgc.mentorg.com ([147.34.90.203]) by relay1.mentorg.com with esmtp id 1cRqei-0000sq-MM from Luis_Gustavo@mentor.com ; Thu, 12 Jan 2017 17:27:48 -0800 Received: from [172.30.9.168] (147.34.91.1) by svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Thu, 12 Jan 2017 17:27:45 -0800 Reply-To: Luis Machado Subject: Re: [PATCH] PR threads/20743: Don't attempt to suspend or resume exited threads. References: <20161223212842.42715-1-jhb@FreeBSD.org> <1700771.1OUYESxIQe@ralph.baldwin.cx> <1723055.CyypAqrLYR@ralph.baldwin.cx> To: John Baldwin , CC: From: Luis Machado Message-ID: <75fc00ff-6472-d5aa-9f74-3495bcf7fb83@codesourcery.com> Date: Fri, 13 Jan 2017 01:27:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: <1723055.CyypAqrLYR@ralph.baldwin.cx> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) X-IsSubscribed: yes X-SW-Source: 2017-01/txt/msg00258.txt.bz2 On 01/12/2017 01:16 PM, John Baldwin wrote: > On Thursday, January 12, 2017 10:29:00 AM Luis Machado wrote: >> On 12/28/2016 11:37 AM, John Baldwin wrote: >>> On Wednesday, December 28, 2016 09:07:07 AM Vasil Dimov wrote: >>>> On Tue, Dec 27, 2016 at 13:03:27 -0800, John Baldwin wrote: >>>> [...] >>>>> I have tried changing fbsd_wait() to return a TARGET_WAITKIND_SPURIOUS >>>>> instead of explicitly continuing the process, but that doesn't help, and it >>>>> means that the ptid being returned is still T1 in that case. >>>>> >>>>> I'm not sure if I should explicitly be calling delete_exited_threads() in >>>>> fbsd_resume() before calling iterate_threads()? Alternatively, fbsd_resume() >>>>> could use ALL_NONEXITED_THREADS() instead of iterate_threads() (it isn't >>>>> clear to me which of these is preferred since both are in use). >>>>> >>>>> I added the assertion for my own sanity. I suspect gdb should never try to >>>>> invoke target_resume() with a ptid of an exited thread, but if for some >>>>> reason it did the effect on FreeBSD would be a hang since we would suspend >>>>> all the other threads and when the process was continued via PT_CONTINUE it >>>>> would have nothing to do and would never return from wait(). I'd rather have >>>>> gdb fail an assertion in that case rather than hang. >>>> [...] >>>> >>>> Hi, >>>> >>>> I am not sure if this is related, but since I get a hang I would rather >>>> mention it: with the John's patch (including the assert) gdb does not >>>> emit the "ptrace: No such process" error, but when I attempt to quit, >>>> it hangs: >>> >>> No, this is a separate bug in the kernel whereby a process doesn't >>> treat PT_KILL as a detach-like event but incorrectly expects to keep >>> getting PT_CONTINUE events for a while until it finally exits. I'm >>> working on writing up regression/unit tests for PT_KILL and then >>> fixing the bug. >>> >> >> I think the patch is mainly papering over a bigger problem. My guess is >> that the native fbsd backend is not doing something it should. >> >> I'd check how linux-nat.c is doing things and then try to confirm the >> fbsd behavior is sane. >> >> For example, i noticed linux-nat.c has exit_lwp (...) that handles >> deletion of both thread information and the thread itself (lwp). Even if >> it is the currently-selected thread, we *will* get the lwp removed from >> the list of existing lwp's. > > FreeBSD's backend doesn't maintain a separate lwp list, it just uses > the existing GDB thread list. For FreeBSD's backend the two lists would > simply mirror each other so it seems a bit of a waste to maintain a > duplicate list. exit_lwp() calls delete_thread() which is the same thing > the FreeBSD backend is doing, so if that is the current thread in > inferior_ptid, the Linux backend will also being leaving the exited > thread around in GDB's list until some future call to delete_exited_threads(). > > I think the thing that makes Linux work is that it doesn't use GDB's > thread list. Meaning, it doesn't walk over GDB's thread list, but instead > iterates over its private LWP list via iterate_over_lwps(). It would seem > that GDB's thread list is designed so that backends shouldn't need their > own thread list (you can add target-specific data with a custom destructor > that gets invoked when freeing a thread for example), but the Linux backend > doesn't choose to use it that way? > > Looking at some other threaded backends: > > - aix-thread.c relies on custom ptrace ops that resume a single thread > - darwin-nat.c uses its own thread list (stored in the inferior's > private data) instead of GDB's thread list. > - gnu-nat.c uses its own thread list instead of GDB's thread list. > - obsd-nat.c uses GDB's thread list but doesn't seem to support resuming > individual threads (only entire processes). > - procfs.c maintains its own thread list, but it doesn't seem to use it > for resume but relies on the associated kernel resuming either an > entire process or a single thread in a process via different ioctls. > - remote.c:remote_resume() uses ALL_NON_EXITED_THREADS > - windows_nat.cwindows_resume() calls windows_continue() which uses a > target-internal thread list rather than GDB's thread list. > >> It doesn't make sense to keep a thread that has already exitted in the >> list of threads we are manipulating. > > FreeBSD's backend isn't making that choice. delete_thread() in threads.c > is the one making that choice. If FreeBSD's backend were to define its > own thread list, the contents would be identical except it would not > include any exited threads, so skipping exited threads gives the same > result as walking a hypothetical private list. > So i take it using ALL_NON_EXITED_THREADS is something that would seem reasonable to use in this case and not iterate through all threads (even ones marked exitting)?