From: Mathieu Desnoyers Date: Mon, 4 Oct 2021 20:44:57 +0000 (-0400) Subject: tracepoints: print debug message when lttng-ust-tracepoint.so is not found X-Git-Tag: v2.13.1~12 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=2af952211343a85341a390e1b7a000aec3b075b5;p=lttng-ust.git tracepoints: print debug message when lttng-ust-tracepoint.so is not found 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 Change-Id: I909f9b8dcd0cbc5faae3789931883f1941973207 --- diff --git a/include/lttng/tracepoint.h b/include/lttng/tracepoint.h index 1f8b9209..0b77d551 100644 --- a/include/lttng/tracepoint.h +++ b/include/lttng/tracepoint.h @@ -11,10 +11,15 @@ #include #include #include +#include +#include +#include + #include #include #include /* for dlopen */ #include /* for memset */ +#include #include /* for sdt */ #include @@ -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 = <tng_ust_tracepoint_destructors_syms; lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_module_register =