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