Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Luis Machado <luis.machado@arm.com>
To: John Baldwin <jhb@FreeBSD.org>,
	Andrew Burgess <aburgess@redhat.com>,
	gdb-patches@sourceware.org
Subject: Re: [PATCHv2 6/7] gdbserver: update target description creation for x86/linux
Date: Tue, 26 Mar 2024 10:01:00 +0000	[thread overview]
Message-ID: <c11c1d80-0d33-4dc9-ae89-c79022ca84a6@arm.com> (raw)
In-Reply-To: <bb59f4e1-fb2b-4f26-b672-1ef901d7985e@FreeBSD.org>

On 3/21/24 17:28, John Baldwin wrote:
> On 3/19/24 11:34 AM, Andrew Burgess wrote:
>> John Baldwin <jhb@FreeBSD.org> writes:
>>
>>> On 3/5/24 9:00 AM, Andrew Burgess wrote:
>>>> This commit is part of a series which aims to share more of the target
>>>> description creation between GDB and gdbserver for x86/Linux.
>>>>
>>>> After some refactoring, the previous commit actually started to share
>>>> some code, we added the shared x86_linux_tdesc_for_tid function into
>>>> nat/x86-linux-tdesc.c.  However, this function still relies on
>>>> amd64_linux_read_description and i386_linux_read_description which are
>>>> implemented separately for both gdbserver and GDB.  Given that at
>>>> their core, all these functions to is:
>>>>
>>>>     1. take an xcr0 value as input,
>>>>     2. mask out some feature bits,
>>>>     3. look for a cached pre-generated target description and return it
>>>>        if found,
>>>>     4. if no cached target description is found then call either
>>>>        amd64_create_target_description or
>>>>        i386_create_target_description to create a new target
>>>>        description, which is then added to the cache.  Return the newly
>>>>        created target description.
>>>>
>>>> The inner functions amd64_create_target_description and
>>>> i386_create_target_description are already shared between GDB and
>>>> gdbserver (in the gdb/arch/ directory), so the only thing that
>>>> the *_read_description functions really do is add the caching layer,
>>>> and it feels like this really could be shared.
>>>>
>>>> However, we have a small problem.
>>>>
>>>> On the GDB side we create target descriptions using a different set of
>>>> cpu features than on the gdbserver side!  This means that for the
>>>> exact same target, we might get a different target description when
>>>> using native GDB vs using gdbserver.  This surely feels like a
>>>> mistake, I would expect to get the same target description on each.
>>>>
>>>> The table below shows the number of possible different target
>>>> descriptions that we can create on the GDB side vs on the gdbserver
>>>> side for each target type:
>>>>
>>>>           | GDB | gdbserver
>>>>     ------|-----|----------
>>>>     i386  | 64  | 7
>>>>     amd64 | 32  | 7
>>>>     x32   | 16  | 7
>>>>
>>>> So in theory, all I want to do is move the GDB version
>>>> of *_read_description into the nat/ directory and have gdbserver use
>>>> that, then both GDB and gdbserver would be able to create any of the
>>>> possible target descriptions.
>>>>
>>>> Unfortunately it's a little more complex than that due to the in
>>>> process agent (IPA).
>>>>
>>>> When the IPA is in use, gdbserver sends a target description index to
>>>> the IPA, and the IPA uses this to find the correct target description
>>>> to use.
>>>>
>>>> ** START OF AN ASIDE **
>>>>
>>>> Back in the day I suspect this approach made perfect sense.  However
>>>> since this commit:
>>>>
>>>>     commit a8806230241d201f808d856eaae4d44088117b0c
>>>>     Date:   Thu Dec 7 17:07:01 2017 +0000
>>>>
>>>>         Initialize target description early in IPA
>>>>
>>>> I think passing the index is now more trouble than its worth.
>>>>
>>>> We used to pass the index, and then use that index to lookup which
>>>> target description to instantiate and use.  However, the above commit
>>>> fixed an issue where we can't call malloc() within (certain parts of)
>>>> the IPA (apparently), so instead we now pre-compute _every_ possible
>>>> target description within the IPA.  The index is now only used to
>>>> lookup which of the (many) pre-computed target descriptions to use.
>>>>
>>>> It would (I think) have been easier all around if the IPA just
>>>> self-inspected, figured out its own xcr0 value, and used that to
>>>> create the one target description that is required.  So long as the
>>>> xcr0 to target description code is shared (at compile time) with
>>>> gdbserver, then we can be sure that the IPA will derive the same
>>>> target description as gdbserver, and we would avoid all this index
>>>> passing business, which has made this commit so very, very painful.
>>>>
>>>> ** END OF AN ASIDE **
>>>>
>>>> Currently then for x86/linux, gdbserver sends a number between 0 and 7
>>>> to the IPA, and the IPA uses this to create a target description.
>>>>
>>>> However, I am proposing that gdbserver should now create one of (up
>>>> to) 64 different target descriptions for i386, so this 0 to 7 index
>>>> isn't going to be good enough any more (amd64 and x32 have slightly
>>>> fewer possible target descriptions, but still more than 8, so the
>>>> problem is the same).
>>>>
>>>> For a while I wondered if I was going to have to try and find some
>>>> backward compatible solution for this mess.  But after seeing how
>>>> lightly the IPA is actually documented, I wonder if it is not the case
>>>> that there is a tight coupling between a version of gdbserver and a
>>>> version of the IPA?  At least I'm hoping so.
>>>>
>>>> In this commit I have thrown out the old IPA target description index
>>>> numbering scheme, and switched to a completely new numbering scheme.
>>>> Instead of the index that is passed being arbitrary, the index is
>>>> instead calculated from the set of cpu features that are present on
>>>> the target.  Within the IPA we can then reverse this logic to recreate
>>>> the xcr0 value based on the index, and from the xcr0 value we can
>>>> create the correct target description.
>>>>
>>>> With the gdbserver to IPA numbering scheme issue resolved I have then
>>>> update the gdbserver versions of amd64_linux_read_description and
>>>> i386_linux_read_description so that they create target descriptions
>>>> using the same set of cpu features as GDB itself.
>>>>
>>>> After this gdbserver should now always come up with the same target
>>>> description as GDB does on any x86/Linux target.
>>>>
>>>> This commit does not introduce any new code sharing between GDB and
>>>> gdbserver as previous commits in this series does.  Instead this
>>>> commit is all about bringing GDB and gdbserver into alignment
>>>> functionally so that the next commit can merge the GDB and gdbserver
>>>> versions of these functions.
>>>
>>> It does seem like the IPA case should just compute the tdesc it needs
>>> if I understand you correctly.
>>
>> Yes, totally.  And it's not like it would even add much code to the IPA,
>> I believe it already pulls in all of the target description creation
>> code, the only thing that is "saved" is the code that probes the
>> hardware to figure out which description we should use.
>>
>> This whole area seems like it has not aged well :-/
>>
>>>
>>> BTW, on other arches like aarch64 and I believe risc-v, a flat array
>>> is not used for the tdesc cache.  Now the cache is a std::unordered_map<>
>>> and there is a 'struct foo_features' that has an operator== and
>>> std::hash<> specialization.  It really would be nice if x86 was the same,
>>> but that would require abandoning a notion of a portable "index" shared
>>> between gdbserver and the IPA.
>>
>> Indeed.  I did the worked on the feature/hash/lookup for RISC-V so I had
>> this in mind when looking at this code.  Originally I had planned to
>> switch to a map style cache, but when I found the IPA/index passing code
>> I lost my nerve and tried to find a solution that was inline with what
>> we had currently.
>>
>> I don't really know about the IPA enough to make claims about what
>> is/isn't a reasonable change in this area.
> 
> I have zero knowledge about the IPA myself.  OTOH, if no one else steps
> up with a strong opinion here, I would suggest that you go ahead and
> fix the IPA as you described so it is more self-contained and then we can
> use a saner approach for dealing with tdesc caching for x86.
> 

