Re: [PATCH v2 02/11] gdbserver: use inheritance to define tracepoint contexts

Simon Marchi
2025-01-06T21:47:29Z

On 2024-12-30 05:49, Tankut Baris Aktemur wrote:
> Use inheritance in the definition of tracepoint contexts. This is a
> refactoring that aims to improve the code. No behavior should be
> altered.
> ---
> gdbserver/tracepoint.cc | 107 ++++++++++++++++++++++--------------------------
> 1 file changed, 48 insertions(+), 59 deletions(-)
>
> diff --git a/gdbserver/tracepoint.cc b/gdbserver/tracepoint.cc
> index 81104b02c8321fcb4cb247a6166be10ba04aea8c..fc0586a5c5ace6edc1fc72d24511c6f36e97f759 100644
> --- a/gdbserver/tracepoint.cc
> +++ b/gdbserver/tracepoint.cc
> @@ -1274,7 +1274,7 @@ static char *tracing_stop_note;
>
> /* Functions local to this file. */
>
> -/* Base "class" for tracepoint type specific data to be passed down to
> +/* Base class for tracepoint type specific data to be passed down to
> collect_data_at_tracepoint. */
> struct tracepoint_hit_ctx
> {
> @@ -1285,23 +1285,13 @@ struct tracepoint_hit_ctx
>
> /* Fast/jump tracepoint specific data to be passed down to
> collect_data_at_tracepoint. */
> -struct fast_tracepoint_ctx
> +struct fast_tracepoint_ctx : public tracepoint_hit_ctx
> {
> - struct tracepoint_hit_ctx base;
> -
> - struct regcache regcache;
> - int regcache_initted;
> - unsigned char *regspace;
> -
> - unsigned char *regs;
> - struct tracepoint *tpoint;
> -};
> -
> -/* Static tracepoint specific data to be passed down to
> - collect_data_at_tracepoint. */
> -struct static_tracepoint_ctx
> -{
> - struct tracepoint_hit_ctx base;
> + fast_tracepoint_ctx (unsigned char *_regs)
> + : regcache_initted (0), regs (_regs)

- explicit
- It's fine to name the parameter `regs` too
- Initialize `regcache_initted` inline
- I think that `tracepoint_hit_ctx` should have a constructor that
takes the type, instead of each variant initializing the `type`
member

> + {
> + type = fast_tracepoint;
> + }
>
> /* The regcache corresponding to the registers state at the time of
> the tracepoint hit. Initialized lazily, from REGS. */
> @@ -1314,25 +1304,41 @@ struct static_tracepoint_ctx
> unsigned char *regspace;
>
> /* The register buffer as passed on by lttng/ust. */
> - struct registers *regs;

Something seems wrong, this field just disappears in the refactor. It
is only used if HAVE_UST is defined, which never happens nowadays
because it used a version of lttng-ust that has been deprecated for a
loooong time (the 0.x series). So everything in HAVE_UST just bitrots.
It might be possible to update all this code to use lttng-ust 2.x (1.x
never existed), but I don't think it's going to happen unless somebody
specifically asks for it.

I would suggest starting with removing support for UST from gdbserver
and rebasing you series, it will end up making this patch simpler. If
we ever want to resurrect support for UST support and port to 2.x, we
can get the code from the git history.

> + unsigned char *regs;
> +
> + /* The GDB tracepoint matching the probed marker that was "hit". */
> + struct tracepoint *tpoint;
> +};
> +
> +/* Static tracepoint specific data to be passed down to
> + collect_data_at_tracepoint. */
> +struct static_tracepoint_ctx : public fast_tracepoint_ctx

I will have to dig deeper, but I'm not sure it conceptually makes sense
for static_tracepoint_ctx to inherit fast_tracepoint_ctx. Are static
tracepoints always based on fast tracepoints?

(I have to stop here for now.)

Simon