public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: John Baldwin <jhb@FreeBSD.org>
To: Simon Marchi <simark@simark.ca>,
	Luis Machado <luis.machado@arm.com>,
	gdb-patches@sourceware.org
Subject: Re: [PATCH] Update auxv cache when inferior pid is 0 (no inferior)
Date: Mon, 12 Sep 2022 14:53:56 +0100	[thread overview]
Message-ID: <42b0147c-22ac-1004-8b35-23008fffb481@FreeBSD.org> (raw)
In-Reply-To: <26831717-834d-91ee-fb08-55f787bd2421@simark.ca>

On 9/12/22 2:30 PM, Simon Marchi via Gdb-patches wrote:
> 
> 
> On 2022-08-05 11:46, Luis Machado via Gdb-patches 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.
>>
>> The fix, suggested by John Baldwin, prevents caching auxv data for pid 0.
> 
> I read the thread where you discussed this with John, I'm not sure I
> completely grasp the problem yet, but this doesn't feel like the right
> fix.  It should be fine to cache the auxv data for an inferior with pid
> 0.  If the inferior's memory and the inferior's target stack don't
> change between two invocations of get_auxv_inferior_data, there's no
> reason for the auxv data to be different for both calls.  I think the
> problem is more that we don't invalidate the data at the right time.
> 
> The first call is done when only the exec target is pushed.  The second
> call is done when the core target is pushed on top of that.  It's
> expected that the returned auxv data can be different for the two calls,
> so the cache should be invalidated somewhere between them.

The problem is that the core target attaching is a multi-step process.
The auxv cache gets invalidated when the pid is changed from 0 to the
"real" value after reading the registers near the "end" of the core
target attach process.  However, in order to read the registers from the
core dump for some architectures (like Linux/AArch64), the
read_description_from_core gdbarch hook needs to be able to fetch auxv
data (specifically the AT_HWCAP bits).  This occurs while the pid is still
zero, so the old value from the exec target is still cached.

This complexity is already present in the way that we fetch an "initial"
gdbarch from the core file and then ask that gdbarch for a more detailed
target description that is used to then instantiate a second gdbarch
(the "actual" gdbarch to use for the core file).  The place to possibly
flush the auxv cache again would perhaps be just before invoking the
core read_description method.  This would need a new observer hook though
that the auxv code could hook into.

OTOH, pid 0 is rather special and short-lived, so caching auxv data for
it seems less important than caching it once a target is fully attached
to a core or running process, etc.

-- 
John Baldwin

  reply	other threads:[~2022-09-12 13:53 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 [this message]
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
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=42b0147c-22ac-1004-8b35-23008fffb481@FreeBSD.org \
    --to=jhb@freebsd.org \
    --cc=gdb-patches@sourceware.org \
    --cc=luis.machado@arm.com \
    --cc=simark@simark.ca \
    /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).