Re: [PATCH v2 09/11] gdbserver: define and use regcache::reset

Simon Marchi
2025-01-07T05:27:47Z

On 2024-12-30 05:49, Tankut Baris Aktemur wrote:
> Define a `reset` method for a regcache and use it for code
> simplification. This patch allows further simplification in the next
> patch.
>
> The reset method fills the register data with zeroes. For the use in
> get_thread_regcache, this is added behavior, making the patch not a
> pure refactoring, and may look like extra overhead. However, it is
> better to avoid having arbitrary values left in the data buffer.
> Hence, it is considered a behavioral improvement.

Given that the regcache initializes the buffer to zeroes at construction
time, it makes sense for a reset method to bring in back in that same
state.

To be pedantic, I would say that having random data in there when the
register status is not REG_VALID is fine, but since this is how regcache
works currently, it's ok.

> diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc
> index 03e975dc00154d01798765273534ca9cdcdc7eb7..7e1a722b0f80b9e5641bddfbbe95cbcf2b228df8 100644
> --- a/gdbserver/regcache.cc
> +++ b/gdbserver/regcache.cc
> @@ -52,8 +52,7 @@ get_thread_regcache (thread_info *thread, bool fetch)
>
> switch_to_thread (thread);
> /* Invalidate all registers, to prevent stale left-overs. */
> - memset (regcache->register_status, REG_UNKNOWN,
> - regcache->tdesc->reg_defs.size ());
> + regcache->reset (REG_UNKNOWN);

Oh, I think we can now make register_status private.

Simon