[DTrace-devel] [PATCH v2 29/38] Set the ERROR PRID in BPF code

eugene.loh at oracle.com eugene.loh at oracle.com
Fri Jun 28 02:03:12 UTC 2024


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

The patch can be simplified if we are willing to assume the
ERROR PRID is always 3, which is probably safe.

Signed-off-by: Eugene Loh <eugene.loh at oracle.com>
---
 bpf/probe_error.c                         |  5 ++++
 libdtrace/dt_bpf.h                        |  1 +
 libdtrace/dt_cc.c                         |  3 +++
 libdtrace/dt_dlibs.c                      |  1 +
 test/unittest/builtinvar/tst.id_ERROR.d   | 32 +++++++++++++++++++++++
 test/unittest/builtinvar/tst.id_ERROR.r   |  3 +++
 test/unittest/builtinvar/tst.id_ERROR.r.p |  4 +++
 7 files changed, 49 insertions(+)
 create mode 100644 test/unittest/builtinvar/tst.id_ERROR.d
 create mode 100644 test/unittest/builtinvar/tst.id_ERROR.r
 create mode 100755 test/unittest/builtinvar/tst.id_ERROR.r.p

diff --git a/bpf/probe_error.c b/bpf/probe_error.c
index c8ddcdfa..a6616c2f 100644
--- a/bpf/probe_error.c
+++ b/bpf/probe_error.c
@@ -7,6 +7,8 @@
 #include <bpf/bpf_helpers.h>
 #include <dt_dctx.h>
 
+extern uint64_t ERROR_PRID;
+
 #ifndef noinline
 # define noinline	__attribute__((noinline))
 #endif
@@ -26,6 +28,7 @@ noinline void dt_probe_error(const dt_dctx_t *dctx, uint64_t pc, uint64_t fault,
 			     uint64_t illval)
 {
 	dt_mstate_t	*mst = dctx->mst;
+	int		oldprid = mst->prid;
 
 	mst->argv[0] = 0;
 	mst->argv[1] = mst->epid;
@@ -34,7 +37,9 @@ noinline void dt_probe_error(const dt_dctx_t *dctx, uint64_t pc, uint64_t fault,
 	mst->argv[4] = fault;
 	mst->argv[5] = illval;
 
+	mst->prid = ((uint64_t)&ERROR_PRID);
 	dt_error(dctx);
+	mst->prid = oldprid;
 
 	mst->fault = fault;
 }
diff --git a/libdtrace/dt_bpf.h b/libdtrace/dt_bpf.h
index 5b2df264..58cf29cc 100644
--- a/libdtrace/dt_bpf.h
+++ b/libdtrace/dt_bpf.h
@@ -56,6 +56,7 @@ extern "C" {
 #define DT_CONST_ZERO_OFF		22
 #define DT_CONST_STACK_OFF		23
 #define DT_CONST_STACK_SKIP		24
+#define DT_CONST_ERROR_PRID		25
 
 #define DT_BPF_LOG_SIZE_DEFAULT	(UINT32_MAX >> 8)
 #define DT_BPF_LOG_SIZE_SMALL	4096
diff --git a/libdtrace/dt_cc.c b/libdtrace/dt_cc.c
index d1ee3843..3d9a9c79 100644
--- a/libdtrace/dt_cc.c
+++ b/libdtrace/dt_cc.c
@@ -1076,6 +1076,9 @@ dt_link_construct(dtrace_hdl_t *dtp, const dt_probe_t *prp, dtrace_difo_t *dp,
 				nrp->dofr_data = sizeof(uint64_t)
 				    * dtp->dt_options[DTRACEOPT_MAXFRAMES];
 				continue;
+			case DT_CONST_ERROR_PRID:
+				nrp->dofr_data = dtp->dt_error->desc->id;
+				continue;
 			case DT_CONST_BOOTTM:
 				if (boottime == 0 && get_boottime())
 					return -1;
diff --git a/libdtrace/dt_dlibs.c b/libdtrace/dt_dlibs.c
index bc883e11..1fb561ad 100644
--- a/libdtrace/dt_dlibs.c
+++ b/libdtrace/dt_dlibs.c
@@ -80,6 +80,7 @@ static const dt_ident_t		dt_bpf_symbols[] = {
 	DT_BPF_SYMBOL_ID(STBSZ, DT_IDENT_SCALAR, DT_CONST_STBSZ),
 	DT_BPF_SYMBOL_ID(STRSZ, DT_IDENT_SCALAR, DT_CONST_STRSZ),
 	DT_BPF_SYMBOL_ID(STKSIZ, DT_IDENT_SCALAR, DT_CONST_STKSIZ),
+	DT_BPF_SYMBOL_ID(ERROR_PRID, DT_IDENT_SCALAR, DT_CONST_ERROR_PRID),
 	DT_BPF_SYMBOL_ID(BOOTTM, DT_IDENT_SCALAR, DT_CONST_BOOTTM),
 	DT_BPF_SYMBOL_ID(NSPEC, DT_IDENT_SCALAR, DT_CONST_NSPEC),
 	DT_BPF_SYMBOL_ID(NCPUS, DT_IDENT_SCALAR, DT_CONST_NCPUS),
diff --git a/test/unittest/builtinvar/tst.id_ERROR.d b/test/unittest/builtinvar/tst.id_ERROR.d
new file mode 100644
index 00000000..59021c60
--- /dev/null
+++ b/test/unittest/builtinvar/tst.id_ERROR.d
@@ -0,0 +1,32 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2024, 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 id in the ERROR probe is 3.
+ *
+ * SECTION: Variables/Built-in Variables
+ */
+
+#pragma D option quiet
+
+tick-1s
+{
+	/* trigger the ERROR probe */
+	trace(*((int*)0));
+}
+
+tick-2s
+{
+	exit(1);
+}
+
+ERROR
+{
+	printf("id of the ERROR probe = %d\n", id);
+	exit(0);
+}
diff --git a/test/unittest/builtinvar/tst.id_ERROR.r b/test/unittest/builtinvar/tst.id_ERROR.r
new file mode 100644
index 00000000..95974abe
--- /dev/null
+++ b/test/unittest/builtinvar/tst.id_ERROR.r
@@ -0,0 +1,3 @@
+id of the ERROR probe = 3
+
+-- @@stderr --
diff --git a/test/unittest/builtinvar/tst.id_ERROR.r.p b/test/unittest/builtinvar/tst.id_ERROR.r.p
new file mode 100755
index 00000000..884b43f4
--- /dev/null
+++ b/test/unittest/builtinvar/tst.id_ERROR.r.p
@@ -0,0 +1,4 @@
+#!/usr/bin/gawk -f
+
+# Drop the line with run-dependent PRID for profile probe.
+!/error on enabled probe ID/ { print }
-- 
2.43.5




More information about the DTrace-devel mailing list