[DTrace-devel] [PATCH] Provide a standard dt_strtab_copystr() function

Eugene Loh eugene.loh at oracle.com
Wed Apr 8 14:06:03 PDT 2020


lgtm


On 04/08/2020 08:00 AM, Kris Van Hees wrote:
> Different parts in the DTrace source code were providing their own
> custom copy string function to be passed to dt_strtab_write().  All
> did essentially the same thing, so it is quite easy to provide a
> single generic function to do this work.  It is still possible to
> use the dt_strtab_write() functionality with a more fancy copy
> string function if needed.
>
> Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
> ---
>   libdtrace/dt_as.c     | 10 ++--------
>   libdtrace/dt_dlibs.c  | 14 ++------------
>   libdtrace/dt_strtab.c | 11 +++++++++++
>   libdtrace/dt_strtab.h |  1 +
>   4 files changed, 16 insertions(+), 20 deletions(-)
>
> diff --git a/libdtrace/dt_as.c b/libdtrace/dt_as.c
> index 096e660a..2ddbc886 100644
> --- a/libdtrace/dt_as.c
> +++ b/libdtrace/dt_as.c
> @@ -113,13 +113,6 @@ dt_copyvar(dt_idhash_t *dhp, dt_ident_t *idp, dtrace_hdl_t *dtp)
>   	return (0);
>   }
>   
> -static ssize_t
> -dt_copystr(const char *s, size_t n, size_t off, dtrace_hdl_t *dtp)
> -{
> -	memcpy(dtp->dt_strtab + off, s, n);
> -	return n;
> -}
> -
>   #ifdef FIXME
>   /*
>    * Rewrite the xlate/xlarg instruction at dtdo_buf[i] so that the instruction's
> @@ -549,7 +542,8 @@ fail:
>   			longjmp(pcb->pcb_jmpbuf, EDT_NOMEM);
>   
>   		dt_strtab_write(dtp->dt_ccstab,
> -				(dt_strtab_write_f *)dt_copystr, dtp);
> +				(dt_strtab_write_f *)dt_strtab_copystr,
> +				dtp->dt_strtab);
>   		dtp->dt_strlen = (uint32_t)n;
>   
>   		dp->dtdo_strtab = dtp->dt_strtab;
> diff --git a/libdtrace/dt_dlibs.c b/libdtrace/dt_dlibs.c
> index 1fd0f0a8..c3b2b902 100644
> --- a/libdtrace/dt_dlibs.c
> +++ b/libdtrace/dt_dlibs.c
> @@ -214,23 +214,13 @@ relcmp(const void *a, const void *b)
>   							      : -1;
>   }
>   
> -/*
> - * Copy strings from the compile-time string table into the final strtab.
> - */
> -static ssize_t
> -copy_stab_str(const char *s, size_t n, size_t off, char *buf)
> -{
> -	memcpy(buf + off, s, n);
> -	return n;
> -}
> -
>   /*
>    * Process the symbols in the ELF object, resolving BPF maps and functions
>    * against the known identifiers  If an unknown identifier is encountered, we
>    * add it to the BPF identifier hash.
>    *
>    * For functions, we fix up the symbol size (to work around an issue with the
> - * gcc BPF compiler not emitting symbol sizes), and then associated any listed
> + * gcc BPF compiler not emitting symbol sizes), and then associate any listed
>    * relocations with each function.
>    */
>   static dt_bpf_func_t **
> @@ -564,7 +554,7 @@ done:
>   			goto out;
>   		}
>   
> -		dt_strtab_write(stab, (dt_strtab_write_f *)copy_stab_str,
> +		dt_strtab_write(stab, (dt_strtab_write_f *)dt_strtab_copystr,
>   				dp->dtdo_strtab);
>   		dt_strtab_destroy(stab);
>   	}
> diff --git a/libdtrace/dt_strtab.c b/libdtrace/dt_strtab.c
> index 49bbc82b..2b9e7ede 100644
> --- a/libdtrace/dt_strtab.c
> +++ b/libdtrace/dt_strtab.c
> @@ -250,6 +250,17 @@ dt_strtab_size(const dt_strtab_t *sp)
>   	return (sp->str_size);
>   }
>   
> +/*
> + * Copy strings from the compile-time string table into a DIFO-dtyle string
> + * table storage memory block.
> + */
> +ssize_t
> +dt_strtab_copystr(const char *s, size_t n, size_t off, char *buf)
> +{
> +	memcpy(buf + off, s, n);
> +	return n;
> +}
> +
>   ssize_t
>   dt_strtab_write(const dt_strtab_t *sp, dt_strtab_write_f *func, void *private)
>   {
> diff --git a/libdtrace/dt_strtab.h b/libdtrace/dt_strtab.h
> index 54a84fbf..d1920f86 100644
> --- a/libdtrace/dt_strtab.h
> +++ b/libdtrace/dt_strtab.h
> @@ -41,6 +41,7 @@ extern void dt_strtab_destroy(dt_strtab_t *);
>   extern ssize_t dt_strtab_index(dt_strtab_t *, const char *);
>   extern ssize_t dt_strtab_insert(dt_strtab_t *, const char *);
>   extern size_t dt_strtab_size(const dt_strtab_t *);
> +extern ssize_t dt_strtab_copystr(const char *, size_t, size_t, char *);
>   extern ssize_t dt_strtab_write(const dt_strtab_t *,
>       dt_strtab_write_f *, void *);
>   extern ulong_t dt_strtab_hash(const char *, size_t *);




More information about the DTrace-devel mailing list