tracepoints: print debug message when lttng-ust-tracepoint.so is not found
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 4 Oct 2021 20:44:57 +0000 (16:44 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 9 Dec 2021 16:09:33 +0000 (11:09 -0500)
Rather than silently disable tracepoints when lttng-ust-tracepoint.so is
not found in the library search path, print a debug message when either
the compile unit including tracepoint.h has defined LTTNG_UST_DEBUG, or
when the LTTNG_UST_DEBUG environment variable is set.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I909f9b8dcd0cbc5faae3789931883f1941973207

include/lttng/tracepoint.h

index 1f8b9209de0c1ec4992af786f32ef623230fbc28..0b77d5512e24fe14fbda11d196a880d78855f223 100644 (file)
 #include <stdlib.h>
 #include <lttng/tracepoint-types.h>
 #include <lttng/tracepoint-rcu.h>
+#include <lttng/ust-utils.h>
+#include <sys/types.h>
+#include <unistd.h>
+
 #include <urcu/compiler.h>
 #include <urcu/system.h>
 #include <dlfcn.h>     /* for dlopen */
 #include <string.h>    /* for memset */
+#include <stdbool.h>
 
 #include <lttng/ust-config.h>  /* for sdt */
 #include <lttng/ust-compiler.h>
@@ -386,6 +391,40 @@ lttng_ust_tracepoint__init_urcu_sym(void)
 }
 #endif
 
+/*
+ * Use getenv() directly and bypass lttng-ust helper functions
+ * because we may not have access to lttng-ust shared libraries.
+ */
+#ifdef LTTNG_UST_DEBUG
+static inline
+bool lttng_ust_tracepoint_logging_debug_enabled(void)
+{
+       return true;
+}
+#else /* #ifdef LTTNG_UST_DEBUG */
+static inline
+bool lttng_ust_tracepoint_logging_debug_enabled(void)
+{
+       return getenv("LTTNG_UST_DEBUG");
+}
+#endif /* #ifdef LTTNG_UST_DEBUG */
+
+#define LTTNG_UST_TRACEPOINT_THIS_IP           \
+       ({ __label__ here; here: &&here; })
+
+static void
+lttng_ust_tracepoints_print_disabled_message(void)
+{
+       if (!lttng_ust_tracepoint_logging_debug_enabled())
+               return;
+       fprintf(stderr, "lttng-ust-tracepoint [%ld]: dlopen() failed to find '%s', tracepoints in this binary won't be registered. "
+               "(at addr=%p in %s() at " __FILE__ ":" lttng_ust_stringify(__LINE__) ")\n",
+               (long) getpid(),
+               LTTNG_UST_TRACEPOINT_LIB_SONAME,
+               LTTNG_UST_TRACEPOINT_THIS_IP,
+               __func__);
+}
+
 static void
 lttng_ust__tracepoints__init(void)
        lttng_ust_notrace __attribute__((constructor));
@@ -404,8 +443,10 @@ lttng_ust__tracepoints__init(void)
        if (!lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle)
                lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle =
                        dlopen(LTTNG_UST_TRACEPOINT_LIB_SONAME, RTLD_NOW | RTLD_GLOBAL);
-       if (!lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle)
+       if (!lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle) {
+               lttng_ust_tracepoints_print_disabled_message();
                return;
+       }
        lttng_ust_tracepoint__init_urcu_sym();
 }
 
@@ -534,8 +575,10 @@ lttng_ust__tracepoints__ptrs_init(void)
        if (!lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle)
                lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle =
                        dlopen(LTTNG_UST_TRACEPOINT_LIB_SONAME, RTLD_NOW | RTLD_GLOBAL);
-       if (!lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle)
+       if (!lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle) {
+               lttng_ust_tracepoints_print_disabled_message();
                return;
+       }
        if (!lttng_ust_tracepoint_destructors_syms_ptr)
                lttng_ust_tracepoint_destructors_syms_ptr = &lttng_ust_tracepoint_destructors_syms;
        lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_module_register =
This page took 0.026664 seconds and 4 git commands to generate.