[DTrace-devel] [PATCH 6/7] cg: allow input to translator to be NULL
Eugene Loh
eugene.loh at oracle.com
Fri Jul 28 00:06:00 UTC 2023
Reviewed-by: Eugene Loh <eugene.loh at oracle.com>
nodemis?
trask_struct?
On 7/27/23 11:30, Kris Van Hees via DTrace-devel wrote:
> Some translators support NULL as input pointer value. The code generator
> was performing a NULL-check on a the LHS of a PTR or DOT node before
> considering the possibility that the nodemis subject to translator
> handling. The check should happen after translator handling.
>
> With this patch, tst.ProcModelTrans.d works but only for the case of
> NULL input. The test is changed to actually use a real trask_struct as
> input. New test tst.NullInput.d exercises the case this patch fixes.
>
> Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
> ---
> libdtrace/dt_cg.c | 4 +--
> test/unittest/translators/tst.NullInput.d | 31 +++++++++++++++++++
> .../unittest/translators/tst.ProcModelTrans.d | 16 ++++------
> 3 files changed, 39 insertions(+), 12 deletions(-)
> create mode 100644 test/unittest/translators/tst.NullInput.d
>
> diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
> index e05a1f64..ebe2e043 100644
> --- a/libdtrace/dt_cg.c
> +++ b/libdtrace/dt_cg.c
> @@ -6305,8 +6305,6 @@ dt_cg_node(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp)
> assert(dnp->dn_right->dn_kind == DT_NODE_IDENT);
> dt_cg_node(dnp->dn_left, dlp, drp);
>
> - dt_cg_check_notnull(dlp, drp, dnp->dn_left->dn_reg);
> -
> /*
> * If the left-hand side of PTR or DOT is a dynamic variable,
> * we expect it to be the output of a D translator. In this
> @@ -6340,6 +6338,8 @@ dt_cg_node(dt_node_t *dnp, dt_irlist_t *dlp, dt_regset_t *drp)
> break;
> }
>
> + dt_cg_check_notnull(dlp, drp, dnp->dn_left->dn_reg);
> +
> ctfp = dnp->dn_left->dn_ctfp;
> type = ctf_type_resolve(ctfp, dnp->dn_left->dn_type);
>
> diff --git a/test/unittest/translators/tst.NullInput.d b/test/unittest/translators/tst.NullInput.d
> new file mode 100644
> index 00000000..6d5f085b
> --- /dev/null
> +++ b/test/unittest/translators/tst.NullInput.d
> @@ -0,0 +1,31 @@
> +/*
> + * Oracle Linux DTrace.
> + * Copyright (c) 2023, 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.
> + */
> +
> +/*
> + * ASSERTION: Translators can receive NULL as input.
> + *
> + * SECTION: Translators/Translator Declarations
> + * SECTION: Translators/Translate Operator
> + *
> + */
> +
> +#pragma D option quiet
> +
> +struct task_struct *T;
> +
> +BEGIN
> +{
> + T = 0;
> + mypr_addr = xlate < psinfo_t > (T).pr_addr;
> + printf("pr_addr: %p", mypr_addr);
> + exit(0);
> +}
> +
> +ERROR
> +{
> + exit(1);
> +}
> diff --git a/test/unittest/translators/tst.ProcModelTrans.d b/test/unittest/translators/tst.ProcModelTrans.d
> index cf445658..7d5fff78 100644
> --- a/test/unittest/translators/tst.ProcModelTrans.d
> +++ b/test/unittest/translators/tst.ProcModelTrans.d
> @@ -1,29 +1,25 @@
> /*
> * Oracle Linux DTrace.
> - * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
> + * Copyright (c) 2006, 2023, 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.
> */
> -/* @@xfail: dtv2 */
>
> /*
> - * ASSERTION:
> - * Use the translators in /usr/lib/dtrace/procfs.d
> + * ASSERTION: Basic test for translators in /usr/lib/dtrace/procfs.d
> *
> - * SECTION: Translators/ Translator Declarations
> - * SECTION: Translators/ Translate Operator
> + * SECTION: Translators/Translator Declarations
> + * SECTION: Translators/Translate Operator
> * SECTION: Translators/Process Model Translators
> *
> */
>
> #pragma D option quiet
>
> -struct task_struct *T;
> -
> BEGIN
> {
> - mypr_addr = xlate < psinfo_t > (T).pr_addr;
> - printf("pr_addr: %d", mypr_addr);
> + mypr_addr = xlate < psinfo_t > (curthread).pr_addr;
> + printf("pr_addr: %p", mypr_addr);
> exit(0);
> }
>
More information about the DTrace-devel
mailing list