Skip to content

Commit

Permalink
Add support for built-in variable caller
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 54581a2 commit 84606f8
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 7 deletions.
8 changes: 8 additions & 0 deletions bpf/get_bvar.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ noinline uint64_t dt_get_bvar(dt_dctx_t *dctx, uint32_t id)
/* FIXME: no stack() yet */
return 0;
}
case DIF_VAR_CALLER: {
uint64_t flags = 0 & BPF_F_SKIP_FIELD_MASK;
uint64_t buf[2];

if (bpf_get_stack(dctx->ctx, buf, sizeof(buf), flags) < 0)
return 0;
return buf[1];
}
case DIF_VAR_PROBEPROV:
case DIF_VAR_PROBEMOD:
case DIF_VAR_PROBEFUNC:
Expand Down
4 changes: 1 addition & 3 deletions test/unittest/builtinvar/tst.caller.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
/* @@xfail: dtv2 */

/*
* ASSERTION:
* print 'caller' and make sure it succeeds.
* ASSERTION: print 'caller' and make sure it succeeds.
*
* SECTION: Variables/Built-in Variables
*/
Expand Down
4 changes: 1 addition & 3 deletions test/unittest/builtinvar/tst.caller1.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
/* @@xfail: dtv2 */

/*
* ASSERTION:
* To print caller form profile and make sure it succeeds.
* ASSERTION: To print caller from profile and make sure it succeeds.
*
* SECTION: Variables/Built-in Variables
*/
Expand Down
1 change: 0 additions & 1 deletion test/unittest/variables/bvar/tst.caller.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
/* @@xfail: dtv2 */

/*
* ASSERTION: The 'caller' variable can be accessed and is not -1.
Expand Down
31 changes: 31 additions & 0 deletions test/unittest/variables/bvar/tst.caller2.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.
*/

/*
* ASSERTION: The 'caller' should be consistent with stack().
*
* SECTION: Variables/Built-in Variables/caller
*/

#pragma D option quiet
#pragma D option destructive

BEGIN
{
system("echo write something > /dev/null");
}

fbt::ksys_write:entry
{
stack(2);
sym(caller);
exit(0);
}

ERROR {
exit(1);
}
1 change: 1 addition & 0 deletions test/unittest/variables/bvar/tst.caller2.r
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2
11 changes: 11 additions & 0 deletions test/unittest/variables/bvar/tst.caller2.r.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# sed: remove +0x{ptr} offsets
# awk: look for the ksys_write frame, then write the next two lines
# uniq: count unique lines
# awk: report the counts

sed 's/+0x.*$//' \
| /usr/bin/gawk '/ksys_write/ {getline; print $1; getline; print $1; exit(0)}' \
| uniq -c \
| /usr/bin/gawk '{print $1}'

0 comments on commit 84606f8

Please sign in to comment.