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

eugene.loh at oracle.com eugene.loh at oracle.com
Wed Jun 16 15:58:11 PDT 2021


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

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees 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 -
 test/unittest/variables/bvar/tst.caller2.d   | 31 ++++++++++++++++++++
 test/unittest/variables/bvar/tst.caller2.r   |  1 +
 test/unittest/variables/bvar/tst.caller2.r.p | 11 +++++++
 7 files changed, 53 insertions(+), 7 deletions(-)
 create mode 100644 test/unittest/variables/bvar/tst.caller2.d
 create mode 100644 test/unittest/variables/bvar/tst.caller2.r
 create mode 100755 test/unittest/variables/bvar/tst.caller2.r.p

diff --git a/bpf/get_bvar.c b/bpf/get_bvar.c
index ab4c2894..0c5d3c7c 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, sizeof(buf), flags) < 0)
+			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.caller2.d b/test/unittest/variables/bvar/tst.caller2.d
new file mode 100644
index 00000000..ca6dbfd2
--- /dev/null
+++ b/test/unittest/variables/bvar/tst.caller2.d
@@ -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);
+}
diff --git a/test/unittest/variables/bvar/tst.caller2.r b/test/unittest/variables/bvar/tst.caller2.r
new file mode 100644
index 00000000..0cfbf088
--- /dev/null
+++ b/test/unittest/variables/bvar/tst.caller2.r
@@ -0,0 +1 @@
+2
diff --git a/test/unittest/variables/bvar/tst.caller2.r.p b/test/unittest/variables/bvar/tst.caller2.r.p
new file mode 100755
index 00000000..1a26a4df
--- /dev/null
+++ b/test/unittest/variables/bvar/tst.caller2.r.p
@@ -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}'
-- 
2.18.4




More information about the DTrace-devel mailing list