From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 2A7AE3858D35 for ; Sat, 1 Aug 2020 22:56:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2A7AE3858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [10.0.0.11] (173-246-6-90.qc.cable.ebox.net [173.246.6.90]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 8E0241EAB8; Sat, 1 Aug 2020 18:56:15 -0400 (EDT) Subject: Re: [PATCH 02/23] Don't rely on inferior_ptid in record_full_wait To: Tom Tromey Cc: Pedro Alves , gdb-patches@sourceware.org References: <20190906232807.6191-1-palves@redhat.com> <20190906232807.6191-3-palves@redhat.com> <87h7tope4d.fsf@tromey.com> <9d4243a6-3b43-802b-b1d6-4cd0497205af@simark.ca> <87d04ap01b.fsf@tromey.com> From: Simon Marchi Message-ID: Date: Sat, 1 Aug 2020 18:56:08 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <87d04ap01b.fsf@tromey.com> Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_PASS, 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: Sat, 01 Aug 2020 22:56:17 -0000 On 2020-08-01 4:46 p.m., Tom Tromey wrote: > Simon> I don't know if this makes sense: you tell the core of GDB that some > Simon> process was signalled (terminated by a signal), but you don't tell > Simon> what process it is. I am not sure what the core of GDB can do with > Simon> this information. > > Simon> The contract that the `wait` implementations must respect is not > Simon> very well documented I believe, so it's not clear which value is > Simon> valid with which event. > > Yeah. I think it would be good to fix this. > > The reason I had it return minus_one_ptid is this text in > target/target.h: > > Return pid of child, or -1 in case of error; > store status through argument pointer STATUS. That (the -1 part) seems erroneous, because... > > remote_target::wait does this as well, though perhaps not with this > target waitkind, e.g.: > > status->kind = TARGET_WAITKIND_NO_RESUMED; > return minus_one_ptid; > > or > > if (status->kind == TARGET_WAITKIND_NO_RESUMED) > return minus_one_ptid; ... TARGET_WAITKIND_NO_RESUMED is an example of waitkind that doesn't have any ptid attached to it. It means "there is no resumed thread, so I won't have any event to report", so it's not tied to a ptid. AFAIK, the wait implementations don't really have a way to report "errors". That's probably fine, because I am not sure what the core could really do about it. > ... though not all returns set the kind. Do you have an example? I think the kind is mandatory, because that's what the core checks right when wait returns (see the do_wait lambda in do_target_wait). If the target doesn't set the kind, then the core will read whatever was in there before. Probably 0, since we memset `ecs` in fetch_inferior_event (don't know about other code paths), which maps to TARGET_WAITKIND_EXITED. Anyway, not setting the kind sounds like a bug to me, and this is something we should be able to assert. > Simon> Note that this waitpid call is blocking (and there's no async stuff in > Simon> inf-ptrace.c), so I presume that this is only used in sync targets. > > Yeah. I found this because I was wondering what it would take to > convert the remaining sync targets, and have only target-async left. > > I suspect the inf-ptrace targets can be converted by just lifting the > Linux code into in inf_ptrace_target. Assuming there isn't too much Linux-ism in there. >This comment in nbsd-nat.c is > worrying though: > > /* The common code passes WNOHANG that leads to crashes, overwrite it. */ Indeed, and that's a recent addition... > Other targets require a little more research. For Windows, Darwin, and > remote-sim, I thought perhaps we could put some of the current > resume/wait code into a separate thread. (Though in the case of the > sim, I think it would be better to move the sims to using the remote > protocol.) For Windows, that's what Pedro suggested here: https://sourceware.org/legacy-ml/gdb/2016-09/msg00055.html If we can avoid separate threads, I'd say it's better to, because it's more difficult to debug. For Windows, that would mean finding if there's an equivalent of SIGCHLD + the self pipe trick but for Windows. In other words, a way to wake up the event loop when we know there's an event available. > Simon> Perhaps we could return TARGET_WAITKIND_NO_RESUMED in both cases? > > remote.c does this in at least one case, though apparently not in all. Simon