[DTrace-devel] [PATCH 05/12] Fix the -xctfpath option

Kris Van Hees kris.van.hees at oracle.com
Wed Jul 13 19:17:44 UTC 2022


The -xctfpath option was (along with all other options) being processed
after dtrace_open().  But the implementation of dtrace_open() included
the instantiation of providers and probes that triggers the loading of
the CTF archive.  As such, this option had no effect.

Instantiation of providers and probes has been moved to a new function:
dtrace_init().  This function is called after all command line options
have been processed, ensuring that -xctfpath sets the pathname to the
CTF archive before it is loaded.

Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 cmd/dtrace.c                         |  7 ++++
 libdtrace/dt_open.c                  | 56 ++++++++++++++++------------
 libdtrace/dtrace.h                   |  1 +
 libdtrace/libdtrace.ver              |  1 +
 test/unittest/options/tst.ctfpath.sh | 28 ++++++++++++++
 5 files changed, 69 insertions(+), 24 deletions(-)
 create mode 100755 test/unittest/options/tst.ctfpath.sh

diff --git a/cmd/dtrace.c b/cmd/dtrace.c
index 7e43e0f1..16ecbd96 100644
--- a/cmd/dtrace.c
+++ b/cmd/dtrace.c
@@ -1324,6 +1324,13 @@ main(int argc, char *argv[])
 		}
 	}
 
+	/*
+	 * Now we are ready to initialize libdtrace based on the chosen
+	 * options.
+	 */
+	if (dtrace_init(g_dtp) < 0)
+		dfatal("failed to initialize libdtrace");
+
 	/*
 	 * In our fourth pass we finish g_cmdv[] by calling dc_func to convert
 	 * each string or file specification into a compiled program structure.
diff --git a/libdtrace/dt_open.c b/libdtrace/dt_open.c
index 316ef4d0..deea0781 100644
--- a/libdtrace/dt_open.c
+++ b/libdtrace/dt_open.c
@@ -1113,30 +1113,6 @@ dt_vopen(int version, int flags, int *errp,
 	if (dt_pfdict_create(dtp) == -1)
 		return set_open_errno(dtp, errp, dtp->dt_errno);
 
-	/*
-	 * Initialize the BPF library handling.
-	 */
-	dt_dlib_init(dtp);
-
-	/*
-	 * Initialize consume handling, e.g. storage of uncommitted speculations.
-	 */
-	if (dt_consume_init(dtp) < 0)
-		return set_open_errno(dtp, errp, dtp->dt_errno);
-
-	/*
-	 * Initialize the collection of probes that is made available by the
-	 * known providers.
-	 */
-	dt_probe_init(dtp);
-	for (i = 0; i < ARRAY_SIZE(dt_providers); i++) {
-		int n;
-
-		n = dt_providers[i]->populate(dtp);
-		dt_dprintf("loaded %d probes for %s\n", n,
-			   dt_providers[i]->name);
-	}
-
 	/*
 	 * Load hard-wired inlines into the definition cache by calling the
 	 * compiler on the raw definition string defined above.
@@ -1182,6 +1158,38 @@ dtrace_vopen(int version, int flags, int *errp,
 	return dt_vopen(version, flags, errp, vector, arg);
 }
 
+int
+dtrace_init(dtrace_hdl_t *dtp)
+{
+	int	i;
+
+	/*
+	 * Initialize the BPF library handling.
+	 */
+	dt_dlib_init(dtp);
+
+	/*
+	 * Initialize consume handling.
+	 */
+	if (dt_consume_init(dtp) < 0)
+		return -1;			/* errno is already set */
+
+	/*
+	 * Initialize the collection of probes that is made available by the
+	 * known providers.
+	 */
+	dt_probe_init(dtp);
+	for (i = 0; i < ARRAY_SIZE(dt_providers); i++) {
+		int	n;
+
+		n = dt_providers[i]->populate(dtp);
+		dt_dprintf("loaded %d probes for %s\n", n,
+			   dt_providers[i]->name);
+	}
+
+	return 0;
+}
+
 void
 dtrace_close(dtrace_hdl_t *dtp)
 {
diff --git a/libdtrace/dtrace.h b/libdtrace/dtrace.h
index 3e55f0af..25c0fe33 100644
--- a/libdtrace/dtrace.h
+++ b/libdtrace/dtrace.h
@@ -43,6 +43,7 @@ typedef struct dtrace_aggdata dtrace_aggdata_t;
 extern dtrace_hdl_t *dtrace_open(int version, int flags, int *errp);
 extern dtrace_hdl_t *dtrace_vopen(int version, int flags, int *errp,
     const dtrace_vector_t *vector, void *arg);
+extern int dtrace_init(dtrace_hdl_t *dtp);
 
 extern int dtrace_go(dtrace_hdl_t *dtp, uint_t cflags);
 extern int dtrace_stop(dtrace_hdl_t *dtp);
diff --git a/libdtrace/libdtrace.ver b/libdtrace/libdtrace.ver
index 5ccf7b5b..d3fd82b5 100644
--- a/libdtrace/libdtrace.ver
+++ b/libdtrace/libdtrace.ver
@@ -45,6 +45,7 @@ LIBDTRACE_1.0 {
 	dtrace_handle_proc;
 	dtrace_handle_setopt;
 	dtrace_id2desc;
+	dtrace_init;
 	dtrace_lookup_by_addr;
 	dtrace_lookup_by_name;
 	dtrace_lookup_by_type;
diff --git a/test/unittest/options/tst.ctfpath.sh b/test/unittest/options/tst.ctfpath.sh
new file mode 100755
index 00000000..ad613b4d
--- /dev/null
+++ b/test/unittest/options/tst.ctfpath.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+#
+# Oracle Linux DTrace.
+# Copyright (c) 2022, 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.
+#
+
+dtrace=$1
+
+#
+# We test whether the -xctfpath option works by replacing the CTF archive name
+# with /dev/null which is guaranteed to cause dtrace to fail.
+#
+$dtrace $dt_flags -xctfpath=/dev/null -n 'BEGIN { exit(0); }'
+rc=$?
+
+#
+# The failure may cause a core dump, so get rid of the core because we do not
+# care about its content.
+#
+rm -f core
+	
+if [ $rc -eq 0 ]; then
+	exit 1
+else
+	exit 0
+fi
-- 
2.34.1




More information about the DTrace-devel mailing list