Re: [PATCH 01/26] gdbserver: convert init_register_cache into regcache::initialize

Simon Marchi
2023-12-21T20:12:44Z

On 2/28/23 06:27, Tankut Baris Aktemur via Gdb-patches wrote:
> This is a refactoring that converts the `init_register_cache` function
> to a method of the regcache struct. During this conversion, we also
> change the return type to void.

I think this is fine. However, with a bit more effort, I think
this could actually become a constructor, which would be nicer than
having to call an initialize function.

The only more "tricky" spot would be the use of regcache in
fast_tracepoint_ctx. I think you could replace the regcache_initted and
regcache fields with an std::optional. When instantiating the regcache,
you would emplace the optional, which would call the constructor at that
point. fast_tracepoint_ctx is only ever allocated as a local variable
in gdb_collect, so using a gdb::optional there should be fine.

Another improvement to try (for a subsequent patch) would be to pass an
array_view to the initialize method (or constructor), and assert that
the register size described by the tdesc matches the size of the
buffer array_view passed.

Simon