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 | |
f04f60a5 MD |
258 | #if defined(__cplusplus) |
259 | ||
2df82195 FD |
260 | /* |
261 | * Stage 0.9.1 | |
f04f60a5 MD |
262 | * Verifying array and sequence elements are of an integer or pointer |
263 | * type. | |
264 | * | |
265 | * This compile-time check is only enabled in C++, because the C | |
266 | * implementation of lttng_ust_is_pointer_type does not support opaque | |
267 | * pointer types. | |
2df82195 FD |
268 | */ |
269 | ||
7f2f82c3 | 270 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
2df82195 FD |
271 | #include <lttng/ust-tracepoint-event-reset.h> |
272 | #include <lttng/ust-tracepoint-event-write.h> | |
273 | #include <lttng/ust-tracepoint-event-nowrite.h> | |
274 | ||
10937ee5 MJ |
275 | #undef lttng_ust__field_array_encoded |
276 | #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, \ | |
2df82195 FD |
277 | _length, _encoding, _nowrite, \ |
278 | _elem_type_base) \ | |
10937ee5 | 279 | lttng_ust_field_array_element_type_is_supported(_type, _item); |
2df82195 | 280 | |
1d188af9 MJ |
281 | #undef lttng_ust__field_sequence_encoded |
282 | #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, \ | |
2df82195 FD |
283 | _length_type, _src_length, _encoding, _nowrite, \ |
284 | _elem_type_base) \ | |
10937ee5 | 285 | lttng_ust_field_array_element_type_is_supported(_type, _item); |
2df82195 | 286 | |
efa14d16 MJ |
287 | #undef LTTNG_UST_TP_FIELDS |
288 | #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */ | |
2df82195 | 289 | |
7f2f82c3 MJ |
290 | #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS |
291 | #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
2df82195 | 292 | _fields |
c785c634 | 293 | |
bb71a8ea | 294 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
c785c634 | 295 | |
f04f60a5 MD |
296 | #endif |
297 | ||
5b675300 MD |
298 | /* |
299 | * Stage 0.9.2 of tracepoint event generation. | |
300 | * | |
301 | * Create probe signature | |
302 | */ | |
303 | ||
304 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ | |
305 | #include <lttng/ust-tracepoint-event-reset.h> | |
306 | ||
307 | #undef LTTNG_UST_TP_ARGS | |
308 | #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__ | |
309 | ||
310 | #define LTTNG_UST__TP_EXTRACT_STRING2(...) #__VA_ARGS__ | |
311 | ||
312 | #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS | |
313 | #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
314 | static const char __tp_event_signature___##_provider##___##_name[] = \ | |
315 | LTTNG_UST__TP_EXTRACT_STRING2(_args); | |
316 | ||
317 | #include LTTNG_UST_TRACEPOINT_INCLUDE | |
318 | ||
319 | #undef LTTNG_UST__TP_EXTRACT_STRING2 | |
320 | ||
1c324e59 MD |
321 | /* |
322 | * Stage 1 of tracepoint event generation. | |
323 | * | |
5b675300 MD |
324 | * Create probe callback prototypes. |
325 | */ | |
326 | ||
327 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ | |
328 | #include <lttng/ust-tracepoint-event-reset.h> | |
329 | ||
330 | #undef LTTNG_UST_TP_ARGS | |
331 | #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__ | |
332 | ||
333 | #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS | |
334 | #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
335 | static void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)); | |
336 | ||
337 | #include LTTNG_UST_TRACEPOINT_INCLUDE | |
338 | ||
2e7160d2 MD |
339 | /* |
340 | * Stage 1.1 of tracepoint event generation. | |
341 | * | |
342 | * Declare toplevel descriptor for the whole probe. | |
343 | * Unlike C, C++ does not allow tentative definitions. Therefore, we | |
344 | * need to explicitly declare the variable with "extern", using hidden | |
345 | * visibility to keep this symbol from being exported to the global | |
346 | * symbol table. | |
347 | */ | |
348 | ||
349 | extern const struct lttng_ust_probe_desc LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___, LTTNG_UST_TRACEPOINT_PROVIDER) | |
350 | __attribute__((visibility("hidden"))); | |
351 | ||
5b675300 MD |
352 | /* |
353 | * Stage 2 of tracepoint event generation. | |
354 | * | |
1c324e59 MD |
355 | * Create event field type metadata section. |
356 | * Each event produce an array of fields. | |
357 | */ | |
358 | ||
7f2f82c3 | 359 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
1c324e59 | 360 | #include <lttng/ust-tracepoint-event-reset.h> |
4774c8f3 MD |
361 | #include <lttng/ust-tracepoint-event-write.h> |
362 | #include <lttng/ust-tracepoint-event-nowrite.h> | |
1c324e59 | 363 | |
b4064f28 MJ |
364 | #undef lttng_ust__field_integer_ext |
365 | #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ | |
5defa774 | 366 | LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \ |
25cff019 MD |
367 | .struct_size = sizeof(struct lttng_ust_event_field), \ |
368 | .name = #_item, \ | |
a084756d | 369 | .type = lttng_ust_type_integer_define(_type, _byte_order, _base), \ |
25cff019 MD |
370 | .nowrite = _nowrite, \ |
371 | .nofilter = 0, \ | |
372 | }), | |
1c324e59 | 373 | |
891226fc MJ |
374 | #undef lttng_ust__field_float |
375 | #define lttng_ust__field_float(_type, _item, _src, _nowrite) \ | |
5defa774 | 376 | LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \ |
25cff019 MD |
377 | .struct_size = sizeof(struct lttng_ust_event_field), \ |
378 | .name = #_item, \ | |
a084756d | 379 | .type = lttng_ust_type_float_define(_type), \ |
25cff019 MD |
380 | .nowrite = _nowrite, \ |
381 | .nofilter = 0, \ | |
382 | }), | |
1c324e59 | 383 | |
10937ee5 MJ |
384 | #undef lttng_ust__field_array_encoded |
385 | #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, \ | |
f3ec4cb5 MD |
386 | _length, _encoding, _nowrite, \ |
387 | _elem_type_base) \ | |
5defa774 | 388 | LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \ |
25cff019 MD |
389 | .struct_size = sizeof(struct lttng_ust_event_field), \ |
390 | .name = #_item, \ | |
5defa774 | 391 | .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_array, { \ |
a084756d MD |
392 | .parent = { \ |
393 | .type = lttng_ust_type_array, \ | |
394 | }, \ | |
395 | .struct_size = sizeof(struct lttng_ust_type_array), \ | |
396 | .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \ | |
397 | .length = _length, \ | |
398 | .alignment = 0, \ | |
399 | .encoding = lttng_ust_string_encoding_##_encoding, \ | |
400 | }), \ | |
25cff019 MD |
401 | .nowrite = _nowrite, \ |
402 | .nofilter = 0, \ | |
403 | }), | |
1c324e59 | 404 | |
1d188af9 MJ |
405 | #undef lttng_ust__field_sequence_encoded |
406 | #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, \ | |
f968510a PP |
407 | _length_type, _src_length, _encoding, _nowrite, \ |
408 | _elem_type_base) \ | |
5defa774 | 409 | LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \ |
25cff019 MD |
410 | .struct_size = sizeof(struct lttng_ust_event_field), \ |
411 | .name = "_" #_item "_length", \ | |
baa8acf3 | 412 | .type = lttng_ust_type_integer_define(_length_type, LTTNG_UST_BYTE_ORDER, 10), \ |
25cff019 MD |
413 | .nowrite = _nowrite, \ |
414 | .nofilter = 1, \ | |
415 | }), \ | |
5defa774 | 416 | LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \ |
25cff019 MD |
417 | .struct_size = sizeof(struct lttng_ust_event_field), \ |
418 | .name = #_item, \ | |
5defa774 | 419 | .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_sequence, { \ |
a084756d MD |
420 | .parent = { \ |
421 | .type = lttng_ust_type_sequence, \ | |
1c324e59 | 422 | }, \ |
a084756d | 423 | .struct_size = sizeof(struct lttng_ust_type_sequence), \ |
28db0827 | 424 | .length_name = NULL, /* Use previous field. */ \ |
a084756d MD |
425 | .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \ |
426 | .alignment = 0, \ | |
427 | .encoding = lttng_ust_string_encoding_##_encoding, \ | |
428 | }), \ | |
25cff019 MD |
429 | .nowrite = _nowrite, \ |
430 | .nofilter = 0, \ | |
431 | }), | |
1c324e59 | 432 | |
3202f63a MJ |
433 | #undef lttng_ust__field_string |
434 | #define lttng_ust__field_string(_item, _src, _nowrite) \ | |
5defa774 | 435 | LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \ |
25cff019 MD |
436 | .struct_size = sizeof(struct lttng_ust_event_field), \ |
437 | .name = #_item, \ | |
5defa774 | 438 | .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_string, { \ |
a084756d MD |
439 | .parent = { \ |
440 | .type = lttng_ust_type_string, \ | |
46d52200 | 441 | }, \ |
a084756d MD |
442 | .struct_size = sizeof(struct lttng_ust_type_string), \ |
443 | .encoding = lttng_ust_string_encoding_UTF8, \ | |
444 | }), \ | |
25cff019 MD |
445 | .nowrite = _nowrite, \ |
446 | .nofilter = 0, \ | |
447 | }), | |
1c324e59 | 448 | |
ddde62ca MJ |
449 | #undef lttng_ust__field_unused |
450 | #define lttng_ust__field_unused(_src) | |
5152f6df | 451 | |
78684808 MJ |
452 | #undef lttng_ust__field_enum |
453 | #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \ | |
5defa774 | 454 | LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \ |
25cff019 | 455 | .struct_size = sizeof(struct lttng_ust_event_field), \ |
c785c634 | 456 | .name = #_item, \ |
5defa774 | 457 | .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_enum, { \ |
a084756d MD |
458 | .parent = { \ |
459 | .type = lttng_ust_type_enum, \ | |
c785c634 | 460 | }, \ |
a084756d MD |
461 | .struct_size = sizeof(struct lttng_ust_type_enum), \ |
462 | .desc = &__enum_##_provider##_##_name, \ | |
baa8acf3 | 463 | .container_type = lttng_ust_type_integer_define(_type, LTTNG_UST_BYTE_ORDER, 10), \ |
a084756d | 464 | }), \ |
c785c634 | 465 | .nowrite = _nowrite, \ |
25cff019 MD |
466 | .nofilter = 0, \ |
467 | }), | |
c785c634 | 468 | |
efa14d16 MJ |
469 | #undef LTTNG_UST_TP_FIELDS |
470 | #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */ | |
1c324e59 | 471 | |
7f2f82c3 MJ |
472 | #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS |
473 | #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
bfcc2759 | 474 | static const struct lttng_ust_event_field * const lttng_ust__event_fields___##_provider##___##_name[] = { \ |
1c324e59 | 475 | _fields \ |
b4064f28 | 476 | lttng_ust_field_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \ |
5b675300 MD |
477 | }; \ |
478 | static const struct lttng_ust_tracepoint_class lttng_ust__event_class___##_provider##___##_name = { \ | |
479 | .struct_size = sizeof(struct lttng_ust_tracepoint_class), \ | |
480 | .fields = lttng_ust__event_fields___##_provider##___##_name, \ | |
481 | .nr_fields = LTTNG_UST__TP_ARRAY_SIZE(lttng_ust__event_fields___##_provider##___##_name) - 1, \ | |
482 | .probe_callback = (void (*)(void)) <tng_ust__event_probe__##_provider##___##_name, \ | |
483 | .signature = __tp_event_signature___##_provider##___##_name, \ | |
2e7160d2 | 484 | .probe_desc = <tng_ust__probe_desc___##_provider, \ |
1c324e59 MD |
485 | }; |
486 | ||
2ebf164b MJ |
487 | #undef LTTNG_UST_TRACEPOINT_ENUM |
488 | #define LTTNG_UST_TRACEPOINT_ENUM(_provider, _name, _values) \ | |
4e48b5d2 | 489 | static const struct lttng_ust_enum_desc __enum_##_provider##_##_name = { \ |
a084756d | 490 | .struct_size = sizeof(struct lttng_ust_enum_desc), \ |
c785c634 MD |
491 | .name = #_provider "_" #_name, \ |
492 | .entries = __enum_values__##_provider##_##_name, \ | |
ca6ed78d | 493 | .nr_entries = LTTNG_UST__TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \ |
2e7160d2 | 494 | .probe_desc = <tng_ust__probe_desc___##_provider, \ |
c785c634 MD |
495 | }; |
496 | ||
bb71a8ea | 497 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
1c324e59 | 498 | |
1c324e59 | 499 | /* |
c785c634 | 500 | * Stage 3.0 of tracepoint event generation. |
1c324e59 | 501 | * |
1c324e59 MD |
502 | * Create static inline function that calculates event size. |
503 | */ | |
504 | ||
7f2f82c3 | 505 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
1c324e59 | 506 | #include <lttng/ust-tracepoint-event-reset.h> |
4774c8f3 | 507 | #include <lttng/ust-tracepoint-event-write.h> |
1c324e59 | 508 | |
b4064f28 MJ |
509 | #undef lttng_ust__field_integer_ext |
510 | #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ | |
5152f6df MJ |
511 | if (0) \ |
512 | (void) (_src); /* Unused */ \ | |
b5457df5 | 513 | __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \ |
1c324e59 MD |
514 | __event_len += sizeof(_type); |
515 | ||
891226fc MJ |
516 | #undef lttng_ust__field_float |
517 | #define lttng_ust__field_float(_type, _item, _src, _nowrite) \ | |
5152f6df MJ |
518 | if (0) \ |
519 | (void) (_src); /* Unused */ \ | |
b5457df5 | 520 | __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \ |
1c324e59 MD |
521 | __event_len += sizeof(_type); |
522 | ||
10937ee5 MJ |
523 | #undef lttng_ust__field_array_encoded |
524 | #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \ | |
f3ec4cb5 | 525 | _nowrite, _elem_type_base) \ |
5152f6df MJ |
526 | if (0) \ |
527 | (void) (_src); /* Unused */ \ | |
b5457df5 | 528 | __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \ |
1c324e59 MD |
529 | __event_len += sizeof(_type) * (_length); |
530 | ||
1d188af9 MJ |
531 | #undef lttng_ust__field_sequence_encoded |
532 | #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \ | |
f968510a | 533 | _src_length, _encoding, _nowrite, _elem_type_base) \ |
5152f6df MJ |
534 | if (0) \ |
535 | (void) (_src); /* Unused */ \ | |
b5457df5 | 536 | __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_length_type)); \ |
1c324e59 | 537 | __event_len += sizeof(_length_type); \ |
b5457df5 | 538 | __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \ |
1c324e59 MD |
539 | __dynamic_len[__dynamic_len_idx] = (_src_length); \ |
540 | __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \ | |
541 | __dynamic_len_idx++; | |
542 | ||
3202f63a MJ |
543 | #undef lttng_ust__field_string |
544 | #define lttng_ust__field_string(_item, _src, _nowrite) \ | |
24a39530 | 545 | __event_len += __dynamic_len[__dynamic_len_idx++] = \ |
ee0889a3 | 546 | strlen((_src) ? (_src) : LTTNG_UST__NULL_STRING) + 1; |
1c324e59 | 547 | |
ddde62ca MJ |
548 | #undef lttng_ust__field_unused |
549 | #define lttng_ust__field_unused(_src) \ | |
5152f6df MJ |
550 | if (0) \ |
551 | (void) (_src); /* Unused */ | |
552 | ||
78684808 MJ |
553 | #undef lttng_ust__field_enum |
554 | #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \ | |
b4064f28 | 555 | lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite) |
c785c634 | 556 | |
cadfcbfc MJ |
557 | #undef LTTNG_UST_TP_ARGS |
558 | #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__ | |
1c324e59 | 559 | |
efa14d16 MJ |
560 | #undef LTTNG_UST_TP_FIELDS |
561 | #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ | |
1c324e59 | 562 | |
7f2f82c3 MJ |
563 | #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS |
564 | #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
106ff4da | 565 | static inline \ |
bfcc2759 | 566 | size_t lttng_ust__event_get_size__##_provider##___##_name(size_t *__dynamic_len, LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \ |
106ff4da | 567 | lttng_ust_notrace; \ |
a8909ba5 | 568 | static inline \ |
bfcc2759 | 569 | size_t lttng_ust__event_get_size__##_provider##___##_name( \ |
5152f6df | 570 | size_t *__dynamic_len __attribute__((__unused__)), \ |
6eddcb06 | 571 | LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \ |
1c324e59 MD |
572 | { \ |
573 | size_t __event_len = 0; \ | |
5152f6df | 574 | unsigned int __dynamic_len_idx __attribute__((__unused__)) = 0; \ |
1c324e59 MD |
575 | \ |
576 | if (0) \ | |
5152f6df MJ |
577 | (void) __tp_data; /* don't warn if unused */ \ |
578 | \ | |
1c324e59 MD |
579 | _fields \ |
580 | return __event_len; \ | |
581 | } | |
582 | ||
bb71a8ea | 583 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
1c324e59 | 584 | |
1ddfd641 MD |
585 | /* |
586 | * Stage 3.1 of tracepoint event generation. | |
587 | * | |
588 | * Create static inline function that layout the filter stack data. | |
4774c8f3 | 589 | * We make both write and nowrite data available to the filter. |
1ddfd641 MD |
590 | */ |
591 | ||
7f2f82c3 | 592 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
1ddfd641 | 593 | #include <lttng/ust-tracepoint-event-reset.h> |
4774c8f3 MD |
594 | #include <lttng/ust-tracepoint-event-write.h> |
595 | #include <lttng/ust-tracepoint-event-nowrite.h> | |
1ddfd641 | 596 | |
b4064f28 MJ |
597 | #undef lttng_ust__field_integer_ext |
598 | #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ | |
eae3c729 | 599 | if (lttng_ust_is_signed_type(_type)) { \ |
3ebeea0d MD |
600 | int64_t __ctf_tmp_int64; \ |
601 | switch (sizeof(_type)) { \ | |
602 | case 1: \ | |
603 | { \ | |
604 | union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \ | |
605 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ | |
606 | break; \ | |
607 | } \ | |
608 | case 2: \ | |
609 | { \ | |
610 | union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \ | |
baa8acf3 MJ |
611 | if (_byte_order != LTTNG_UST_BYTE_ORDER) \ |
612 | __tmp.v = lttng_ust_bswap_16(__tmp.v); \ | |
3ebeea0d MD |
613 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ |
614 | break; \ | |
615 | } \ | |
616 | case 4: \ | |
617 | { \ | |
618 | union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \ | |
baa8acf3 MJ |
619 | if (_byte_order != LTTNG_UST_BYTE_ORDER) \ |
620 | __tmp.v = lttng_ust_bswap_32(__tmp.v); \ | |
3ebeea0d MD |
621 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ |
622 | break; \ | |
623 | } \ | |
624 | case 8: \ | |
625 | { \ | |
626 | union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \ | |
baa8acf3 MJ |
627 | if (_byte_order != LTTNG_UST_BYTE_ORDER) \ |
628 | __tmp.v = lttng_ust_bswap_64(__tmp.v); \ | |
3ebeea0d MD |
629 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ |
630 | break; \ | |
631 | } \ | |
632 | default: \ | |
633 | abort(); \ | |
634 | }; \ | |
fa099471 MD |
635 | memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \ |
636 | } else { \ | |
3ebeea0d MD |
637 | uint64_t __ctf_tmp_uint64; \ |
638 | switch (sizeof(_type)) { \ | |
639 | case 1: \ | |
640 | { \ | |
641 | union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \ | |
642 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ | |
643 | break; \ | |
644 | } \ | |
645 | case 2: \ | |
646 | { \ | |
647 | union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \ | |
baa8acf3 MJ |
648 | if (_byte_order != LTTNG_UST_BYTE_ORDER) \ |
649 | __tmp.v = lttng_ust_bswap_16(__tmp.v); \ | |
3ebeea0d MD |
650 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ |
651 | break; \ | |
652 | } \ | |
653 | case 4: \ | |
654 | { \ | |
655 | union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \ | |
baa8acf3 MJ |
656 | if (_byte_order != LTTNG_UST_BYTE_ORDER) \ |
657 | __tmp.v = lttng_ust_bswap_32(__tmp.v); \ | |
3ebeea0d MD |
658 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ |
659 | break; \ | |
660 | } \ | |
661 | case 8: \ | |
662 | { \ | |
663 | union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \ | |
baa8acf3 MJ |
664 | if (_byte_order != LTTNG_UST_BYTE_ORDER) \ |
665 | __tmp.v = lttng_ust_bswap_64(__tmp.v); \ | |
3ebeea0d MD |
666 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ |
667 | break; \ | |
668 | } \ | |
669 | default: \ | |
670 | abort(); \ | |
671 | }; \ | |
fa099471 MD |
672 | memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \ |
673 | } \ | |
1ddfd641 MD |
674 | __stack_data += sizeof(int64_t); |
675 | ||
891226fc MJ |
676 | #undef lttng_ust__field_float |
677 | #define lttng_ust__field_float(_type, _item, _src, _nowrite) \ | |
fa099471 MD |
678 | { \ |
679 | double __ctf_tmp_double = (double) (_type) (_src); \ | |
680 | memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \ | |
681 | __stack_data += sizeof(double); \ | |
682 | } | |
1ddfd641 | 683 | |
10937ee5 MJ |
684 | #undef lttng_ust__field_array_encoded |
685 | #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \ | |
f3ec4cb5 | 686 | _encoding, _nowrite, _elem_type_base) \ |
fa099471 MD |
687 | { \ |
688 | unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \ | |
59034aab | 689 | const void *__ctf_tmp_ptr = (_src); \ |
fa099471 MD |
690 | memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \ |
691 | __stack_data += sizeof(unsigned long); \ | |
b1239ad6 MD |
692 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \ |
693 | __stack_data += sizeof(void *); \ | |
fa099471 | 694 | } |
1ddfd641 | 695 | |
1d188af9 MJ |
696 | #undef lttng_ust__field_sequence_encoded |
697 | #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \ | |
f968510a | 698 | _src_length, _encoding, _nowrite, _elem_type_base) \ |
fa099471 MD |
699 | { \ |
700 | unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \ | |
59034aab | 701 | const void *__ctf_tmp_ptr = (_src); \ |
fa099471 MD |
702 | memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \ |
703 | __stack_data += sizeof(unsigned long); \ | |
b1239ad6 MD |
704 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \ |
705 | __stack_data += sizeof(void *); \ | |
fa099471 | 706 | } |
1ddfd641 | 707 | |
3202f63a MJ |
708 | #undef lttng_ust__field_string |
709 | #define lttng_ust__field_string(_item, _src, _nowrite) \ | |
fa099471 | 710 | { \ |
24a39530 | 711 | const void *__ctf_tmp_ptr = \ |
ee0889a3 | 712 | ((_src) ? (_src) : LTTNG_UST__NULL_STRING); \ |
b1239ad6 MD |
713 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \ |
714 | __stack_data += sizeof(void *); \ | |
fa099471 | 715 | } |
1ddfd641 | 716 | |
ddde62ca MJ |
717 | #undef lttng_ust__field_unused |
718 | #define lttng_ust__field_unused(_src) \ | |
5152f6df MJ |
719 | if (0) \ |
720 | (void) (_src); | |
721 | ||
78684808 MJ |
722 | #undef lttng_ust__field_enum |
723 | #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \ | |
b4064f28 | 724 | lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite) |
c785c634 | 725 | |
cadfcbfc MJ |
726 | #undef LTTNG_UST_TP_ARGS |
727 | #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__ | |
1ddfd641 | 728 | |
efa14d16 MJ |
729 | #undef LTTNG_UST_TP_FIELDS |
730 | #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ | |
1ddfd641 | 731 | |
7f2f82c3 MJ |
732 | #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS |
733 | #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
1ddfd641 | 734 | static inline \ |
bfcc2759 | 735 | void lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(char *__stack_data,\ |
6eddcb06 | 736 | LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \ |
1ddfd641 | 737 | { \ |
5152f6df MJ |
738 | if (0) { \ |
739 | (void) __tp_data; /* don't warn if unused */ \ | |
740 | (void) __stack_data; /* don't warn if unused */ \ | |
741 | } \ | |
742 | \ | |
1ddfd641 MD |
743 | _fields \ |
744 | } | |
745 | ||
bb71a8ea | 746 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
1ddfd641 | 747 | |
1c324e59 | 748 | /* |
df854e41 | 749 | * Stage 4 of tracepoint event generation. |
1c324e59 MD |
750 | * |
751 | * Create static inline function that calculates event payload alignment. | |
752 | */ | |
753 | ||
7f2f82c3 | 754 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
1c324e59 | 755 | #include <lttng/ust-tracepoint-event-reset.h> |
4774c8f3 | 756 | #include <lttng/ust-tracepoint-event-write.h> |
1c324e59 | 757 | |
b4064f28 MJ |
758 | #undef lttng_ust__field_integer_ext |
759 | #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ | |
5152f6df MJ |
760 | if (0) \ |
761 | (void) (_src); /* Unused */ \ | |
26376e52 | 762 | __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type)); |
1c324e59 | 763 | |
891226fc MJ |
764 | #undef lttng_ust__field_float |
765 | #define lttng_ust__field_float(_type, _item, _src, _nowrite) \ | |
5152f6df MJ |
766 | if (0) \ |
767 | (void) (_src); /* Unused */ \ | |
26376e52 | 768 | __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type)); |
1c324e59 | 769 | |
10937ee5 MJ |
770 | #undef lttng_ust__field_array_encoded |
771 | #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \ | |
f3ec4cb5 | 772 | _encoding, _nowrite, _elem_type_base) \ |
5152f6df MJ |
773 | if (0) \ |
774 | (void) (_src); /* Unused */ \ | |
26376e52 | 775 | __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type)); |
1c324e59 | 776 | |
1d188af9 MJ |
777 | #undef lttng_ust__field_sequence_encoded |
778 | #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \ | |
f968510a | 779 | _src_length, _encoding, _nowrite, _elem_type_base) \ |
5152f6df MJ |
780 | if (0) \ |
781 | (void) (_src); /* Unused */ \ | |
782 | if (0) \ | |
783 | (void) (_src_length); /* Unused */ \ | |
26376e52 MD |
784 | __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_length_type)); \ |
785 | __event_align = lttng_ust__tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type)); | |
1c324e59 | 786 | |
3202f63a MJ |
787 | #undef lttng_ust__field_string |
788 | #define lttng_ust__field_string(_item, _src, _nowrite) \ | |
5152f6df MJ |
789 | if (0) \ |
790 | (void) (_src); /* Unused */ | |
791 | ||
ddde62ca MJ |
792 | #undef lttng_ust__field_unused |
793 | #define lttng_ust__field_unused(_src) \ | |
5152f6df MJ |
794 | if (0) \ |
795 | (void) (_src); /* Unused */ | |
1c324e59 | 796 | |
78684808 MJ |
797 | #undef lttng_ust__field_enum |
798 | #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \ | |
b4064f28 | 799 | lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite) |
c785c634 | 800 | |
cadfcbfc MJ |
801 | #undef LTTNG_UST_TP_ARGS |
802 | #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__ | |
1c324e59 | 803 | |
efa14d16 MJ |
804 | #undef LTTNG_UST_TP_FIELDS |
805 | #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ | |
1c324e59 | 806 | |
7f2f82c3 MJ |
807 | #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS |
808 | #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
106ff4da | 809 | static inline \ |
bfcc2759 | 810 | size_t lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(_args)) \ |
106ff4da | 811 | lttng_ust_notrace; \ |
1c324e59 | 812 | static inline \ |
bfcc2759 | 813 | size_t lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(_args)) \ |
1c324e59 | 814 | { \ |
26376e52 | 815 | size_t __event_align = 1; \ |
1c324e59 | 816 | _fields \ |
26376e52 | 817 | return __event_align; \ |
1c324e59 MD |
818 | } |
819 | ||
bb71a8ea | 820 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
1c324e59 MD |
821 | |
822 | ||
823 | /* | |
df854e41 | 824 | * Stage 5 of tracepoint event generation. |
1c324e59 MD |
825 | * |
826 | * Create the probe function. This function calls event size calculation | |
827 | * and writes event data into the buffer. | |
828 | */ | |
829 | ||
7f2f82c3 | 830 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
1c324e59 | 831 | #include <lttng/ust-tracepoint-event-reset.h> |
4774c8f3 | 832 | #include <lttng/ust-tracepoint-event-write.h> |
1c324e59 | 833 | |
b4064f28 MJ |
834 | #undef lttng_ust__field_integer_ext |
835 | #define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ | |
1c324e59 MD |
836 | { \ |
837 | _type __tmp = (_src); \ | |
8936b6c0 | 838 | __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\ |
1c324e59 MD |
839 | } |
840 | ||
891226fc MJ |
841 | #undef lttng_ust__field_float |
842 | #define lttng_ust__field_float(_type, _item, _src, _nowrite) \ | |
1c324e59 MD |
843 | { \ |
844 | _type __tmp = (_src); \ | |
8936b6c0 | 845 | __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\ |
1c324e59 MD |
846 | } |
847 | ||
10937ee5 MJ |
848 | #undef lttng_ust__field_array_encoded |
849 | #define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \ | |
f3ec4cb5 | 850 | _encoding, _nowrite, _elem_type_base) \ |
27927814 | 851 | if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \ |
8936b6c0 | 852 | __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length), lttng_ust_rb_alignof(_type)); \ |
27927814 | 853 | else \ |
1f41dc0a | 854 | __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), _length); |
1c324e59 | 855 | |
1d188af9 MJ |
856 | #undef lttng_ust__field_sequence_encoded |
857 | #define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \ | |
f968510a | 858 | _src_length, _encoding, _nowrite, _elem_type_base) \ |
1c324e59 | 859 | { \ |
d71b57b9 | 860 | _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \ |
8936b6c0 | 861 | __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type), lttng_ust_rb_alignof(_length_type));\ |
1c324e59 | 862 | } \ |
27927814 MD |
863 | if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \ |
864 | __chan->ops->event_write(&__ctx, _src, \ | |
bae1f483 | 865 | sizeof(_type) * lttng_ust__get_dynamic_len(dest), lttng_ust_rb_alignof(_type)); \ |
27927814 | 866 | else \ |
bae1f483 | 867 | __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), lttng_ust__get_dynamic_len(dest)); \ |
1c324e59 | 868 | |
3202f63a MJ |
869 | #undef lttng_ust__field_string |
870 | #define lttng_ust__field_string(_item, _src, _nowrite) \ | |
24a39530 PP |
871 | { \ |
872 | const char *__ctf_tmp_string = \ | |
ee0889a3 | 873 | ((_src) ? (_src) : LTTNG_UST__NULL_STRING); \ |
f9ec4a97 | 874 | __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \ |
bae1f483 | 875 | lttng_ust__get_dynamic_len(dest)); \ |
24a39530 PP |
876 | } |
877 | ||
ddde62ca MJ |
878 | #undef lttng_ust__field_unused |
879 | #define lttng_ust__field_unused(_src) | |
1c324e59 | 880 | |
78684808 MJ |
881 | #undef lttng_ust__field_enum |
882 | #define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \ | |
b4064f28 | 883 | lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite) |
c785c634 | 884 | |
1c324e59 | 885 | /* Beware: this get len actually consumes the len value */ |
bae1f483 MJ |
886 | #undef lttng_ust__get_dynamic_len |
887 | #define lttng_ust__get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++] | |
1c324e59 | 888 | |
cadfcbfc MJ |
889 | #undef LTTNG_UST_TP_ARGS |
890 | #define LTTNG_UST_TP_ARGS(...) __VA_ARGS__ | |
1c324e59 | 891 | |
efa14d16 MJ |
892 | #undef LTTNG_UST_TP_FIELDS |
893 | #define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ | |
1c324e59 | 894 | |
95c25348 PW |
895 | /* |
896 | * For state dump, check that "session" argument (mandatory) matches the | |
897 | * session this event belongs to. Ensures that we write state dump data only | |
898 | * into the started session, not into all sessions. | |
899 | */ | |
91fe3e13 MJ |
900 | #undef LTTNG_UST__TP_SESSION_CHECK |
901 | #ifdef LTTNG_UST_TP_SESSION_CHECK | |
902 | #define LTTNG_UST__TP_SESSION_CHECK(session, csession) (session == csession) | |
95c25348 | 903 | #else /* TP_SESSION_CHECK */ |
91fe3e13 | 904 | #define LTTNG_UST__TP_SESSION_CHECK(session, csession) 1 |
95c25348 PW |
905 | #endif /* TP_SESSION_CHECK */ |
906 | ||
97904b41 MD |
907 | /* |
908 | * Use of __builtin_return_address(0) sometimes seems to cause stack | |
909 | * corruption on 32-bit PowerPC. Disable this feature on that | |
910 | * architecture for now by always using the NULL value for the ip | |
911 | * context. | |
912 | */ | |
c28c4a88 MJ |
913 | #undef LTTNG_UST__TP_IP_PARAM |
914 | ||
915 | #ifdef LTTNG_UST_TP_IP_PARAM | |
916 | #define LTTNG_UST__TP_IP_PARAM(x) (x) | |
5dadb547 | 917 | #else /* TP_IP_PARAM */ |
97904b41 | 918 | |
2eba8e39 | 919 | #if defined(LTTNG_UST_ARCH_PPC) && !defined(LTTNG_UST_ARCH_PPC64) |
c28c4a88 | 920 | #define LTTNG_UST__TP_IP_PARAM(x) NULL |
2eba8e39 | 921 | #else |
c28c4a88 | 922 | #define LTTNG_UST__TP_IP_PARAM(x) __builtin_return_address(0) |
2eba8e39 | 923 | #endif |
97904b41 | 924 | |
5dadb547 MD |
925 | #endif /* TP_IP_PARAM */ |
926 | ||
1ddfd641 MD |
927 | /* |
928 | * Using twice size for filter stack data to hold size and pointer for | |
929 | * each field (worse case). For integers, max size required is 64-bit. | |
930 | * Same for double-precision floats. Those fit within | |
931 | * 2*sizeof(unsigned long) for all supported architectures. | |
61ce3223 | 932 | * Perform UNION (||) of filter runtime list. |
1ddfd641 | 933 | */ |
7f2f82c3 | 934 | #undef LTTNG_UST__TRACEPOINT_EVENT_CLASS |
b2e37d27 | 935 | #define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ |
106ff4da | 936 | static \ |
b2e37d27 | 937 | void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \ |
106ff4da | 938 | lttng_ust_notrace; \ |
a8909ba5 | 939 | static \ |
b2e37d27 | 940 | void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \ |
1c324e59 | 941 | { \ |
ba99fbe2 | 942 | struct lttng_ust_event_common *__event = (struct lttng_ust_event_common *) __tp_data; \ |
1c324e59 | 943 | size_t __dynamic_len_idx = 0; \ |
bfcc2759 | 944 | const size_t __num_fields = LTTNG_UST__TP_ARRAY_SIZE(lttng_ust__event_fields___##_provider##___##_name) - 1; \ |
b2e37d27 | 945 | struct lttng_ust_probe_ctx __probe_ctx; \ |
d71b57b9 | 946 | union { \ |
75026e9f | 947 | size_t __dynamic_len[__num_fields]; \ |
ba99fbe2 | 948 | char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \ |
d71b57b9 | 949 | } __stackvar; \ |
1c324e59 | 950 | int __ret; \ |
a2e4d05e | 951 | bool __interpreter_stack_prepared = false; \ |
1c324e59 MD |
952 | \ |
953 | if (0) \ | |
954 | (void) __dynamic_len_idx; /* don't warn if unused */ \ | |
ba99fbe2 MD |
955 | switch (__event->type) { \ |
956 | case LTTNG_UST_EVENT_TYPE_RECORDER: \ | |
957 | { \ | |
26376e52 MD |
958 | struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \ |
959 | struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \ | |
e7bc0ef6 | 960 | struct lttng_ust_channel_common *__chan_common = __chan->parent; \ |
ba99fbe2 | 961 | \ |
b2e37d27 | 962 | if (!LTTNG_UST__TP_SESSION_CHECK(session, __chan_common->session)) \ |
ba99fbe2 | 963 | return; \ |
e7bc0ef6 | 964 | if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->session->active))) \ |
ba99fbe2 | 965 | return; \ |
e7bc0ef6 | 966 | if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->enabled))) \ |
ba99fbe2 MD |
967 | return; \ |
968 | break; \ | |
969 | } \ | |
970 | case LTTNG_UST_EVENT_TYPE_NOTIFIER: \ | |
971 | break; \ | |
972 | } \ | |
973 | if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \ | |
1c324e59 | 974 | return; \ |
b2e37d27 | 975 | if (caa_unlikely(!LTTNG_UST_TP_RCU_LINK_TEST())) \ |
1b436e01 | 976 | return; \ |
b2e37d27 MD |
977 | __probe_ctx.struct_size = sizeof(struct lttng_ust_probe_ctx); \ |
978 | __probe_ctx.ip = LTTNG_UST__TP_IP_PARAM(LTTNG_UST_TP_IP_PARAM); \ | |
979 | if (caa_unlikely(CMM_ACCESS_ONCE(__event->eval_filter))) { \ | |
bfcc2759 | 980 | lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \ |
b2e37d27 | 981 | LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \ |
a2e4d05e | 982 | __interpreter_stack_prepared = true; \ |
b2e37d27 MD |
983 | if (caa_likely(__event->run_filter(__event, \ |
984 | __stackvar.__interpreter_stack_data, &__probe_ctx, NULL) != LTTNG_UST_EVENT_FILTER_ACCEPT)) \ | |
61ce3223 | 985 | return; \ |
1ddfd641 | 986 | } \ |
ba99fbe2 MD |
987 | switch (__event->type) { \ |
988 | case LTTNG_UST_EVENT_TYPE_RECORDER: \ | |
989 | { \ | |
26376e52 MD |
990 | size_t __event_len, __event_align; \ |
991 | struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \ | |
992 | struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \ | |
b2e37d27 | 993 | struct lttng_ust_ring_buffer_ctx __ctx; \ |
ba99fbe2 | 994 | \ |
bfcc2759 | 995 | __event_len = lttng_ust__event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \ |
6eddcb06 | 996 | LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \ |
26376e52 MD |
997 | __event_align = lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_VAR(_args)); \ |
998 | lttng_ust_ring_buffer_ctx_init(&__ctx, __event_recorder, __event_len, __event_align, \ | |
b2e37d27 | 999 | &__probe_ctx); \ |
8936b6c0 | 1000 | __ret = __chan->ops->event_reserve(&__ctx); \ |
ba99fbe2 MD |
1001 | if (__ret < 0) \ |
1002 | return; \ | |
1003 | _fields \ | |
1004 | __chan->ops->event_commit(&__ctx); \ | |
1005 | break; \ | |
1006 | } \ | |
1007 | case LTTNG_UST_EVENT_TYPE_NOTIFIER: \ | |
1008 | { \ | |
26376e52 | 1009 | struct lttng_ust_event_notifier *__event_notifier = (struct lttng_ust_event_notifier *) __event->child; \ |
a2e4d05e MD |
1010 | struct lttng_ust_notification_ctx __notif_ctx; \ |
1011 | \ | |
1012 | __notif_ctx.struct_size = sizeof(struct lttng_ust_notification_ctx); \ | |
26376e52 | 1013 | __notif_ctx.eval_capture = CMM_ACCESS_ONCE(__event_notifier->eval_capture); \ |
ba99fbe2 | 1014 | \ |
a2e4d05e | 1015 | if (caa_unlikely(!__interpreter_stack_prepared && __notif_ctx.eval_capture)) \ |
bfcc2759 | 1016 | lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \ |
b2e37d27 | 1017 | LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \ |
ba99fbe2 | 1018 | \ |
26376e52 | 1019 | __event_notifier->notification_send(__event_notifier, \ |
a2e4d05e | 1020 | __stackvar.__interpreter_stack_data, \ |
b2e37d27 | 1021 | &__probe_ctx, \ |
a2e4d05e | 1022 | &__notif_ctx); \ |
ba99fbe2 MD |
1023 | break; \ |
1024 | } \ | |
1025 | } \ | |
1c324e59 MD |
1026 | } |
1027 | ||
bb71a8ea | 1028 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
1c324e59 | 1029 | |
bae1f483 | 1030 | #undef lttng_ust__get_dynamic_len |
1c324e59 | 1031 | |
05ceaafd | 1032 | /* |
882a56d7 | 1033 | * Stage 6 of tracepoint event generation. |
1c324e59 | 1034 | * |
df854e41 MD |
1035 | * Tracepoint loglevel mapping definition generation. We generate a |
1036 | * symbol for each mapping for a provider/event to ensure at most a 1 to | |
1037 | * 1 mapping between events and loglevels. If the symbol is repeated, | |
1038 | * the compiler will complain. | |
05ceaafd MD |
1039 | */ |
1040 | ||
7f2f82c3 | 1041 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
05ceaafd MD |
1042 | #include <lttng/ust-tracepoint-event-reset.h> |
1043 | ||
4ea4f80e MD |
1044 | /* |
1045 | * Declare _loglevel___##__provider##___##__name as non-static, with | |
1046 | * hidden visibility for c++ handling of weakref. We do a weakref to the | |
1047 | * symbol in a later stage, which requires that the symbol is not | |
1048 | * mangled. | |
1049 | */ | |
1050 | #ifdef __cplusplus | |
fc6d7bef | 1051 | #define LTTNG_UST_TP_EXTERN_C extern "C" |
4ea4f80e | 1052 | #else |
fc6d7bef | 1053 | #define LTTNG_UST_TP_EXTERN_C |
4ea4f80e MD |
1054 | #endif |
1055 | ||
612e9ce4 MJ |
1056 | #undef LTTNG_UST_TRACEPOINT_LOGLEVEL |
1057 | #define LTTNG_UST_TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \ | |
3d33ca1d MD |
1058 | static const int _loglevel_value___##__provider##___##__name = __loglevel; \ |
1059 | LTTNG_UST_TP_EXTERN_C const int * const _loglevel___##__provider##___##__name \ | |
1060 | __attribute__((visibility("hidden"))) = \ | |
457a6b58 | 1061 | &_loglevel_value___##__provider##___##__name; |
df854e41 | 1062 | |
bb71a8ea | 1063 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
df854e41 | 1064 | |
fc6d7bef | 1065 | #undef LTTNG_UST_TP_EXTERN_C |
4ea4f80e | 1066 | |
6ddc916d MD |
1067 | /* |
1068 | * Stage 6.1 of tracepoint event generation. | |
1069 | * | |
1070 | * Tracepoint UML URI info. | |
1071 | */ | |
1072 | ||
7f2f82c3 | 1073 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
6ddc916d MD |
1074 | #include <lttng/ust-tracepoint-event-reset.h> |
1075 | ||
4ea4f80e MD |
1076 | /* |
1077 | * Declare _model_emf_uri___##__provider##___##__name as non-static, | |
1078 | * with hidden visibility for c++ handling of weakref. We do a weakref | |
1079 | * to the 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 | ||
dbcc2f92 MJ |
1088 | #undef LTTNG_UST_TRACEPOINT_MODEL_EMF_URI |
1089 | #define LTTNG_UST_TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \ | |
3d33ca1d | 1090 | LTTNG_UST_TP_EXTERN_C const char * const _model_emf_uri___##__provider##___##__name \ |
082802f9 | 1091 | __attribute__((visibility("hidden"))) = __uri; \ |
6ddc916d | 1092 | |
bb71a8ea | 1093 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
6ddc916d | 1094 | |
fc6d7bef | 1095 | #undef LTTNG_UST_TP_EXTERN_C |
4ea4f80e | 1096 | |
5b4c6da4 MD |
1097 | /* |
1098 | * Stage 7.0 of tracepoint event generation. | |
1099 | * | |
df854e41 | 1100 | * Create events description structures. We use a weakref because |
3d33ca1d | 1101 | * loglevels are optional. If not declared, the event will point to |
df854e41 | 1102 | * a loglevel that contains NULL. |
3d33ca1d MD |
1103 | * |
1104 | * C++ requires that const objects have a user-declared default | |
1105 | * constructor. However, in both C++ and C, weakref cannot be | |
1106 | * initialized because it causes the weakref attribute to be ignored. | |
1107 | * Therefore, the loglevel and model_emf_uri pointers are not const | |
1108 | * to ensure C++ compilers default-initialize them. | |
df854e41 MD |
1109 | */ |
1110 | ||
7f2f82c3 | 1111 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
df854e41 MD |
1112 | #include <lttng/ust-tracepoint-event-reset.h> |
1113 | ||
7f2f82c3 | 1114 | #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE |
5b675300 | 1115 | #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \ |
882a56d7 MD |
1116 | static const int * \ |
1117 | __ref_loglevel___##_provider##___##_name \ | |
1118 | __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \ | |
6ddc916d MD |
1119 | static const char * \ |
1120 | __ref_model_emf_uri___##_provider##___##_name \ | |
1121 | __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\ | |
bfcc2759 | 1122 | static const struct lttng_ust_event_desc lttng_ust__event_desc___##_provider##_##_name = { \ |
dc11f93f | 1123 | .struct_size = sizeof(struct lttng_ust_event_desc), \ |
5b4c6da4 | 1124 | .event_name = #_name, \ |
c9201081 | 1125 | .probe_desc = <tng_ust__probe_desc___##_provider, \ |
5b675300 | 1126 | .tp_class = <tng_ust__event_class___##_template_provider##___##_template_name, \ |
882a56d7 | 1127 | .loglevel = &__ref_loglevel___##_provider##___##_name, \ |
dc11f93f | 1128 | .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \ |
df854e41 MD |
1129 | }; |
1130 | ||
bb71a8ea | 1131 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
05ceaafd | 1132 | |
df854e41 | 1133 | /* |
2e7160d2 | 1134 | * Stage 7.1 of tracepoint event generation. |
df854e41 MD |
1135 | * |
1136 | * Create array of events. | |
1137 | */ | |
1138 | ||
7f2f82c3 | 1139 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
df854e41 MD |
1140 | #include <lttng/ust-tracepoint-event-reset.h> |
1141 | ||
7f2f82c3 | 1142 | #undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE |
5b675300 | 1143 | #define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_template_provider, _template_name, _provider, _name, _args) \ |
bfcc2759 | 1144 | <tng_ust__event_desc___##_provider##_##_name, |
df854e41 | 1145 | |
0997899b | 1146 | static const struct lttng_ust_event_desc * const LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__provider_event_desc___, LTTNG_UST_TRACEPOINT_PROVIDER)[] = { |
bb71a8ea | 1147 | #include LTTNG_UST_TRACEPOINT_INCLUDE |
1c80c909 | 1148 | NULL, /* Dummy, C99 forbids 0-len array. */ |
05ceaafd MD |
1149 | }; |
1150 | ||
df854e41 | 1151 | |
05ceaafd | 1152 | /* |
882a56d7 | 1153 | * Stage 8 of tracepoint event generation. |
05ceaafd MD |
1154 | * |
1155 | * Create a toplevel descriptor for the whole probe. | |
1156 | */ | |
1157 | ||
c9201081 | 1158 | const struct lttng_ust_probe_desc LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___, LTTNG_UST_TRACEPOINT_PROVIDER) = { |
dc11f93f | 1159 | .struct_size = sizeof(struct lttng_ust_probe_desc), |
061fc37a | 1160 | .provider_name = lttng_ust__tp_stringify(LTTNG_UST_TRACEPOINT_PROVIDER), |
0997899b MD |
1161 | .event_desc = LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__provider_event_desc___, LTTNG_UST_TRACEPOINT_PROVIDER), |
1162 | .nr_events = LTTNG_UST__TP_ARRAY_SIZE(LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__provider_event_desc___, LTTNG_UST_TRACEPOINT_PROVIDER)) - 1, | |
71d31690 MD |
1163 | .major = LTTNG_UST_PROVIDER_MAJOR, |
1164 | .minor = LTTNG_UST_PROVIDER_MINOR, | |
05ceaafd MD |
1165 | }; |
1166 | ||
03221919 | 1167 | static int LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___, LTTNG_UST_TRACEPOINT_PROVIDER); |
f082dde9 | 1168 | static struct lttng_ust_registered_probe *LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER); |
f0cc794d | 1169 | |
05ceaafd | 1170 | /* |
882a56d7 | 1171 | * Stage 9 of tracepoint event generation. |
05ceaafd | 1172 | * |
1c324e59 | 1173 | * Register/unregister probes at module load/unload. |
628e1d81 MD |
1174 | * |
1175 | * Generate the constructor as an externally visible symbol for use when | |
1176 | * linking the probe statically. | |
f0cc794d MD |
1177 | * |
1178 | * Register refcount is protected by libc dynamic loader mutex. | |
05bfa3dc JG |
1179 | * |
1180 | * Note that when building this code as C++, the definition of constructors | |
1181 | * and destructors invoking the registration and unregistration functions | |
1182 | * must be performed _after_ the initialization of the probes. | |
1183 | * | |
1184 | * This is because we rely on the order of initialization of static variables | |
1185 | * and anonymous namespaces (their order of declaration) to ensure probes are | |
1186 | * fully initialized, see | |
1187 | * https://en.cppreference.com/w/cpp/language/initialization. This is especially | |
1188 | * important when LTTNG_UST_ALLOCATE_COMPOUND_LITERAL_ON_HEAP is defined as | |
1189 | * compound literals are then dynamically initialized. | |
1c324e59 MD |
1190 | */ |
1191 | ||
7f2f82c3 | 1192 | /* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */ |
1c324e59 | 1193 | #include <lttng/ust-tracepoint-event-reset.h> |
05bfa3dc | 1194 | |
465a0d04 | 1195 | static void |
05bfa3dc | 1196 | LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__, LTTNG_UST_TRACEPOINT_PROVIDER)(void) lttng_ust_notrace; |
a8909ba5 | 1197 | static void |
11bce056 | 1198 | LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__, LTTNG_UST_TRACEPOINT_PROVIDER)(void) |
1c324e59 | 1199 | { |
4e48b5d2 | 1200 | struct lttng_ust_registered_probe *reg_probe; |
1c324e59 | 1201 | |
03221919 | 1202 | if (LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___, |
5b393d64 | 1203 | LTTNG_UST_TRACEPOINT_PROVIDER)++) { |
f0cc794d MD |
1204 | return; |
1205 | } | |
e8bd1da7 | 1206 | /* |
5b393d64 | 1207 | * lttng_ust_tracepoint_provider_check_ ## LTTNG_UST_TRACEPOINT_PROVIDER() is a |
e8bd1da7 MD |
1208 | * static inline function that ensures every probe PROVIDER |
1209 | * argument match the provider within which they appear. It | |
1210 | * calls empty static inline functions, and therefore has no | |
1211 | * runtime effect. However, if it detects an error, a linker | |
1212 | * error will appear. | |
1213 | */ | |
5b393d64 | 1214 | LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_, LTTNG_UST_TRACEPOINT_PROVIDER)(); |
f082dde9 | 1215 | assert(!LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER)); |
c9201081 | 1216 | reg_probe = lttng_ust_probe_register(<TNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___, LTTNG_UST_TRACEPOINT_PROVIDER)); |
4e48b5d2 MD |
1217 | if (!reg_probe) { |
1218 | fprintf(stderr, "LTTng-UST: Error while registering tracepoint probe.\n"); | |
7d381d6e MD |
1219 | abort(); |
1220 | } | |
f082dde9 | 1221 | LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER) = reg_probe; |
1c324e59 MD |
1222 | } |
1223 | ||
c589eca2 | 1224 | static void |
05bfa3dc | 1225 | LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__, LTTNG_UST_TRACEPOINT_PROVIDER)(void) lttng_ust_notrace; |
a8909ba5 | 1226 | static void |
638ce920 | 1227 | LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__, LTTNG_UST_TRACEPOINT_PROVIDER)(void) |
1c324e59 | 1228 | { |
03221919 | 1229 | if (--LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___, |
5b393d64 | 1230 | LTTNG_UST_TRACEPOINT_PROVIDER)) { |
f0cc794d MD |
1231 | return; |
1232 | } | |
f082dde9 MJ |
1233 | lttng_ust_probe_unregister(LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER)); |
1234 | LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER) = NULL; | |
1c324e59 | 1235 | } |
628e1d81 | 1236 | |
05bfa3dc JG |
1237 | LTTNG_UST_DECLARE_CONSTRUCTOR_DESTRUCTOR( |
1238 | LTTNG_UST_TRACEPOINT_PROVIDER, | |
1239 | LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__, LTTNG_UST_TRACEPOINT_PROVIDER), | |
1240 | LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__, LTTNG_UST_TRACEPOINT_PROVIDER), | |
1241 | lttng_ust_notrace) | |
1242 | ||
29d6f421 MD |
1243 | /* |
1244 | * LTTNG_UST_TRACEPOINT_PROVIDER_HIDDEN_DEFINITION: Define this before | |
1245 | * including a tracepoint instrumentation header to hide symbols | |
1246 | * associated with the tracepoint provider. This is useful if the | |
1247 | * tracepoint definition (including the header after defining | |
1248 | * LTTNG_UST_TRACEPOINT_DEFINE) is in the same module as the provider | |
1249 | * (including the header after defining | |
1250 | * LTTNG_UST_TRACEPOINT_CREATE_PROBES). | |
1251 | */ | |
1252 | #undef LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY | |
1253 | #ifdef LTTNG_UST_TRACEPOINT_PROVIDER_HIDDEN_DEFINITION | |
1254 | #define LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY __attribute__((visibility("hidden"))) | |
1255 | #else | |
1256 | #define LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY __attribute__((visibility("default"))) | |
1257 | #endif | |
1258 | ||
5b393d64 | 1259 | int LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_, LTTNG_UST_TRACEPOINT_PROVIDER) |
29d6f421 | 1260 | LTTNG_UST__TRACEPOINT_PROVIDER_DEFINITION_VISIBILITY; |