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 11F213858D28 for ; Fri, 17 Mar 2023 17:15:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 11F213858D28 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) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 01F1C1E0D3; Fri, 17 Mar 2023 13:15:49 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1679073350; bh=Df3slov+U95h/vL9Hnjd8NgkyYedtZuWBxvoFY8IB4c=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=HbNXcXrm6o/EPbXIppyxqozjY17pUXixSew/MNX+7zSNiuj1AWyRG4Z92zja7awXj HmX+xMgRbIN3/4aamtbYllHa+bgD7NNlaKX8msRJiL6LWZ7OjnlXCB55EkaQpy40US rK7B6wHLEBT+6dTe17iE9kSnSipke/j/oQsobrSk= Message-ID: <6aa8edc2-81f7-b08a-805f-9a20185995d2@simark.ca> Date: Fri, 17 Mar 2023 13:15:49 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH] aarch64: Check for valid inferior thread/regcache before reading pauth registers Content-Language: en-US To: Luis Machado , Andrew Burgess , gdb-patches@sourceware.org, pedro@palves.net Cc: marcan@marcan.st References: <20230316103904.1947447-1-luis.machado@arm.com> <873564g0h3.fsf@redhat.com> <5ce96222-d665-5129-8d65-27c6933a6623@arm.com> From: Simon Marchi In-Reply-To: <5ce96222-d665-5129-8d65-27c6933a6623@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.8 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: > ... despite the call to switch_to_no_thread in switch_to_inferior_no_thread from do_target_wait_1 > in the backtrace above, the call to ps_xfer_memory sets inferior_ptid momentarily before reading > memory: > > > static ps_err_e > ps_xfer_memory (const struct ps_prochandle *ph, psaddr_t addr, > gdb_byte *buf, size_t len, int write) > { > scoped_restore_current_inferior restore_inferior; > set_current_inferior (ph->thread->inf); > > scoped_restore_current_program_space restore_current_progspace; > set_current_program_space (ph->thread->inf->pspace); > > scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); > inferior_ptid = ph->thread->ptid; > > CORE_ADDR core_addr = ps_addr_to_core_addr (addr); > > int ret; > if (write) > ret = target_write_memory (core_addr, buf, len); > else > ret = target_read_memory (core_addr, buf, len); > return (ret == 0 ? PS_OK : PS_ERR); > } > > > Maybe this shouldn't happen, or maybe it is just an unfortunate state to be in. But this > prevents the use of target_has_registers to guard against the lack of registers, since, > although current_thread_ is still nullptr, inferior_ptid is valid and is not null_ptid. It's needed to set inferior_ptid here because it's how we communicate to the targets which inferior / thread we want to read or write memory from. And we can't set current_thread_ to the the correponding thread_info *, because it does not exist at this point (we are in the process of creating it). And the problem is that aarch64_remove_non_address_bits assumes there is a current_thread_. Can we change aarch64_remove_non_address_bits to get the regcache using the ptid? get_thread_regcache (current_inferior ()->process_target (), inferior_ptid); Simon