[DTrace-devel] [PATCH 07/12] Add support for built-in variable caller

Kris Van Hees kris.van.hees at oracle.com
Tue Jun 8 22:38:57 PDT 2021


Reviewed-by: Kris Van Hees <kris.van.hees at oracle.com>

... with small change as mentioned below.

On Fri, May 28, 2021 at 02:35:11PM -0400, eugene.loh at oracle.com wrote:
> From: Eugene Loh <eugene.loh at oracle.com>
> 
> Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
> ---
>  bpf/get_bvar.c                                |  8 +++++
>  test/unittest/builtinvar/tst.caller.d         |  4 +--
>  test/unittest/builtinvar/tst.caller1.d        |  4 +--
>  test/unittest/variables/bvar/tst.caller.d     |  1 -
>  .../variables/bvar/tst.caller_ksys_write.d    | 30 +++++++++++++++++++
>  .../variables/bvar/tst.caller_ksys_write.r    |  1 +
>  6 files changed, 41 insertions(+), 7 deletions(-)
>  create mode 100644 test/unittest/variables/bvar/tst.caller_ksys_write.d
>  create mode 100644 test/unittest/variables/bvar/tst.caller_ksys_write.r
> 
> diff --git a/bpf/get_bvar.c b/bpf/get_bvar.c
> index ab4c2894..198cb673 100644
> --- a/bpf/get_bvar.c
> +++ b/bpf/get_bvar.c
> @@ -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, 16, flags) < 0)

Instead of 16, use sizeof(buf), since that is what it refers to anyway.

> +			return 0;
> +		return buf[1];
> +	}
>  	case DIF_VAR_PROBEPROV: {
>  		uint32_t	key;
>  		dt_bpf_probe_t	*pinfo;
> diff --git a/test/unittest/builtinvar/tst.caller.d b/test/unittest/builtinvar/tst.caller.d
> index a6d867ea..19a4bab9 100644
> --- a/test/unittest/builtinvar/tst.caller.d
> +++ b/test/unittest/builtinvar/tst.caller.d
> @@ -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
>   */
> diff --git a/test/unittest/builtinvar/tst.caller1.d b/test/unittest/builtinvar/tst.caller1.d
> index 0f568190..ca0f098f 100644
> --- a/test/unittest/builtinvar/tst.caller1.d
> +++ b/test/unittest/builtinvar/tst.caller1.d
> @@ -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
>   */
> diff --git a/test/unittest/variables/bvar/tst.caller.d b/test/unittest/variables/bvar/tst.caller.d
> index a2476a24..3d64fa98 100644
> --- a/test/unittest/variables/bvar/tst.caller.d
> +++ b/test/unittest/variables/bvar/tst.caller.d
> @@ -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.
> diff --git a/test/unittest/variables/bvar/tst.caller_ksys_write.d b/test/unittest/variables/bvar/tst.caller_ksys_write.d
> new file mode 100644
> index 00000000..3bb4807c
> --- /dev/null
> +++ b/test/unittest/variables/bvar/tst.caller_ksys_write.d
> @@ -0,0 +1,30 @@
> +/*
> + * 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' for __vfs_write should be ksys_write.
> + *
> + * SECTION: Variables/Built-in Variables/caller
> + */
> +
> +#pragma D option quiet
> +#pragma D option destructive
> +
> +BEGIN
> +{
> +        system("echo write something > /dev/null");
> +}
> +
> +fbt::__vfs_write:entry
> +{
> +	sym(caller);
> +	exit(0);
> +}
> +
> +ERROR {
> +	exit(1);
> +}
> diff --git a/test/unittest/variables/bvar/tst.caller_ksys_write.r b/test/unittest/variables/bvar/tst.caller_ksys_write.r
> new file mode 100644
> index 00000000..9b88037d
> --- /dev/null
> +++ b/test/unittest/variables/bvar/tst.caller_ksys_write.r
> @@ -0,0 +1 @@
> +  vmlinux`ksys_write                                
> -- 
> 2.18.4
> 
> 
> _______________________________________________
> 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