From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 4F7B83858D39 for ; Wed, 13 Sep 2023 14:20:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4F7B83858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 38DEK8Ig003918 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 Sep 2023 10:20:13 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 38DEK8Ig003918 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1694614813; bh=oAB397C5l2PKVispZBK3uZEZYGbumhOmXD2+dXjepEA=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=c1gqseH01uKokIG4ZOuHKbUediB9aLBDkFwWCuhFUhZNT7Fl+cX5S+6CVUO9zgZB6 72LLNZBcik39KGs+dp657Ceb2NXaMMn9bTzgwCdnN374vC+pLwZI27FQieoiQGse2f VulHR40/KMhDqyzMcJOYsY4K9SI6AaJ+0NchEu5A= Received: from [172.16.0.192] (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 4928A1E028; Wed, 13 Sep 2023 10:20:08 -0400 (EDT) Message-ID: <2f5d1ae1-8b26-4aef-a674-0f271761620d@polymtl.ca> Date: Wed, 13 Sep 2023 10:20:07 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 14/17] [gdb/generic] corefile/bug: Use thread-specific gdbarch when dumping register state to core files Content-Language: fr To: Luis Machado , gdb-patches@sourceware.org Cc: thiago.bauermann@linaro.org References: <20230913101815.178154-1-luis.machado@arm.com> <20230913101815.178154-15-luis.machado@arm.com> From: Simon Marchi In-Reply-To: <20230913101815.178154-15-luis.machado@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 13 Sep 2023 14:20:08 +0000 X-Spam-Status: No, score=-3037.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 9/13/23 06:18, Luis Machado wrote: > When we have a core file generated by gdb (via the gcore command), gdb dumps > the target description to a note. During loading of that core file, gdb will > first try to load that saved target description. > > This works fine for almost all architectures. But AArch64 has a few > dynamically-generated target descriptions/gdbarch depending on the vector > length that was in use at the time the core file was generated. > > The target description gdb dumps to the core file note is the one generated > at the time of attachment/startup. If, for example, the SVE vector length > changed during execution, this would not reflect on the core file, as gdb > would still dump the initial target description. > > Another issue is that the gdbarch potentially doesn't match the thread's > real gdbarch, and so things like the register cache may have different formats > and sizes. > > To address this, fetch the thread's architecture before dumping its register > state. That way we will always use the correct target description/gdbarch. > --- > gdb/linux-tdep.c | 23 +++++++++++++++++++---- > 1 file changed, 19 insertions(+), 4 deletions(-) > > diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c > index a4a86b01bdb..2885afd60c7 100644 > --- a/gdb/linux-tdep.c > +++ b/gdb/linux-tdep.c > @@ -2078,15 +2078,30 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size) > stop_signal = GDB_SIGNAL_0; > > if (signalled_thr != nullptr) > - linux_corefile_thread (signalled_thr, gdbarch, obfd, note_data, note_size, > - stop_signal); > + { > + /* On some architectures, like AArch64, each thread can have a distinct > + gdbarch (due to scalable extensions), and using the inferior gdbarch > + is incorrect. > + > + Fetch each thread's gdbarch and pass it down to the lower layers so > + we can dump the right set of registers. */ > + linux_corefile_thread (signalled_thr, > + target_thread_architecture (signalled_thr->ptid), > + obfd, note_data, note_size, stop_signal); > + } > for (thread_info *thr : current_inferior ()->non_exited_threads ()) > { > if (thr == signalled_thr) > continue; > > - linux_corefile_thread (thr, gdbarch, obfd, note_data, note_size, > - stop_signal); > + /* On some architectures, like AArch64, each thread can have a distinct > + gdbarch (due to scalable extensions), and using the inferior gdbarch > + is incorrect. > + > + Fetch each thread's gdbarch and pass it down to the lower layers so > + we can dump the right set of registers. */ > + linux_corefile_thread (thr, target_thread_architecture (thr->ptid), > + obfd, note_data, note_size, stop_signal); > } > > if (!note_data) > -- > 2.25.1 > Approved-By: Simon Marchi Simon