| 1 | // SPDX-FileCopyrightText: 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 2 | // |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | |
| 5 | #ifndef _LTTNG_UST_TRACEPOINT_H |
| 6 | #define _LTTNG_UST_TRACEPOINT_H |
| 7 | |
| 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> |
| 10 | #include <lttng/tracepoint-types.h> |
| 11 | #include <lttng/tracepoint-rcu.h> |
| 12 | #include <lttng/ust-utils.h> |
| 13 | #include <sys/types.h> |
| 14 | #include <unistd.h> |
| 15 | |
| 16 | #include <urcu/compiler.h> |
| 17 | #include <urcu/system.h> |
| 18 | #include <dlfcn.h> /* for dlopen */ |
| 19 | #include <string.h> /* for memset */ |
| 20 | #include <stdbool.h> |
| 21 | |
| 22 | #include <lttng/ust-config.h> /* for sdt */ |
| 23 | #include <lttng/ust-compiler.h> |
| 24 | #include <lttng/ust-tracer.h> |
| 25 | #include <lttng/ust-api-compat.h> |
| 26 | |
| 27 | #if (defined(__cplusplus) && (__cplusplus <= 199711L)) |
| 28 | #error "C++11 support is required to build tracepoints and providers as C++" |
| 29 | #endif |
| 30 | |
| 31 | #define LTTNG_UST_TRACEPOINT_NAME_LEN_MAX 256 |
| 32 | |
| 33 | #ifdef LTTNG_UST_HAVE_SDT_INTEGRATION |
| 34 | /* |
| 35 | * Instead of using SDT_USE_VARIADIC from 'sys/sdt.h', use our own namespaced |
| 36 | * macros since the instrumented application might already have included |
| 37 | * 'sys/sdt.h' without variadic support. |
| 38 | */ |
| 39 | #include <sys/sdt.h> |
| 40 | |
| 41 | #define LTTNG_UST__SDT_NARG(...) \ |
| 42 | LTTNG_UST___SDT_NARG(__VA_ARGS__, 12,11,10,9,8,7,6,5,4,3,2,1,0) |
| 43 | |
| 44 | #define LTTNG_UST___SDT_NARG(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12, N, ...) N |
| 45 | |
| 46 | #define LTTNG_UST__SDT_PROBE_N(provider, name, N, ...) \ |
| 47 | _SDT_PROBE(provider, name, N, (__VA_ARGS__)) |
| 48 | |
| 49 | #define LTTNG_UST_STAP_PROBEV(provider, name, ...) \ |
| 50 | LTTNG_UST__SDT_PROBE_N(provider, name, LTTNG_UST__SDT_NARG(0, ##__VA_ARGS__), ##__VA_ARGS__) |
| 51 | |
| 52 | #else |
| 53 | #define LTTNG_UST_STAP_PROBEV(...) |
| 54 | #endif |
| 55 | |
| 56 | #ifdef __cplusplus |
| 57 | extern "C" { |
| 58 | #endif |
| 59 | |
| 60 | #define lttng_ust_tracepoint_enabled(provider, name) \ |
| 61 | caa_unlikely(CMM_LOAD_SHARED(lttng_ust_tracepoint_##provider##___##name.state)) |
| 62 | |
| 63 | #define lttng_ust_do_tracepoint(provider, name, ...) \ |
| 64 | lttng_ust_tracepoint_cb_##provider##___##name(__VA_ARGS__) |
| 65 | |
| 66 | #define lttng_ust_tracepoint(provider, name, ...) \ |
| 67 | do { \ |
| 68 | LTTNG_UST_STAP_PROBEV(provider, name, ## __VA_ARGS__); \ |
| 69 | if (lttng_ust_tracepoint_enabled(provider, name)) \ |
| 70 | lttng_ust_do_tracepoint(provider, name, __VA_ARGS__); \ |
| 71 | } while (0) |
| 72 | |
| 73 | #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__ |
| 74 | |
| 75 | /* |
| 76 | * LTTNG_UST_TP_ARGS takes tuples of type, argument separated by a comma. |
| 77 | * It can take up to 10 tuples (which means that less than 10 tuples is |
| 78 | * fine too). |
| 79 | * Each tuple is also separated by a comma. |
| 80 | */ |
| 81 | #define LTTNG_UST___TP_COMBINE_TOKENS(_tokena, _tokenb) \ |
| 82 | _tokena##_tokenb |
| 83 | #define LTTNG_UST__TP_COMBINE_TOKENS(_tokena, _tokenb) \ |
| 84 | LTTNG_UST___TP_COMBINE_TOKENS(_tokena, _tokenb) |
| 85 | #define LTTNG_UST___TP_COMBINE_TOKENS3(_tokena, _tokenb, _tokenc) \ |
| 86 | _tokena##_tokenb##_tokenc |
| 87 | #define LTTNG_UST__TP_COMBINE_TOKENS3(_tokena, _tokenb, _tokenc) \ |
| 88 | LTTNG_UST___TP_COMBINE_TOKENS3(_tokena, _tokenb, _tokenc) |
| 89 | #define LTTNG_UST___TP_COMBINE_TOKENS4(_tokena, _tokenb, _tokenc, _tokend) \ |
| 90 | _tokena##_tokenb##_tokenc##_tokend |
| 91 | #define LTTNG_UST__TP_COMBINE_TOKENS4(_tokena, _tokenb, _tokenc, _tokend) \ |
| 92 | LTTNG_UST___TP_COMBINE_TOKENS4(_tokena, _tokenb, _tokenc, _tokend) |
| 93 | |
| 94 | /* |
| 95 | * LTTNG_UST__TP_EXVAR* extract the var names. |
| 96 | * LTTNG_UST__TP_EXVAR1 and LTTNG_UST__TP_EXDATA_VAR1 are needed for -std=c99. |
| 97 | */ |
| 98 | #define LTTNG_UST__TP_EXVAR0() |
| 99 | #define LTTNG_UST__TP_EXVAR1(a) |
| 100 | #define LTTNG_UST__TP_EXVAR2(a,b) b |
| 101 | #define LTTNG_UST__TP_EXVAR4(a,b,c,d) b,d |
| 102 | #define LTTNG_UST__TP_EXVAR6(a,b,c,d,e,f) b,d,f |
| 103 | #define LTTNG_UST__TP_EXVAR8(a,b,c,d,e,f,g,h) b,d,f,h |
| 104 | #define LTTNG_UST__TP_EXVAR10(a,b,c,d,e,f,g,h,i,j) b,d,f,h,j |
| 105 | #define LTTNG_UST__TP_EXVAR12(a,b,c,d,e,f,g,h,i,j,k,l) b,d,f,h,j,l |
| 106 | #define LTTNG_UST__TP_EXVAR14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) b,d,f,h,j,l,n |
| 107 | #define LTTNG_UST__TP_EXVAR16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) b,d,f,h,j,l,n,p |
| 108 | #define LTTNG_UST__TP_EXVAR18(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) b,d,f,h,j,l,n,p,r |
| 109 | #define LTTNG_UST__TP_EXVAR20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) b,d,f,h,j,l,n,p,r,t |
| 110 | |
| 111 | #define LTTNG_UST__TP_EXDATA_VAR0() __tp_data |
| 112 | #define LTTNG_UST__TP_EXDATA_VAR1(a) __tp_data |
| 113 | #define LTTNG_UST__TP_EXDATA_VAR2(a,b) __tp_data,b |
| 114 | #define LTTNG_UST__TP_EXDATA_VAR4(a,b,c,d) __tp_data,b,d |
| 115 | #define LTTNG_UST__TP_EXDATA_VAR6(a,b,c,d,e,f) __tp_data,b,d,f |
| 116 | #define LTTNG_UST__TP_EXDATA_VAR8(a,b,c,d,e,f,g,h) __tp_data,b,d,f,h |
| 117 | #define LTTNG_UST__TP_EXDATA_VAR10(a,b,c,d,e,f,g,h,i,j) __tp_data,b,d,f,h,j |
| 118 | #define LTTNG_UST__TP_EXDATA_VAR12(a,b,c,d,e,f,g,h,i,j,k,l) __tp_data,b,d,f,h,j,l |
| 119 | #define LTTNG_UST__TP_EXDATA_VAR14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) __tp_data,b,d,f,h,j,l,n |
| 120 | #define LTTNG_UST__TP_EXDATA_VAR16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) __tp_data,b,d,f,h,j,l,n,p |
| 121 | #define LTTNG_UST__TP_EXDATA_VAR18(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) __tp_data,b,d,f,h,j,l,n,p,r |
| 122 | #define LTTNG_UST__TP_EXDATA_VAR20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) __tp_data,b,d,f,h,j,l,n,p,r,t |
| 123 | |
| 124 | /* |
| 125 | * LTTNG_UST__TP_EXPROTO* extract tuples of type, var. |
| 126 | * LTTNG_UST__TP_EXPROTO1 and LTTNG_UST__TP_EXDATA_PROTO1 are needed for -std=c99. |
| 127 | */ |
| 128 | #define LTTNG_UST__TP_EXPROTO0() void |
| 129 | #define LTTNG_UST__TP_EXPROTO1(a) void |
| 130 | #define LTTNG_UST__TP_EXPROTO2(a,b) a b |
| 131 | #define LTTNG_UST__TP_EXPROTO4(a,b,c,d) a b,c d |
| 132 | #define LTTNG_UST__TP_EXPROTO6(a,b,c,d,e,f) a b,c d,e f |
| 133 | #define LTTNG_UST__TP_EXPROTO8(a,b,c,d,e,f,g,h) a b,c d,e f,g h |
| 134 | #define LTTNG_UST__TP_EXPROTO10(a,b,c,d,e,f,g,h,i,j) a b,c d,e f,g h,i j |
| 135 | #define LTTNG_UST__TP_EXPROTO12(a,b,c,d,e,f,g,h,i,j,k,l) a b,c d,e f,g h,i j,k l |
| 136 | #define LTTNG_UST__TP_EXPROTO14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) a b,c d,e f,g h,i j,k l,m n |
| 137 | #define LTTNG_UST__TP_EXPROTO16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) a b,c d,e f,g h,i j,k l,m n,o p |
| 138 | #define LTTNG_UST__TP_EXPROTO18(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) a b,c d,e f,g h,i j,k l,m n,o p,q r |
| 139 | #define LTTNG_UST__TP_EXPROTO20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) a b,c d,e f,g h,i j,k l,m n,o p,q r,s t |
| 140 | |
| 141 | #define LTTNG_UST__TP_EXDATA_PROTO0() void *__tp_data |
| 142 | #define LTTNG_UST__TP_EXDATA_PROTO1(a) void *__tp_data |
| 143 | #define LTTNG_UST__TP_EXDATA_PROTO2(a,b) void *__tp_data,a b |
| 144 | #define LTTNG_UST__TP_EXDATA_PROTO4(a,b,c,d) void *__tp_data,a b,c d |
| 145 | #define LTTNG_UST__TP_EXDATA_PROTO6(a,b,c,d,e,f) void *__tp_data,a b,c d,e f |
| 146 | #define LTTNG_UST__TP_EXDATA_PROTO8(a,b,c,d,e,f,g,h) void *__tp_data,a b,c d,e f,g h |
| 147 | #define LTTNG_UST__TP_EXDATA_PROTO10(a,b,c,d,e,f,g,h,i,j) void *__tp_data,a b,c d,e f,g h,i j |
| 148 | #define LTTNG_UST__TP_EXDATA_PROTO12(a,b,c,d,e,f,g,h,i,j,k,l) void *__tp_data,a b,c d,e f,g h,i j,k l |
| 149 | #define LTTNG_UST__TP_EXDATA_PROTO14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) void *__tp_data,a b,c d,e f,g h,i j,k l,m n |
| 150 | #define LTTNG_UST__TP_EXDATA_PROTO16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) void *__tp_data,a b,c d,e f,g h,i j,k l,m n,o p |
| 151 | #define LTTNG_UST__TP_EXDATA_PROTO18(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) void *__tp_data,a b,c d,e f,g h,i j,k l,m n,o p,q r |
| 152 | #define LTTNG_UST__TP_EXDATA_PROTO20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) void *__tp_data,a b,c d,e f,g h,i j,k l,m n,o p,q r,s t |
| 153 | |
| 154 | /* Preprocessor trick to count arguments. Inspired from sdt.h. */ |
| 155 | #define LTTNG_UST__TP_NARGS(...) LTTNG_UST___TP_NARGS(__VA_ARGS__, 20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0) |
| 156 | #define LTTNG_UST___TP_NARGS(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_20, N, ...) N |
| 157 | #define LTTNG_UST__TP_PROTO_N(N, ...) LTTNG_UST__TP_PARAMS(LTTNG_UST__TP_COMBINE_TOKENS(LTTNG_UST__TP_EXPROTO, N)(__VA_ARGS__)) |
| 158 | #define LTTNG_UST__TP_VAR_N(N, ...) LTTNG_UST__TP_PARAMS(LTTNG_UST__TP_COMBINE_TOKENS(LTTNG_UST__TP_EXVAR, N)(__VA_ARGS__)) |
| 159 | #define LTTNG_UST__TP_DATA_PROTO_N(N, ...) LTTNG_UST__TP_PARAMS(LTTNG_UST__TP_COMBINE_TOKENS(LTTNG_UST__TP_EXDATA_PROTO, N)(__VA_ARGS__)) |
| 160 | #define LTTNG_UST__TP_DATA_VAR_N(N, ...) LTTNG_UST__TP_PARAMS(LTTNG_UST__TP_COMBINE_TOKENS(LTTNG_UST__TP_EXDATA_VAR, N)(__VA_ARGS__)) |
| 161 | #define LTTNG_UST__TP_ARGS_PROTO(...) LTTNG_UST__TP_PROTO_N(LTTNG_UST__TP_NARGS(0, ##__VA_ARGS__), ##__VA_ARGS__) |
| 162 | #define LTTNG_UST__TP_ARGS_VAR(...) LTTNG_UST__TP_VAR_N(LTTNG_UST__TP_NARGS(0, ##__VA_ARGS__), ##__VA_ARGS__) |
| 163 | #define LTTNG_UST__TP_ARGS_DATA_PROTO(...) LTTNG_UST__TP_DATA_PROTO_N(LTTNG_UST__TP_NARGS(0, ##__VA_ARGS__), ##__VA_ARGS__) |
| 164 | #define LTTNG_UST__TP_ARGS_DATA_VAR(...) LTTNG_UST__TP_DATA_VAR_N(LTTNG_UST__TP_NARGS(0, ##__VA_ARGS__), ##__VA_ARGS__) |
| 165 | #define LTTNG_UST__TP_PARAMS(...) __VA_ARGS__ |
| 166 | |
| 167 | /* |
| 168 | * sizeof(#_provider) - 1 : length of the provider string (excluding \0). |
| 169 | * sizeof(#_name) - 1 : length of the name string (excluding \0). |
| 170 | * + 1 : separator between provider and event name. |
| 171 | * |
| 172 | * Upper bound (inclusive) is LTTNG_UST_TRACEPOINT_NAME_LEN_MAX - 1 to |
| 173 | * account for \0. |
| 174 | * |
| 175 | * The comparison is: |
| 176 | * left hand side: sizeof(#_provider) - 1 + sizeof(#_name) - 1 + 1 |
| 177 | * right hand side: LTTNG_UST_TRACEPOINT_NAME_LEN_MAX - 1 |
| 178 | * operator: <= (inclusive) |
| 179 | * Simplified in the code below. |
| 180 | */ |
| 181 | #define lttng_ust_tracepoint_validate_name_len(_provider, _name) \ |
| 182 | lttng_ust_static_assert(sizeof(#_provider) + sizeof(#_name) <= LTTNG_UST_TRACEPOINT_NAME_LEN_MAX, \ |
| 183 | "Tracepoint name length is too long", \ |
| 184 | Tracepoint_name_length_is_too_long) |
| 185 | |
| 186 | /* |
| 187 | * The tracepoint cb is marked always inline so we can distinguish |
| 188 | * between caller's ip addresses within the probe using the return |
| 189 | * address. |
| 190 | */ |
| 191 | #define LTTNG_UST__DECLARE_TRACEPOINT(_provider, _name, ...) \ |
| 192 | extern struct lttng_ust_tracepoint lttng_ust_tracepoint_##_provider##___##_name \ |
| 193 | LTTNG_UST__TRACEPOINT_DEFINITION_VISIBILITY; \ |
| 194 | static inline \ |
| 195 | void lttng_ust_tracepoint_cb_##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(__VA_ARGS__)) \ |
| 196 | __attribute__((always_inline, unused)) lttng_ust_notrace; \ |
| 197 | static \ |
| 198 | void lttng_ust_tracepoint_cb_##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(__VA_ARGS__)) \ |
| 199 | { \ |
| 200 | struct lttng_ust_tracepoint_probe *__tp_probe; \ |
| 201 | \ |
| 202 | if (caa_unlikely(!LTTNG_UST_TP_RCU_LINK_TEST())) \ |
| 203 | return; \ |
| 204 | lttng_ust_tp_rcu_read_lock(); \ |
| 205 | __tp_probe = lttng_ust_tp_rcu_dereference(lttng_ust_tracepoint_##_provider##___##_name.probes); \ |
| 206 | if (caa_unlikely(!__tp_probe)) \ |
| 207 | goto end; \ |
| 208 | do { \ |
| 209 | void (*__tp_cb)(void) = __tp_probe->func; \ |
| 210 | void *__tp_data = __tp_probe->data; \ |
| 211 | \ |
| 212 | URCU_FORCE_CAST(void (*)(LTTNG_UST__TP_ARGS_DATA_PROTO(__VA_ARGS__)), __tp_cb) \ |
| 213 | (LTTNG_UST__TP_ARGS_DATA_VAR(__VA_ARGS__)); \ |
| 214 | } while ((++__tp_probe)->func); \ |
| 215 | end: \ |
| 216 | lttng_ust_tp_rcu_read_unlock(); \ |
| 217 | } \ |
| 218 | static inline \ |
| 219 | void lttng_ust_tracepoint_register_##_provider##___##_name(char *provider_name, char *event_name, \ |
| 220 | void (*func)(void), void *data) \ |
| 221 | lttng_ust_notrace; \ |
| 222 | static inline \ |
| 223 | void lttng_ust_tracepoint_register_##_provider##___##_name(char *provider_name, char *event_name, \ |
| 224 | void (*func)(void), void *data) \ |
| 225 | { \ |
| 226 | lttng_ust_tracepoint_provider_register(provider_name, event_name, func, data, \ |
| 227 | lttng_ust_tracepoint_##_provider##___##_name.signature); \ |
| 228 | } \ |
| 229 | static inline \ |
| 230 | void lttng_ust_tracepoint_unregister_##_provider##___##_name(char *provider_name, char *event_name, \ |
| 231 | void (*func)(void), void *data) \ |
| 232 | lttng_ust_notrace; \ |
| 233 | static inline \ |
| 234 | void lttng_ust_tracepoint_unregister_##_provider##___##_name(char *provider_name, char *event_name, \ |
| 235 | void (*func)(void), void *data) \ |
| 236 | { \ |
| 237 | lttng_ust_tracepoint_provider_unregister(provider_name, event_name, func, data); \ |
| 238 | } |
| 239 | |
| 240 | /* |
| 241 | * Registration of tracepoint provider probe functions with |
| 242 | * lttng_ust_tracepoint_provider_register, unregistration with |
| 243 | * lttng_ust_tracepoint_provider_unregister. |
| 244 | */ |
| 245 | int lttng_ust_tracepoint_provider_register(const char *provider_name, const char *event_name, |
| 246 | void (*func)(void), void *data, const char *signature); |
| 247 | int lttng_ust_tracepoint_provider_unregister(const char *provider_name, const char *event_name, |
| 248 | void (*func)(void), void *data); |
| 249 | |
| 250 | /* |
| 251 | * Registration of tracepoint instrumentation modules with lttng_ust_tracepoint_module_register, |
| 252 | * unregistration with lttng_ust_tracepoint_module_unregister. |
| 253 | */ |
| 254 | int lttng_ust_tracepoint_module_register(struct lttng_ust_tracepoint * const *tracepoints_start, |
| 255 | int tracepoints_count); |
| 256 | int lttng_ust_tracepoint_module_unregister(struct lttng_ust_tracepoint * const *tracepoints_start); |
| 257 | |
| 258 | /* |
| 259 | * tracepoint dynamic linkage handling (callbacks). Hidden visibility: |
| 260 | * shared across objects in a module/main executable. |
| 261 | * |
| 262 | * IMPORTANT: this structure is part of the ABI between instrumented |
| 263 | * applications and UST. Fields need to be only added at the end, never |
| 264 | * reordered, never removed. |
| 265 | * |
| 266 | * The field @struct_size should be used to determine the size of the |
| 267 | * structure. It should be queried before using additional fields added |
| 268 | * at the end of the structure. |
| 269 | */ |
| 270 | struct lttng_ust_tracepoint_dlopen { |
| 271 | uint32_t struct_size; |
| 272 | |
| 273 | void *liblttngust_handle; |
| 274 | |
| 275 | int (*lttng_ust_tracepoint_module_register)(struct lttng_ust_tracepoint * const *tracepoints_start, |
| 276 | int tracepoints_count); |
| 277 | int (*lttng_ust_tracepoint_module_unregister)(struct lttng_ust_tracepoint * const *tracepoints_start); |
| 278 | void (*rcu_read_lock_sym)(void); |
| 279 | void (*rcu_read_unlock_sym)(void); |
| 280 | void *(*rcu_dereference_sym)(void *p); |
| 281 | |
| 282 | /* End of base ABI. Fields below should be used after checking struct_size. */ |
| 283 | }; |
| 284 | |
| 285 | extern struct lttng_ust_tracepoint_dlopen lttng_ust_tracepoint_dlopen; |
| 286 | extern struct lttng_ust_tracepoint_dlopen *lttng_ust_tracepoint_dlopen_ptr; |
| 287 | |
| 288 | /* |
| 289 | * These weak symbols, the constructor, and destructor take care of |
| 290 | * registering only _one_ instance of the tracepoints per shared-ojbect |
| 291 | * (or for the whole main program). |
| 292 | */ |
| 293 | int lttng_ust_tracepoint_registered |
| 294 | __attribute__((weak, visibility("hidden"))); |
| 295 | int lttng_ust_tracepoint_ptrs_registered |
| 296 | __attribute__((weak, visibility("hidden"))); |
| 297 | struct lttng_ust_tracepoint_dlopen lttng_ust_tracepoint_dlopen |
| 298 | __attribute__((weak, visibility("hidden"))) = { |
| 299 | .struct_size = sizeof(struct lttng_ust_tracepoint_dlopen), |
| 300 | }; |
| 301 | /* |
| 302 | * Deal with gcc O1 optimisation issues with weak hidden symbols. gcc |
| 303 | * 4.8 and prior does not have the same behavior for symbol scoping on |
| 304 | * 32-bit powerpc depending on the object size: symbols for objects of 8 |
| 305 | * bytes or less have the same address throughout a module, whereas they |
| 306 | * have different addresses between compile units for objects larger |
| 307 | * than 8 bytes. Add this pointer indirection to ensure that the symbol |
| 308 | * scoping match that of the other weak hidden symbols found in this |
| 309 | * header. |
| 310 | */ |
| 311 | struct lttng_ust_tracepoint_dlopen *lttng_ust_tracepoint_dlopen_ptr |
| 312 | __attribute__((weak, visibility("hidden"))); |
| 313 | |
| 314 | /* |
| 315 | * Tracepoint dynamic linkage handling (callbacks). Hidden visibility: shared |
| 316 | * across objects in a module/main executable. The callbacks are used to |
| 317 | * control and check if the destructors should be executed. |
| 318 | * |
| 319 | * IMPORTANT: this structure is part of the ABI between instrumented |
| 320 | * applications and UST. Fields need to be only added at the end, never |
| 321 | * reordered, never removed. |
| 322 | * |
| 323 | * The field @struct_size should be used to determine the size of the |
| 324 | * structure. It should be queried before using additional fields added |
| 325 | * at the end of the structure. |
| 326 | */ |
| 327 | struct lttng_ust_tracepoint_destructors_syms { |
| 328 | uint32_t struct_size; |
| 329 | |
| 330 | void (*tracepoint_disable_destructors)(void); |
| 331 | int (*tracepoint_get_destructors_state)(void); |
| 332 | |
| 333 | /* End of base ABI. Fields below should be used after checking struct_size. */ |
| 334 | }; |
| 335 | |
| 336 | extern struct lttng_ust_tracepoint_destructors_syms lttng_ust_tracepoint_destructors_syms; |
| 337 | extern struct lttng_ust_tracepoint_destructors_syms *lttng_ust_tracepoint_destructors_syms_ptr; |
| 338 | |
| 339 | struct lttng_ust_tracepoint_destructors_syms lttng_ust_tracepoint_destructors_syms |
| 340 | __attribute__((weak, visibility("hidden"))) = { |
| 341 | .struct_size = sizeof(struct lttng_ust_tracepoint_destructors_syms), |
| 342 | }; |
| 343 | struct lttng_ust_tracepoint_destructors_syms *lttng_ust_tracepoint_destructors_syms_ptr |
| 344 | __attribute__((weak, visibility("hidden"))); |
| 345 | |
| 346 | static inline void tracepoint_disable_destructors(void) |
| 347 | { |
| 348 | if (!lttng_ust_tracepoint_dlopen_ptr) |
| 349 | lttng_ust_tracepoint_dlopen_ptr = <tng_ust_tracepoint_dlopen; |
| 350 | if (!lttng_ust_tracepoint_destructors_syms_ptr) |
| 351 | lttng_ust_tracepoint_destructors_syms_ptr = <tng_ust_tracepoint_destructors_syms; |
| 352 | if (lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle |
| 353 | && lttng_ust_tracepoint_destructors_syms_ptr->tracepoint_disable_destructors) |
| 354 | lttng_ust_tracepoint_destructors_syms_ptr->tracepoint_disable_destructors(); |
| 355 | } |
| 356 | |
| 357 | #ifndef _LGPL_SOURCE |
| 358 | static inline void |
| 359 | lttng_ust_tracepoint__init_urcu_sym(void) |
| 360 | lttng_ust_notrace; |
| 361 | static inline void |
| 362 | lttng_ust_tracepoint__init_urcu_sym(void) |
| 363 | { |
| 364 | if (!lttng_ust_tracepoint_dlopen_ptr) |
| 365 | lttng_ust_tracepoint_dlopen_ptr = <tng_ust_tracepoint_dlopen; |
| 366 | /* |
| 367 | * Symbols below are needed by tracepoint call sites and probe |
| 368 | * providers. |
| 369 | */ |
| 370 | if (!lttng_ust_tracepoint_dlopen_ptr->rcu_read_lock_sym) |
| 371 | lttng_ust_tracepoint_dlopen_ptr->rcu_read_lock_sym = |
| 372 | URCU_FORCE_CAST(void (*)(void), |
| 373 | dlsym(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle, |
| 374 | "lttng_ust_tp_rcu_read_lock")); |
| 375 | if (!lttng_ust_tracepoint_dlopen_ptr->rcu_read_unlock_sym) |
| 376 | lttng_ust_tracepoint_dlopen_ptr->rcu_read_unlock_sym = |
| 377 | URCU_FORCE_CAST(void (*)(void), |
| 378 | dlsym(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle, |
| 379 | "lttng_ust_tp_rcu_read_unlock")); |
| 380 | if (!lttng_ust_tracepoint_dlopen_ptr->rcu_dereference_sym) |
| 381 | lttng_ust_tracepoint_dlopen_ptr->rcu_dereference_sym = |
| 382 | URCU_FORCE_CAST(void *(*)(void *p), |
| 383 | dlsym(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle, |
| 384 | "lttng_ust_tp_rcu_dereference_sym")); |
| 385 | } |
| 386 | #else |
| 387 | static inline void |
| 388 | lttng_ust_tracepoint__init_urcu_sym(void) |
| 389 | lttng_ust_notrace; |
| 390 | static inline void |
| 391 | lttng_ust_tracepoint__init_urcu_sym(void) |
| 392 | { |
| 393 | } |
| 394 | #endif |
| 395 | |
| 396 | /* |
| 397 | * Use getenv() directly and bypass lttng-ust helper functions |
| 398 | * because we may not have access to lttng-ust shared libraries. |
| 399 | */ |
| 400 | #ifdef LTTNG_UST_DEBUG |
| 401 | static inline |
| 402 | bool lttng_ust_tracepoint_logging_debug_enabled(void) |
| 403 | { |
| 404 | return true; |
| 405 | } |
| 406 | #else /* #ifdef LTTNG_UST_DEBUG */ |
| 407 | static inline |
| 408 | bool lttng_ust_tracepoint_logging_debug_enabled(void) |
| 409 | { |
| 410 | return getenv("LTTNG_UST_DEBUG"); |
| 411 | } |
| 412 | #endif /* #ifdef LTTNG_UST_DEBUG */ |
| 413 | |
| 414 | #ifdef LTTNG_UST_ABORT_ON_CRITICAL |
| 415 | static inline |
| 416 | bool lttng_ust_tracepoint_logging_abort_on_critical_enabled(void) |
| 417 | { |
| 418 | return true; |
| 419 | } |
| 420 | #else /* #ifdef LTTNG_UST_ABORT_ON_CRITICAL */ |
| 421 | static inline |
| 422 | bool lttng_ust_tracepoint_logging_abort_on_critical_enabled(void) |
| 423 | { |
| 424 | return getenv("LTTNG_UST_ABORT_ON_CRITICAL"); |
| 425 | } |
| 426 | #endif |
| 427 | |
| 428 | #define LTTNG_UST_TRACEPOINT_THIS_IP \ |
| 429 | ({ __label__ here; here: &&here; }) |
| 430 | |
| 431 | static void |
| 432 | lttng_ust_tracepoints_print_disabled_message(void) |
| 433 | { |
| 434 | if (lttng_ust_tracepoint_logging_debug_enabled()) |
| 435 | fprintf(stderr, "lttng-ust-tracepoint [%ld]: Critical: dlopen() failed to find '%s', tracepoints in this binary won't be registered. " |
| 436 | "(at addr=%p in %s() at " __FILE__ ":" lttng_ust_stringify(__LINE__) ")\n", |
| 437 | (long) getpid(), |
| 438 | LTTNG_UST_TRACEPOINT_LIB_SONAME, |
| 439 | LTTNG_UST_TRACEPOINT_THIS_IP, |
| 440 | __func__); |
| 441 | if (lttng_ust_tracepoint_logging_abort_on_critical_enabled()) |
| 442 | abort(); |
| 443 | } |
| 444 | |
| 445 | static void |
| 446 | lttng_ust__tracepoints__init(void) |
| 447 | lttng_ust_notrace __attribute__((constructor(LTTNG_UST_CONSTRUCTOR_PRIO))); |
| 448 | static void |
| 449 | lttng_ust__tracepoints__init(void) |
| 450 | { |
| 451 | if (lttng_ust_tracepoint_registered++) { |
| 452 | if (!lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle) |
| 453 | return; |
| 454 | lttng_ust_tracepoint__init_urcu_sym(); |
| 455 | return; |
| 456 | } |
| 457 | |
| 458 | if (!lttng_ust_tracepoint_dlopen_ptr) |
| 459 | lttng_ust_tracepoint_dlopen_ptr = <tng_ust_tracepoint_dlopen; |
| 460 | if (!lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle) |
| 461 | lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle = |
| 462 | dlopen(LTTNG_UST_TRACEPOINT_LIB_SONAME, RTLD_NOW | RTLD_GLOBAL); |
| 463 | if (!lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle) { |
| 464 | lttng_ust_tracepoints_print_disabled_message(); |
| 465 | return; |
| 466 | } |
| 467 | lttng_ust_tracepoint__init_urcu_sym(); |
| 468 | } |
| 469 | |
| 470 | static void |
| 471 | lttng_ust__tracepoints__destroy(void) |
| 472 | lttng_ust_notrace __attribute__((destructor(LTTNG_UST_CONSTRUCTOR_PRIO))); |
| 473 | static void |
| 474 | lttng_ust__tracepoints__destroy(void) |
| 475 | { |
| 476 | int ret; |
| 477 | |
| 478 | if (--lttng_ust_tracepoint_registered) |
| 479 | return; |
| 480 | if (!lttng_ust_tracepoint_dlopen_ptr) |
| 481 | lttng_ust_tracepoint_dlopen_ptr = <tng_ust_tracepoint_dlopen; |
| 482 | if (!lttng_ust_tracepoint_destructors_syms_ptr) |
| 483 | lttng_ust_tracepoint_destructors_syms_ptr = <tng_ust_tracepoint_destructors_syms; |
| 484 | if (!lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle) |
| 485 | return; |
| 486 | if (lttng_ust_tracepoint_ptrs_registered) |
| 487 | return; |
| 488 | /* |
| 489 | * Lookup if destructors must be executed using the new method. |
| 490 | */ |
| 491 | if (lttng_ust_tracepoint_destructors_syms_ptr->tracepoint_get_destructors_state |
| 492 | && !lttng_ust_tracepoint_destructors_syms_ptr->tracepoint_get_destructors_state()) { |
| 493 | /* |
| 494 | * The tracepoint_get_destructors_state symbol was found with |
| 495 | * dlsym but its returned value is 0 meaning that destructors |
| 496 | * must not be executed. |
| 497 | */ |
| 498 | return; |
| 499 | } |
| 500 | ret = dlclose(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle); |
| 501 | if (ret) { |
| 502 | fprintf(stderr, "Error (%d) in dlclose\n", ret); |
| 503 | abort(); |
| 504 | } |
| 505 | memset(lttng_ust_tracepoint_dlopen_ptr, 0, sizeof(*lttng_ust_tracepoint_dlopen_ptr)); |
| 506 | } |
| 507 | |
| 508 | #if LTTNG_UST_COMPAT_API(0) |
| 509 | # if defined(TRACEPOINT_DEFINE) && !defined(LTTNG_UST_TRACEPOINT_DEFINE) |
| 510 | # define LTTNG_UST_TRACEPOINT_DEFINE |
| 511 | # endif |
| 512 | #endif /* #if LTTNG_UST_COMPAT_API(0) */ |
| 513 | |
| 514 | #if LTTNG_UST_COMPAT_API(0) |
| 515 | #define tracepoint lttng_ust_tracepoint |
| 516 | #define do_tracepoint lttng_ust_do_tracepoint |
| 517 | #define tracepoint_enabled lttng_ust_tracepoint_enabled |
| 518 | #define TP_ARGS LTTNG_UST_TP_ARGS |
| 519 | #endif /* #if LTTNG_UST_COMPAT_API(0) */ |
| 520 | |
| 521 | #ifdef __cplusplus |
| 522 | } |
| 523 | #endif |
| 524 | |
| 525 | #endif /* _LTTNG_UST_TRACEPOINT_H */ |
| 526 | |
| 527 | /* The following declarations must be outside re-inclusion protection. */ |
| 528 | |
| 529 | #ifdef LTTNG_UST_TRACEPOINT_DEFINE |
| 530 | |
| 531 | #ifndef _LTTNG_UST_TRACEPOINT_DEFINE_ONCE |
| 532 | #define _LTTNG_UST_TRACEPOINT_DEFINE_ONCE |
| 533 | |
| 534 | #ifdef __cplusplus |
| 535 | extern "C" { |
| 536 | #endif |
| 537 | |
| 538 | /* |
| 539 | * These weak symbols, the constructor, and destructor take care of |
| 540 | * registering only _one_ instance of the tracepoints per shared-ojbect |
| 541 | * (or for the whole main program). |
| 542 | */ |
| 543 | extern struct lttng_ust_tracepoint * const __start_lttng_ust_tracepoints_ptrs[] |
| 544 | __attribute__((weak, visibility("hidden"))); |
| 545 | extern struct lttng_ust_tracepoint * const __stop_lttng_ust_tracepoints_ptrs[] |
| 546 | __attribute__((weak, visibility("hidden"))); |
| 547 | |
| 548 | /* |
| 549 | * When LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE is defined, we do not emit a |
| 550 | * unresolved symbol that requires the provider to be linked in. When |
| 551 | * LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE is not defined, we emit an |
| 552 | * unresolved symbol that depends on having the provider linked in, |
| 553 | * otherwise the linker complains. This deals with use of static |
| 554 | * libraries, ensuring that the linker does not remove the provider |
| 555 | * object from the executable. |
| 556 | */ |
| 557 | |
| 558 | #if LTTNG_UST_COMPAT_API(0) |
| 559 | # if defined(TRACEPOINT_PROBE_DYNAMIC_LINKAGE) && !defined(LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE) |
| 560 | # define LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE |
| 561 | # endif |
| 562 | #endif /* #if LTTNG_UST_COMPAT_API(0) */ |
| 563 | |
| 564 | #ifdef LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE |
| 565 | #define LTTNG_UST__TRACEPOINT_UNDEFINED_REF(provider) NULL |
| 566 | #else /* LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE */ |
| 567 | #define LTTNG_UST__TRACEPOINT_UNDEFINED_REF(provider) <tng_ust_tracepoint_provider_##provider |
| 568 | #endif /* LTTNG_UST_TRACEPOINT_PROBE_DYNAMIC_LINKAGE */ |
| 569 | |
| 570 | /* |
| 571 | * Note: to allow PIC code, we need to allow the linker to update the pointers |
| 572 | * in the lttng_ust_tracepoints_ptrs section. |
| 573 | * Therefore, this section is _not_ const (read-only). |
| 574 | */ |
| 575 | #define LTTNG_UST__TP_EXTRACT_STRING(...) #__VA_ARGS__ |
| 576 | |
| 577 | #undef LTTNG_UST__DEFINE_TRACEPOINT |
| 578 | #define LTTNG_UST__DEFINE_TRACEPOINT(_provider, _name, _args) \ |
| 579 | lttng_ust_tracepoint_validate_name_len(_provider, _name); \ |
| 580 | extern int lttng_ust_tracepoint_provider_##_provider \ |
| 581 | LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY; \ |
| 582 | static const char lttng_ust_tp_provider_strtab_##_provider##___##_name[] \ |
| 583 | __attribute__((section("lttng_ust_tracepoints_strings"))) = \ |
| 584 | #_provider; \ |
| 585 | static const char lttng_ust_tp_name_strtab_##_provider##___##_name[] \ |
| 586 | __attribute__((section("lttng_ust_tracepoints_strings"))) = \ |
| 587 | #_name; \ |
| 588 | struct lttng_ust_tracepoint lttng_ust_tracepoint_##_provider##___##_name \ |
| 589 | __attribute__((section("lttng_ust_tracepoints"))) \ |
| 590 | LTTNG_UST__TRACEPOINT_DEFINITION_VISIBILITY = { \ |
| 591 | sizeof(struct lttng_ust_tracepoint), \ |
| 592 | lttng_ust_tp_provider_strtab_##_provider##___##_name, \ |
| 593 | lttng_ust_tp_name_strtab_##_provider##___##_name, \ |
| 594 | 0, \ |
| 595 | NULL, \ |
| 596 | LTTNG_UST__TRACEPOINT_UNDEFINED_REF(_provider), \ |
| 597 | LTTNG_UST__TP_EXTRACT_STRING(_args), \ |
| 598 | }; \ |
| 599 | static struct lttng_ust_tracepoint * \ |
| 600 | lttng_ust_tracepoint_ptr_##_provider##___##_name \ |
| 601 | __attribute__((section("lttng_ust_tracepoints_ptrs"), used)) \ |
| 602 | __lttng_ust_variable_attribute_no_sanitize_address = \ |
| 603 | <tng_ust_tracepoint_##_provider##___##_name; |
| 604 | |
| 605 | static void |
| 606 | lttng_ust__tracepoints__ptrs_init(void) |
| 607 | lttng_ust_notrace __attribute__((constructor(LTTNG_UST_CONSTRUCTOR_PRIO))); |
| 608 | static void |
| 609 | lttng_ust__tracepoints__ptrs_init(void) |
| 610 | { |
| 611 | if (lttng_ust_tracepoint_ptrs_registered++) |
| 612 | return; |
| 613 | if (!lttng_ust_tracepoint_dlopen_ptr) |
| 614 | lttng_ust_tracepoint_dlopen_ptr = <tng_ust_tracepoint_dlopen; |
| 615 | if (!lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle) |
| 616 | lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle = |
| 617 | dlopen(LTTNG_UST_TRACEPOINT_LIB_SONAME, RTLD_NOW | RTLD_GLOBAL); |
| 618 | if (!lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle) { |
| 619 | lttng_ust_tracepoints_print_disabled_message(); |
| 620 | return; |
| 621 | } |
| 622 | if (!lttng_ust_tracepoint_destructors_syms_ptr) |
| 623 | lttng_ust_tracepoint_destructors_syms_ptr = <tng_ust_tracepoint_destructors_syms; |
| 624 | lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_module_register = |
| 625 | URCU_FORCE_CAST(int (*)(struct lttng_ust_tracepoint * const *, int), |
| 626 | dlsym(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle, |
| 627 | "lttng_ust_tracepoint_module_register")); |
| 628 | lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_module_unregister = |
| 629 | URCU_FORCE_CAST(int (*)(struct lttng_ust_tracepoint * const *), |
| 630 | dlsym(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle, |
| 631 | "lttng_ust_tracepoint_module_unregister")); |
| 632 | lttng_ust_tracepoint_destructors_syms_ptr->tracepoint_disable_destructors = |
| 633 | URCU_FORCE_CAST(void (*)(void), |
| 634 | dlsym(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle, |
| 635 | "lttng_ust_tp_disable_destructors")); |
| 636 | lttng_ust_tracepoint_destructors_syms_ptr->tracepoint_get_destructors_state = |
| 637 | URCU_FORCE_CAST(int (*)(void), |
| 638 | dlsym(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle, |
| 639 | "lttng_ust_tp_get_destructors_state")); |
| 640 | lttng_ust_tracepoint__init_urcu_sym(); |
| 641 | if (lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_module_register) { |
| 642 | lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_module_register(__start_lttng_ust_tracepoints_ptrs, |
| 643 | __stop_lttng_ust_tracepoints_ptrs - |
| 644 | __start_lttng_ust_tracepoints_ptrs); |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | static void |
| 649 | lttng_ust__tracepoints__ptrs_destroy(void) |
| 650 | lttng_ust_notrace __attribute__((destructor(LTTNG_UST_CONSTRUCTOR_PRIO))); |
| 651 | static void |
| 652 | lttng_ust__tracepoints__ptrs_destroy(void) |
| 653 | { |
| 654 | int ret; |
| 655 | |
| 656 | if (--lttng_ust_tracepoint_ptrs_registered) |
| 657 | return; |
| 658 | if (!lttng_ust_tracepoint_dlopen_ptr) |
| 659 | lttng_ust_tracepoint_dlopen_ptr = <tng_ust_tracepoint_dlopen; |
| 660 | if (!lttng_ust_tracepoint_destructors_syms_ptr) |
| 661 | lttng_ust_tracepoint_destructors_syms_ptr = <tng_ust_tracepoint_destructors_syms; |
| 662 | if (lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_module_unregister) |
| 663 | lttng_ust_tracepoint_dlopen_ptr->lttng_ust_tracepoint_module_unregister(__start_lttng_ust_tracepoints_ptrs); |
| 664 | if (lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle |
| 665 | && lttng_ust_tracepoint_destructors_syms_ptr->tracepoint_get_destructors_state |
| 666 | && lttng_ust_tracepoint_destructors_syms_ptr->tracepoint_get_destructors_state() |
| 667 | && !lttng_ust_tracepoint_ptrs_registered) { |
| 668 | ret = dlclose(lttng_ust_tracepoint_dlopen_ptr->liblttngust_handle); |
| 669 | if (ret) { |
| 670 | fprintf(stderr, "Error (%d) in dlclose\n", ret); |
| 671 | abort(); |
| 672 | } |
| 673 | memset(lttng_ust_tracepoint_dlopen_ptr, 0, sizeof(*lttng_ust_tracepoint_dlopen_ptr)); |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | #ifdef __cplusplus |
| 678 | } |
| 679 | #endif |
| 680 | |
| 681 | #endif /* _LTTNG_UST_TRACEPOINT_DEFINE_ONCE */ |
| 682 | |
| 683 | #else /* LTTNG_UST_TRACEPOINT_DEFINE */ |
| 684 | |
| 685 | #undef LTTNG_UST__DEFINE_TRACEPOINT |
| 686 | #define LTTNG_UST__DEFINE_TRACEPOINT(_provider, _name, _args) |
| 687 | |
| 688 | #endif /* #else LTTNG_UST_TRACEPOINT_DEFINE */ |
| 689 | |
| 690 | /* |
| 691 | * LTTNG_UST_TRACEPOINT_HIDDEN_DEFINITION: Define this before including |
| 692 | * a tracepoint instrumentation header to hide symbols associated with |
| 693 | * tracepoint module instrumentation. This is useful if all compile |
| 694 | * units using the lttng_ust_tracepoint(), |
| 695 | * lttng_ust_tracepoint_enabled() and lttng_ust_do_tracepoint() macros |
| 696 | * is within the same module as the compile unit including the |
| 697 | * tracepoint header after defining LTTNG_UST_TRACEPOINT_DEFINE. |
| 698 | */ |
| 699 | |
| 700 | #undef LTTNG_UST__TRACEPOINT_DEFINITION_VISIBILITY |
| 701 | #ifdef LTTNG_UST_TRACEPOINT_HIDDEN_DEFINITION |
| 702 | #define LTTNG_UST__TRACEPOINT_DEFINITION_VISIBILITY __attribute__((visibility("hidden"))) |
| 703 | #else |
| 704 | #define LTTNG_UST__TRACEPOINT_DEFINITION_VISIBILITY __attribute__((visibility("default"))) |
| 705 | #endif |
| 706 | |
| 707 | /* |
| 708 | * LTTNG_UST_TRACEPOINT_PROVIDER_HIDDEN_DEFINITION: Define this before |
| 709 | * including a tracepoint instrumentation header to hide symbols |
| 710 | * associated with the tracepoint provider. This is useful if the |
| 711 | * tracepoint definition (including the header after defining |
| 712 | * LTTNG_UST_TRACEPOINT_DEFINE) is in the same module as the provider |
| 713 | * (including the header after defining |
| 714 | * LTTNG_UST_TRACEPOINT_CREATE_PROBES). |
| 715 | */ |
| 716 | #undef LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY |
| 717 | #ifdef LTTNG_UST_TRACEPOINT_PROVIDER_HIDDEN_DEFINITION |
| 718 | #define LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY __attribute__((visibility("hidden"))) |
| 719 | #else |
| 720 | #define LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY __attribute__((visibility("default"))) |
| 721 | #endif |
| 722 | |
| 723 | #ifndef LTTNG_UST_TRACEPOINT_ENUM |
| 724 | |
| 725 | /* |
| 726 | * Tracepoint Enumerations |
| 727 | * |
| 728 | * The enumeration is a mapping between an integer, or range of integers, and |
| 729 | * a string. It can be used to have a more compact trace in cases where the |
| 730 | * possible values for a field are limited: |
| 731 | * |
| 732 | * An example: |
| 733 | * |
| 734 | * LTTNG_UST_TRACEPOINT_ENUM(someproject_component, enumname, |
| 735 | * LTTNG_UST_TP_ENUM_VALUES( |
| 736 | * lttng_ust_field_enum_value("even", 0) |
| 737 | * lttng_ust_field_enum_value("uneven", 1) |
| 738 | * lttng_ust_field_enum_range("twoto4", 2, 4) |
| 739 | * lttng_ust_field_enum_value("five", 5) |
| 740 | * ) |
| 741 | * ) |
| 742 | * |
| 743 | * Where "someproject_component" is the name of the component this enumeration |
| 744 | * belongs to and "enumname" identifies this enumeration. Inside the |
| 745 | * LTTNG_UST_TP_ENUM_VALUES macro is the actual mapping. Each string value can map |
| 746 | * to either a single value with lttng_ust_field_enum_value or a range of values |
| 747 | * with lttng_ust_field_enum_range. |
| 748 | * |
| 749 | * Enumeration ranges may overlap, but the behavior is implementation-defined, |
| 750 | * each trace reader will handle overlapping as it wishes. |
| 751 | * |
| 752 | * That enumeration can then be used in a field inside the TP_FIELD macro using |
| 753 | * the following line: |
| 754 | * |
| 755 | * lttng_ust_field_enum(someproject_component, enumname, enumtype, enumfield, enumval) |
| 756 | * |
| 757 | * Where "someproject_component" and "enumname" match those in the |
| 758 | * LTTNG_UST_TRACEPOINT_ENUM, "enumtype" is a signed or unsigned integer type |
| 759 | * backing the enumeration, "enumfield" is the name of the field and |
| 760 | * "enumval" is the value. |
| 761 | */ |
| 762 | |
| 763 | #define LTTNG_UST_TRACEPOINT_ENUM(provider, name, values) |
| 764 | |
| 765 | #if LTTNG_UST_COMPAT_API(0) |
| 766 | #define TRACEPOINT_ENUM LTTNG_UST_TRACEPOINT_ENUM |
| 767 | #endif /* #if LTTNG_UST_COMPAT_API(0) */ |
| 768 | |
| 769 | #endif /* #ifndef LTTNG_UST_TRACEPOINT_ENUM */ |
| 770 | |
| 771 | #ifndef LTTNG_UST_TRACEPOINT_EVENT |
| 772 | |
| 773 | /* |
| 774 | * How to use the LTTNG_UST_TRACEPOINT_EVENT macro: |
| 775 | * |
| 776 | * An example: |
| 777 | * |
| 778 | * LTTNG_UST_TRACEPOINT_EVENT(someproject_component, event_name, |
| 779 | * |
| 780 | * * LTTNG_UST_TP_ARGS takes from 0 to 10 "type, field_name" pairs * |
| 781 | * |
| 782 | * LTTNG_UST_TP_ARGS(int, arg0, void *, arg1, char *, string, size_t, strlen, |
| 783 | * long *, arg4, size_t, arg4_len), |
| 784 | * |
| 785 | * * LTTNG_UST_TP_FIELDS describes the event payload layout in the trace * |
| 786 | * |
| 787 | * LTTNG_UST_TP_FIELDS( |
| 788 | * * Integer, printed in base 10 * |
| 789 | * lttng_ust_field_integer(int, field_a, arg0) |
| 790 | * |
| 791 | * * Integer, printed with 0x base 16 * |
| 792 | * lttng_ust_field_integer_hex(unsigned long, field_d, arg1) |
| 793 | * |
| 794 | * * Enumeration * |
| 795 | * lttng_ust_field_enum(someproject_component, enum_name, int, field_e, arg0) |
| 796 | * |
| 797 | * * Array Sequence, printed as UTF8-encoded array of bytes * |
| 798 | * lttng_ust_field_array_text(char, field_b, string, FIXED_LEN) |
| 799 | * lttng_ust_field_sequence_text(char, field_c, string, size_t, strlen) |
| 800 | * |
| 801 | * * String, printed as UTF8-encoded string * |
| 802 | * lttng_ust_field_string(field_e, string) |
| 803 | * |
| 804 | * * Array sequence of signed integer values * |
| 805 | * lttng_ust_field_array(long, field_f, arg4, FIXED_LEN4) |
| 806 | * lttng_ust_field_sequence(long, field_g, arg4, size_t, arg4_len) |
| 807 | * ) |
| 808 | * ) |
| 809 | * |
| 810 | * More detailed explanation: |
| 811 | * |
| 812 | * The name of the tracepoint is expressed as a tuple with the provider |
| 813 | * and name arguments. |
| 814 | * |
| 815 | * The provider and name should be a proper C99 identifier. |
| 816 | * The "provider" and "name" MUST follow these rules to ensure no |
| 817 | * namespace clash occurs: |
| 818 | * |
| 819 | * For projects (applications and libraries) for which an entity |
| 820 | * specific to the project controls the source code and thus its |
| 821 | * tracepoints (typically with a scope larger than a single company): |
| 822 | * |
| 823 | * either: |
| 824 | * project_component, event |
| 825 | * or: |
| 826 | * project, event |
| 827 | * |
| 828 | * Where "project" is the name of the project, |
| 829 | * "component" is the name of the project component (which may |
| 830 | * include several levels of sub-components, e.g. |
| 831 | * ...component_subcomponent_...) where the tracepoint is located |
| 832 | * (optional), |
| 833 | * "event" is the name of the tracepoint event. |
| 834 | * |
| 835 | * For projects issued from a single company wishing to advertise that |
| 836 | * the company controls the source code and thus the tracepoints, the |
| 837 | * "com_" prefix should be used: |
| 838 | * |
| 839 | * either: |
| 840 | * com_company_project_component, event |
| 841 | * or: |
| 842 | * com_company_project, event |
| 843 | * |
| 844 | * Where "company" is the name of the company, |
| 845 | * "project" is the name of the project, |
| 846 | * "component" is the name of the project component (which may |
| 847 | * include several levels of sub-components, e.g. |
| 848 | * ...component_subcomponent_...) where the tracepoint is located |
| 849 | * (optional), |
| 850 | * "event" is the name of the tracepoint event. |
| 851 | * |
| 852 | * the provider:event identifier is limited to 127 characters. |
| 853 | */ |
| 854 | |
| 855 | #define LTTNG_UST_TRACEPOINT_EVENT(provider, name, args, fields) \ |
| 856 | LTTNG_UST__DECLARE_TRACEPOINT(provider, name, LTTNG_UST__TP_PARAMS(args)) \ |
| 857 | LTTNG_UST__DEFINE_TRACEPOINT(provider, name, LTTNG_UST__TP_PARAMS(args)) |
| 858 | |
| 859 | #define LTTNG_UST_TRACEPOINT_EVENT_CLASS(provider, name, args, fields) |
| 860 | |
| 861 | #define LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(template_provider, template_name, provider, name, args) \ |
| 862 | LTTNG_UST__DECLARE_TRACEPOINT(provider, name, LTTNG_UST__TP_PARAMS(args)) \ |
| 863 | LTTNG_UST__DEFINE_TRACEPOINT(provider, name, LTTNG_UST__TP_PARAMS(args)) |
| 864 | |
| 865 | #if LTTNG_UST_COMPAT_API(0) |
| 866 | #define TRACEPOINT_EVENT LTTNG_UST_TRACEPOINT_EVENT |
| 867 | #define TRACEPOINT_EVENT_CLASS LTTNG_UST_TRACEPOINT_EVENT_CLASS |
| 868 | #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, args) \ |
| 869 | LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(_provider, _template, \ |
| 870 | _provider, _name, LTTNG_UST__TP_PARAMS(args)) |
| 871 | |
| 872 | #endif /* #if LTTNG_UST_COMPAT_API(0) */ |
| 873 | |
| 874 | #endif /* #ifndef LTTNG_UST_TRACEPOINT_EVENT */ |
| 875 | |
| 876 | #ifndef LTTNG_UST_TRACEPOINT_LOGLEVEL |
| 877 | |
| 878 | /* |
| 879 | * Tracepoint Loglevels |
| 880 | * |
| 881 | * Typical use of these loglevels: |
| 882 | * |
| 883 | * The loglevels go from 0 to 14. Higher numbers imply the most |
| 884 | * verbosity (higher event throughput expected. |
| 885 | * |
| 886 | * Loglevels 0 through 6, and loglevel 14, match syslog(3) loglevels |
| 887 | * semantic. Loglevels 7 through 13 offer more fine-grained selection of |
| 888 | * debug information. |
| 889 | * |
| 890 | * LTTNG_UST_TRACEPOINT_LOGLEVEL_EMERG 0 |
| 891 | * system is unusable |
| 892 | * |
| 893 | * LTTNG_UST_TRACEPOINT_LOGLEVEL_ALERT 1 |
| 894 | * action must be taken immediately |
| 895 | * |
| 896 | * LTTNG_UST_TRACEPOINT_LOGLEVEL_CRIT 2 |
| 897 | * critical conditions |
| 898 | * |
| 899 | * LTTNG_UST_TRACEPOINT_LOGLEVEL_ERR 3 |
| 900 | * error conditions |
| 901 | * |
| 902 | * LTTNG_UST_TRACEPOINT_LOGLEVEL_WARNING 4 |
| 903 | * warning conditions |
| 904 | * |
| 905 | * LTTNG_UST_TRACEPOINT_LOGLEVEL_NOTICE 5 |
| 906 | * normal, but significant, condition |
| 907 | * |
| 908 | * LTTNG_UST_TRACEPOINT_LOGLEVEL_INFO 6 |
| 909 | * informational message |
| 910 | * |
| 911 | * LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_SYSTEM 7 |
| 912 | * debug information with system-level scope (set of programs) |
| 913 | * |
| 914 | * LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_PROGRAM 8 |
| 915 | * debug information with program-level scope (set of processes) |
| 916 | * |
| 917 | * LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_PROCESS 9 |
| 918 | * debug information with process-level scope (set of modules) |
| 919 | * |
| 920 | * LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_MODULE 10 |
| 921 | * debug information with module (executable/library) scope (set of units) |
| 922 | * |
| 923 | * LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_UNIT 11 |
| 924 | * debug information with compilation unit scope (set of functions) |
| 925 | * |
| 926 | * LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_FUNCTION 12 |
| 927 | * debug information with function-level scope |
| 928 | * |
| 929 | * LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_LINE 13 |
| 930 | * debug information with line-level scope (LTTNG_UST_TRACEPOINT_EVENT default) |
| 931 | * |
| 932 | * LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG 14 |
| 933 | * debug-level message |
| 934 | * |
| 935 | * Declare tracepoint loglevels for tracepoints. A LTTNG_UST_TRACEPOINT_EVENT |
| 936 | * should be declared prior to the the LTTNG_UST_TRACEPOINT_LOGLEVEL for a given |
| 937 | * tracepoint name. The first field is the provider name, the second |
| 938 | * field is the name of the tracepoint, the third field is the loglevel |
| 939 | * name. |
| 940 | * |
| 941 | * LTTNG_UST_TRACEPOINT_LOGLEVEL(< [com_company_]project[_component] >, < event >, |
| 942 | * < loglevel_name >) |
| 943 | * |
| 944 | * The LTTNG_UST_TRACEPOINT_PROVIDER must be already declared before declaring a |
| 945 | * LTTNG_UST_TRACEPOINT_LOGLEVEL. |
| 946 | */ |
| 947 | |
| 948 | enum { |
| 949 | LTTNG_UST_TRACEPOINT_LOGLEVEL_EMERG = 0, |
| 950 | LTTNG_UST_TRACEPOINT_LOGLEVEL_ALERT = 1, |
| 951 | LTTNG_UST_TRACEPOINT_LOGLEVEL_CRIT = 2, |
| 952 | LTTNG_UST_TRACEPOINT_LOGLEVEL_ERR = 3, |
| 953 | LTTNG_UST_TRACEPOINT_LOGLEVEL_WARNING = 4, |
| 954 | LTTNG_UST_TRACEPOINT_LOGLEVEL_NOTICE = 5, |
| 955 | LTTNG_UST_TRACEPOINT_LOGLEVEL_INFO = 6, |
| 956 | LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_SYSTEM = 7, |
| 957 | LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_PROGRAM = 8, |
| 958 | LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_PROCESS = 9, |
| 959 | LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_MODULE = 10, |
| 960 | LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_UNIT = 11, |
| 961 | LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_FUNCTION = 12, |
| 962 | LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_LINE = 13, |
| 963 | LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG = 14, |
| 964 | }; |
| 965 | |
| 966 | #define LTTNG_UST_TRACEPOINT_LOGLEVEL(provider, name, loglevel) |
| 967 | |
| 968 | #if LTTNG_UST_COMPAT_API(0) |
| 969 | #define TRACEPOINT_LOGLEVEL LTTNG_UST_TRACEPOINT_LOGLEVEL |
| 970 | |
| 971 | #define TRACE_EMERG LTTNG_UST_TRACEPOINT_LOGLEVEL_EMERG |
| 972 | #define TRACE_ALERT LTTNG_UST_TRACEPOINT_LOGLEVEL_ALERT |
| 973 | #define TRACE_CRIT LTTNG_UST_TRACEPOINT_LOGLEVEL_CRIT |
| 974 | #define TRACE_ERR LTTNG_UST_TRACEPOINT_LOGLEVEL_ERR |
| 975 | #define TRACE_WARNING LTTNG_UST_TRACEPOINT_LOGLEVEL_WARNING |
| 976 | #define TRACE_NOTICE LTTNG_UST_TRACEPOINT_LOGLEVEL_NOTICE |
| 977 | #define TRACE_INFO LTTNG_UST_TRACEPOINT_LOGLEVEL_INFO |
| 978 | #define TRACE_DEBUG_SYSTEM LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_SYSTEM |
| 979 | #define TRACE_DEBUG_PROGRAM LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_PROGRAM |
| 980 | #define TRACE_DEBUG_PROCESS LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_PROCESS |
| 981 | #define TRACE_DEBUG_MODULE LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_MODULE |
| 982 | #define TRACE_DEBUG_UNIT LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_UNIT |
| 983 | #define TRACE_DEBUG_FUNCTION LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_FUNCTION |
| 984 | #define TRACE_DEBUG_LINE LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG_LINE |
| 985 | #define TRACE_DEBUG LTTNG_UST_TRACEPOINT_LOGLEVEL_DEBUG |
| 986 | #endif |
| 987 | |
| 988 | #endif /* #ifndef LTTNG_UST_TRACEPOINT_LOGLEVEL */ |
| 989 | |
| 990 | #ifndef LTTNG_UST_TRACEPOINT_MODEL_EMF_URI |
| 991 | |
| 992 | #define LTTNG_UST_TRACEPOINT_MODEL_EMF_URI(provider, name, uri) |
| 993 | |
| 994 | #if LTTNG_UST_COMPAT_API(0) |
| 995 | #define TRACEPOINT_MODEL_EMF_URI LTTNG_UST_TRACEPOINT_MODEL_EMF_URI |
| 996 | #endif |
| 997 | |
| 998 | #endif /* #ifndef LTTNG_UST_TRACEPOINT_MODEL_EMF_URI */ |