[DTrace-devel] [PATCH 2/4] Add an offsetof() function for CTF types

Nick Alcock nick.alcock at oracle.com
Fri May 19 16:57:22 UTC 2023


On 18 May 2023, eugene loh verbalised:

> +/*
> + * 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)
> +{
> +	ctf_file_t *cfp = yypcb->pcb_hdl->dt_shared_ctf;
> +	ctf_id_t type;
> +	ctf_membinfo_t ctm;
> +
> +	if (!cfp)
> +		longjmp(yypcb->pcb_jmpbuf, EDT_NOCTF);
> +	type = ctf_lookup_by_name(cfp, structname);

If you want to look up a struct or a union foo, you should look up
"struct foo" or "union foo". What you've got here will I believe work
for typedefs of structs, but not structs themselves (or unions). (It's
been a while since I tried doing a ctf_lookup_by_name() without
qualification on a struct, but I'm fairly sure "struct " is necessary to
disambiguate.)

-- 
NULL && (void)



More information about the DTrace-devel mailing list