[DTrace-devel] [PATCH 5/7] Add support for built-in variable caller

eugene.loh at oracle.com eugene.loh at oracle.com
Thu May 6 12:31:48 PDT 2021


From: Eugene Loh <eugene.loh at oracle.com>

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 bpf/get_bvar.c                                | 10 +++++++
 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, 43 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 7e7b25a3..3116e1a8 100644
--- a/bpf/get_bvar.c
+++ b/bpf/get_bvar.c
@@ -52,6 +52,16 @@ 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 skip = 1;
+		uint64_t buf[2];
+
+		/* need bufsize=2*8=16 to work around a bpf_get_stack bug? */
+		if (bpf_get_stack(dctx->ctx, buf, 16,
+				  skip & BPF_F_SKIP_FIELD_MASK) < 0)
+			return 0;
+		return buf[0];
+	}
 	case DIF_VAR_PID: {
 		uint64_t	val = bpf_get_current_pid_tgid();
 
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




More information about the DTrace-devel mailing list