From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3441 invoked by alias); 18 Jan 2018 16:41:37 -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 3432 invoked by uid 89); 18 Jan 2018 16:41:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=undertaking, go, H*M:f10c X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 18 Jan 2018 16:41:35 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0618F8B126; Thu, 18 Jan 2018 16:41:34 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65DB160CA9; Thu, 18 Jan 2018 16:41:33 +0000 (UTC) Subject: Re: [PATCH 2/3] Pass inferior down to target_detach and to_detach To: Simon Marchi , gdb-patches@sourceware.org References: <1514699454-18587-1-git-send-email-simon.marchi@ericsson.com> <1514699454-18587-2-git-send-email-simon.marchi@ericsson.com> From: Pedro Alves Message-ID: <71c999db-f10c-ca2b-911e-4d6968121a3f@redhat.com> Date: Thu, 18 Jan 2018 16:41:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <1514699454-18587-2-git-send-email-simon.marchi@ericsson.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2018-01/txt/msg00375.txt.bz2 On 12/31/2017 05:50 AM, Simon Marchi wrote: > The to_detach target_ops method implementations are currently expected > to work on current_inferior/inferior_ptid. In order to make things more > explicit, and remove some "shadow" parameter passing through globals, > this patch adds an "inferior" parameter to to_detach. Implementations > will be expected to use this instead of relying on the global. However, > to keep things simple, this patch only does the minimum that is > necessary to add the parameter. The following patch gives an example of > how one such implementation would be adapted. If the approach is deemed > good, we can then look into adapting more implementations. Until then, > they'll continue to work as they do currently. On the multi-target work/branch, I ended up hanging the current target stack to the current inferior. Which means that in practice we have to switch the current inferior/thread before calling any target method. I can't see any other practical way. I've pondered making every target method take an inferior or some kind of "execution context" object as parameter, but that's a massive undertaking. The result is still better for relying more on thread pointers instead of inferior_ptid / ptid_t, though, IMO. Note that in practice, even with your patch (in master) we still have to switch the current inferior before calling target_detach anyway, for making sure things like the current program space is set correctly, target_gdbarch(), target description, removing breakpoints, accessing memory, registers, etc., like here: > /* Note that the detach above makes PARENT_INF dangling. */ > @@ -976,7 +976,7 @@ handle_vfork_child_exec_or_exit (int exec) > } > } > > - target_detach (0); > + target_detach (inf->vfork_parent, 0); ... this still relies on the switch_to_thread call a bit above. Or look at the prepare_to_detach call in target_detach. All that said, I'm totally fine with incremental progress. Actually, it's probably the only way to go! So I'm fine with the patch, though, I think we should add a temporary assertion in target_detach, like: gdb_assert (inf == current_inferior ()); until everything beneath either uses an explicit inferior, or switches the current inferior temporarily. Thanks, Pedro Alves