X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=include%2Flttng%2Ftracepoint.h;h=17fa2a0c68ef884857cc6dfa5066172e425d2b0d;hb=e0ca901df9ff4742dfcaf1c8839f042760197555;hp=23f01547720b67a5068eb940df210c6714c6467e;hpb=29d6f42146cb632bd8c8cee3d087aefc0f84dd91;p=lttng-ust.git diff --git a/include/lttng/tracepoint.h b/include/lttng/tracepoint.h index 23f01547..17fa2a0c 100644 --- a/include/lttng/tracepoint.h +++ b/include/lttng/tracepoint.h @@ -11,16 +11,25 @@ #include #include #include +#include +#include +#include + #include #include #include /* for dlopen */ #include /* for memset */ +#include #include /* for sdt */ #include #include #include +#if (defined(__cplusplus) && (__cplusplus <= 199711L)) +#error "C++11 support is required to build tracepoints and providers as C++" +#endif + #define LTTNG_UST_TRACEPOINT_NAME_LEN_MAX 256 #ifdef LTTNG_UST_HAVE_SDT_INTEGRATION @@ -216,7 +225,7 @@ static inline \ void lttng_ust_tracepoint_register_##_provider##___##_name(char *provider_name, char *event_name, \ void (*func)(void), void *data) \ { \ - lttng_ust_tracepoint_probe_register(provider_name, event_name, func, data, \ + lttng_ust_tracepoint_provider_register(provider_name, event_name, func, data, \ lttng_ust_tracepoint_##_provider##___##_name.signature); \ } \ static inline \ @@ -227,14 +236,27 @@ static inline \ void lttng_ust_tracepoint_unregister_##_provider##___##_name(char *provider_name, char *event_name, \ void (*func)(void), void *data) \ { \ - lttng_ust_tracepoint_probe_unregister(provider_name, event_name, func, data); \ + lttng_ust_tracepoint_provider_unregister(provider_name, event_name, func, data); \ } -extern int lttng_ust_tracepoint_probe_register(const char *provider_name, const char *event_name, +/* + * Registration of tracepoint provider probe functions with + * lttng_ust_tracepoint_provider_register, unregistration with + * lttng_ust_tracepoint_provider_unregister. + */ +int lttng_ust_tracepoint_provider_register(const char *provider_name, const char *event_name, void (*func)(void), void *data, const char *signature); -extern int lttng_ust_tracepoint_probe_unregister(const char *provider_name, const char *event_name, +int lttng_ust_tracepoint_provider_unregister(const char *provider_name, const char *event_name, void (*func)(void), void *data); +/* + * Registration of tracepoint instrumentation modules with lttng_ust_tracepoint_module_register, + * unregistration with lttng_ust_tracepoint_module_unregister. + */ +int lttng_ust_tracepoint_module_register(struct lttng_ust_tracepoint * const *tracepoints_start, + int tracepoints_count); +int lttng_ust_tracepoint_module_unregister(struct lttng_ust_tracepoint * const *tracepoints_start); + /* * tracepoint dynamic linkage handling (callbacks). Hidden visibility: * shared across objects in a module/main executable. @@ -252,9 +274,9 @@ struct lttng_ust_tracepoint_dlopen { void *liblttngust_handle; - int (*lttng_ust_tracepoint_register_lib)(struct lttng_ust_tracepoint * const *tracepoints_start, + int (*lttng_ust_tracepoint_module_register)(struct lttng_ust_tracepoint * const *tracepoints_start, int tracepoints_count); - int (*lttng_ust_tracepoint_unregister_lib)(struct lttng_ust_tracepoint * const *tracepoints_start); + int (*lttng_ust_tracepoint_module_unregister)(struct lttng_ust_tracepoint * const *tracepoints_start); void (*rcu_read_lock_sym)(void); void (*rcu_read_unlock_sym)(void); void *(*rcu_dereference_sym)(void *p); @@ -373,6 +395,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)); @@ -391,8 +447,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(); } @@ -521,18 +579,20 @@ 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_register_lib = + lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_module_register = URCU_FORCE_CAST(int (*)(struct lttng_ust_tracepoint * const *, int), dlsym(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle, - "lttng_ust_tracepoint_register_lib")); - lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_unregister_lib = + "lttng_ust_tracepoint_module_register")); + lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_module_unregister = URCU_FORCE_CAST(int (*)(struct lttng_ust_tracepoint * const *), dlsym(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle, - "lttng_ust_tracepoint_unregister_lib")); + "lttng_ust_tracepoint_module_unregister")); lttng_ust_tracepoint_destructors_syms_ptr->tracepoint_disable_destructors = URCU_FORCE_CAST(void (*)(void), dlsym(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle, @@ -542,8 +602,8 @@ lttng_ust__tracepoints__ptrs_init(void) dlsym(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle, "lttng_ust_tp_get_destructors_state")); lttng_ust_tracepoint__init_urcu_sym(); - if (lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_register_lib) { - lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_register_lib(__start_lttng_ust_tracepoints_ptrs, + if (lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_module_register) { + lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_module_register(__start_lttng_ust_tracepoints_ptrs, __stop_lttng_ust_tracepoints_ptrs - __start_lttng_ust_tracepoints_ptrs); } @@ -563,8 +623,8 @@ lttng_ust__tracepoints__ptrs_destroy(void) lttng_ust_tracepoint_dlopen_ptr = <tng_ust_tracepoint_dlopen; if (!lttng_ust_tracepoint_destructors_syms_ptr) lttng_ust_tracepoint_destructors_syms_ptr = <tng_ust_tracepoint_destructors_syms; - if (lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_unregister_lib) - lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_unregister_lib(__start_lttng_ust_tracepoints_ptrs); + if (lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_module_unregister) + lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_module_unregister(__start_lttng_ust_tracepoints_ptrs); if (lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle && lttng_ust_tracepoint_destructors_syms_ptr->tracepoint_get_destructors_state && lttng_ust_tracepoint_destructors_syms_ptr->tracepoint_get_destructors_state() @@ -770,14 +830,17 @@ lttng_ust__tracepoints__ptrs_destroy(void) #define LTTNG_UST_TRACEPOINT_EVENT_CLASS(provider, name, args, fields) -#define LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(provider, _template, name, args) \ +#define LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(template_provider, template_name, provider, name, args) \ LTTNG_UST__DECLARE_TRACEPOINT(provider, name, LTTNG_UST__TP_PARAMS(args)) \ LTTNG_UST__DEFINE_TRACEPOINT(provider, name, LTTNG_UST__TP_PARAMS(args)) #if LTTNG_UST_COMPAT_API(0) #define TRACEPOINT_EVENT LTTNG_UST_TRACEPOINT_EVENT #define TRACEPOINT_EVENT_CLASS LTTNG_UST_TRACEPOINT_EVENT_CLASS -#define TRACEPOINT_EVENT_INSTANCE LTTNG_UST_TRACEPOINT_EVENT_INSTANCE +#define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, args) \ + LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(_provider, _template, \ + _provider, _name, LTTNG_UST__TP_PARAMS(args)) + #endif /* #if LTTNG_UST_COMPAT_API(0) */ #endif /* #ifndef LTTNG_UST_TRACEPOINT_EVENT */