From: John Baldwin <jhb@FreeBSD.org>
To: Luis Machado <luis.machado@arm.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Invalidate auxv cache before creating a core target
Date: Tue, 20 Sep 2022 10:49:06 -0700 [thread overview]
Message-ID: <91d08341-8edf-fa77-b233-d36134e755d9@FreeBSD.org> (raw)
In-Reply-To: <20220920122828.188190-1-luis.machado@arm.com>
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
next prev parent reply other threads:[~2022-09-20 17:49 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-19 14:45 [PATCH] Update auxv cache when there is no auxv cached data Luis Machado
2022-07-25 9:42 ` [PING][PATCH] " Luis Machado
2022-07-25 16:05 ` [PATCH] " John Baldwin
2022-07-25 18:03 ` Luis Machado
2022-07-25 19:13 ` John Baldwin
2022-08-02 15:05 ` Luis Machado
2022-08-02 16:05 ` John Baldwin
2022-08-05 15:46 ` [PATCH] Update auxv cache when inferior pid is 0 (no inferior) Luis Machado
2022-08-11 9:05 ` [PING][PATCH] " Luis Machado
2022-08-18 15:48 ` Luis Machado
2022-09-01 9:29 ` Luis Machado
2022-09-07 8:20 ` Luis Machado
2022-09-12 12:48 ` Luis Machado
2022-09-12 13:30 ` [PATCH] " Simon Marchi
2022-09-12 13:53 ` John Baldwin
2022-09-12 13:59 ` Luis Machado
2022-09-20 12:28 ` [PATCH] Invalidate auxv cache before creating a core target Luis Machado
2022-09-20 17:49 ` John Baldwin [this message]
2022-10-07 20:44 ` [PATCH] gdb: fix auxv caching Simon Marchi
2022-10-07 21:43 ` John Baldwin
2022-10-09 0:39 ` Simon Marchi
2022-10-10 18:32 ` John Baldwin
2022-10-11 17:52 ` Simon Marchi
2022-10-11 20:31 ` Pedro Alves
2022-10-11 20:34 ` Pedro Alves
2022-10-11 20:42 ` John Baldwin
2022-10-12 1:11 ` Simon Marchi
2022-10-10 9:33 ` Luis Machado
2022-10-11 17:53 ` Simon Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=91d08341-8edf-fa77-b233-d36134e755d9@FreeBSD.org \
--to=jhb@freebsd.org \
--cc=gdb-patches@sourceware.org \
--cc=luis.machado@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).