Commit | Line | Data |
---|---|---|
1c196845 MJ |
1 | // SPDX-FileCopyrightText: 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
2 | // | |
3 | // SPDX-License-Identifier: MIT | |
1c324e59 | 4 | |
fb31eb73 | 5 | #include <stdint.h> |
1c324e59 | 6 | #include <stdio.h> |
7d381d6e | 7 | #include <stdlib.h> |
1c324e59 | 8 | #include <urcu/compiler.h> |
f488575f | 9 | #include <urcu/rculist.h> |
1c324e59 | 10 | #include <lttng/ust-events.h> |
0b4b8811 | 11 | #include <lttng/ust-ringbuffer-context.h> |
2eba8e39 | 12 | #include <lttng/ust-arch.h> |
a8909ba5 | 13 | #include <lttng/ust-compiler.h> |
000b8662 | 14 | #include <lttng/tracepoint.h> |
3208818b | 15 | #include <lttng/ust-endian.h> |
4849bc7a | 16 | #include <lttng/ust-api-compat.h> |
44c72f10 | 17 | #include <string.h> |
f3b06377 MD |
18 | #include <lttng/ust-api-compat.h> |
19 | ||
20 | #if LTTNG_UST_COMPAT_API(0) | |
21 | #define TP_FIELDS LTTNG_UST_TP_FIELDS | |
22 | ||
23 | #define ctf_integer lttng_ust_field_integer | |
24 | #define ctf_integer_hex lttng_ust_field_integer_hex | |
25 | #define ctf_integer_network lttng_ust_field_integer_network | |
26 | #define ctf_integer_network_hex lttng_ust_field_integer_network_hex | |
27 | #define ctf_integer_nowrite lttng_ust_field_integer_nowrite | |
28 | ||
29 | #define ctf_float lttng_ust_field_float | |
30 | #define ctf_float_nowrite lttng_ust_field_float_nowrite | |
31 | ||
32 | #define ctf_array lttng_ust_field_array | |
33 | #define ctf_array_hex lttng_ust_field_array_hex | |
34 | #define ctf_array_network lttng_ust_field_array_network | |
35 | #define ctf_array_network_hex lttng_ust_field_array_network_hex | |
36 | #define ctf_array_text lttng_ust_field_array_text | |
37 | #define ctf_array_nowrite lttng_ust_field_array_nowrite | |
38 | #define ctf_array_nowrite_hex lttng_ust_field_array_nowrite_hex | |
39 | #define ctf_array_network_nowrite lttng_ust_field_array_network_nowrite | |
40 | #define ctf_array_network_nowrite_hex lttng_ust_field_array_network_nowrite_hex | |
41 | #define ctf_array_text_nowrite lttng_ust_field_array_text_nowrite | |
42 | ||
43 | #define ctf_sequence lttng_ust_field_sequence | |
44 | #define ctf_sequence_hex lttng_ust_field_sequence_hex | |
45 | #define ctf_sequence_network lttng_ust_field_sequence_network | |
46 | #define ctf_sequence_network_hex lttng_ust_field_sequence_network_hex | |
47 | #define ctf_sequence_text lttng_ust_field_sequence_text | |
48 | #define ctf_sequence_nowrite lttng_ust_field_sequence_nowrite | |
49 | #define ctf_sequence_nowrite_hex lttng_ust_field_sequence_nowrite_hex | |
50 | #define ctf_sequence_network_nowrite lttng_ust_field_sequence_network_nowrite | |
51 | #define ctf_sequence_network_nowrite_hex lttng_ust_field_sequence_network_nowrite_hex | |
52 | #define ctf_sequence_text_nowrite lttng_ust_field_sequence_text_nowrite | |
53 | ||
54 | #define ctf_string lttng_ust_field_string | |
55 | #define ctf_string_nowrite lttng_ust_field_string_nowrite | |
56 | ||
57 | #define ctf_unused lttng_ust_field_unused | |
58 | #define ctf_unused_nowrite lttng_ust_field_unused_nowrite | |
59 | ||
60 | #define ctf_enum lttng_ust_field_enum | |
61 | #define ctf_enum_nowrite lttng_ust_field_enum_nowrite | |
62 | #define ctf_enum_value lttng_ust_field_enum_value | |
63 | #define ctf_enum_range lttng_ust_field_enum_range | |
64 | #define ctf_enum_auto lttng_ust_field_enum_auto | |
65 | #endif /* #if LTTNG_UST_COMPAT_API(0) */ | |
1c324e59 | 66 | |
ee0889a3 | 67 | #define LTTNG_UST__NULL_STRING "(null)" |
24a39530 | 68 | |
1c324e59 | 69 | /* |
7f2f82c3 | 70 | * LTTNG_UST_TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the |
1c324e59 MD |
71 | * same arguments and having the same field layout. |
72 | * | |
7f2f82c3 | 73 | * LTTNG_UST_TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with |
1c324e59 MD |
74 | * its own provider and name. It refers to a class (template). |
75 | * | |
7f2f82c3 | 76 | * LTTNG_UST_TRACEPOINT_EVENT declared both a class and an instance and does a |
1c324e59 MD |
77 | * direct mapping from the instance to the class. |
78 | */ | |
79 | ||
7f2f82c3 MJ |
80 | #undef LTTNG_UST_TRACEPOINT_EVENT |
81 | #define LTTNG_UST_TRACEPOINT_EVENT(_provider, _name, _args, _fields) \ | |
82 | LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, \ | |
6eddcb06 MJ |
83 | LTTNG_UST__TP_PARAMS(_args), \ |
84 | LTTNG_UST__TP_PARAMS(_fields)) \ | |
5b675300 | 85 | LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _name, _provider, _name, \ |
6eddcb06 | 86 | LTTNG_UST__TP_PARAMS(_args)) |
1c324e59 | 87 | |
7f2f82c3 MJ |
88 | #undef LTTNG_UST_TRACEPOINT_EVENT_CLASS |
89 | #define LTTNG_UST_TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
6eddcb06 | 90 | LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, LTTNG_UST__TP_PARAMS(_args), LTTNG_UST__TP_PARAMS(_fields)) |
f8021d08 | 91 | |
7f2f82c3 | 92 | #undef LTTNG_UST_TRACEPOINT_EVENT_INSTANCE |
5b675300 MD |
93 | #define LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \ |
94 | LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, LTTNG_UST__TP_PARAMS(_args)) | |
f8021d08 | 95 | |
1c324e59 | 96 | /* Helpers */ |
ca6ed78d | 97 | #define LTTNG_UST__TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) |
1c324e59 | 98 | |
1210ca90 | 99 | #define lttng_ust__tp_max_t(type, x, y) \ |
1c324e59 | 100 | ({ \ |
1210ca90 MJ |
101 | type lttng_ust__max1 = (x); \ |
102 | type lttng_ust__max2 = (y); \ | |
103 | lttng_ust__max1 > lttng_ust__max2 ? lttng_ust__max1: lttng_ust__max2; \ | |
1c324e59 MD |
104 | }) |
105 | ||
106 | /* | |
107 | * Stage 0 of tracepoint event generation. | |
108 | * | |
7f2f82c3 | 109 | * Check that each LTTNG_UST_TRACEPOINT_EVENT provider argument match the |
5b393d64 | 110 | * LTTNG_UST_TRACEPOINT_PROVIDER by creating dummy callbacks. |
1c324e59 MD |
111 | */ |
112 | ||
7f2f82c3 | 113 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
1c324e59 MD |
114 | #include <lttng/ust-tracepoint-event-reset.h> |
115 | ||
106ff4da | 116 | static inline |
5b393d64 | 117 | void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_mismatch_, LTTNG_UST_TRACEPOINT_PROVIDER)(void) |
106ff4da | 118 | lttng_ust_notrace; |
1c324e59 | 119 | static inline |
5b393d64 | 120 | void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_mismatch_, LTTNG_UST_TRACEPOINT_PROVIDER)(void) |
1c324e59 MD |
121 | { |
122 | } | |
123 | ||
7f2f82c3 MJ |
124 | #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS |
125 | #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
0274f7f2 | 126 | lttng_ust_tracepoint_provider_mismatch_##_provider(); |
1c324e59 | 127 | |
7f2f82c3 | 128 | #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE |
5b675300 | 129 | #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \ |
0274f7f2 | 130 | lttng_ust_tracepoint_provider_mismatch_##_provider(); |
1c324e59 | 131 | |
106ff4da | 132 | static inline |
5b393d64 | 133 | void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_, LTTNG_UST_TRACEPOINT_PROVIDER)(void) |
106ff4da | 134 | lttng_ust_notrace; |
e8bd1da7 | 135 | static inline |
5b393d64 | 136 | void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_, LTTNG_UST_TRACEPOINT_PROVIDER)(void) |
1c324e59 | 137 | { |
bb71a8ea | 138 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
1c324e59 MD |
139 | } |
140 | ||
f56cd1d5 MD |
141 | /* |
142 | * Stage 0.1 of tracepoint event generation. | |
143 | * | |
7f2f82c3 | 144 | * Check that each LTTNG_UST_TRACEPOINT_EVENT provider:name does not exceed the |
f56cd1d5 MD |
145 | * tracepoint name length limit. |
146 | */ | |
147 | ||
7f2f82c3 | 148 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
f56cd1d5 MD |
149 | #include <lttng/ust-tracepoint-event-reset.h> |
150 | ||
7f2f82c3 | 151 | #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE |
5b675300 | 152 | #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \ |
81b16412 | 153 | lttng_ust_tracepoint_validate_name_len(_provider, _name); |
f56cd1d5 | 154 | |
bb71a8ea | 155 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
f56cd1d5 | 156 | |
c75c0422 MD |
157 | /* |
158 | * Stage 0.2 of tracepoint event generation. | |
159 | * | |
160 | * Create dummy trace prototypes for each event class, and for each used | |
161 | * template. This will allow checking whether the prototypes from the | |
162 | * class and the instance using the class actually match. | |
163 | */ | |
164 | ||
7f2f82c3 | 165 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
c75c0422 MD |
166 | #include <lttng/ust-tracepoint-event-reset.h> |
167 | ||
cadfcbfc MJ |
168 | #undef LTTNG_UST_TP_ARGS |
169 | #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__ | |
c75c0422 | 170 | |
7f2f82c3 | 171 | #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE |
5b675300 MD |
172 | #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \ |
173 | void lttng_ust__event_template_proto___##_template_provider##___##_template_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)); | |
c75c0422 | 174 | |
7f2f82c3 MJ |
175 | #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS |
176 | #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
bfcc2759 | 177 | void lttng_ust__event_template_proto___##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)); |
c75c0422 | 178 | |
bb71a8ea | 179 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
c75c0422 | 180 | |
c785c634 MD |
181 | /* |
182 | * Stage 0.9 of tracepoint event generation | |
183 | * | |
184 | * Unfolding the enums | |
185 | */ | |
186 | #include <lttng/ust-tracepoint-event-reset.h> | |
187 | ||
188 | /* Enumeration entry (single value) */ | |
78684808 MJ |
189 | #undef lttng_ust_field_enum_value |
190 | #define lttng_ust_field_enum_value(_string, _value) \ | |
5defa774 | 191 | LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \ |
891d6b55 | 192 | .struct_size = sizeof(struct lttng_ust_enum_entry), \ |
a6f80644 | 193 | .start = { \ |
eae3c729 | 194 | .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \ |
a6f80644 | 195 | (long long) (_value) : (_value), \ |
eae3c729 | 196 | .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \ |
a6f80644 MD |
197 | }, \ |
198 | .end = { \ | |
eae3c729 | 199 | .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \ |
a6f80644 | 200 | (long long) (_value) : (_value), \ |
eae3c729 | 201 | .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \ |
a6f80644 MD |
202 | }, \ |
203 | .string = (_string), \ | |
891d6b55 | 204 | }), |
c785c634 MD |
205 | |
206 | /* Enumeration entry (range) */ | |
78684808 MJ |
207 | #undef lttng_ust_field_enum_range |
208 | #define lttng_ust_field_enum_range(_string, _range_start, _range_end) \ | |
5defa774 | 209 | LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \ |
891d6b55 | 210 | .struct_size = sizeof(struct lttng_ust_enum_entry), \ |
a6f80644 | 211 | .start = { \ |
eae3c729 | 212 | .value = lttng_ust_is_signed_type(__typeof__(_range_start)) ? \ |
a6f80644 | 213 | (long long) (_range_start) : (_range_start), \ |
eae3c729 | 214 | .signedness = lttng_ust_is_signed_type(__typeof__(_range_start)), \ |
a6f80644 MD |
215 | }, \ |
216 | .end = { \ | |
eae3c729 | 217 | .value = lttng_ust_is_signed_type(__typeof__(_range_end)) ? \ |
a6f80644 | 218 | (long long) (_range_end) : (_range_end), \ |
eae3c729 | 219 | .signedness = lttng_ust_is_signed_type(__typeof__(_range_end)), \ |
a6f80644 MD |
220 | }, \ |
221 | .string = (_string), \ | |
891d6b55 | 222 | }), |
c785c634 | 223 | |
3e762260 | 224 | /* Enumeration entry (automatic value; follows the rules of CTF) */ |
78684808 MJ |
225 | #undef lttng_ust_field_enum_auto |
226 | #define lttng_ust_field_enum_auto(_string) \ | |
5defa774 | 227 | LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \ |
891d6b55 | 228 | .struct_size = sizeof(struct lttng_ust_enum_entry), \ |
3e762260 PP |
229 | .start = { \ |
230 | .value = -1ULL, \ | |
231 | .signedness = 0, \ | |
232 | }, \ | |
233 | .end = { \ | |
234 | .value = -1ULL, \ | |
235 | .signedness = 0, \ | |
236 | }, \ | |
237 | .string = (_string), \ | |
1a37a873 | 238 | .options = LTTNG_UST_ENUM_ENTRY_OPTION_IS_AUTO, \ |
891d6b55 | 239 | }), |
3e762260 | 240 | |
4849bc7a MJ |
241 | #undef LTTNG_UST_TP_ENUM_VALUES |
242 | #define LTTNG_UST_TP_ENUM_VALUES(...) \ | |
c785c634 MD |
243 | __VA_ARGS__ |
244 | ||
4849bc7a MJ |
245 | #if LTTNG_UST_COMPAT_API(0) |
246 | # undef TP_ENUM_VALUES | |
247 | # define TP_ENUM_VALUES LTTNG_UST_TP_ENUM_VALUES | |
248 | #endif /* #if LTTNG_UST_COMPAT_API(0) */ | |
249 | ||
2ebf164b MJ |
250 | #undef LTTNG_UST_TRACEPOINT_ENUM |
251 | #define LTTNG_UST_TRACEPOINT_ENUM(_provider, _name, _values) \ | |
3d33ca1d | 252 | const struct lttng_ust_enum_entry * const __enum_values__##_provider##_##_name[] = { \ |
c785c634 | 253 | _values \ |
78684808 | 254 | lttng_ust_field_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \ |
c785c634 | 255 | }; |
bb71a8ea | 256 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
2df82195 | 257 | |
2e8e9740 OD |
258 | |
259 | /* | |
260 | * Stage 0.9.0 | |
261 | * Verifying sequence length types are of an unsigned type. | |
262 | */ | |
263 | ||
264 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ | |
265 | #include <lttng/ust-tracepoint-event-reset.h> | |
266 | #include <lttng/ust-tracepoint-event-write.h> | |
267 | #include <lttng/ust-tracepoint-event-nowrite.h> | |
268 | ||
269 | /* | |
270 | * Note that it is not possible to encode the length type as a C identifier, | |
271 | * since it can be multiple tokens. | |
272 | */ | |
273 | #undef lttng_ust__field_sequence_encoded | |
274 | #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, \ | |
275 | _length_type, _src_length, _encoding, _nowrite, \ | |
276 | _elem_type_base) \ | |
277 | lttng_ust_static_assert(!lttng_ust_is_signed_type(_length_type), \ | |
278 | "Length type " #_length_type " is not a unsigned integer type", \ | |
279 | Length_type_is_not_a_unsigned_integer_type); | |
280 | ||
281 | #undef LTTNG_UST_TP_FIELDS | |
282 | #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */ | |
283 | ||
284 | #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS | |
285 | #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
286 | _fields | |
287 | ||
288 | #include LTTNG_UST_TRACEPOINT_INCLUDE | |
289 | ||
f04f60a5 MD |
290 | #if defined(__cplusplus) |
291 | ||
2df82195 FD |
292 | /* |
293 | * Stage 0.9.1 | |
f04f60a5 MD |
294 | * Verifying array and sequence elements are of an integer or pointer |
295 | * type. | |
296 | * | |
297 | * This compile-time check is only enabled in C++, because the C | |
298 | * implementation of lttng_ust_is_pointer_type does not support opaque | |
299 | * pointer types. | |
2df82195 FD |
300 | */ |
301 | ||
7f2f82c3 | 302 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
2df82195 FD |
303 | #include <lttng/ust-tracepoint-event-reset.h> |
304 | #include <lttng/ust-tracepoint-event-write.h> | |
305 | #include <lttng/ust-tracepoint-event-nowrite.h> | |
306 | ||
10937ee5 MJ |
307 | #undef lttng_ust__field_array_encoded |
308 | #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, \ | |
2df82195 FD |
309 | _length, _encoding, _nowrite, \ |
310 | _elem_type_base) \ | |
10937ee5 | 311 | lttng_ust_field_array_element_type_is_supported(_type, _item); |
2df82195 | 312 | |
1d188af9 MJ |
313 | #undef lttng_ust__field_sequence_encoded |
314 | #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, \ | |
2df82195 FD |
315 | _length_type, _src_length, _encoding, _nowrite, \ |
316 | _elem_type_base) \ | |
10937ee5 | 317 | lttng_ust_field_array_element_type_is_supported(_type, _item); |
2df82195 | 318 | |
efa14d16 MJ |
319 | #undef LTTNG_UST_TP_FIELDS |
320 | #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */ | |
2df82195 | 321 | |
7f2f82c3 MJ |
322 | #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS |
323 | #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
2df82195 | 324 | _fields |
c785c634 | 325 | |
bb71a8ea | 326 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
c785c634 | 327 | |
f04f60a5 MD |
328 | #endif |
329 | ||
5b675300 MD |
330 | /* |
331 | * Stage 0.9.2 of tracepoint event generation. | |
332 | * | |
333 | * Create probe signature | |
334 | */ | |
335 | ||
336 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ | |
337 | #include <lttng/ust-tracepoint-event-reset.h> | |
338 | ||
339 | #undef LTTNG_UST_TP_ARGS | |
340 | #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__ | |
341 | ||
342 | #define LTTNG_UST__TP_EXTRACT_STRING2(...) #__VA_ARGS__ | |
343 | ||
344 | #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS | |
345 | #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
346 | static const char __tp_event_signature___##_provider##___##_name[] = \ | |
347 | LTTNG_UST__TP_EXTRACT_STRING2(_args); | |
348 | ||
349 | #include LTTNG_UST_TRACEPOINT_INCLUDE | |
350 | ||
351 | #undef LTTNG_UST__TP_EXTRACT_STRING2 | |
352 | ||
1c324e59 MD |
353 | /* |
354 | * Stage 1 of tracepoint event generation. | |
355 | * | |
5b675300 MD |
356 | * Create probe callback prototypes. |
357 | */ | |
358 | ||
359 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ | |
360 | #include <lttng/ust-tracepoint-event-reset.h> | |
361 | ||
362 | #undef LTTNG_UST_TP_ARGS | |
363 | #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__ | |
364 | ||
365 | #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS | |
366 | #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
367 | static void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)); | |
368 | ||
369 | #include LTTNG_UST_TRACEPOINT_INCLUDE | |
370 | ||
2e7160d2 MD |
371 | /* |
372 | * Stage 1.1 of tracepoint event generation. | |
373 | * | |
374 | * Declare toplevel descriptor for the whole probe. | |
375 | * Unlike C, C++ does not allow tentative definitions. Therefore, we | |
376 | * need to explicitly declare the variable with "extern", using hidden | |
377 | * visibility to keep this symbol from being exported to the global | |
378 | * symbol table. | |
379 | */ | |
380 | ||
381 | extern const struct lttng_ust_probe_desc LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___, LTTNG_UST_TRACEPOINT_PROVIDER) | |
382 | __attribute__((visibility("hidden"))); | |
383 | ||
5b675300 MD |
384 | /* |
385 | * Stage 2 of tracepoint event generation. | |
386 | * | |
1c324e59 MD |
387 | * Create event field type metadata section. |
388 | * Each event produce an array of fields. | |
389 | */ | |
390 | ||
7f2f82c3 | 391 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
1c324e59 | 392 | #include <lttng/ust-tracepoint-event-reset.h> |
4774c8f3 MD |
393 | #include <lttng/ust-tracepoint-event-write.h> |
394 | #include <lttng/ust-tracepoint-event-nowrite.h> | |
1c324e59 | 395 | |
b4064f28 MJ |
396 | #undef lttng_ust__field_integer_ext |
397 | #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ | |
5defa774 | 398 | LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \ |
25cff019 MD |
399 | .struct_size = sizeof(struct lttng_ust_event_field), \ |
400 | .name = #_item, \ | |
a084756d | 401 | .type = lttng_ust_type_integer_define(_type, _byte_order, _base), \ |
25cff019 MD |
402 | .nowrite = _nowrite, \ |
403 | .nofilter = 0, \ | |
404 | }), | |
1c324e59 | 405 | |
891226fc MJ |
406 | #undef lttng_ust__field_float |
407 | #define lttng_ust__field_float(_type, _item, _src, _nowrite) \ | |
5defa774 | 408 | LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \ |
25cff019 MD |
409 | .struct_size = sizeof(struct lttng_ust_event_field), \ |
410 | .name = #_item, \ | |
a084756d | 411 | .type = lttng_ust_type_float_define(_type), \ |
25cff019 MD |
412 | .nowrite = _nowrite, \ |
413 | .nofilter = 0, \ | |
414 | }), | |
1c324e59 | 415 | |
10937ee5 MJ |
416 | #undef lttng_ust__field_array_encoded |
417 | #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, \ | |
f3ec4cb5 MD |
418 | _length, _encoding, _nowrite, \ |
419 | _elem_type_base) \ | |
5defa774 | 420 | LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \ |
25cff019 MD |
421 | .struct_size = sizeof(struct lttng_ust_event_field), \ |
422 | .name = #_item, \ | |
5defa774 | 423 | .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_array, { \ |
a084756d MD |
424 | .parent = { \ |
425 | .type = lttng_ust_type_array, \ | |
426 | }, \ | |
427 | .struct_size = sizeof(struct lttng_ust_type_array), \ | |
428 | .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \ | |
429 | .length = _length, \ | |
430 | .alignment = 0, \ | |
431 | .encoding = lttng_ust_string_encoding_##_encoding, \ | |
432 | }), \ | |
25cff019 MD |
433 | .nowrite = _nowrite, \ |
434 | .nofilter = 0, \ | |
435 | }), | |
1c324e59 | 436 | |
1d188af9 MJ |
437 | #undef lttng_ust__field_sequence_encoded |
438 | #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, \ | |
f968510a PP |
439 | _length_type, _src_length, _encoding, _nowrite, \ |
440 | _elem_type_base) \ | |
5defa774 | 441 | LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \ |
25cff019 MD |
442 | .struct_size = sizeof(struct lttng_ust_event_field), \ |
443 | .name = "_" #_item "_length", \ | |
baa8acf3 | 444 | .type = lttng_ust_type_integer_define(_length_type, LTTNG_UST_BYTE_ORDER, 10), \ |
25cff019 MD |
445 | .nowrite = _nowrite, \ |
446 | .nofilter = 1, \ | |
447 | }), \ | |
5defa774 | 448 | LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \ |
25cff019 MD |
449 | .struct_size = sizeof(struct lttng_ust_event_field), \ |
450 | .name = #_item, \ | |
5defa774 | 451 | .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_sequence, { \ |
a084756d MD |
452 | .parent = { \ |
453 | .type = lttng_ust_type_sequence, \ | |
1c324e59 | 454 | }, \ |
a084756d | 455 | .struct_size = sizeof(struct lttng_ust_type_sequence), \ |
28db0827 | 456 | .length_name = NULL, /* Use previous field. */ \ |
a084756d MD |
457 | .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \ |
458 | .alignment = 0, \ | |
459 | .encoding = lttng_ust_string_encoding_##_encoding, \ | |
460 | }), \ | |
25cff019 MD |
461 | .nowrite = _nowrite, \ |
462 | .nofilter = 0, \ | |
463 | }), | |
1c324e59 | 464 | |
3202f63a MJ |
465 | #undef lttng_ust__field_string |
466 | #define lttng_ust__field_string(_item, _src, _nowrite) \ | |
5defa774 | 467 | LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \ |
25cff019 MD |
468 | .struct_size = sizeof(struct lttng_ust_event_field), \ |
469 | .name = #_item, \ | |
5defa774 | 470 | .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_string, { \ |
a084756d MD |
471 | .parent = { \ |
472 | .type = lttng_ust_type_string, \ | |
46d52200 | 473 | }, \ |
a084756d MD |
474 | .struct_size = sizeof(struct lttng_ust_type_string), \ |
475 | .encoding = lttng_ust_string_encoding_UTF8, \ | |
476 | }), \ | |
25cff019 MD |
477 | .nowrite = _nowrite, \ |
478 | .nofilter = 0, \ | |
479 | }), | |
1c324e59 | 480 | |
ddde62ca MJ |
481 | #undef lttng_ust__field_unused |
482 | #define lttng_ust__field_unused(_src) | |
5152f6df | 483 | |
78684808 MJ |
484 | #undef lttng_ust__field_enum |
485 | #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \ | |
5defa774 | 486 | LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \ |
25cff019 | 487 | .struct_size = sizeof(struct lttng_ust_event_field), \ |
c785c634 | 488 | .name = #_item, \ |
5defa774 | 489 | .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_enum, { \ |
a084756d MD |
490 | .parent = { \ |
491 | .type = lttng_ust_type_enum, \ | |
c785c634 | 492 | }, \ |
a084756d MD |
493 | .struct_size = sizeof(struct lttng_ust_type_enum), \ |
494 | .desc = &__enum_##_provider##_##_name, \ | |
baa8acf3 | 495 | .container_type = lttng_ust_type_integer_define(_type, LTTNG_UST_BYTE_ORDER, 10), \ |
a084756d | 496 | }), \ |
c785c634 | 497 | .nowrite = _nowrite, \ |
25cff019 MD |
498 | .nofilter = 0, \ |
499 | }), | |
c785c634 | 500 | |
efa14d16 MJ |
501 | #undef LTTNG_UST_TP_FIELDS |
502 | #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */ | |
1c324e59 | 503 | |
7f2f82c3 MJ |
504 | #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS |
505 | #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
bfcc2759 | 506 | static const struct lttng_ust_event_field * const lttng_ust__event_fields___##_provider##___##_name[] = { \ |
1c324e59 | 507 | _fields \ |
b4064f28 | 508 | lttng_ust_field_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \ |
5b675300 MD |
509 | }; \ |
510 | static const struct lttng_ust_tracepoint_class lttng_ust__event_class___##_provider##___##_name = { \ | |
511 | .struct_size = sizeof(struct lttng_ust_tracepoint_class), \ | |
512 | .fields = lttng_ust__event_fields___##_provider##___##_name, \ | |
513 | .nr_fields = LTTNG_UST__TP_ARRAY_SIZE(lttng_ust__event_fields___##_provider##___##_name) - 1, \ | |
514 | .probe_callback = (void (*)(void)) <tng_ust__event_probe__##_provider##___##_name, \ | |
515 | .signature = __tp_event_signature___##_provider##___##_name, \ | |
2e7160d2 | 516 | .probe_desc = <tng_ust__probe_desc___##_provider, \ |
1c324e59 MD |
517 | }; |
518 | ||
2ebf164b MJ |
519 | #undef LTTNG_UST_TRACEPOINT_ENUM |
520 | #define LTTNG_UST_TRACEPOINT_ENUM(_provider, _name, _values) \ | |
4e48b5d2 | 521 | static const struct lttng_ust_enum_desc __enum_##_provider##_##_name = { \ |
a084756d | 522 | .struct_size = sizeof(struct lttng_ust_enum_desc), \ |
c785c634 MD |
523 | .name = #_provider "_" #_name, \ |
524 | .entries = __enum_values__##_provider##_##_name, \ | |
ca6ed78d | 525 | .nr_entries = LTTNG_UST__TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \ |
2e7160d2 | 526 | .probe_desc = <tng_ust__probe_desc___##_provider, \ |
c785c634 MD |
527 | }; |
528 | ||
bb71a8ea | 529 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
1c324e59 | 530 | |
1c324e59 | 531 | /* |
c785c634 | 532 | * Stage 3.0 of tracepoint event generation. |
1c324e59 | 533 | * |
1c324e59 MD |
534 | * Create static inline function that calculates event size. |
535 | */ | |
536 | ||
7f2f82c3 | 537 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
1c324e59 | 538 | #include <lttng/ust-tracepoint-event-reset.h> |
4774c8f3 | 539 | #include <lttng/ust-tracepoint-event-write.h> |
1c324e59 | 540 | |
b4064f28 MJ |
541 | #undef lttng_ust__field_integer_ext |
542 | #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ | |
5152f6df MJ |
543 | if (0) \ |
544 | (void) (_src); /* Unused */ \ | |
b5457df5 | 545 | __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \ |
1c324e59 MD |
546 | __event_len += sizeof(_type); |
547 | ||
891226fc MJ |
548 | #undef lttng_ust__field_float |
549 | #define lttng_ust__field_float(_type, _item, _src, _nowrite) \ | |
5152f6df MJ |
550 | if (0) \ |
551 | (void) (_src); /* Unused */ \ | |
b5457df5 | 552 | __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \ |
1c324e59 MD |
553 | __event_len += sizeof(_type); |
554 | ||
10937ee5 MJ |
555 | #undef lttng_ust__field_array_encoded |
556 | #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \ | |
f3ec4cb5 | 557 | _nowrite, _elem_type_base) \ |
5152f6df MJ |
558 | if (0) \ |
559 | (void) (_src); /* Unused */ \ | |
b5457df5 | 560 | __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \ |
1c324e59 MD |
561 | __event_len += sizeof(_type) * (_length); |
562 | ||
1d188af9 MJ |
563 | #undef lttng_ust__field_sequence_encoded |
564 | #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \ | |
f968510a | 565 | _src_length, _encoding, _nowrite, _elem_type_base) \ |
5152f6df MJ |
566 | if (0) \ |
567 | (void) (_src); /* Unused */ \ | |
b5457df5 | 568 | __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_length_type)); \ |
1c324e59 | 569 | __event_len += sizeof(_length_type); \ |
b5457df5 | 570 | __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \ |
1c324e59 MD |
571 | __dynamic_len[__dynamic_len_idx] = (_src_length); \ |
572 | __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \ | |
573 | __dynamic_len_idx++; | |
574 | ||
3202f63a MJ |
575 | #undef lttng_ust__field_string |
576 | #define lttng_ust__field_string(_item, _src, _nowrite) \ | |
24a39530 | 577 | __event_len += __dynamic_len[__dynamic_len_idx++] = \ |
ee0889a3 | 578 | strlen((_src) ? (_src) : LTTNG_UST__NULL_STRING) + 1; |
1c324e59 | 579 | |
ddde62ca MJ |
580 | #undef lttng_ust__field_unused |
581 | #define lttng_ust__field_unused(_src) \ | |
5152f6df MJ |
582 | if (0) \ |
583 | (void) (_src); /* Unused */ | |
584 | ||
78684808 MJ |
585 | #undef lttng_ust__field_enum |
586 | #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \ | |
b4064f28 | 587 | lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite) |
c785c634 | 588 | |
cadfcbfc MJ |
589 | #undef LTTNG_UST_TP_ARGS |
590 | #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__ | |
1c324e59 | 591 | |
efa14d16 MJ |
592 | #undef LTTNG_UST_TP_FIELDS |
593 | #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ | |
1c324e59 | 594 | |
7f2f82c3 MJ |
595 | #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS |
596 | #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
106ff4da | 597 | static inline \ |
bfcc2759 | 598 | size_t lttng_ust__event_get_size__##_provider##___##_name(size_t *__dynamic_len, LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \ |
106ff4da | 599 | lttng_ust_notrace; \ |
a8909ba5 | 600 | static inline \ |
bfcc2759 | 601 | size_t lttng_ust__event_get_size__##_provider##___##_name( \ |
5152f6df | 602 | size_t *__dynamic_len __attribute__((__unused__)), \ |
6eddcb06 | 603 | LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \ |
1c324e59 MD |
604 | { \ |
605 | size_t __event_len = 0; \ | |
5152f6df | 606 | unsigned int __dynamic_len_idx __attribute__((__unused__)) = 0; \ |
1c324e59 MD |
607 | \ |
608 | if (0) \ | |
5152f6df MJ |
609 | (void) __tp_data; /* don't warn if unused */ \ |
610 | \ | |
1c324e59 MD |
611 | _fields \ |
612 | return __event_len; \ | |
613 | } | |
614 | ||
bb71a8ea | 615 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
1c324e59 | 616 | |
1ddfd641 MD |
617 | /* |
618 | * Stage 3.1 of tracepoint event generation. | |
619 | * | |
620 | * Create static inline function that layout the filter stack data. | |
4774c8f3 | 621 | * We make both write and nowrite data available to the filter. |
1ddfd641 MD |
622 | */ |
623 | ||
7f2f82c3 | 624 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
1ddfd641 | 625 | #include <lttng/ust-tracepoint-event-reset.h> |
4774c8f3 MD |
626 | #include <lttng/ust-tracepoint-event-write.h> |
627 | #include <lttng/ust-tracepoint-event-nowrite.h> | |
1ddfd641 | 628 | |
b4064f28 MJ |
629 | #undef lttng_ust__field_integer_ext |
630 | #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ | |
eae3c729 | 631 | if (lttng_ust_is_signed_type(_type)) { \ |
3ebeea0d MD |
632 | int64_t __ctf_tmp_int64; \ |
633 | switch (sizeof(_type)) { \ | |
634 | case 1: \ | |
635 | { \ | |
636 | union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \ | |
637 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ | |
638 | break; \ | |
639 | } \ | |
640 | case 2: \ | |
641 | { \ | |
642 | union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \ | |
baa8acf3 MJ |
643 | if (_byte_order != LTTNG_UST_BYTE_ORDER) \ |
644 | __tmp.v = lttng_ust_bswap_16(__tmp.v); \ | |
3ebeea0d MD |
645 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ |
646 | break; \ | |
647 | } \ | |
648 | case 4: \ | |
649 | { \ | |
650 | union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \ | |
baa8acf3 MJ |
651 | if (_byte_order != LTTNG_UST_BYTE_ORDER) \ |
652 | __tmp.v = lttng_ust_bswap_32(__tmp.v); \ | |
3ebeea0d MD |
653 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ |
654 | break; \ | |
655 | } \ | |
656 | case 8: \ | |
657 | { \ | |
658 | union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \ | |
baa8acf3 MJ |
659 | if (_byte_order != LTTNG_UST_BYTE_ORDER) \ |
660 | __tmp.v = lttng_ust_bswap_64(__tmp.v); \ | |
3ebeea0d MD |
661 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ |
662 | break; \ | |
663 | } \ | |
664 | default: \ | |
665 | abort(); \ | |
666 | }; \ | |
fa099471 MD |
667 | memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \ |
668 | } else { \ | |
3ebeea0d MD |
669 | uint64_t __ctf_tmp_uint64; \ |
670 | switch (sizeof(_type)) { \ | |
671 | case 1: \ | |
672 | { \ | |
673 | union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \ | |
674 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ | |
675 | break; \ | |
676 | } \ | |
677 | case 2: \ | |
678 | { \ | |
679 | union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \ | |
baa8acf3 MJ |
680 | if (_byte_order != LTTNG_UST_BYTE_ORDER) \ |
681 | __tmp.v = lttng_ust_bswap_16(__tmp.v); \ | |
3ebeea0d MD |
682 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ |
683 | break; \ | |
684 | } \ | |
685 | case 4: \ | |
686 | { \ | |
687 | union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \ | |
baa8acf3 MJ |
688 | if (_byte_order != LTTNG_UST_BYTE_ORDER) \ |
689 | __tmp.v = lttng_ust_bswap_32(__tmp.v); \ | |
3ebeea0d MD |
690 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ |
691 | break; \ | |
692 | } \ | |
693 | case 8: \ | |
694 | { \ | |
695 | union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \ | |
baa8acf3 MJ |
696 | if (_byte_order != LTTNG_UST_BYTE_ORDER) \ |
697 | __tmp.v = lttng_ust_bswap_64(__tmp.v); \ | |
3ebeea0d MD |
698 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ |
699 | break; \ | |
700 | } \ | |
701 | default: \ | |
702 | abort(); \ | |
703 | }; \ | |
fa099471 MD |
704 | memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \ |
705 | } \ | |
1ddfd641 MD |
706 | __stack_data += sizeof(int64_t); |
707 | ||
891226fc MJ |
708 | #undef lttng_ust__field_float |
709 | #define lttng_ust__field_float(_type, _item, _src, _nowrite) \ | |
fa099471 MD |
710 | { \ |
711 | double __ctf_tmp_double = (double) (_type) (_src); \ | |
712 | memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \ | |
713 | __stack_data += sizeof(double); \ | |
714 | } | |
1ddfd641 | 715 | |
10937ee5 MJ |
716 | #undef lttng_ust__field_array_encoded |
717 | #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \ | |
f3ec4cb5 | 718 | _encoding, _nowrite, _elem_type_base) \ |
fa099471 MD |
719 | { \ |
720 | unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \ | |
59034aab | 721 | const void *__ctf_tmp_ptr = (_src); \ |
fa099471 MD |
722 | memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \ |
723 | __stack_data += sizeof(unsigned long); \ | |
b1239ad6 MD |
724 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \ |
725 | __stack_data += sizeof(void *); \ | |
fa099471 | 726 | } |
1ddfd641 | 727 | |
1d188af9 MJ |
728 | #undef lttng_ust__field_sequence_encoded |
729 | #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \ | |
f968510a | 730 | _src_length, _encoding, _nowrite, _elem_type_base) \ |
fa099471 MD |
731 | { \ |
732 | unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \ | |
59034aab | 733 | const void *__ctf_tmp_ptr = (_src); \ |
fa099471 MD |
734 | memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \ |
735 | __stack_data += sizeof(unsigned long); \ | |
b1239ad6 MD |
736 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \ |
737 | __stack_data += sizeof(void *); \ | |
fa099471 | 738 | } |
1ddfd641 | 739 | |
3202f63a MJ |
740 | #undef lttng_ust__field_string |
741 | #define lttng_ust__field_string(_item, _src, _nowrite) \ | |
fa099471 | 742 | { \ |
24a39530 | 743 | const void *__ctf_tmp_ptr = \ |
ee0889a3 | 744 | ((_src) ? (_src) : LTTNG_UST__NULL_STRING); \ |
b1239ad6 MD |
745 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \ |
746 | __stack_data += sizeof(void *); \ | |
fa099471 | 747 | } |
1ddfd641 | 748 | |
ddde62ca MJ |
749 | #undef lttng_ust__field_unused |
750 | #define lttng_ust__field_unused(_src) \ | |
5152f6df MJ |
751 | if (0) \ |
752 | (void) (_src); | |
753 | ||
78684808 MJ |
754 | #undef lttng_ust__field_enum |
755 | #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \ | |
b4064f28 | 756 | lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite) |
c785c634 | 757 | |
cadfcbfc MJ |
758 | #undef LTTNG_UST_TP_ARGS |
759 | #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__ | |
1ddfd641 | 760 | |
efa14d16 MJ |
761 | #undef LTTNG_UST_TP_FIELDS |
762 | #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ | |
1ddfd641 | 763 | |
7f2f82c3 MJ |
764 | #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS |
765 | #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
1ddfd641 | 766 | static inline \ |
bfcc2759 | 767 | void lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(char *__stack_data,\ |
6eddcb06 | 768 | LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \ |
1ddfd641 | 769 | { \ |
5152f6df MJ |
770 | if (0) { \ |
771 | (void) __tp_data; /* don't warn if unused */ \ | |
772 | (void) __stack_data; /* don't warn if unused */ \ | |
773 | } \ | |
774 | \ | |
1ddfd641 MD |
775 | _fields \ |
776 | } | |
777 | ||
bb71a8ea | 778 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
1ddfd641 | 779 | |
1c324e59 | 780 | /* |
df854e41 | 781 | * Stage 4 of tracepoint event generation. |
1c324e59 MD |
782 | * |
783 | * Create static inline function that calculates event payload alignment. | |
784 | */ | |
785 | ||
7f2f82c3 | 786 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
1c324e59 | 787 | #include <lttng/ust-tracepoint-event-reset.h> |
4774c8f3 | 788 | #include <lttng/ust-tracepoint-event-write.h> |
1c324e59 | 789 | |
b4064f28 MJ |
790 | #undef lttng_ust__field_integer_ext |
791 | #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ | |
5152f6df MJ |
792 | if (0) \ |
793 | (void) (_src); /* Unused */ \ | |
26376e52 | 794 | __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type)); |
1c324e59 | 795 | |
891226fc MJ |
796 | #undef lttng_ust__field_float |
797 | #define lttng_ust__field_float(_type, _item, _src, _nowrite) \ | |
5152f6df MJ |
798 | if (0) \ |
799 | (void) (_src); /* Unused */ \ | |
26376e52 | 800 | __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type)); |
1c324e59 | 801 | |
10937ee5 MJ |
802 | #undef lttng_ust__field_array_encoded |
803 | #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \ | |
f3ec4cb5 | 804 | _encoding, _nowrite, _elem_type_base) \ |
5152f6df MJ |
805 | if (0) \ |
806 | (void) (_src); /* Unused */ \ | |
26376e52 | 807 | __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type)); |
1c324e59 | 808 | |
1d188af9 MJ |
809 | #undef lttng_ust__field_sequence_encoded |
810 | #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \ | |
f968510a | 811 | _src_length, _encoding, _nowrite, _elem_type_base) \ |
5152f6df MJ |
812 | if (0) \ |
813 | (void) (_src); /* Unused */ \ | |
814 | if (0) \ | |
815 | (void) (_src_length); /* Unused */ \ | |
26376e52 MD |
816 | __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_length_type)); \ |
817 | __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type)); | |
1c324e59 | 818 | |
3202f63a MJ |
819 | #undef lttng_ust__field_string |
820 | #define lttng_ust__field_string(_item, _src, _nowrite) \ | |
5152f6df MJ |
821 | if (0) \ |
822 | (void) (_src); /* Unused */ | |
823 | ||
ddde62ca MJ |
824 | #undef lttng_ust__field_unused |
825 | #define lttng_ust__field_unused(_src) \ | |
5152f6df MJ |
826 | if (0) \ |
827 | (void) (_src); /* Unused */ | |
1c324e59 | 828 | |
78684808 MJ |
829 | #undef lttng_ust__field_enum |
830 | #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \ | |
b4064f28 | 831 | lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite) |
c785c634 | 832 | |
cadfcbfc MJ |
833 | #undef LTTNG_UST_TP_ARGS |
834 | #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__ | |
1c324e59 | 835 | |
efa14d16 MJ |
836 | #undef LTTNG_UST_TP_FIELDS |
837 | #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ | |
1c324e59 | 838 | |
7f2f82c3 MJ |
839 | #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS |
840 | #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
106ff4da | 841 | static inline \ |
bfcc2759 | 842 | size_t lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(_args)) \ |
106ff4da | 843 | lttng_ust_notrace; \ |
1c324e59 | 844 | static inline \ |
bfcc2759 | 845 | size_t lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(_args)) \ |
1c324e59 | 846 | { \ |
26376e52 | 847 | size_t __event_align = 1; \ |
1c324e59 | 848 | _fields \ |
26376e52 | 849 | return __event_align; \ |
1c324e59 MD |
850 | } |
851 | ||
bb71a8ea | 852 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
1c324e59 MD |
853 | |
854 | ||
855 | /* | |
df854e41 | 856 | * Stage 5 of tracepoint event generation. |
1c324e59 MD |
857 | * |
858 | * Create the probe function. This function calls event size calculation | |
859 | * and writes event data into the buffer. | |
860 | */ | |
861 | ||
7f2f82c3 | 862 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
1c324e59 | 863 | #include <lttng/ust-tracepoint-event-reset.h> |
4774c8f3 | 864 | #include <lttng/ust-tracepoint-event-write.h> |
1c324e59 | 865 | |
b4064f28 MJ |
866 | #undef lttng_ust__field_integer_ext |
867 | #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ | |
1c324e59 MD |
868 | { \ |
869 | _type __tmp = (_src); \ | |
8936b6c0 | 870 | __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\ |
1c324e59 MD |
871 | } |
872 | ||
891226fc MJ |
873 | #undef lttng_ust__field_float |
874 | #define lttng_ust__field_float(_type, _item, _src, _nowrite) \ | |
1c324e59 MD |
875 | { \ |
876 | _type __tmp = (_src); \ | |
8936b6c0 | 877 | __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\ |
1c324e59 MD |
878 | } |
879 | ||
10937ee5 MJ |
880 | #undef lttng_ust__field_array_encoded |
881 | #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \ | |
f3ec4cb5 | 882 | _encoding, _nowrite, _elem_type_base) \ |
27927814 | 883 | if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \ |
8936b6c0 | 884 | __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length), lttng_ust_rb_alignof(_type)); \ |
27927814 | 885 | else \ |
1f41dc0a | 886 | __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), _length); |
1c324e59 | 887 | |
1d188af9 MJ |
888 | #undef lttng_ust__field_sequence_encoded |
889 | #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \ | |
f968510a | 890 | _src_length, _encoding, _nowrite, _elem_type_base) \ |
1c324e59 | 891 | { \ |
d71b57b9 | 892 | _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \ |
8936b6c0 | 893 | __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type), lttng_ust_rb_alignof(_length_type));\ |
1c324e59 | 894 | } \ |
27927814 MD |
895 | if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \ |
896 | __chan->ops->event_write(&__ctx, _src, \ | |
bae1f483 | 897 | sizeof(_type) * lttng_ust__get_dynamic_len(dest), lttng_ust_rb_alignof(_type)); \ |
27927814 | 898 | else \ |
bae1f483 | 899 | __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), lttng_ust__get_dynamic_len(dest)); \ |
1c324e59 | 900 | |
3202f63a MJ |
901 | #undef lttng_ust__field_string |
902 | #define lttng_ust__field_string(_item, _src, _nowrite) \ | |
24a39530 PP |
903 | { \ |
904 | const char *__ctf_tmp_string = \ | |
ee0889a3 | 905 | ((_src) ? (_src) : LTTNG_UST__NULL_STRING); \ |
f9ec4a97 | 906 | __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \ |
bae1f483 | 907 | lttng_ust__get_dynamic_len(dest)); \ |
24a39530 PP |
908 | } |
909 | ||
ddde62ca MJ |
910 | #undef lttng_ust__field_unused |
911 | #define lttng_ust__field_unused(_src) | |
1c324e59 | 912 | |
78684808 MJ |
913 | #undef lttng_ust__field_enum |
914 | #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \ | |
b4064f28 | 915 | lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite) |
c785c634 | 916 | |
1c324e59 | 917 | /* Beware: this get len actually consumes the len value */ |
bae1f483 MJ |
918 | #undef lttng_ust__get_dynamic_len |
919 | #define lttng_ust__get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++] | |
1c324e59 | 920 | |
cadfcbfc MJ |
921 | #undef LTTNG_UST_TP_ARGS |
922 | #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__ | |
1c324e59 | 923 | |
efa14d16 MJ |
924 | #undef LTTNG_UST_TP_FIELDS |
925 | #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ | |
1c324e59 | 926 | |
95c25348 PW |
927 | /* |
928 | * For state dump, check that "session" argument (mandatory) matches the | |
929 | * session this event belongs to. Ensures that we write state dump data only | |
930 | * into the started session, not into all sessions. | |
931 | */ | |
91fe3e13 MJ |
932 | #undef LTTNG_UST__TP_SESSION_CHECK |
933 | #ifdef LTTNG_UST_TP_SESSION_CHECK | |
934 | #define LTTNG_UST__TP_SESSION_CHECK(session, csession) (session == csession) | |
95c25348 | 935 | #else /* TP_SESSION_CHECK */ |
91fe3e13 | 936 | #define LTTNG_UST__TP_SESSION_CHECK(session, csession) 1 |
95c25348 PW |
937 | #endif /* TP_SESSION_CHECK */ |
938 | ||
97904b41 MD |
939 | /* |
940 | * Use of __builtin_return_address(0) sometimes seems to cause stack | |
941 | * corruption on 32-bit PowerPC. Disable this feature on that | |
942 | * architecture for now by always using the NULL value for the ip | |
943 | * context. | |
944 | */ | |
c28c4a88 MJ |
945 | #undef LTTNG_UST__TP_IP_PARAM |
946 | ||
947 | #ifdef LTTNG_UST_TP_IP_PARAM | |
948 | #define LTTNG_UST__TP_IP_PARAM(x) (x) | |
5dadb547 | 949 | #else /* TP_IP_PARAM */ |
97904b41 | 950 | |
2eba8e39 | 951 | #if defined(LTTNG_UST_ARCH_PPC) && !defined(LTTNG_UST_ARCH_PPC64) |
c28c4a88 | 952 | #define LTTNG_UST__TP_IP_PARAM(x) NULL |
2eba8e39 | 953 | #else |
c28c4a88 | 954 | #define LTTNG_UST__TP_IP_PARAM(x) __builtin_return_address(0) |
2eba8e39 | 955 | #endif |
97904b41 | 956 | |
5dadb547 MD |
957 | #endif /* TP_IP_PARAM */ |
958 | ||
1ddfd641 MD |
959 | /* |
960 | * Using twice size for filter stack data to hold size and pointer for | |
961 | * each field (worse case). For integers, max size required is 64-bit. | |
962 | * Same for double-precision floats. Those fit within | |
963 | * 2*sizeof(unsigned long) for all supported architectures. | |
61ce3223 | 964 | * Perform UNION (||) of filter runtime list. |
1ddfd641 | 965 | */ |
7f2f82c3 | 966 | #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS |
b2e37d27 | 967 | #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ |
106ff4da | 968 | static \ |
b2e37d27 | 969 | void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \ |
106ff4da | 970 | lttng_ust_notrace; \ |
a8909ba5 | 971 | static \ |
b2e37d27 | 972 | void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \ |
1c324e59 | 973 | { \ |
ba99fbe2 | 974 | struct lttng_ust_event_common *__event = (struct lttng_ust_event_common *) __tp_data; \ |
1c324e59 | 975 | size_t __dynamic_len_idx = 0; \ |
bfcc2759 | 976 | const size_t __num_fields = LTTNG_UST__TP_ARRAY_SIZE(lttng_ust__event_fields___##_provider##___##_name) - 1; \ |
b2e37d27 | 977 | struct lttng_ust_probe_ctx __probe_ctx; \ |
d71b57b9 | 978 | union { \ |
75026e9f | 979 | size_t __dynamic_len[__num_fields]; \ |
ba99fbe2 | 980 | char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \ |
d71b57b9 | 981 | } __stackvar; \ |
1c324e59 | 982 | int __ret; \ |
a2e4d05e | 983 | bool __interpreter_stack_prepared = false; \ |
1c324e59 MD |
984 | \ |
985 | if (0) \ | |
986 | (void) __dynamic_len_idx; /* don't warn if unused */ \ | |
ba99fbe2 MD |
987 | switch (__event->type) { \ |
988 | case LTTNG_UST_EVENT_TYPE_RECORDER: \ | |
989 | { \ | |
26376e52 MD |
990 | struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \ |
991 | struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \ | |
e7bc0ef6 | 992 | struct lttng_ust_channel_common *__chan_common = __chan->parent; \ |
ba99fbe2 | 993 | \ |
b2e37d27 | 994 | if (!LTTNG_UST__TP_SESSION_CHECK(session, __chan_common->session)) \ |
ba99fbe2 | 995 | return; \ |
e7bc0ef6 | 996 | if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->session->active))) \ |
ba99fbe2 | 997 | return; \ |
e7bc0ef6 | 998 | if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->enabled))) \ |
ba99fbe2 MD |
999 | return; \ |
1000 | break; \ | |
1001 | } \ | |
1002 | case LTTNG_UST_EVENT_TYPE_NOTIFIER: \ | |
1003 | break; \ | |
1004 | } \ | |
1005 | if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \ | |
1c324e59 | 1006 | return; \ |
b2e37d27 | 1007 | if (caa_unlikely(!LTTNG_UST_TP_RCU_LINK_TEST())) \ |
1b436e01 | 1008 | return; \ |
b2e37d27 MD |
1009 | __probe_ctx.struct_size = sizeof(struct lttng_ust_probe_ctx); \ |
1010 | __probe_ctx.ip = LTTNG_UST__TP_IP_PARAM(LTTNG_UST_TP_IP_PARAM); \ | |
1011 | if (caa_unlikely(CMM_ACCESS_ONCE(__event->eval_filter))) { \ | |
bfcc2759 | 1012 | lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \ |
b2e37d27 | 1013 | LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \ |
a2e4d05e | 1014 | __interpreter_stack_prepared = true; \ |
b2e37d27 MD |
1015 | if (caa_likely(__event->run_filter(__event, \ |
1016 | __stackvar.__interpreter_stack_data, &__probe_ctx, NULL) != LTTNG_UST_EVENT_FILTER_ACCEPT)) \ | |
61ce3223 | 1017 | return; \ |
1ddfd641 | 1018 | } \ |
ba99fbe2 MD |
1019 | switch (__event->type) { \ |
1020 | case LTTNG_UST_EVENT_TYPE_RECORDER: \ | |
1021 | { \ | |
26376e52 MD |
1022 | size_t __event_len, __event_align; \ |
1023 | struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \ | |
1024 | struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \ | |
b2e37d27 | 1025 | struct lttng_ust_ring_buffer_ctx __ctx; \ |
ba99fbe2 | 1026 | \ |
bfcc2759 | 1027 | __event_len = lttng_ust__event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \ |
6eddcb06 | 1028 | LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \ |
26376e52 MD |
1029 | __event_align = lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_VAR(_args)); \ |
1030 | lttng_ust_ring_buffer_ctx_init(&__ctx, __event_recorder, __event_len, __event_align, \ | |
b2e37d27 | 1031 | &__probe_ctx); \ |
8936b6c0 | 1032 | __ret = __chan->ops->event_reserve(&__ctx); \ |
ba99fbe2 MD |
1033 | if (__ret < 0) \ |
1034 | return; \ | |
1035 | _fields \ | |
1036 | __chan->ops->event_commit(&__ctx); \ | |
1037 | break; \ | |
1038 | } \ | |
1039 | case LTTNG_UST_EVENT_TYPE_NOTIFIER: \ | |
1040 | { \ | |
26376e52 | 1041 | struct lttng_ust_event_notifier *__event_notifier = (struct lttng_ust_event_notifier *) __event->child; \ |
a2e4d05e MD |
1042 | struct lttng_ust_notification_ctx __notif_ctx; \ |
1043 | \ | |
1044 | __notif_ctx.struct_size = sizeof(struct lttng_ust_notification_ctx); \ | |
26376e52 | 1045 | __notif_ctx.eval_capture = CMM_ACCESS_ONCE(__event_notifier->eval_capture); \ |
ba99fbe2 | 1046 | \ |
a2e4d05e | 1047 | if (caa_unlikely(!__interpreter_stack_prepared && __notif_ctx.eval_capture)) \ |
bfcc2759 | 1048 | lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \ |
b2e37d27 | 1049 | LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \ |
ba99fbe2 | 1050 | \ |
26376e52 | 1051 | __event_notifier->notification_send(__event_notifier, \ |
a2e4d05e | 1052 | __stackvar.__interpreter_stack_data, \ |
b2e37d27 | 1053 | &__probe_ctx, \ |
a2e4d05e | 1054 | &__notif_ctx); \ |
ba99fbe2 MD |
1055 | break; \ |
1056 | } \ | |
1057 | } \ | |
1c324e59 MD |
1058 | } |
1059 | ||
bb71a8ea | 1060 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
1c324e59 | 1061 | |
bae1f483 | 1062 | #undef lttng_ust__get_dynamic_len |
1c324e59 | 1063 | |
05ceaafd | 1064 | /* |
882a56d7 | 1065 | * Stage 6 of tracepoint event generation. |
1c324e59 | 1066 | * |
df854e41 MD |
1067 | * Tracepoint loglevel mapping definition generation. We generate a |
1068 | * symbol for each mapping for a provider/event to ensure at most a 1 to | |
1069 | * 1 mapping between events and loglevels. If the symbol is repeated, | |
1070 | * the compiler will complain. | |
05ceaafd MD |
1071 | */ |
1072 | ||
7f2f82c3 | 1073 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
05ceaafd MD |
1074 | #include <lttng/ust-tracepoint-event-reset.h> |
1075 | ||
4ea4f80e MD |
1076 | /* |
1077 | * Declare _loglevel___##__provider##___##__name as non-static, with | |
1078 | * hidden visibility for c++ handling of weakref. We do a weakref to the | |
1079 | * symbol in a later stage, which requires that the symbol is not | |
1080 | * mangled. | |
1081 | */ | |
1082 | #ifdef __cplusplus | |
fc6d7bef | 1083 | #define LTTNG_UST_TP_EXTERN_C extern "C" |
4ea4f80e | 1084 | #else |
fc6d7bef | 1085 | #define LTTNG_UST_TP_EXTERN_C |
4ea4f80e MD |
1086 | #endif |
1087 | ||
612e9ce4 MJ |
1088 | #undef LTTNG_UST_TRACEPOINT_LOGLEVEL |
1089 | #define LTTNG_UST_TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \ | |
3d33ca1d MD |
1090 | static const int _loglevel_value___##__provider##___##__name = __loglevel; \ |
1091 | LTTNG_UST_TP_EXTERN_C const int * const _loglevel___##__provider##___##__name \ | |
1092 | __attribute__((visibility("hidden"))) = \ | |
457a6b58 | 1093 | &_loglevel_value___##__provider##___##__name; |
df854e41 | 1094 | |
bb71a8ea | 1095 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
df854e41 | 1096 | |
fc6d7bef | 1097 | #undef LTTNG_UST_TP_EXTERN_C |
4ea4f80e | 1098 | |
6ddc916d MD |
1099 | /* |
1100 | * Stage 6.1 of tracepoint event generation. | |
1101 | * | |
1102 | * Tracepoint UML URI info. | |
1103 | */ | |
1104 | ||
7f2f82c3 | 1105 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
6ddc916d MD |
1106 | #include <lttng/ust-tracepoint-event-reset.h> |
1107 | ||
4ea4f80e MD |
1108 | /* |
1109 | * Declare _model_emf_uri___##__provider##___##__name as non-static, | |
1110 | * with hidden visibility for c++ handling of weakref. We do a weakref | |
1111 | * to the symbol in a later stage, which requires that the symbol is not | |
1112 | * mangled. | |
1113 | */ | |
1114 | #ifdef __cplusplus | |
fc6d7bef | 1115 | #define LTTNG_UST_TP_EXTERN_C extern "C" |
4ea4f80e | 1116 | #else |
fc6d7bef | 1117 | #define LTTNG_UST_TP_EXTERN_C |
4ea4f80e MD |
1118 | #endif |
1119 | ||
dbcc2f92 MJ |
1120 | #undef LTTNG_UST_TRACEPOINT_MODEL_EMF_URI |
1121 | #define LTTNG_UST_TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \ | |
3d33ca1d | 1122 | LTTNG_UST_TP_EXTERN_C const char * const _model_emf_uri___##__provider##___##__name \ |
082802f9 | 1123 | __attribute__((visibility("hidden"))) = __uri; \ |
6ddc916d | 1124 | |
bb71a8ea | 1125 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
6ddc916d | 1126 | |
fc6d7bef | 1127 | #undef LTTNG_UST_TP_EXTERN_C |
4ea4f80e | 1128 | |
5b4c6da4 MD |
1129 | /* |
1130 | * Stage 7.0 of tracepoint event generation. | |
1131 | * | |
df854e41 | 1132 | * Create events description structures. We use a weakref because |
3d33ca1d | 1133 | * loglevels are optional. If not declared, the event will point to |
df854e41 | 1134 | * a loglevel that contains NULL. |
3d33ca1d MD |
1135 | * |
1136 | * C++ requires that const objects have a user-declared default | |
1137 | * constructor. However, in both C++ and C, weakref cannot be | |
1138 | * initialized because it causes the weakref attribute to be ignored. | |
1139 | * Therefore, the loglevel and model_emf_uri pointers are not const | |
1140 | * to ensure C++ compilers default-initialize them. | |
df854e41 MD |
1141 | */ |
1142 | ||
7f2f82c3 | 1143 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
df854e41 MD |
1144 | #include <lttng/ust-tracepoint-event-reset.h> |
1145 | ||
7f2f82c3 | 1146 | #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE |
5b675300 | 1147 | #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \ |
882a56d7 MD |
1148 | static const int * \ |
1149 | __ref_loglevel___##_provider##___##_name \ | |
1150 | __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \ | |
6ddc916d MD |
1151 | static const char * \ |
1152 | __ref_model_emf_uri___##_provider##___##_name \ | |
1153 | __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\ | |
bfcc2759 | 1154 | static const struct lttng_ust_event_desc lttng_ust__event_desc___##_provider##_##_name = { \ |
dc11f93f | 1155 | .struct_size = sizeof(struct lttng_ust_event_desc), \ |
5b4c6da4 | 1156 | .event_name = #_name, \ |
c9201081 | 1157 | .probe_desc = <tng_ust__probe_desc___##_provider, \ |
5b675300 | 1158 | .tp_class = <tng_ust__event_class___##_template_provider##___##_template_name, \ |
882a56d7 | 1159 | .loglevel = &__ref_loglevel___##_provider##___##_name, \ |
dc11f93f | 1160 | .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \ |
df854e41 MD |
1161 | }; |
1162 | ||
bb71a8ea | 1163 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
05ceaafd | 1164 | |
df854e41 | 1165 | /* |
2e7160d2 | 1166 | * Stage 7.1 of tracepoint event generation. |
df854e41 MD |
1167 | * |
1168 | * Create array of events. | |
1169 | */ | |
1170 | ||
7f2f82c3 | 1171 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
df854e41 MD |
1172 | #include <lttng/ust-tracepoint-event-reset.h> |
1173 | ||
7f2f82c3 | 1174 | #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE |
5b675300 | 1175 | #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \ |
bfcc2759 | 1176 | <tng_ust__event_desc___##_provider##_##_name, |
df854e41 | 1177 | |
0997899b | 1178 | static const struct lttng_ust_event_desc * const LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__provider_event_desc___, LTTNG_UST_TRACEPOINT_PROVIDER)[] = { |
bb71a8ea | 1179 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
1c80c909 | 1180 | NULL, /* Dummy, C99 forbids 0-len array. */ |
05ceaafd MD |
1181 | }; |
1182 | ||
df854e41 | 1183 | |
05ceaafd | 1184 | /* |
882a56d7 | 1185 | * Stage 8 of tracepoint event generation. |
05ceaafd MD |
1186 | * |
1187 | * Create a toplevel descriptor for the whole probe. | |
1188 | */ | |
1189 | ||
c9201081 | 1190 | const struct lttng_ust_probe_desc LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___, LTTNG_UST_TRACEPOINT_PROVIDER) = { |
dc11f93f | 1191 | .struct_size = sizeof(struct lttng_ust_probe_desc), |
061fc37a | 1192 | .provider_name = lttng_ust__tp_stringify(LTTNG_UST_TRACEPOINT_PROVIDER), |
0997899b MD |
1193 | .event_desc = LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__provider_event_desc___, LTTNG_UST_TRACEPOINT_PROVIDER), |
1194 | .nr_events = LTTNG_UST__TP_ARRAY_SIZE(LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__provider_event_desc___, LTTNG_UST_TRACEPOINT_PROVIDER)) - 1, | |
71d31690 MD |
1195 | .major = LTTNG_UST_PROVIDER_MAJOR, |
1196 | .minor = LTTNG_UST_PROVIDER_MINOR, | |
05ceaafd MD |
1197 | }; |
1198 | ||
03221919 | 1199 | static int LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___, LTTNG_UST_TRACEPOINT_PROVIDER); |
f082dde9 | 1200 | static struct lttng_ust_registered_probe *LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER); |
f0cc794d | 1201 | |
05ceaafd | 1202 | /* |
882a56d7 | 1203 | * Stage 9 of tracepoint event generation. |
05ceaafd | 1204 | * |
1c324e59 | 1205 | * Register/unregister probes at module load/unload. |
628e1d81 MD |
1206 | * |
1207 | * Generate the constructor as an externally visible symbol for use when | |
1208 | * linking the probe statically. | |
f0cc794d MD |
1209 | * |
1210 | * Register refcount is protected by libc dynamic loader mutex. | |
05bfa3dc JG |
1211 | * |
1212 | * Note that when building this code as C++, the definition of constructors | |
1213 | * and destructors invoking the registration and unregistration functions | |
1214 | * must be performed _after_ the initialization of the probes. | |
1215 | * | |
1216 | * This is because we rely on the order of initialization of static variables | |
1217 | * and anonymous namespaces (their order of declaration) to ensure probes are | |
1218 | * fully initialized, see | |
1219 | * https://en.cppreference.com/w/cpp/language/initialization. This is especially | |
1220 | * important when LTTNG_UST_ALLOCATE_COMPOUND_LITERAL_ON_HEAP is defined as | |
1221 | * compound literals are then dynamically initialized. | |
1c324e59 MD |
1222 | */ |
1223 | ||
7f2f82c3 | 1224 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
1c324e59 | 1225 | #include <lttng/ust-tracepoint-event-reset.h> |
05bfa3dc | 1226 | |
465a0d04 | 1227 | static void |
05bfa3dc | 1228 | LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__, LTTNG_UST_TRACEPOINT_PROVIDER)(void) lttng_ust_notrace; |
a8909ba5 | 1229 | static void |
11bce056 | 1230 | LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__, LTTNG_UST_TRACEPOINT_PROVIDER)(void) |
1c324e59 | 1231 | { |
4e48b5d2 | 1232 | struct lttng_ust_registered_probe *reg_probe; |
1c324e59 | 1233 | |
03221919 | 1234 | if (LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___, |
5b393d64 | 1235 | LTTNG_UST_TRACEPOINT_PROVIDER)++) { |
f0cc794d MD |
1236 | return; |
1237 | } | |
e8bd1da7 | 1238 | /* |
5b393d64 | 1239 | * lttng_ust_tracepoint_provider_check_ ## LTTNG_UST_TRACEPOINT_PROVIDER() is a |
e8bd1da7 MD |
1240 | * static inline function that ensures every probe PROVIDER |
1241 | * argument match the provider within which they appear. It | |
1242 | * calls empty static inline functions, and therefore has no | |
1243 | * runtime effect. However, if it detects an error, a linker | |
1244 | * error will appear. | |
1245 | */ | |
5b393d64 | 1246 | LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_, LTTNG_UST_TRACEPOINT_PROVIDER)(); |
f082dde9 | 1247 | assert(!LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER)); |
c9201081 | 1248 | reg_probe = lttng_ust_probe_register(<TNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___, LTTNG_UST_TRACEPOINT_PROVIDER)); |
4e48b5d2 MD |
1249 | if (!reg_probe) { |
1250 | fprintf(stderr, "LTTng-UST: Error while registering tracepoint probe.\n"); | |
7d381d6e MD |
1251 | abort(); |
1252 | } | |
f082dde9 | 1253 | LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER) = reg_probe; |
1c324e59 MD |
1254 | } |
1255 | ||
c589eca2 | 1256 | static void |
05bfa3dc | 1257 | LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__, LTTNG_UST_TRACEPOINT_PROVIDER)(void) lttng_ust_notrace; |
a8909ba5 | 1258 | static void |
638ce920 | 1259 | LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__, LTTNG_UST_TRACEPOINT_PROVIDER)(void) |
1c324e59 | 1260 | { |
03221919 | 1261 | if (--LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___, |
5b393d64 | 1262 | LTTNG_UST_TRACEPOINT_PROVIDER)) { |
f0cc794d MD |
1263 | return; |
1264 | } | |
f082dde9 MJ |
1265 | lttng_ust_probe_unregister(LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER)); |
1266 | LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER) = NULL; | |
1c324e59 | 1267 | } |
628e1d81 | 1268 | |
05bfa3dc JG |
1269 | LTTNG_UST_DECLARE_CONSTRUCTOR_DESTRUCTOR( |
1270 | LTTNG_UST_TRACEPOINT_PROVIDER, | |
1271 | LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__, LTTNG_UST_TRACEPOINT_PROVIDER), | |
1272 | LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__, LTTNG_UST_TRACEPOINT_PROVIDER), | |
1273 | lttng_ust_notrace) | |
1274 | ||
29d6f421 MD |
1275 | /* |
1276 | * LTTNG_UST_TRACEPOINT_PROVIDER_HIDDEN_DEFINITION: Define this before | |
1277 | * including a tracepoint instrumentation header to hide symbols | |
1278 | * associated with the tracepoint provider. This is useful if the | |
1279 | * tracepoint definition (including the header after defining | |
1280 | * LTTNG_UST_TRACEPOINT_DEFINE) is in the same module as the provider | |
1281 | * (including the header after defining | |
1282 | * LTTNG_UST_TRACEPOINT_CREATE_PROBES). | |
1283 | */ | |
1284 | #undef LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY | |
1285 | #ifdef LTTNG_UST_TRACEPOINT_PROVIDER_HIDDEN_DEFINITION | |
1286 | #define LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY __attribute__((visibility("hidden"))) | |
1287 | #else | |
1288 | #define LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY __attribute__((visibility("default"))) | |
1289 | #endif | |
1290 | ||
5b393d64 | 1291 | int LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_, LTTNG_UST_TRACEPOINT_PROVIDER) |
29d6f421 | 1292 | LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY; |