public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: John Baldwin <jhb@FreeBSD.org>
To: gdb-patches@sourceware.org
Subject: Re: [RFC PATCH 0/4] Handle variable XSAVE layouts
Date: Thu, 17 Mar 2022 11:03:10 -0700	[thread overview]
Message-ID: <f8f6b0e5-4deb-bfc8-4f03-ede703786cd1@FreeBSD.org> (raw)
In-Reply-To: <8e08b537-fe97-3c06-58d0-1e41cded2054@FreeBSD.org>

On 3/17/22 9:20 AM, John Baldwin wrote:
> On 3/17/22 6:17 AM, Willgerodt, Felix wrote:
>>> This is a first attempt at resolving the issue with XSAVE I described
>>> previously.  There are more details in the commit logs, but here I think
>>> will describe some caveats about the current prototype:
>>>
>>> - It is probably terrible performance-wise to be reading the offsets
>>>     from the target every time collect/supply_xsave is called.  I'd
>>>     actually much prefer to store these (along with the total XSAVE area
>>>     size) in the tdep.  The issue is that you can have gdbarches with the
>>>     same tdesc that use different layouts (e.g. if you open a core dump
>>>     from an Intel CPU on a host with an AMD CPU, the two CPUs could have
>>>     identical XCR0 masks, but the layout in the core dump wouldn't match
>>>     the layout of a live process).  Perhaps if I can fetch the offsets
>>>     from the target in i386_gdbarch_init though I can iterate over
>>>     matching arches looking for a match.
>>
>> I don't quite understand why storing them in tdep wouldn't work.
>> We get XCR0 from the coredump, not from the CPU analysing
>> the coredump. For live targets we would query CPUID on GDB/gdbserver.
>> I don't see how this would clash in your example, but maybe I missed
>> something in your patches.
> 
> The problem is that two tdep's with the same XCR0 value currently
> have an identical tdesc and thus share the same 'struct gdbarch'.
> However, an Intel CPU with XCR0 of 0x207 uses a different layout
> than an AMD CPU with an XCR0 of 0x207.  We would thus need separate
> gdbarches for those.  I think though I can make that work if I fetch
> TARGET_OBJECT_X86_XSAVE_OFFSETS in i386_gdbarch_init() before this
> loop:
> 
>     /* If there is already a candidate, use it.  */
>     arches = gdbarch_list_lookup_by_info (arches, &info);
>     if (arches != NULL)
>       return arches->gdbarch;
> 
> And instead only return an existing gdbarch if it has the same XSAVE
> layout.  For example, RISC-V does the following logic to handle
> differences in gdbarches that aren't fully handled by the tdesc:
> 
>     /* Find a candidate among the list of pre-declared architectures.  */
>     for (arches = gdbarch_list_lookup_by_info (arches, &info);
>          arches != NULL;
>          arches = gdbarch_list_lookup_by_info (arches->next, &info))
>       {
>         /* Check that the feature set of the ARCHES matches the feature set
> 	 we are looking for.  If it doesn't then we can't reuse this
> 	 gdbarch.  */
>         riscv_gdbarch_tdep *other_tdep
> 	= (riscv_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
> 
>         if (other_tdep->isa_features != features
> 	  || other_tdep->abi_features != abi_features)
> 	continue;
> 
>         break;
>       }
> 
>     if (arches != NULL)
>       return arches->gdbarch;
> 
> I think it would also be handy in this case to extend the xsave_offsets
> structure to include the total size that can be used in the collect/supply
> callbacks.

I have made these changes and it does appear to work.  I do think the approach
of a new TARGET_OBJECT will work (and it will support adding a new
NT_X86_XSAVE_LAYOUT or the like in the future to better support core dumps).
If you agree with that part of the design (and storing it in the tdep, etc.
I can try to merge in parts of your patchset (in particular, moving some
things to gdbsupport and similar gdbserver patches) or I'm happy to let you
drive.  I will send a V2 with the changes to store the layout in the tdep.

-- 
John Baldwin

  reply	other threads:[~2022-03-17 18:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-16 19:46 John Baldwin
2022-03-16 19:46 ` [RFC PATCH 1/4] x86: Add an xsave_offsets structure to handle " John Baldwin
2022-03-16 19:46 ` [RFC PATCH 2/4] core: Support fetching TARGET_OBJECT_X86_XSAVE_OFFSETS from architectures John Baldwin
2022-03-16 19:46 ` [RFC PATCH 3/4] Update x86 FreeBSD architectures to support XSAVE offsets John Baldwin
2022-03-16 19:46 ` [RFC PATCH 4/4] Support XSAVE layouts for the current host in the FreeBSD/amd64 target John Baldwin
2022-03-17 13:17 ` [RFC PATCH 0/4] Handle variable XSAVE layouts Willgerodt, Felix
2022-03-17 16:20   ` John Baldwin
2022-03-17 18:03     ` John Baldwin [this message]
2022-03-18 13:49       ` Willgerodt, Felix
2022-03-18 17:27         ` John Baldwin

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=f8f6b0e5-4deb-bfc8-4f03-ede703786cd1@FreeBSD.org \
    --to=jhb@freebsd.org \
    --cc=gdb-patches@sourceware.org \
    /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).