Skip to content

Commit

Permalink
Add support for umod(), usym(), and uaddr()
Browse files Browse the repository at this point in the history
Signed-off-by: Eugene Loh <eugene.loh@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
euloh authored and kvanhees committed Jun 18, 2021
1 parent 865f5fc commit 996b1a6
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 6 deletions.
27 changes: 25 additions & 2 deletions libdtrace/dt_cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ dt_cg_store_val(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind,
dt_pfargv_t *pfp, int arg)
{
dtrace_diftype_t vtype;
dtrace_hdl_t *dtp = pcb->pcb_hdl;
dt_irlist_t *dlp = &pcb->pcb_ir;
dt_regset_t *drp = pcb->pcb_regs;
uint_t off;
Expand All @@ -759,13 +760,35 @@ dt_cg_store_val(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind,
size = sizeof(dnp->dn_ident->di_id);
} else {
dt_cg_node(dnp, &pcb->pcb_ir, drp);
dt_node_diftype(pcb->pcb_hdl, dnp, &vtype);
dt_node_diftype(dtp, dnp, &vtype);
size = vtype.dtdt_size;
}

if (kind == DTRACEACT_USYM ||
kind == DTRACEACT_UMOD ||
kind == DTRACEACT_UADDR) {
off = dt_rec_add(dtp, dt_cg_fill_gap, kind, 16, 8, NULL, arg);

/* preface the value with the user process tgid */
if (dt_regset_xalloc_args(drp) == -1)
longjmp(yypcb->pcb_jmpbuf, EDT_NOREG);
dt_regset_xalloc(drp, BPF_REG_0);
emit(dlp, BPF_CALL_HELPER(BPF_FUNC_get_current_pid_tgid));
dt_regset_free_args(drp);
emit(dlp, BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 0xffffffff));
emit(dlp, BPF_STORE(BPF_DW, BPF_REG_9, off, BPF_REG_0));
dt_regset_free(drp, BPF_REG_0);

/* then store the value */
emit(dlp, BPF_STORE(BPF_DW, BPF_REG_9, off + 8, dnp->dn_reg));
dt_regset_free(drp, dnp->dn_reg);

return 0;
}

if (dt_node_is_scalar(dnp) || dt_node_is_float(dnp) ||
dnp->dn_kind == DT_NODE_AGG) {
off = dt_rec_add(pcb->pcb_hdl, dt_cg_fill_gap, kind,
off = dt_rec_add(dtp, dt_cg_fill_gap, kind,
size, size, pfp, arg);

assert(size > 0 && size <= 8 && (size & (size - 1)) == 0);
Expand Down
17 changes: 13 additions & 4 deletions libdtrace/dt_consume.c
Original file line number Diff line number Diff line change
Expand Up @@ -1235,9 +1235,9 @@ static int
dt_print_usym(dtrace_hdl_t *dtp, FILE *fp, caddr_t addr, dtrace_actkind_t act)
{
/* LINTED - alignment */
uint64_t tgid = ((uint64_t *)addr)[1];
uint64_t tgid = ((uint64_t *)addr)[0];
/* LINTED - alignment */
uint64_t pc = ((uint64_t *)addr)[2];
uint64_t pc = ((uint64_t *)addr)[1];
const char *format = " %-50s";
char *s;
int n, len = 256;
Expand Down Expand Up @@ -1269,9 +1269,9 @@ int
dt_print_umod(dtrace_hdl_t *dtp, FILE *fp, const char *format, caddr_t addr)
{
/* LINTED - alignment */
uint64_t tgid = ((uint64_t *)addr)[1];
uint64_t tgid = ((uint64_t *)addr)[0];
/* LINTED - alignment */
uint64_t pc = ((uint64_t *)addr)[2];
uint64_t pc = ((uint64_t *)addr)[1];
int err = 0;

char objname[PATH_MAX], c[PATH_MAX * 2];
Expand Down Expand Up @@ -2097,6 +2097,15 @@ dt_consume_one(dtrace_hdl_t *dtp, FILE *fp, char *buf,
recdata, rec->dtrd_arg) < 0)
return -1;
continue;
case DTRACEACT_USYM:
case DTRACEACT_UADDR:
if (dt_print_usym(dtp, fp, recdata, act) < 0)
return -1;
continue;
case DTRACEACT_UMOD:
if (dt_print_umod(dtp, fp, NULL, recdata) < 0)
return -1;
continue;
case DTRACEACT_PRINTF:
func = dtrace_fprintf;
break;
Expand Down
17 changes: 17 additions & 0 deletions test/unittest/ustack/tst.uaddr.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2021, 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.
*/

/* @@trigger: ustack-tst-basic */

#pragma D option quiet

profile-1
/pid == $target/
{
uaddr(ucaller);
exit(0);
}
1 change: 1 addition & 0 deletions test/unittest/ustack/tst.uaddr.r
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ustack-tst-basic`myfunc_y+{ptr}
17 changes: 17 additions & 0 deletions test/unittest/ustack/tst.ufunc.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2021, 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.
*/

/* @@trigger: ustack-tst-basic */

#pragma D option quiet

profile-1
/pid == $target/
{
ufunc(ucaller);
exit(0);
}
1 change: 1 addition & 0 deletions test/unittest/ustack/tst.ufunc.r
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ustack-tst-basic`myfunc_y
17 changes: 17 additions & 0 deletions test/unittest/ustack/tst.umod.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2021, 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.
*/

/* @@trigger: ustack-tst-basic */

#pragma D option quiet

profile-1
/pid == $target/
{
umod(ucaller);
exit(0);
}
1 change: 1 addition & 0 deletions test/unittest/ustack/tst.umod.r
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ustack-tst-basic
17 changes: 17 additions & 0 deletions test/unittest/ustack/tst.usym.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Oracle Linux DTrace.
* Copyright (c) 2021, 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.
*/

/* @@trigger: ustack-tst-basic */

#pragma D option quiet

profile-1
/pid == $target/
{
usym(ucaller);
exit(0);
}
1 change: 1 addition & 0 deletions test/unittest/ustack/tst.usym.r
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ustack-tst-basic`myfunc_y

0 comments on commit 996b1a6

Please sign in to comment.