[DTrace-devel] [PATCH 6/6] Add disassembler annotations for assoc arrays

Kris Van Hees kris.van.hees at oracle.com
Mon Mar 7 20:06:20 UTC 2022


Sorry for posting two copies of this patch - I hit resend by accident.

On Mon, Mar 07, 2022 at 02:51:49PM -0500, Kris Van Hees via DTrace-devel wrote:
> Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
> ---
>  libdtrace/dt_dis.c                         | 44 ++++++++++++++++++++++
>  test/unittest/disasm/tst.ann-gvar-assoc.r  |  1 +
>  test/unittest/disasm/tst.ann-gvar-assoc.sh | 19 ++++++++++
>  test/unittest/disasm/tst.ann-tvar-assoc.r  |  1 +
>  test/unittest/disasm/tst.ann-tvar-assoc.sh | 19 ++++++++++
>  5 files changed, 84 insertions(+)
>  create mode 100644 test/unittest/disasm/tst.ann-gvar-assoc.r
>  create mode 100755 test/unittest/disasm/tst.ann-gvar-assoc.sh
>  create mode 100644 test/unittest/disasm/tst.ann-tvar-assoc.r
>  create mode 100755 test/unittest/disasm/tst.ann-tvar-assoc.sh
> 
> diff --git a/libdtrace/dt_dis.c b/libdtrace/dt_dis.c
> index d911dbf5..37c5059e 100644
> --- a/libdtrace/dt_dis.c
> +++ b/libdtrace/dt_dis.c
> @@ -337,6 +337,50 @@ dt_dis_bpf_args(const dtrace_difo_t *dp, const char *fn,
>  			 dt_dis_varname_id(dp, in->imm + DIF_VAR_OTHER_UBASE,
>  					DIFV_SCOPE_THREAD, addr));
>  		return buf;
> +	} else if (strcmp(fn, "dt_get_assoc") == 0) {
> +		uint_t		varid;
> +		dof_relodesc_t	*rp = dp->dtdo_breltab;
> +		int		cnt = dp->dtdo_brelen;
> +		const char	*rname = NULL;
> +
> +		/*
> +		 * We know that the previous four instructions exist and
> +		 * move the variable id to a register in the first instruction
> +		 * of that seqeuence (because we wrote the code generator to
> +		 * emit the instructions in this exact order.)
> +		 */
> +		in -= 4;
> +		varid = in->imm + DIF_VAR_OTHER_UBASE;
> +
> +		/*
> +		 * We need to determine whether this is a associative TLS array
> +		 * or a global array.  We know that for a TLS assoc, a call to
> +		 * dt_tlskey must be present 5 instructions earlier (actually
> +		 * 9 instructions before the call to dt_get_assoc).
> +		 */
> +		if (addr < 9 || in[-5].code != (BPF_JMP | BPF_CALL) ||
> +				in[-5].src_reg != BPF_PSEUDO_CALL)
> +			goto gvar_assoc;
> +
> +		addr -= 9;
> +		for (; cnt; cnt--, rp++) {
> +			if (rp->dofr_offset > addr * sizeof(uint64_t))
> +				break;
> +			if (rp->dofr_offset == addr * sizeof(uint64_t))
> +				rname = dt_difo_getstr(dp, rp->dofr_name);
> +		}
> +
> +		if (strcmp(rname, "dt_tlskey") != 0)
> +			goto gvar_assoc;
> +
> +		snprintf(buf, len, "self->%s[]",
> +			 dt_dis_varname_id(dp, varid, DIFV_SCOPE_THREAD, addr));
> +		return buf;
> +
> +gvar_assoc:
> +		snprintf(buf, len, "%s[]",
> +			 dt_dis_varname_id(dp, varid, DIFV_SCOPE_GLOBAL, addr));
> +		return buf;
>  	}
>  
>  	return NULL;
> diff --git a/test/unittest/disasm/tst.ann-gvar-assoc.r b/test/unittest/disasm/tst.ann-gvar-assoc.r
> new file mode 100644
> index 00000000..522ba6f6
> --- /dev/null
> +++ b/test/unittest/disasm/tst.ann-gvar-assoc.r
> @@ -0,0 +1 @@
> +85 0 1 0000 ffffffff    call dt_get_assoc             ! var[]
> diff --git a/test/unittest/disasm/tst.ann-gvar-assoc.sh b/test/unittest/disasm/tst.ann-gvar-assoc.sh
> new file mode 100755
> index 00000000..c0fc4bf2
> --- /dev/null
> +++ b/test/unittest/disasm/tst.ann-gvar-assoc.sh
> @@ -0,0 +1,19 @@
> +#!/bin/bash
> +#
> +# Oracle Linux DTrace.
> +# Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
> +# Licensed under the Universal Permissive License v 1.0 as shown at
> +# http://oss.oracle.com/licenses/upl.
> +#
> +
> +dtrace=$1
> +
> +$dtrace $dt_flags -Sen '
> +BEGIN
> +{
> +	var["foo"] = 42;
> +	exit(0);
> +}
> +' 2>&1 | awk '/ call dt_get_assoc/ { sub(/^[^:]+: /, ""); print; }'
> +
> +exit $?
> diff --git a/test/unittest/disasm/tst.ann-tvar-assoc.r b/test/unittest/disasm/tst.ann-tvar-assoc.r
> new file mode 100644
> index 00000000..2ae89edb
> --- /dev/null
> +++ b/test/unittest/disasm/tst.ann-tvar-assoc.r
> @@ -0,0 +1 @@
> +85 0 1 0000 ffffffff    call dt_get_assoc             ! self->var[]
> diff --git a/test/unittest/disasm/tst.ann-tvar-assoc.sh b/test/unittest/disasm/tst.ann-tvar-assoc.sh
> new file mode 100755
> index 00000000..e4690a28
> --- /dev/null
> +++ b/test/unittest/disasm/tst.ann-tvar-assoc.sh
> @@ -0,0 +1,19 @@
> +#!/bin/bash
> +#
> +# Oracle Linux DTrace.
> +# Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
> +# Licensed under the Universal Permissive License v 1.0 as shown at
> +# http://oss.oracle.com/licenses/upl.
> +#
> +
> +dtrace=$1
> +
> +$dtrace $dt_flags -Sen '
> +BEGIN
> +{
> +	self->var["foo"] = 42;
> +	exit(0);
> +}
> +' 2>&1 | awk '/ call dt_get_assoc/ { sub(/^[^:]+: /, ""); print; }'
> +
> +exit $?
> -- 
> 2.34.1
> 
> 
> _______________________________________________
> 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