Skip to content

Commit

Permalink
cg: allow input to translator to be NULL
Browse files Browse the repository at this point in the history
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 node is 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 task_struct as
input.  New test tst.NullInput.d exercises the case this patch fixes.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
  • Loading branch information
kvanhees committed Aug 16, 2023
1 parent 9509c5c commit d7521a1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
4 changes: 2 additions & 2 deletions libdtrace/dt_cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down
31 changes: 31 additions & 0 deletions test/unittest/translators/tst.NullInput.d
Original file line number Diff line number Diff line change
@@ -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);
}
16 changes: 6 additions & 10 deletions test/unittest/translators/tst.ProcModelTrans.d
Original file line number Diff line number Diff line change
@@ -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);
}

Expand Down

0 comments on commit d7521a1

Please sign in to comment.