From: Luis Machado <luis.machado@arm.com>
To: Thiago Jung Bauermann <thiago.bauermann@linaro.org>,
Simon Marchi <simark@simark.ca>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v2 6/6] gdb/aarch64: Detect vector length changes when debugging remotely
Date: Thu, 1 Dec 2022 08:32:16 +0000 [thread overview]
Message-ID: <7924fd9d-edc1-b0dd-4cbc-07026fd9f1c5@arm.com> (raw)
In-Reply-To: <87r0xjg6e4.fsf@linaro.org>
On 12/1/22 03:16, Thiago Jung Bauermann wrote:
>
> Simon Marchi <simark@simark.ca> writes:
>
>> On 11/25/22 21:04, Thiago Jung Bauermann via Gdb-patches wrote:
>>> If the remote target provides an expedited VG register, use it to update
>>> the thread's gdbarch. This allows debugging programs that change their SVE
>>> vector length during runtime.
>>>
>>> This is accomplished by implementing the thread_architecture method in
>>> remote_target, which returns the gdbarch corresponding to the expedited
>>> registers provided by the last stop reply.
>>>
>>> To allow changing the architecture based on the expedited registers, add a
>>> new gdbarch method to allow arch-specific code to make the adjustment.
>>
>> I get this when applying, can you address that?
>>
>> Applying: gdb/aarch64: Detect vector length changes when debugging remotely
>> .git/rebase-apply/patch:164: indent with spaces.
>> "gdbarch_dump: update_architecture = <%s>\n",
>> .git/rebase-apply/patch:165: indent with spaces.
>> host_address_to_string (gdbarch->update_architecture));
>> .git/rebase-apply/patch:186: indent with spaces.
>> gdbarch_update_architecture_ftype update_architecture)
>> warning: 3 lines add whitespace errors.
>
> This is because gdbarch.py generates these lines in gdbarch.c with
> spaces-only indentation. I will send a separate patch to fix it.
>
>> I think the idea makes sense. Short of adding a packet for "get thread
>> architecture" or extending the stop reply format to add a note about a
>> thread having a special tdesc, I don't see another way to do this. We
>
> I guess we could define such a packet, but this approach is indeed
> simpler.
>
Just a FYI, we now have a feature hash for determining the target features for aarch64. It is a 64-bit
number and doesn't rely on positioning of registers.
This situation with vg/SVE will also apply to svg/SME in the future.
>> can't read the vq register using 'g', because to interpret the 'g'
>> result, we need to know the full architecture. We wouldn't know for
>> sure the offset of vq in the reply. By using expedited registers, we
>> just need to make sure vq's register number is stable. I guess that is
>> the case?
>
> The register number is determined by the function
> aarch64_create_target_description. If SVE is supported, VG will always
> have the register number 85. If not, then AFAIU the register number will
> be unused (since the PAuth, MTE and TLS features only have a few
> registers). But it could potentially be used by another feature in the
> future...
>
> Do we have to reserve the number 85 for the VG pseudo-register?
>
>>> @@ -8068,6 +8078,21 @@ remote_target::process_stop_reply (struct stop_reply *stop_reply,
>>> /* Expedited registers. */
>>> if (!stop_reply->regcache.empty ())
>>> {
>>> + /* If GDB already knows about this thread, we can give the
>>> + architecture-specific code a chance to update the gdbarch based on
>>> + the expedited registers. */
>>> + if (find_thread_ptid (this, ptid) != nullptr)
>>> + {
>>> + stop_reply->arch = gdbarch_update_architecture (stop_reply->arch,
>>> + stop_reply->regcache);
>>> +
>>> + /* Save stop_reply->arch so that it can be returned by the
>>> + thread_architecture method. */
>>> + remote_thread_info *remote_thr = get_remote_thread_info (this,
>>> + ptid);
>>> + remote_thr->expedited_arch = stop_reply->arch;
>>> + }
>>> +
>>> struct regcache *regcache
>>> = get_thread_arch_regcache (this, ptid, stop_reply->arch);
>>
>>
>> What happens with threads that are not yet known? Imagine the process
>> starts with SVE == X, the main threads spawns a worker thread, the
>> worker thread updates its SVE to Y, and the worker thread hits a
>> breakpoint. This is the first time we hear about that worker thread.
>
> I tested this scenario and... it sort of works, but not quite. When the
> unknown thread hits the breakpoint, gdbserver sends a T stop reply
> packet with the new VG value in the expedited registers. It will be the
> first time we hear about that worker thread, but at the same time we
> will also learn about the value of its VG pseudo-register. So GDB
> reports the breakpoint hit event and gets to the prompt as expected. You
> can even print the new value of the VG pseudo-register, or any other
> expedited register such as PC or SP.
>
> It's only when you try to print the value of a non-expedited register
> that you get an error indicating that GDB and gdbserver don't agree on
> the size of the SVE registers (“Truncated register 51 in remote 'g'
> packet”).
>
>> If we don't do a "gdbarch_update_architecture" for it and save it
>> somewhere, we'll never set the gdbarch with SVE == Y, will we?
>
> We do that in remote_target::process_stop_reply, and I was under the
> impression that it happened early enough for GDB to have the correct
> gdbarch available when it needs it, but unfortunately that's not the
> case.
>
> I will add a testcase exercising this issue and see if I can find a
> solution. Thank you for spotting it.
>
next prev parent reply other threads:[~2022-12-01 8:32 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-26 2:04 [PATCH v2 0/6] gdbserver improvements for AArch64 SVE support Thiago Jung Bauermann
2022-11-26 2:04 ` [PATCH v2 1/6] gdbserver: Add asserts in register_size and register_data functions Thiago Jung Bauermann
2022-11-28 11:51 ` Luis Machado
2022-11-29 2:53 ` Thiago Jung Bauermann
2022-11-28 14:48 ` Simon Marchi
2022-11-28 14:53 ` Simon Marchi
2022-11-29 2:52 ` Thiago Jung Bauermann
2022-11-29 2:43 ` Thiago Jung Bauermann
2022-11-26 2:04 ` [PATCH v2 2/6] gdbserver: Add PID parameter to linux_get_auxv and linux_get_hwcap Thiago Jung Bauermann
2022-11-28 11:50 ` Luis Machado
2022-11-28 15:01 ` Simon Marchi
2022-11-29 3:10 ` Thiago Jung Bauermann
2022-11-28 15:07 ` Simon Marchi
2022-11-28 15:20 ` Luis Machado
2022-11-29 3:17 ` Thiago Jung Bauermann
2022-11-26 2:04 ` [PATCH v2 3/6] gdbserver/linux-aarch64: Factor out function to get aarch64_features Thiago Jung Bauermann
2022-11-28 11:54 ` Luis Machado
2022-11-29 3:19 ` Thiago Jung Bauermann
2022-11-28 15:12 ` Simon Marchi
2022-11-29 3:26 ` Thiago Jung Bauermann
2022-11-26 2:04 ` [PATCH v2 4/6] gdbserver/linux-aarch64: When thread stops, update its target description Thiago Jung Bauermann
2022-11-28 12:06 ` Luis Machado
2022-11-29 3:59 ` Thiago Jung Bauermann
2022-11-28 15:47 ` Simon Marchi
2022-11-28 16:01 ` Luis Machado
2022-11-28 16:07 ` Simon Marchi
2022-11-29 4:30 ` Thiago Jung Bauermann
2022-11-26 2:04 ` [PATCH v2 5/6] gdb/aarch64: Factor out most of the thread_architecture method Thiago Jung Bauermann
2022-11-28 12:09 ` Luis Machado
2022-11-29 4:32 ` Thiago Jung Bauermann
2022-11-28 16:09 ` Simon Marchi
2022-11-29 4:33 ` Thiago Jung Bauermann
2022-11-26 2:04 ` [PATCH v2 6/6] gdb/aarch64: Detect vector length changes when debugging remotely Thiago Jung Bauermann
2022-11-28 13:27 ` Luis Machado
2022-12-01 1:15 ` Thiago Jung Bauermann
2022-11-28 16:36 ` Simon Marchi
2022-12-01 3:16 ` Thiago Jung Bauermann
2022-12-01 8:32 ` Luis Machado [this message]
2022-12-01 16:16 ` Simon Marchi
2022-11-30 8:43 ` Luis Machado
2022-12-05 22:37 ` Thiago Jung Bauermann
2022-12-07 17:05 ` Luis Machado
2022-12-07 19:25 ` Simon Marchi
2022-12-07 23:01 ` Luis Machado
2022-12-09 2:20 ` Thiago Jung Bauermann
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=7924fd9d-edc1-b0dd-4cbc-07026fd9f1c5@arm.com \
--to=luis.machado@arm.com \
--cc=gdb-patches@sourceware.org \
--cc=simark@simark.ca \
--cc=thiago.bauermann@linaro.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).