[DTrace-devel] [PATCH 2/7] Make dt_cg_ctf_offsetof() available outside of dt_cg.c

Kris Van Hees kris.van.hees at oracle.com
Mon Sep 25 17:57:05 UTC 2023


On Tue, Aug 22, 2023 at 05:51:09PM -0400, eugene.loh--- via DTrace-devel wrote:
> From: Eugene Loh <eugene.loh at oracle.com>
> 
> Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
> ---
>  libdtrace/dt_cg.c | 12 ++++++------
>  libdtrace/dt_cg.h |  3 ++-
>  2 files changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
> index a8f5077b..ea7fb6d5 100644
> --- a/libdtrace/dt_cg.c
> +++ b/libdtrace/dt_cg.c
> @@ -4187,10 +4187,10 @@ dt_cg_asgn_op(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp)
>   * Get offsetof(structname, membername) information from CTF.
>   * Optionally, also get member size.
>   */
> -static int
> -dt_cg_ctf_offsetof(const char *structname, const char *membername, size_t *sizep)
> +int
> +dt_cg_ctf_offsetof(dtrace_hdl_t *dtp, const char *structname, const char *membername, size_t *sizep)
>  {
> -	ctf_file_t *cfp = yypcb->pcb_hdl->dt_shared_ctf;
> +	ctf_file_t *cfp = dtp->dt_shared_ctf;

I think it is valid to continue using yypcb because that refers to the current
compilation context.  Especially because callers already tend to use yypcb to
get dtp anyway.

At some point in the future we should do a massive review of the compiler code
to either have everything depend on yypcb or pass along pcb or dtp (they have
ptrs to eachother so they can be used interchangeably).  But not now - that is
a massive undertaking.  FOr now we live with the impact of the original code
we work from.

So, this patch can be limited to just making the function non-static and
adding the extern declaration in dt_cg.h.  So it might as well get combined
with the next patch (changing from search in the shared dict to searching
across all modules).

>  	ctf_id_t type;
>  	ctf_membinfo_t ctm;
>  
> @@ -4228,10 +4228,10 @@ dt_cg_uregs(unsigned int idx, dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp
>  			char *memnames[] = { "ds", "es", "fsbase", "gsbase", "trap_nr" };
>  
>  			/* Look up task->thread offset. */
> -			offset = dt_cg_ctf_offsetof("struct task_struct", "thread", NULL);
> +			offset = dt_cg_ctf_offsetof(dtp, "struct task_struct", "thread", NULL);
>  
>  			/* Add the thread->member offset. */
> -			offset += dt_cg_ctf_offsetof("struct thread_struct",
> +			offset += dt_cg_ctf_offsetof(dtp, "struct thread_struct",
>  						     memnames[idx - 21], &size);
>  
>  			/* Get task. */
> @@ -4302,7 +4302,7 @@ dt_cg_uregs(unsigned int idx, dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp
>  		/* Copy contents at task->stack to %fp+DT_STK_SP (scratch space). */
>  		emit(dlp, BPF_MOV_REG(BPF_REG_3, BPF_REG_0));
>  		emit(dlp, BPF_ALU64_IMM(BPF_ADD, BPF_REG_3,
> -		    dt_cg_ctf_offsetof("struct task_struct", "stack", NULL)));
> +		    dt_cg_ctf_offsetof(dtp, "struct task_struct", "stack", NULL)));
>  		emit(dlp, BPF_MOV_IMM(BPF_REG_2, sizeof(uint64_t)));
>  		emit(dlp, BPF_LOAD(BPF_DW, BPF_REG_1, BPF_REG_FP, DT_STK_SP));
>  		emit(dlp, BPF_CALL_HELPER(dtp->dt_bpfhelper[BPF_FUNC_probe_read_kernel]));
> diff --git a/libdtrace/dt_cg.h b/libdtrace/dt_cg.h
> index 95bf507f..0ced6dd2 100644
> --- a/libdtrace/dt_cg.h
> +++ b/libdtrace/dt_cg.h
> @@ -37,7 +37,8 @@ extern void dt_cg_tramp_epilogue_advance(dt_pcb_t *pcb, dt_activity_t act);
>  extern void dt_cg_tramp_error(dt_pcb_t *pcb);
>  extern uint_t dt_cg_ldsize(dt_node_t *dnp, ctf_file_t *ctfp, ctf_id_t type,
>  			 ssize_t *ret_size);
> -
> +extern int dt_cg_ctf_offsetof(dtrace_hdl_t *dtp, const char *structname,
> +			      const char *membername, size_t *sizep);
>  #ifdef	__cplusplus
>  }
>  #endif
> -- 
> 2.18.4
> 
> 
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel



More information about the DTrace-devel mailing list