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 69A0A385B19A for ; Mon, 28 Nov 2022 15:01:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 69A0A385B19A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca Received: from [10.0.0.11] (unknown [217.28.27.60]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id DF7AA1E0CB; Mon, 28 Nov 2022 10:01:14 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1669647675; bh=bFkZ+Ph67UDOx57CmR3lyriqoykgGS9ImubqFCKofoA=; h=Date:Subject:To:References:From:In-Reply-To:From; b=siwfeI+w6g1CAe35h3VLJrSozKiZ45A78Pxs47jOU2MPbfP2Cnn6WUIgt2Sy2vyTE Vg5meyOuvODYxlLlm472Lumk3wVlsaaQAO4klhVfcWartHhBpu1+Q6k2yh7qAsXrkJ AsSn76ip9a2I+ar17ioi2mbb3AOFLRvOQitq6xys= Message-ID: Date: Mon, 28 Nov 2022 10:01:14 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH v2 2/6] gdbserver: Add PID parameter to linux_get_auxv and linux_get_hwcap Content-Language: en-US To: Luis Machado , Thiago Jung Bauermann , gdb-patches@sourceware.org References: <20221126020452.1686509-1-thiago.bauermann@linaro.org> <20221126020452.1686509-3-thiago.bauermann@linaro.org> <5309bed5-3145-0763-150d-75cad9ef4e44@arm.com> From: Simon Marchi In-Reply-To: <5309bed5-3145-0763-150d-75cad9ef4e44@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 11/28/22 06:50, Luis Machado via Gdb-patches wrote: > Hi, > > On 11/26/22 02:04, Thiago Jung Bauermann wrote: >> This patch doesn't change gdbserver behaviour, but after later changes are >> made it avoids a null pointer dereference when HWCAP needs to be obtained >> for a specific process while current_thread is nullptr. >> >> Fixing linux_read_auxv, linux_get_hwcap and linux_get_hwcap2 to take a PID >> parameter seems more correct than setting current_thread in one particular >> code path. > > I'm wondering if passing the pid is needed at all in gdbserver for the purposes of fetching the hwcap entries from auxv. > > While current thread can be nullptr, I suppose current_process will never be nullptr if we have a valid inferior. And the auxv entries are per-process rather than per-thread. > > There is a bit of a corner case when we have extended-remote without a live process and we need to fetch the hwcap bits to determine a particular feature to report via qSupported. But I suppose this is not what this change is trying to address, is it? > > If not, it may be the case that we don't need these changes, and we can just use current_process. Even if we could just use current_process, this patch is going in the general direction I like, which is to reduce referring to the global state everywhere, try to fetch it only at the entry points and then pass the necessary context down by parameters. Simon