Re: [PATCH v3 4/8] gdbserver/linux-aarch64: When thread stops, update its target description

Thiago Jung Bauermann via Gdb-patches
2023-02-07T21:07:03Z

Pedro Alves <pedro@palves.net> writes:

> On 2023-02-02 2:54 a.m., Thiago Jung Bauermann via Gdb-patches wrote:
>>
>> Luis Machado <luis.machado@arm.com> writes:
>>
>>> On 2/1/23 16:21, Simon Marchi wrote:
>>>>
>>>>>> diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
>>>>>> index 221de85aa2ee..b52eb23cc444 100644
>>>>>> --- a/gdbserver/linux-low.h
>>>>>> +++ b/gdbserver/linux-low.h
>>>>>> @@ -604,6 +604,12 @@ class linux_process_target : public process_stratum_target
>>>>>> /* Architecture-specific setup for the current thread. */
>>>>>> virtual void low_arch_setup () = 0;
>>>>>> + /* Allows arch-specific code to set the thread's target description when the
>>>>>> + inferior stops. Returns nullptr if no thread-specific target description
>>>>>> + is necessary. */
>>>>>> + virtual const struct target_desc *
>>>>>> + get_thread_tdesc (const thread_info *thread);
>>>>>
>>>>> I think the comment for this function is not correct. The function does
>>>>> not SET the thread's target description, but just GETS a target
>>>>> description suitable for `thread`. It's the caller's job to do the
>>>>> setting.
>>>> This comment also gave me pause. How does a getter set something. I
>>>> then understood that it allowed the arch-specific code to provide a
>>>> thread-specific tdesc. I would suggest just:
>>>
>>> FWIW, I read it as "the functions *allows* arch-specific code to set".
>>> So it doesn't set on its own, but it does allow something else to do
>>> it.
>>
>> Yes, that's what was in my mind when I wrote the comment. But I agree
>> it's unclear, and I adopted Simon's suggested version.
>>
>>>> The other thought I had while re-reading the patch is why do we need to
>>>> return and store nullptr if the thread target description is the same as
>>>> the main one for the process. get_thread_tdesc could just return
>>>> process_info->tdesc if we don't need a separate tdesc, and we would
>>>> store that same pointer in thread_info->tdesc.
>>
>> We don't need to return and store nullptr if the thread target
>> description is the same as the main one for the process. Things will
>> work fine if we do as you suggest. IIRC my private branch worked liked
>> that for a while, before I changed it to the current version.
>>
>> I changed it because I thought it was a clearer mental model if
>> thread_info->tdesc is nullptr when there's not thread-specific target
>> description. I can make the get_thread_tdesc method always return a
>> valid target description if you think it's better that way.
>>
>>>> And get_thread_tdesc would just return that (in fact,
>>>> get_thread_tdesc might not be necessary then). Perhaps it makes some
>>>> things more complicated down the road, but I can't think of anything.
>>
>> Sorry, I don't understand this part. get_thread_tdesc is necessary
>> because it's the hook that allows arch-specific code to provide a target
>> description for the thread. I don't see how it can become unnecessary.
>>
>> Perhaps you mean the get_thread_target_desc function? Sorry about the
>> names being so similar, I spent some time trying to think of a better
>> name for either the method or the function but failed.
>
> Please drop the "get_" prefix from the class method, it doesn't really
> add value, and we typically don't add it. Most GDB getter/setters are
> in foo() / set_foo() pair style, rather than get_foo() / set_foo().
>
> A "get_" prefix is however typically used for global getter functions.

Ok, I will drop the prefix. Thank you for explaining the pattern.
I wasn't aware of it.

> FWIW, I have the same thought as Simon while reading this.

Ok, I'll change the code to always store a tdesc in thread_info even if
it's the same as the process-wide one. If both you and Simon thought
along the same lines it may be a more intuitive mental model than the
one I was considering.

That is, assuming we continue with the thread-specific tdesc approach
rather than the one which expands tdescs to allow describing one
register's type in terms of another one. I'll revisit my notes and think
more about this.

--
Thiago