Should we start thinking of deprecating the IPA if no one shows any interest in
keeping it alive? It is there to provide support for (fast/static) tracepoints,
and I haven't seen anyone using it in the open for years now.

The cost of maintenance may not justify keeping it alive.

  reply	other threads:[~2024-03-26 10:01 UTC|newest]

Thread overview: 116+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-01 15:28 [PATCH 0/7] x86/Linux Target Description Changes Andrew Burgess
2024-02-01 15:28 ` [PATCH 1/7] gdbserver: convert have_ptrace_getregset to a tribool Andrew Burgess
2024-02-01 15:28 ` [PATCH 2/7] gdb/x86: move reading of cs and ds state into gdb/nat directory Andrew Burgess
2024-02-01 15:28 ` [PATCH 3/7] gdbserver/x86: move no-xml code earlier in x86_linux_read_description Andrew Burgess
2024-02-01 15:28 ` [PATCH 4/7] gdb/gdbserver: share I386_LINUX_XSAVE_XCR0_OFFSET definition Andrew Burgess
2024-02-01 15:28 ` [PATCH 5/7] gdb/gdbserver: share some code relating to target description creation Andrew Burgess
2024-02-01 15:28 ` [PATCH 6/7] gdbserver: update target description creation for x86/linux Andrew Burgess
2024-02-01 15:28 ` [PATCH 7/7] gdb/gdbserver: share x86/linux tdesc caching Andrew Burgess
2024-03-05 17:00 ` [PATCHv2 0/7] x86/Linux Target Description Changes Andrew Burgess
2024-03-05 17:00   ` [PATCHv2 1/7] gdbserver: convert have_ptrace_getregset to a tribool Andrew Burgess
2024-03-05 17:00   ` [PATCHv2 2/7] gdb/x86: move reading of cs and ds state into gdb/nat directory Andrew Burgess
2024-03-05 17:00   ` [PATCHv2 3/7] gdbserver/x86: move no-xml code earlier in x86_linux_read_description Andrew Burgess
2024-03-05 17:00   ` [PATCHv2 4/7] gdb/gdbserver: share I386_LINUX_XSAVE_XCR0_OFFSET definition Andrew Burgess
2024-03-05 17:00   ` [PATCHv2 5/7] gdb/gdbserver: share some code relating to target description creation Andrew Burgess
2024-03-05 17:00   ` [PATCHv2 6/7] gdbserver: update target description creation for x86/linux Andrew Burgess
2024-03-19 16:01     ` John Baldwin
2024-03-19 18:34       ` Andrew Burgess
2024-03-21 17:28         ` John Baldwin
2024-03-26 10:01           ` Luis Machado [this message]
2024-03-26 15:31             ` Tom Tromey
2024-03-05 17:00   ` [PATCHv2 7/7] gdb/gdbserver: share x86/linux tdesc caching Andrew Burgess
2024-03-19 16:05   ` [PATCHv2 0/7] x86/Linux Target Description Changes John Baldwin
2024-03-23 16:35   ` [PATCHv3 0/8] " Andrew Burgess
2024-03-23 16:35     ` [PATCHv3 1/8] gdbserver: convert have_ptrace_getregset to a tribool Andrew Burgess
2024-03-23 16:35     ` [PATCHv3 2/8] gdb/x86: move reading of cs and ds state into gdb/nat directory Andrew Burgess
2024-03-23 16:35     ` [PATCHv3 3/8] gdbserver/x86: move no-xml code earlier in x86_linux_read_description Andrew Burgess
2024-03-23 16:35     ` [PATCHv3 4/8] gdb/gdbserver: share I386_LINUX_XSAVE_XCR0_OFFSET definition Andrew Burgess
2024-03-23 16:35     ` [PATCHv3 5/8] gdb/gdbserver: share some code relating to target description creation Andrew Burgess
2024-03-23 16:35     ` [PATCHv3 6/8] gdb/arch: assert that X86_XSTATE_MPX is not set for x32 Andrew Burgess
2024-03-23 16:35     ` [PATCHv3 7/8] gdbserver: update target description creation for x86/linux Andrew Burgess
2024-03-23 16:35     ` [PATCHv3 8/8] gdb/gdbserver: share x86/linux tdesc caching Andrew Burgess
2024-03-26 12:17       ` Andrew Burgess
2024-03-25 17:20     ` [PATCHv3 0/8] x86/Linux Target Description Changes Andrew Burgess
2024-03-25 18:26       ` Simon Marchi
2024-03-26 12:15         ` Andrew Burgess
2024-03-26 13:51           ` H.J. Lu
2024-03-26 14:16             ` H.J. Lu
2024-03-26 16:36       ` Andrew Burgess
2024-03-26 19:03         ` Andrew Burgess
2024-04-05 12:33     ` [PATCHv4 00/10] " Andrew Burgess
2024-04-05 12:33       ` [PATCHv4 01/10] gdbserver/ipa/x86: remove unneeded declarations Andrew Burgess
2024-04-05 12:33       ` [PATCHv4 02/10] gdbserver: convert have_ptrace_getregset to a tribool Andrew Burgess
2024-04-05 12:33       ` [PATCHv4 03/10] gdb/x86: move reading of cs and ds state into gdb/nat directory Andrew Burgess
2024-04-05 12:33       ` [PATCHv4 04/10] gdbserver/x86: move no-xml code earlier in x86_linux_read_description Andrew Burgess
2024-04-05 12:33       ` [PATCHv4 05/10] gdb/gdbserver: share I386_LINUX_XSAVE_XCR0_OFFSET definition Andrew Burgess
2024-04-05 12:33       ` [PATCHv4 06/10] gdb/gdbserver: share some code relating to target description creation Andrew Burgess
2024-04-05 12:33       ` [PATCHv4 07/10] gdb/arch: assert that X86_XSTATE_MPX is not set for x32 Andrew Burgess
2024-04-05 12:33       ` [PATCHv4 08/10] gdbserver: update target description creation for x86/linux Andrew Burgess
2024-04-05 12:33       ` [PATCHv4 09/10] gdb: move xcr0 == 0 check into i386_linux_core_read_description Andrew Burgess
2024-04-05 12:33       ` [PATCHv4 10/10] gdb/gdbserver: share x86/linux tdesc caching Andrew Burgess
2024-04-09 18:37       ` [PATCHv4 00/10] x86/Linux Target Description Changes John Baldwin
2024-04-25 13:35       ` Willgerodt, Felix
2024-04-25 16:06         ` Andrew Burgess
2024-04-26 15:01       ` [PATCHv5 00/11] " Andrew Burgess
2024-04-26 15:01         ` [PATCHv5 01/11] gdbserver/ipa/x86: remove unneeded declarations Andrew Burgess
2024-04-29 14:34           ` Willgerodt, Felix
2024-05-07 15:05             ` Andrew Burgess
2024-05-08  7:49               ` Willgerodt, Felix
2024-04-26 15:01         ` [PATCHv5 02/11] gdbserver: convert have_ptrace_getregset to a tribool Andrew Burgess
2024-04-29 14:34           ` Willgerodt, Felix
2024-05-07 15:28             ` Andrew Burgess
2024-04-26 15:01         ` [PATCHv5 03/11] gdb/x86: move reading of cs and ds state into gdb/nat directory Andrew Burgess
2024-04-29 14:34           ` Willgerodt, Felix
2024-04-26 15:01         ` [PATCHv5 04/11] gdb/x86: move have_ptrace_getfpxregs global " Andrew Burgess
2024-04-29 14:34           ` Willgerodt, Felix
2024-04-26 15:01         ` [PATCHv5 05/11] gdbserver/x86: move no-xml code earlier in x86_linux_read_description Andrew Burgess
2024-04-29 14:34           ` Willgerodt, Felix
2024-05-07 11:55             ` Luis Machado
2024-05-07 15:43               ` Andrew Burgess
2024-05-07 15:56                 ` Luis Machado
2024-05-08  7:49                 ` Willgerodt, Felix
2024-05-08 13:18                   ` Andrew Burgess
2024-04-26 15:01         ` [PATCHv5 06/11] gdb/gdbserver: share I386_LINUX_XSAVE_XCR0_OFFSET definition Andrew Burgess
2024-04-29 14:34           ` Willgerodt, Felix
2024-04-26 15:01         ` [PATCHv5 07/11] gdb/gdbserver: share some code relating to target description creation Andrew Burgess
2024-04-29 14:34           ` Willgerodt, Felix
2024-05-07 11:40             ` Andrew Burgess
2024-04-26 15:01         ` [PATCHv5 08/11] gdb/arch: assert that X86_XSTATE_MPX is not set for x32 Andrew Burgess
2024-04-29 14:34           ` Willgerodt, Felix
2024-05-07 16:08             ` Andrew Burgess
2024-04-26 15:01         ` [PATCHv5 09/11] gdbserver: update target description creation for x86/linux Andrew Burgess
2024-04-29 14:35           ` Willgerodt, Felix
2024-05-07 14:24             ` Andrew Burgess
2024-05-08  7:47               ` Willgerodt, Felix
2024-05-08 13:28                 ` Andrew Burgess
2024-04-26 15:01         ` [PATCHv5 10/11] gdb: move xcr0 == 0 check into i386_linux_core_read_description Andrew Burgess
2024-04-29 14:35           ` Willgerodt, Felix
2024-04-26 15:01         ` [PATCHv5 11/11] gdb/gdbserver: share x86/linux tdesc caching Andrew Burgess
2024-04-29 14:35           ` Willgerodt, Felix
2024-05-07 14:50             ` Andrew Burgess
2024-05-08  7:49               ` Willgerodt, Felix
2024-05-08 16:09                 ` Andrew Burgess
2024-05-08 16:46         ` [PATCHv6 0/9] x86/Linux Target Description Changes Andrew Burgess
2024-05-08 16:46           ` [PATCHv6 1/9] gdb/gdbserver: share I386_LINUX_XSAVE_XCR0_OFFSET definition Andrew Burgess
2024-05-08 16:46           ` [PATCHv6 2/9] gdbserver/x86: move no-xml code earlier in x86_linux_read_description Andrew Burgess
2024-05-08 16:46           ` [PATCHv6 3/9] gdb/x86: move have_ptrace_getfpxregs global into gdb/nat directory Andrew Burgess
2024-05-08 22:52             ` John Baldwin
2024-05-08 16:46           ` [PATCHv6 4/9] gdb/x86: move have_ptrace_getregset " Andrew Burgess
2024-05-08 22:53             ` John Baldwin
2024-05-08 16:46           ` [PATCHv6 5/9] gdb/x86: move reading of cs and ds state " Andrew Burgess
2024-05-08 16:46           ` [PATCHv6 6/9] gdb: move xcr0 == 0 check into i386_linux_core_read_description Andrew Burgess
2024-05-08 22:54             ` John Baldwin
2024-05-08 16:46           ` [PATCHv6 7/9] gdb/gdbserver: share some code relating to target description creation Andrew Burgess
2024-05-08 22:58             ` John Baldwin
2024-05-08 16:46           ` [PATCHv6 8/9] gdbserver: update target description creation for x86/linux Andrew Burgess
2024-05-08 16:46           ` [PATCHv6 9/9] gdb/gdbserver: share x86/linux tdesc caching Andrew Burgess
2024-05-11 10:08           ` [PATCHv7 0/9] x86/Linux Target Description Changes Andrew Burgess
2024-05-11 10:08             ` [PATCHv7 1/9] gdb/gdbserver: share I386_LINUX_XSAVE_XCR0_OFFSET definition Andrew Burgess
2024-05-11 10:08             ` [PATCHv7 2/9] gdbserver/x86: move no-xml code earlier in x86_linux_read_description Andrew Burgess
2024-05-11 10:08             ` [PATCHv7 3/9] gdb/x86: move have_ptrace_getfpxregs global into gdb/nat directory Andrew Burgess
2024-05-11 10:08             ` [PATCHv7 4/9] gdb: move have_ptrace_getregset declaration " Andrew Burgess
2024-05-11 10:08             ` [PATCHv7 5/9] gdb/x86: move reading of cs and ds state " Andrew Burgess
2024-05-11 10:08             ` [PATCHv7 6/9] gdb: move xcr0 == 0 check into i386_linux_core_read_description Andrew Burgess
2024-05-11 10:08             ` [PATCHv7 7/9] gdb/gdbserver: share some code relating to target description creation Andrew Burgess
2024-05-11 10:08             ` [PATCHv7 8/9] gdbserver: update target description creation for x86/linux Andrew Burgess
2024-05-11 10:08             ` [PATCHv7 9/9] gdb/gdbserver: share x86/linux tdesc caching Andrew Burgess

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=c11c1d80-0d33-4dc9-ae89-c79022ca84a6@arm.com \
    --to=luis.machado@arm.com \
    --cc=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jhb@FreeBSD.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