[DTrace-devel] [PATCH] Make it possible to add BPF variables dynamically

Eugene Loh eugene.loh at oracle.com
Mon Mar 29 18:38:20 PDT 2021


Reviewed-by: Eugene Loh <eugene.loh at oracle.com>
comments below

On 3/29/21 1:28 PM, Kris Van Hees wrote:
> Future development needs to be able to create BPF variable identifiers
> dynamically during compilation.  The dt_dlib_add_var() function can be
> used to do thid.  Both a name and an unsigned int value are to be
> provided when adding a BPF variable.

thid typo

> diff --git a/libdtrace/dt_dlibs.c b/libdtrace/dt_dlibs.c
> @@ -134,15 +134,15 @@ dt_dlib_get_xsym(dtrace_hdl_t *dtp, const char *name, int kind)
>   }
>   
>   /*
> - * Add a BPF identifier of a given type.
> + * Add a BPF identifier of a given type with given id.
>    */

s/type/kind/

> -dt_ident_t *
> -dt_dlib_add_sym(dtrace_hdl_t *dtp, const char *name, int kind)
> +static dt_ident_t *
> +dt_dlib_add_sym_id(dtrace_hdl_t *dtp, const char *name, int kind, uint_t id)
>   {
>   	dt_idhash_t	*dhp = dtp->dt_bpfsyms;
>   	dt_ident_t	*idp;
>   
> -	idp = dt_idhash_insert(dhp, name, kind, DT_IDFLG_BPF, DT_IDENT_UNDEF,
> +	idp = dt_idhash_insert(dhp, name, kind, DT_IDFLG_BPF, id,
>   			       dt_bpf_attr, DT_VERS_2_0,
>   			       kind == DT_IDENT_SYMBOL ? &dt_idops_difo : NULL,
>   			       dtp, 0);
> @@ -150,6 +150,15 @@ dt_dlib_add_sym(dtrace_hdl_t *dtp, const char *name, int kind)
> +/*
> + * Add a BPF identifier of a given type.
> + */
> +static dt_ident_t *
> +dt_dlib_add_sym(dtrace_hdl_t *dtp, const char *name, int kind)
> +{
> +	return dt_dlib_add_sym_id(dtp, name, kind, DT_IDENT_UNDEF);
> +}

s/type/kind/

> diff --git a/libdtrace/dt_impl.h b/libdtrace/dt_impl.h
> @@ -698,11 +698,13 @@ extern void dt_setcontext(dtrace_hdl_t *, dtrace_probedesc_t *);
>   extern void dt_endcontext(dtrace_hdl_t *);
>   
>   extern void dt_dlib_init(dtrace_hdl_t *dtp);
> +extern dt_ident_t *dt_dlib_get_sym(dtrace_hdl_t *, const char *);
>   extern dt_ident_t *dt_dlib_add_func(dtrace_hdl_t *, const char *);
>   extern dt_ident_t *dt_dlib_get_func(dtrace_hdl_t *, const char *);
>   extern dt_ident_t *dt_dlib_get_map(dtrace_hdl_t *, const char *);
>   extern dt_ident_t *dt_dlib_get_var(dtrace_hdl_t *, const char *);
> -extern dt_ident_t *dt_dlib_get_sym(dtrace_hdl_t *, const char *);
> +extern dt_ident_t *dt_dlib_add_var(dtrace_hdl_t *dtp, const char *name,
> +				   uint_t id);
Seems like add_var should come before get_var, whether you're going 
alphabetically or being consistent with add_func/get_func.



More information about the DTrace-devel mailing list