From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.freebsd.org (mx2.freebsd.org [IPv6:2610:1c1:1:606c::19:2]) by sourceware.org (Postfix) with ESMTPS id 712983858C55 for ; Tue, 20 Sep 2022 17:49:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 712983858C55 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=FreeBSD.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits)) (Client CN "mx1.freebsd.org", Issuer "R3" (verified OK)) by mx2.freebsd.org (Postfix) with ESMTPS id 4MX8Dh57Zcz43W9; Tue, 20 Sep 2022 17:49:08 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MX8Dh4KmSz3wBt; Tue, 20 Sep 2022 17:49:08 +0000 (UTC) (envelope-from jhb@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663696148; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GZ1CGcGg6/7Xfvdh15YNpvCvm+/P+/FXn6wixIkncJI=; b=TPXU8Jif+2+QfZ/5CGHqHcO8rtS+wZB3wa9HppwyNEdOMChXAwZnALq8IYIfno9UAhJnmK HaOWX8In1ICMwhzYaP2uygdsW14dFUdFOHlz6sCj6NAt4iZNEFVpYVYP91DZF8Ii+iJgHl 2GqqZocrIaS2jEuhr9xesH8rdWhmQy3qxGJoiYtlo5wjrVoalWcxnoxyd69V1QpGDbw+g1 SxrXIf6KT9J/8e/I9+qj7AzGnIHqLZyypcrjpI9/2TcU2msfk5eOmv1Z5alkOyDk2amPyX f2cuF/qP1r3r3wGB6y/EtP9XJOlibbrnvJLWSZwG0AoMW3NyRJjtvm5VJiV3cQ== Received: from [10.0.1.4] (ralph.baldwin.cx [66.234.199.215]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: jhb) by smtp.freebsd.org (Postfix) with ESMTPSA id 4MX8Dh1H0wz1BNF; Tue, 20 Sep 2022 17:49:08 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Message-ID: <91d08341-8edf-fa77-b233-d36134e755d9@FreeBSD.org> Date: Tue, 20 Sep 2022 10:49:06 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: [PATCH] Invalidate auxv cache before creating a core target Content-Language: en-US To: Luis Machado , gdb-patches@sourceware.org References: <20220719144542.1478037-1-luis.machado@arm.com> <20220920122828.188190-1-luis.machado@arm.com> From: John Baldwin In-Reply-To: <20220920122828.188190-1-luis.machado@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663696148; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GZ1CGcGg6/7Xfvdh15YNpvCvm+/P+/FXn6wixIkncJI=; b=beiTcfHwCZGSbEqIxTQsxC5+XseblOCTIwsDhm6RyjH+jUQsW5x0OF70mxbmwGhBq+6ZQn ObuPV7mFNUF+AQ4qcoV942CvTYEdX7r3vtYJwEl01yakjXcQxircOeeFAn6+kNSOUW3+Zf VkuI7fH3quQTPocYKFMLTGXIogELAAMZKeOPOJTB842DZ5dbFvimA/AXQzjO9IO6lYBBmj KqlZuoF0xuZnTnO00tSMBxE9IL/24xJi7fOfP9gmV+Y/4cAPvBbLV9oH1HM7D5Gnw146h/ xUBdLkMdfY2yhBbuhiv3HzbiofccEJaLD4S3/Wy9/m5d6vf5K+y+jWPPMkkKmw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1663696148; a=rsa-sha256; cv=none; b=TiP9SVmdyWardmo3dXimSG2ytoaer0meSzG/JLBNarHCDPWj9cZXyQINSM1Ioh9zbPz8X/ T8CNyaNuU/EazUaLxkPTFBlgT+WP3oBYrvU2R9fTjpKk7xjyVDh67nja4x+L/dqvTuHnEK Y/KPfUVvX4sozDuR5NMS7co9rHv1pHCxFwzDIv/mhnRWueBSvGa8u65tXtA67EMIAJyYpA oVERfUGooGMOI+oHFMWjUi+l1ZKdnQMIQcJQz1x8qh0/hwQQl19ARPFMC/Lo3O5K9koiPV l5r3RdleMvpRoo+3Tv4AVBNcswo31CAzO2Mar9RH4FLGlLZ6QXZW/Q64axH2bA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, SPF_HELO_NONE, 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 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: Tue, 20 Sep 2022 17:49:14 -0000 On 9/20/22 1:28 PM, Luis Machado wrote: > While adding support for MTE corefiles and running the MTE corefile tests, > I noticed a strange situation where loading the symbol file + core file > through the command line has a different behavior compared to firing up > GDB, loading the symbol file with the "file" command and then loading the > core file with the "core" command. > > I tracked this down to gdb/auxv.c:get_auxv_inferior_data returning empty > auxv data for pid 0, which gets cached. This is triggered by attempting to > read auxv data for the exec target. > > In the early stages of reading the core file, we're still using inferior pid > 0, so when we attempt to read auxv to determine corefile features, we get the > cached empty data vector again. This breaks core_gdbarch setup. > > To overcome this, make sure we invalidate the auxv data when creating a new core > target. > --- > gdb/auxv.c | 4 ++-- > gdb/auxv.h | 2 ++ > gdb/corelow.c | 15 +++++++++++++++ > 3 files changed, 19 insertions(+), 2 deletions(-) > > diff --git a/gdb/auxv.c b/gdb/auxv.c > index 6154988f6dd..2423f51f224 100644 > --- a/gdb/auxv.c > +++ b/gdb/auxv.c > @@ -342,9 +342,9 @@ invalidate_auxv_cache_inf (struct inferior *inf) > auxv_inferior_data.clear (inf); > } > > -/* Invalidate current inferior's auxv cache. */ > +/* See auxv.h */ > > -static void > +void > invalidate_auxv_cache (void) > { > invalidate_auxv_cache_inf (current_inferior ()); > diff --git a/gdb/auxv.h b/gdb/auxv.h > index a4801c34d2f..242bc2eff00 100644 > --- a/gdb/auxv.h > +++ b/gdb/auxv.h > @@ -79,5 +79,7 @@ extern int fprint_target_auxv (struct ui_file *file, struct target_ops *ops); > > extern target_xfer_partial_ftype memory_xfer_auxv; > > +/* Invalidate current inferior's auxv cache. */ > +void invalidate_auxv_cache (void); > > #endif > diff --git a/gdb/corelow.c b/gdb/corelow.c > index 293bc8d4f59..1c30c7d011c 100644 > --- a/gdb/corelow.c > +++ b/gdb/corelow.c > @@ -53,6 +53,7 @@ > #include "gdbcmd.h" > #include "xml-tdesc.h" > #include "memtag.h" > +#include "auxv.h" > > #ifndef O_LARGEFILE > #define O_LARGEFILE 0 > @@ -515,6 +516,20 @@ core_target_open (const char *arg, int from_tty) > > current_program_space->cbfd = std::move (temp_bfd); > > + /* Some architectures identify features using the hwcap bits that > + come from the auxv. Before creating a new core target, make sure we > + invalidate the auxv cache so we can get fresh data. > + > + This is required when we have an exec target before loading the core > + file. Under such conditions the pid is 0, and the exec target may > + attempt to fetch and cache the auxv. This results in GDB caching > + empty contents as the exec target doesn't have auxv data. > + > + Given we haven't determined the pid yet (we will read it later), it can > + still be 0 and simply fetching the auxv may return the cached empty > + data. This ultimately results in problems coming up with the proper > + gdbarch data. */ > + invalidate_auxv_cache (); > core_target *target = new core_target (); > > /* Own the target until it is successfully pushed. */ This looks good to me. -- John Baldwin