Commit | Line | Data |
---|---|---|
1c324e59 | 1 | /* |
c0c0989a | 2 | * SPDX-License-Identifier: MIT |
1c324e59 | 3 | * |
c0c0989a | 4 | * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
1c324e59 MD |
5 | */ |
6 | ||
fb31eb73 | 7 | #include <stdint.h> |
1c324e59 | 8 | #include <stdio.h> |
7d381d6e | 9 | #include <stdlib.h> |
1c324e59 | 10 | #include <urcu/compiler.h> |
f488575f | 11 | #include <urcu/rculist.h> |
1c324e59 | 12 | #include <lttng/ust-events.h> |
0466ac28 | 13 | #include <lttng/ringbuffer-context.h> |
2eba8e39 | 14 | #include <lttng/ust-arch.h> |
a8909ba5 | 15 | #include <lttng/ust-compiler.h> |
000b8662 | 16 | #include <lttng/tracepoint.h> |
3208818b | 17 | #include <lttng/ust-endian.h> |
44c72f10 | 18 | #include <string.h> |
1c324e59 | 19 | |
24a39530 PP |
20 | #define __LTTNG_UST_NULL_STRING "(null)" |
21 | ||
000b8662 MD |
22 | #undef tp_list_for_each_entry_rcu |
23 | #define tp_list_for_each_entry_rcu(pos, head, member) \ | |
10544ee8 | 24 | for (pos = cds_list_entry(tp_rcu_dereference((head)->next), __typeof__(*pos), member); \ |
000b8662 | 25 | &pos->member != (head); \ |
10544ee8 | 26 | pos = cds_list_entry(tp_rcu_dereference(pos->member.next), __typeof__(*pos), member)) |
000b8662 | 27 | |
1c324e59 MD |
28 | /* |
29 | * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the | |
30 | * same arguments and having the same field layout. | |
31 | * | |
32 | * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with | |
33 | * its own provider and name. It refers to a class (template). | |
34 | * | |
35 | * TRACEPOINT_EVENT declared both a class and an instance and does a | |
36 | * direct mapping from the instance to the class. | |
37 | */ | |
38 | ||
39 | #undef TRACEPOINT_EVENT | |
40 | #define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \ | |
f8021d08 | 41 | _TRACEPOINT_EVENT_CLASS(_provider, _name, \ |
1c324e59 MD |
42 | _TP_PARAMS(_args), \ |
43 | _TP_PARAMS(_fields)) \ | |
f8021d08 | 44 | _TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \ |
68755429 | 45 | _TP_PARAMS(_args)) |
1c324e59 | 46 | |
f8021d08 CB |
47 | #undef TRACEPOINT_EVENT_CLASS |
48 | #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
49 | _TRACEPOINT_EVENT_CLASS(_provider, _name, _TP_PARAMS(_args), _TP_PARAMS(_fields)) | |
50 | ||
51 | #undef TRACEPOINT_EVENT_INSTANCE | |
52 | #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \ | |
53 | _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _TP_PARAMS(_args)) | |
54 | ||
1c324e59 MD |
55 | /* Helpers */ |
56 | #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) | |
57 | ||
58 | #define _tp_max_t(type, x, y) \ | |
59 | ({ \ | |
60 | type __max1 = (x); \ | |
61 | type __max2 = (y); \ | |
62 | __max1 > __max2 ? __max1: __max2; \ | |
63 | }) | |
64 | ||
65 | /* | |
66 | * Stage 0 of tracepoint event generation. | |
67 | * | |
68 | * Check that each TRACEPOINT_EVENT provider argument match the | |
69 | * TRACEPOINT_PROVIDER by creating dummy callbacks. | |
70 | */ | |
71 | ||
72 | /* Reset all macros within TRACEPOINT_EVENT */ | |
73 | #include <lttng/ust-tracepoint-event-reset.h> | |
74 | ||
7ce6b21d PW |
75 | static inline lttng_ust_notrace |
76 | void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void); | |
1c324e59 MD |
77 | static inline |
78 | void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void) | |
79 | { | |
80 | } | |
81 | ||
f8021d08 CB |
82 | #undef _TRACEPOINT_EVENT_CLASS |
83 | #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
1c324e59 MD |
84 | __tracepoint_provider_mismatch_##_provider(); |
85 | ||
f8021d08 CB |
86 | #undef _TRACEPOINT_EVENT_INSTANCE |
87 | #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \ | |
1c324e59 MD |
88 | __tracepoint_provider_mismatch_##_provider(); |
89 | ||
7ce6b21d PW |
90 | static inline lttng_ust_notrace |
91 | void _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void); | |
e8bd1da7 | 92 | static inline |
1c324e59 MD |
93 | void _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void) |
94 | { | |
95 | #include TRACEPOINT_INCLUDE | |
96 | } | |
97 | ||
f56cd1d5 MD |
98 | /* |
99 | * Stage 0.1 of tracepoint event generation. | |
100 | * | |
101 | * Check that each TRACEPOINT_EVENT provider:name does not exceed the | |
102 | * tracepoint name length limit. | |
103 | */ | |
104 | ||
105 | /* Reset all macros within TRACEPOINT_EVENT */ | |
106 | #include <lttng/ust-tracepoint-event-reset.h> | |
107 | ||
f8021d08 CB |
108 | #undef _TRACEPOINT_EVENT_INSTANCE |
109 | #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \ | |
f56cd1d5 | 110 | static const char \ |
fd17d7ce | 111 | __tp_name_len_check##_provider##___##_name[LTTNG_UST_ABI_SYM_NAME_LEN] \ |
f56cd1d5 MD |
112 | __attribute__((unused)) = \ |
113 | #_provider ":" #_name; | |
114 | ||
115 | #include TRACEPOINT_INCLUDE | |
116 | ||
c75c0422 MD |
117 | /* |
118 | * Stage 0.2 of tracepoint event generation. | |
119 | * | |
120 | * Create dummy trace prototypes for each event class, and for each used | |
121 | * template. This will allow checking whether the prototypes from the | |
122 | * class and the instance using the class actually match. | |
123 | */ | |
124 | ||
125 | /* Reset all macros within TRACEPOINT_EVENT */ | |
126 | #include <lttng/ust-tracepoint-event-reset.h> | |
127 | ||
128 | #undef TP_ARGS | |
129 | #define TP_ARGS(...) __VA_ARGS__ | |
130 | ||
f8021d08 CB |
131 | #undef _TRACEPOINT_EVENT_INSTANCE |
132 | #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \ | |
c75c0422 MD |
133 | void __event_template_proto___##_provider##___##_template(_TP_ARGS_DATA_PROTO(_args)); |
134 | ||
f8021d08 CB |
135 | #undef _TRACEPOINT_EVENT_CLASS |
136 | #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
c75c0422 MD |
137 | void __event_template_proto___##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); |
138 | ||
139 | #include TRACEPOINT_INCLUDE | |
140 | ||
c785c634 MD |
141 | /* |
142 | * Stage 0.9 of tracepoint event generation | |
143 | * | |
144 | * Unfolding the enums | |
145 | */ | |
146 | #include <lttng/ust-tracepoint-event-reset.h> | |
147 | ||
148 | /* Enumeration entry (single value) */ | |
149 | #undef ctf_enum_value | |
150 | #define ctf_enum_value(_string, _value) \ | |
891d6b55 MD |
151 | __LTTNG_COMPOUND_LITERAL(struct lttng_ust_enum_entry, { \ |
152 | .struct_size = sizeof(struct lttng_ust_enum_entry), \ | |
a6f80644 | 153 | .start = { \ |
eae3c729 | 154 | .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \ |
a6f80644 | 155 | (long long) (_value) : (_value), \ |
eae3c729 | 156 | .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \ |
a6f80644 MD |
157 | }, \ |
158 | .end = { \ | |
eae3c729 | 159 | .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \ |
a6f80644 | 160 | (long long) (_value) : (_value), \ |
eae3c729 | 161 | .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \ |
a6f80644 MD |
162 | }, \ |
163 | .string = (_string), \ | |
891d6b55 | 164 | }), |
c785c634 MD |
165 | |
166 | /* Enumeration entry (range) */ | |
167 | #undef ctf_enum_range | |
168 | #define ctf_enum_range(_string, _range_start, _range_end) \ | |
891d6b55 MD |
169 | __LTTNG_COMPOUND_LITERAL(struct lttng_ust_enum_entry, { \ |
170 | .struct_size = sizeof(struct lttng_ust_enum_entry), \ | |
a6f80644 | 171 | .start = { \ |
eae3c729 | 172 | .value = lttng_ust_is_signed_type(__typeof__(_range_start)) ? \ |
a6f80644 | 173 | (long long) (_range_start) : (_range_start), \ |
eae3c729 | 174 | .signedness = lttng_ust_is_signed_type(__typeof__(_range_start)), \ |
a6f80644 MD |
175 | }, \ |
176 | .end = { \ | |
eae3c729 | 177 | .value = lttng_ust_is_signed_type(__typeof__(_range_end)) ? \ |
a6f80644 | 178 | (long long) (_range_end) : (_range_end), \ |
eae3c729 | 179 | .signedness = lttng_ust_is_signed_type(__typeof__(_range_end)), \ |
a6f80644 MD |
180 | }, \ |
181 | .string = (_string), \ | |
891d6b55 | 182 | }), |
c785c634 | 183 | |
3e762260 PP |
184 | /* Enumeration entry (automatic value; follows the rules of CTF) */ |
185 | #undef ctf_enum_auto | |
891d6b55 MD |
186 | #define ctf_enum_auto(_string) \ |
187 | __LTTNG_COMPOUND_LITERAL(struct lttng_ust_enum_entry, { \ | |
188 | .struct_size = sizeof(struct lttng_ust_enum_entry), \ | |
3e762260 PP |
189 | .start = { \ |
190 | .value = -1ULL, \ | |
191 | .signedness = 0, \ | |
192 | }, \ | |
193 | .end = { \ | |
194 | .value = -1ULL, \ | |
195 | .signedness = 0, \ | |
196 | }, \ | |
197 | .string = (_string), \ | |
1a37a873 | 198 | .options = LTTNG_UST_ENUM_ENTRY_OPTION_IS_AUTO, \ |
891d6b55 | 199 | }), |
3e762260 | 200 | |
c785c634 MD |
201 | #undef TP_ENUM_VALUES |
202 | #define TP_ENUM_VALUES(...) \ | |
203 | __VA_ARGS__ | |
204 | ||
205 | #undef TRACEPOINT_ENUM | |
206 | #define TRACEPOINT_ENUM(_provider, _name, _values) \ | |
a084756d | 207 | struct lttng_ust_enum_entry *__enum_values__##_provider##_##_name[] = { \ |
c785c634 | 208 | _values \ |
1c80c909 | 209 | ctf_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \ |
c785c634 | 210 | }; |
2df82195 FD |
211 | #include TRACEPOINT_INCLUDE |
212 | ||
213 | /* | |
214 | * Stage 0.9.1 | |
215 | * Verifying array and sequence elements are of an integer type. | |
216 | */ | |
217 | ||
218 | /* Reset all macros within TRACEPOINT_EVENT */ | |
219 | #include <lttng/ust-tracepoint-event-reset.h> | |
220 | #include <lttng/ust-tracepoint-event-write.h> | |
221 | #include <lttng/ust-tracepoint-event-nowrite.h> | |
222 | ||
223 | #undef _ctf_array_encoded | |
224 | #define _ctf_array_encoded(_type, _item, _src, _byte_order, \ | |
225 | _length, _encoding, _nowrite, \ | |
226 | _elem_type_base) \ | |
eae3c729 | 227 | lttng_ust_ctf_array_element_type_is_supported(_type, _item) |
2df82195 FD |
228 | |
229 | #undef _ctf_sequence_encoded | |
230 | #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \ | |
231 | _length_type, _src_length, _encoding, _nowrite, \ | |
232 | _elem_type_base) \ | |
eae3c729 | 233 | lttng_ust_ctf_array_element_type_is_supported(_type, _item) |
2df82195 FD |
234 | |
235 | #undef TP_FIELDS | |
236 | #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */ | |
237 | ||
f8021d08 CB |
238 | #undef _TRACEPOINT_EVENT_CLASS |
239 | #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
2df82195 | 240 | _fields |
c785c634 MD |
241 | |
242 | #include TRACEPOINT_INCLUDE | |
243 | ||
1c324e59 MD |
244 | /* |
245 | * Stage 1 of tracepoint event generation. | |
246 | * | |
247 | * Create event field type metadata section. | |
248 | * Each event produce an array of fields. | |
249 | */ | |
250 | ||
251 | /* Reset all macros within TRACEPOINT_EVENT */ | |
252 | #include <lttng/ust-tracepoint-event-reset.h> | |
4774c8f3 MD |
253 | #include <lttng/ust-tracepoint-event-write.h> |
254 | #include <lttng/ust-tracepoint-event-nowrite.h> | |
1c324e59 | 255 | |
4774c8f3 | 256 | #undef _ctf_integer_ext |
25cff019 | 257 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
a084756d | 258 | __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \ |
25cff019 MD |
259 | .struct_size = sizeof(struct lttng_ust_event_field), \ |
260 | .name = #_item, \ | |
a084756d | 261 | .type = lttng_ust_type_integer_define(_type, _byte_order, _base), \ |
25cff019 MD |
262 | .nowrite = _nowrite, \ |
263 | .nofilter = 0, \ | |
264 | }), | |
1c324e59 | 265 | |
4774c8f3 | 266 | #undef _ctf_float |
180901e6 | 267 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
a084756d | 268 | __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \ |
25cff019 MD |
269 | .struct_size = sizeof(struct lttng_ust_event_field), \ |
270 | .name = #_item, \ | |
a084756d | 271 | .type = lttng_ust_type_float_define(_type), \ |
25cff019 MD |
272 | .nowrite = _nowrite, \ |
273 | .nofilter = 0, \ | |
274 | }), | |
1c324e59 | 275 | |
4774c8f3 | 276 | #undef _ctf_array_encoded |
f3ec4cb5 MD |
277 | #define _ctf_array_encoded(_type, _item, _src, _byte_order, \ |
278 | _length, _encoding, _nowrite, \ | |
279 | _elem_type_base) \ | |
a084756d | 280 | __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \ |
25cff019 MD |
281 | .struct_size = sizeof(struct lttng_ust_event_field), \ |
282 | .name = #_item, \ | |
a084756d MD |
283 | .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_array, { \ |
284 | .parent = { \ | |
285 | .type = lttng_ust_type_array, \ | |
286 | }, \ | |
287 | .struct_size = sizeof(struct lttng_ust_type_array), \ | |
288 | .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \ | |
289 | .length = _length, \ | |
290 | .alignment = 0, \ | |
291 | .encoding = lttng_ust_string_encoding_##_encoding, \ | |
292 | }), \ | |
25cff019 MD |
293 | .nowrite = _nowrite, \ |
294 | .nofilter = 0, \ | |
295 | }), | |
1c324e59 | 296 | |
4774c8f3 | 297 | #undef _ctf_sequence_encoded |
48d660d1 | 298 | #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \ |
f968510a PP |
299 | _length_type, _src_length, _encoding, _nowrite, \ |
300 | _elem_type_base) \ | |
a084756d | 301 | __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \ |
25cff019 MD |
302 | .struct_size = sizeof(struct lttng_ust_event_field), \ |
303 | .name = "_" #_item "_length", \ | |
a084756d | 304 | .type = lttng_ust_type_integer_define(_length_type, BYTE_ORDER, 10), \ |
25cff019 MD |
305 | .nowrite = _nowrite, \ |
306 | .nofilter = 1, \ | |
307 | }), \ | |
a084756d | 308 | __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \ |
25cff019 MD |
309 | .struct_size = sizeof(struct lttng_ust_event_field), \ |
310 | .name = #_item, \ | |
a084756d MD |
311 | .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_sequence, { \ |
312 | .parent = { \ | |
313 | .type = lttng_ust_type_sequence, \ | |
1c324e59 | 314 | }, \ |
a084756d MD |
315 | .struct_size = sizeof(struct lttng_ust_type_sequence), \ |
316 | .length_name = "_" #_item "_length", \ | |
317 | .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \ | |
318 | .alignment = 0, \ | |
319 | .encoding = lttng_ust_string_encoding_##_encoding, \ | |
320 | }), \ | |
25cff019 MD |
321 | .nowrite = _nowrite, \ |
322 | .nofilter = 0, \ | |
323 | }), | |
1c324e59 | 324 | |
4774c8f3 | 325 | #undef _ctf_string |
180901e6 | 326 | #define _ctf_string(_item, _src, _nowrite) \ |
a084756d | 327 | __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \ |
25cff019 MD |
328 | .struct_size = sizeof(struct lttng_ust_event_field), \ |
329 | .name = #_item, \ | |
a084756d MD |
330 | .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_string, { \ |
331 | .parent = { \ | |
332 | .type = lttng_ust_type_string, \ | |
46d52200 | 333 | }, \ |
a084756d MD |
334 | .struct_size = sizeof(struct lttng_ust_type_string), \ |
335 | .encoding = lttng_ust_string_encoding_UTF8, \ | |
336 | }), \ | |
25cff019 MD |
337 | .nowrite = _nowrite, \ |
338 | .nofilter = 0, \ | |
339 | }), | |
1c324e59 | 340 | |
c785c634 MD |
341 | #undef _ctf_enum |
342 | #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \ | |
a084756d | 343 | __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \ |
25cff019 | 344 | .struct_size = sizeof(struct lttng_ust_event_field), \ |
c785c634 | 345 | .name = #_item, \ |
a084756d MD |
346 | .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_enum, { \ |
347 | .parent = { \ | |
348 | .type = lttng_ust_type_enum, \ | |
c785c634 | 349 | }, \ |
a084756d MD |
350 | .struct_size = sizeof(struct lttng_ust_type_enum), \ |
351 | .desc = &__enum_##_provider##_##_name, \ | |
352 | .container_type = lttng_ust_type_integer_define(_type, BYTE_ORDER, 10), \ | |
353 | }), \ | |
c785c634 | 354 | .nowrite = _nowrite, \ |
25cff019 MD |
355 | .nofilter = 0, \ |
356 | }), | |
c785c634 | 357 | |
1c324e59 | 358 | #undef TP_FIELDS |
2eda209b | 359 | #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */ |
1c324e59 | 360 | |
f8021d08 CB |
361 | #undef _TRACEPOINT_EVENT_CLASS |
362 | #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
a084756d | 363 | static struct lttng_ust_event_field *__event_fields___##_provider##___##_name[] = { \ |
1c324e59 | 364 | _fields \ |
1c80c909 | 365 | ctf_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \ |
1c324e59 MD |
366 | }; |
367 | ||
c785c634 MD |
368 | #undef TRACEPOINT_ENUM |
369 | #define TRACEPOINT_ENUM(_provider, _name, _values) \ | |
a084756d MD |
370 | static struct lttng_ust_enum_desc __enum_##_provider##_##_name = { \ |
371 | .struct_size = sizeof(struct lttng_ust_enum_desc), \ | |
c785c634 MD |
372 | .name = #_provider "_" #_name, \ |
373 | .entries = __enum_values__##_provider##_##_name, \ | |
1c80c909 | 374 | .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \ |
c785c634 MD |
375 | }; |
376 | ||
1c324e59 MD |
377 | #include TRACEPOINT_INCLUDE |
378 | ||
379 | /* | |
380 | * Stage 2 of tracepoint event generation. | |
381 | * | |
382 | * Create probe callback prototypes. | |
383 | */ | |
384 | ||
385 | /* Reset all macros within TRACEPOINT_EVENT */ | |
386 | #include <lttng/ust-tracepoint-event-reset.h> | |
387 | ||
388 | #undef TP_ARGS | |
2eda209b | 389 | #define TP_ARGS(...) __VA_ARGS__ |
1c324e59 | 390 | |
f8021d08 CB |
391 | #undef _TRACEPOINT_EVENT_CLASS |
392 | #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
1c324e59 MD |
393 | static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); |
394 | ||
395 | #include TRACEPOINT_INCLUDE | |
396 | ||
397 | /* | |
c785c634 | 398 | * Stage 3.0 of tracepoint event generation. |
1c324e59 | 399 | * |
1c324e59 MD |
400 | * Create static inline function that calculates event size. |
401 | */ | |
402 | ||
403 | /* Reset all macros within TRACEPOINT_EVENT */ | |
404 | #include <lttng/ust-tracepoint-event-reset.h> | |
4774c8f3 | 405 | #include <lttng/ust-tracepoint-event-write.h> |
1c324e59 | 406 | |
4774c8f3 | 407 | #undef _ctf_integer_ext |
180901e6 | 408 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
dc325c1d | 409 | __event_len += lttng_ust_lib_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \ |
1c324e59 MD |
410 | __event_len += sizeof(_type); |
411 | ||
4774c8f3 | 412 | #undef _ctf_float |
180901e6 | 413 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
dc325c1d | 414 | __event_len += lttng_ust_lib_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \ |
1c324e59 MD |
415 | __event_len += sizeof(_type); |
416 | ||
4774c8f3 | 417 | #undef _ctf_array_encoded |
f3ec4cb5 MD |
418 | #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \ |
419 | _nowrite, _elem_type_base) \ | |
dc325c1d | 420 | __event_len += lttng_ust_lib_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \ |
1c324e59 MD |
421 | __event_len += sizeof(_type) * (_length); |
422 | ||
4774c8f3 | 423 | #undef _ctf_sequence_encoded |
48d660d1 | 424 | #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \ |
f968510a | 425 | _src_length, _encoding, _nowrite, _elem_type_base) \ |
dc325c1d | 426 | __event_len += lttng_ust_lib_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_length_type)); \ |
1c324e59 | 427 | __event_len += sizeof(_length_type); \ |
dc325c1d | 428 | __event_len += lttng_ust_lib_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \ |
1c324e59 MD |
429 | __dynamic_len[__dynamic_len_idx] = (_src_length); \ |
430 | __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \ | |
431 | __dynamic_len_idx++; | |
432 | ||
4774c8f3 | 433 | #undef _ctf_string |
180901e6 | 434 | #define _ctf_string(_item, _src, _nowrite) \ |
24a39530 PP |
435 | __event_len += __dynamic_len[__dynamic_len_idx++] = \ |
436 | strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1; | |
1c324e59 | 437 | |
c785c634 MD |
438 | #undef _ctf_enum |
439 | #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \ | |
440 | _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite) | |
441 | ||
1c324e59 | 442 | #undef TP_ARGS |
2eda209b | 443 | #define TP_ARGS(...) __VA_ARGS__ |
1c324e59 MD |
444 | |
445 | #undef TP_FIELDS | |
2eda209b | 446 | #define TP_FIELDS(...) __VA_ARGS__ |
1c324e59 | 447 | |
f8021d08 CB |
448 | #undef _TRACEPOINT_EVENT_CLASS |
449 | #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
a8909ba5 PW |
450 | static inline lttng_ust_notrace \ |
451 | size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \ | |
452 | static inline \ | |
453 | size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \ | |
1c324e59 MD |
454 | { \ |
455 | size_t __event_len = 0; \ | |
456 | unsigned int __dynamic_len_idx = 0; \ | |
457 | \ | |
458 | if (0) \ | |
459 | (void) __dynamic_len_idx; /* don't warn if unused */ \ | |
460 | _fields \ | |
461 | return __event_len; \ | |
462 | } | |
463 | ||
464 | #include TRACEPOINT_INCLUDE | |
465 | ||
1ddfd641 MD |
466 | /* |
467 | * Stage 3.1 of tracepoint event generation. | |
468 | * | |
469 | * Create static inline function that layout the filter stack data. | |
4774c8f3 | 470 | * We make both write and nowrite data available to the filter. |
1ddfd641 MD |
471 | */ |
472 | ||
473 | /* Reset all macros within TRACEPOINT_EVENT */ | |
474 | #include <lttng/ust-tracepoint-event-reset.h> | |
4774c8f3 MD |
475 | #include <lttng/ust-tracepoint-event-write.h> |
476 | #include <lttng/ust-tracepoint-event-nowrite.h> | |
1ddfd641 | 477 | |
4774c8f3 | 478 | #undef _ctf_integer_ext |
180901e6 | 479 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
eae3c729 | 480 | if (lttng_ust_is_signed_type(_type)) { \ |
3ebeea0d MD |
481 | int64_t __ctf_tmp_int64; \ |
482 | switch (sizeof(_type)) { \ | |
483 | case 1: \ | |
484 | { \ | |
485 | union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \ | |
486 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ | |
487 | break; \ | |
488 | } \ | |
489 | case 2: \ | |
490 | { \ | |
491 | union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \ | |
39ad74cf MD |
492 | if (_byte_order != BYTE_ORDER) \ |
493 | __tmp.v = bswap_16(__tmp.v); \ | |
3ebeea0d MD |
494 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ |
495 | break; \ | |
496 | } \ | |
497 | case 4: \ | |
498 | { \ | |
499 | union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \ | |
39ad74cf MD |
500 | if (_byte_order != BYTE_ORDER) \ |
501 | __tmp.v = bswap_32(__tmp.v); \ | |
3ebeea0d MD |
502 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ |
503 | break; \ | |
504 | } \ | |
505 | case 8: \ | |
506 | { \ | |
507 | union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \ | |
39ad74cf MD |
508 | if (_byte_order != BYTE_ORDER) \ |
509 | __tmp.v = bswap_64(__tmp.v); \ | |
3ebeea0d MD |
510 | __ctf_tmp_int64 = (int64_t) __tmp.v; \ |
511 | break; \ | |
512 | } \ | |
513 | default: \ | |
514 | abort(); \ | |
515 | }; \ | |
fa099471 MD |
516 | memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \ |
517 | } else { \ | |
3ebeea0d MD |
518 | uint64_t __ctf_tmp_uint64; \ |
519 | switch (sizeof(_type)) { \ | |
520 | case 1: \ | |
521 | { \ | |
522 | union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \ | |
523 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ | |
524 | break; \ | |
525 | } \ | |
526 | case 2: \ | |
527 | { \ | |
528 | union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \ | |
39ad74cf MD |
529 | if (_byte_order != BYTE_ORDER) \ |
530 | __tmp.v = bswap_16(__tmp.v); \ | |
3ebeea0d MD |
531 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ |
532 | break; \ | |
533 | } \ | |
534 | case 4: \ | |
535 | { \ | |
536 | union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \ | |
39ad74cf MD |
537 | if (_byte_order != BYTE_ORDER) \ |
538 | __tmp.v = bswap_32(__tmp.v); \ | |
3ebeea0d MD |
539 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ |
540 | break; \ | |
541 | } \ | |
542 | case 8: \ | |
543 | { \ | |
544 | union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \ | |
39ad74cf MD |
545 | if (_byte_order != BYTE_ORDER) \ |
546 | __tmp.v = bswap_64(__tmp.v); \ | |
3ebeea0d MD |
547 | __ctf_tmp_uint64 = (uint64_t) __tmp.v; \ |
548 | break; \ | |
549 | } \ | |
550 | default: \ | |
551 | abort(); \ | |
552 | }; \ | |
fa099471 MD |
553 | memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \ |
554 | } \ | |
1ddfd641 MD |
555 | __stack_data += sizeof(int64_t); |
556 | ||
4774c8f3 | 557 | #undef _ctf_float |
180901e6 | 558 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
fa099471 MD |
559 | { \ |
560 | double __ctf_tmp_double = (double) (_type) (_src); \ | |
561 | memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \ | |
562 | __stack_data += sizeof(double); \ | |
563 | } | |
1ddfd641 | 564 | |
4774c8f3 | 565 | #undef _ctf_array_encoded |
f3ec4cb5 MD |
566 | #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \ |
567 | _encoding, _nowrite, _elem_type_base) \ | |
fa099471 MD |
568 | { \ |
569 | unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \ | |
59034aab | 570 | const void *__ctf_tmp_ptr = (_src); \ |
fa099471 MD |
571 | memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \ |
572 | __stack_data += sizeof(unsigned long); \ | |
b1239ad6 MD |
573 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \ |
574 | __stack_data += sizeof(void *); \ | |
fa099471 | 575 | } |
1ddfd641 | 576 | |
4774c8f3 | 577 | #undef _ctf_sequence_encoded |
48d660d1 | 578 | #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \ |
f968510a | 579 | _src_length, _encoding, _nowrite, _elem_type_base) \ |
fa099471 MD |
580 | { \ |
581 | unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \ | |
59034aab | 582 | const void *__ctf_tmp_ptr = (_src); \ |
fa099471 MD |
583 | memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \ |
584 | __stack_data += sizeof(unsigned long); \ | |
b1239ad6 MD |
585 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \ |
586 | __stack_data += sizeof(void *); \ | |
fa099471 | 587 | } |
1ddfd641 | 588 | |
4774c8f3 | 589 | #undef _ctf_string |
180901e6 | 590 | #define _ctf_string(_item, _src, _nowrite) \ |
fa099471 | 591 | { \ |
24a39530 PP |
592 | const void *__ctf_tmp_ptr = \ |
593 | ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \ | |
b1239ad6 MD |
594 | memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \ |
595 | __stack_data += sizeof(void *); \ | |
fa099471 | 596 | } |
1ddfd641 | 597 | |
c785c634 MD |
598 | #undef _ctf_enum |
599 | #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \ | |
600 | _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite) | |
601 | ||
1ddfd641 MD |
602 | #undef TP_ARGS |
603 | #define TP_ARGS(...) __VA_ARGS__ | |
604 | ||
605 | #undef TP_FIELDS | |
606 | #define TP_FIELDS(...) __VA_ARGS__ | |
607 | ||
f8021d08 CB |
608 | #undef _TRACEPOINT_EVENT_CLASS |
609 | #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
1ddfd641 | 610 | static inline \ |
d37ecb3f | 611 | void __event_prepare_interpreter_stack__##_provider##___##_name(char *__stack_data,\ |
1ddfd641 MD |
612 | _TP_ARGS_DATA_PROTO(_args)) \ |
613 | { \ | |
614 | _fields \ | |
615 | } | |
616 | ||
617 | #include TRACEPOINT_INCLUDE | |
618 | ||
1c324e59 | 619 | /* |
df854e41 | 620 | * Stage 4 of tracepoint event generation. |
1c324e59 MD |
621 | * |
622 | * Create static inline function that calculates event payload alignment. | |
623 | */ | |
624 | ||
625 | /* Reset all macros within TRACEPOINT_EVENT */ | |
626 | #include <lttng/ust-tracepoint-event-reset.h> | |
4774c8f3 | 627 | #include <lttng/ust-tracepoint-event-write.h> |
1c324e59 | 628 | |
4774c8f3 | 629 | #undef _ctf_integer_ext |
180901e6 | 630 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
dc325c1d | 631 | __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type)); |
1c324e59 | 632 | |
4774c8f3 | 633 | #undef _ctf_float |
180901e6 | 634 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
dc325c1d | 635 | __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type)); |
1c324e59 | 636 | |
4774c8f3 | 637 | #undef _ctf_array_encoded |
f3ec4cb5 MD |
638 | #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \ |
639 | _encoding, _nowrite, _elem_type_base) \ | |
dc325c1d | 640 | __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type)); |
1c324e59 | 641 | |
4774c8f3 | 642 | #undef _ctf_sequence_encoded |
48d660d1 | 643 | #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \ |
f968510a | 644 | _src_length, _encoding, _nowrite, _elem_type_base) \ |
dc325c1d MJ |
645 | __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_length_type)); \ |
646 | __event_align = _tp_max_t(size_t, __event_align, lttng_ust_rb_alignof(_type)); | |
1c324e59 | 647 | |
4774c8f3 | 648 | #undef _ctf_string |
180901e6 | 649 | #define _ctf_string(_item, _src, _nowrite) |
1c324e59 | 650 | |
c785c634 MD |
651 | #undef _ctf_enum |
652 | #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \ | |
653 | _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite) | |
654 | ||
1c324e59 | 655 | #undef TP_ARGS |
2eda209b | 656 | #define TP_ARGS(...) __VA_ARGS__ |
1c324e59 MD |
657 | |
658 | #undef TP_FIELDS | |
2eda209b | 659 | #define TP_FIELDS(...) __VA_ARGS__ |
1c324e59 | 660 | |
f8021d08 CB |
661 | #undef _TRACEPOINT_EVENT_CLASS |
662 | #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
a8909ba5 PW |
663 | static inline lttng_ust_notrace \ |
664 | size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \ | |
1c324e59 MD |
665 | static inline \ |
666 | size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \ | |
667 | { \ | |
668 | size_t __event_align = 1; \ | |
669 | _fields \ | |
670 | return __event_align; \ | |
671 | } | |
672 | ||
673 | #include TRACEPOINT_INCLUDE | |
674 | ||
675 | ||
676 | /* | |
df854e41 | 677 | * Stage 5 of tracepoint event generation. |
1c324e59 MD |
678 | * |
679 | * Create the probe function. This function calls event size calculation | |
680 | * and writes event data into the buffer. | |
681 | */ | |
682 | ||
683 | /* Reset all macros within TRACEPOINT_EVENT */ | |
684 | #include <lttng/ust-tracepoint-event-reset.h> | |
4774c8f3 | 685 | #include <lttng/ust-tracepoint-event-write.h> |
1c324e59 | 686 | |
4774c8f3 | 687 | #undef _ctf_integer_ext |
180901e6 | 688 | #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ |
1c324e59 MD |
689 | { \ |
690 | _type __tmp = (_src); \ | |
8936b6c0 | 691 | __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\ |
1c324e59 MD |
692 | } |
693 | ||
4774c8f3 | 694 | #undef _ctf_float |
180901e6 | 695 | #define _ctf_float(_type, _item, _src, _nowrite) \ |
1c324e59 MD |
696 | { \ |
697 | _type __tmp = (_src); \ | |
8936b6c0 | 698 | __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\ |
1c324e59 MD |
699 | } |
700 | ||
4774c8f3 | 701 | #undef _ctf_array_encoded |
f3ec4cb5 MD |
702 | #define _ctf_array_encoded(_type, _item, _src, _byte_order, _length, \ |
703 | _encoding, _nowrite, _elem_type_base) \ | |
27927814 | 704 | if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \ |
8936b6c0 | 705 | __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length), lttng_ust_rb_alignof(_type)); \ |
27927814 | 706 | else \ |
879f9b0a | 707 | __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), _length); \ |
1c324e59 | 708 | |
4774c8f3 | 709 | #undef _ctf_sequence_encoded |
48d660d1 | 710 | #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \ |
f968510a | 711 | _src_length, _encoding, _nowrite, _elem_type_base) \ |
1c324e59 | 712 | { \ |
d71b57b9 | 713 | _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \ |
8936b6c0 | 714 | __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type), lttng_ust_rb_alignof(_length_type));\ |
1c324e59 | 715 | } \ |
27927814 MD |
716 | if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \ |
717 | __chan->ops->event_write(&__ctx, _src, \ | |
8936b6c0 | 718 | sizeof(_type) * __get_dynamic_len(dest), lttng_ust_rb_alignof(_type)); \ |
27927814 | 719 | else \ |
879f9b0a | 720 | __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), __get_dynamic_len(dest)); \ |
1c324e59 | 721 | |
4774c8f3 | 722 | #undef _ctf_string |
8936b6c0 | 723 | #define _ctf_string(_item, _src, _nowrite) \ |
24a39530 PP |
724 | { \ |
725 | const char *__ctf_tmp_string = \ | |
726 | ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \ | |
f9ec4a97 MD |
727 | __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \ |
728 | __get_dynamic_len(dest)); \ | |
24a39530 PP |
729 | } |
730 | ||
1c324e59 | 731 | |
c785c634 MD |
732 | #undef _ctf_enum |
733 | #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \ | |
734 | _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite) | |
735 | ||
1c324e59 MD |
736 | /* Beware: this get len actually consumes the len value */ |
737 | #undef __get_dynamic_len | |
d71b57b9 | 738 | #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++] |
1c324e59 MD |
739 | |
740 | #undef TP_ARGS | |
2eda209b | 741 | #define TP_ARGS(...) __VA_ARGS__ |
1c324e59 MD |
742 | |
743 | #undef TP_FIELDS | |
2eda209b | 744 | #define TP_FIELDS(...) __VA_ARGS__ |
1c324e59 | 745 | |
95c25348 PW |
746 | /* |
747 | * For state dump, check that "session" argument (mandatory) matches the | |
748 | * session this event belongs to. Ensures that we write state dump data only | |
749 | * into the started session, not into all sessions. | |
750 | */ | |
751 | #undef _TP_SESSION_CHECK | |
752 | #ifdef TP_SESSION_CHECK | |
753 | #define _TP_SESSION_CHECK(session, csession) (session == csession) | |
754 | #else /* TP_SESSION_CHECK */ | |
755 | #define _TP_SESSION_CHECK(session, csession) 1 | |
756 | #endif /* TP_SESSION_CHECK */ | |
757 | ||
97904b41 MD |
758 | /* |
759 | * Use of __builtin_return_address(0) sometimes seems to cause stack | |
760 | * corruption on 32-bit PowerPC. Disable this feature on that | |
761 | * architecture for now by always using the NULL value for the ip | |
762 | * context. | |
763 | */ | |
5dadb547 MD |
764 | #undef _TP_IP_PARAM |
765 | #ifdef TP_IP_PARAM | |
e1d09f9e | 766 | #define _TP_IP_PARAM(x) (x) |
5dadb547 | 767 | #else /* TP_IP_PARAM */ |
97904b41 | 768 | |
2eba8e39 | 769 | #if defined(LTTNG_UST_ARCH_PPC) && !defined(LTTNG_UST_ARCH_PPC64) |
97904b41 | 770 | #define _TP_IP_PARAM(x) NULL |
2eba8e39 | 771 | #else |
e1d09f9e | 772 | #define _TP_IP_PARAM(x) __builtin_return_address(0) |
2eba8e39 | 773 | #endif |
97904b41 | 774 | |
5dadb547 MD |
775 | #endif /* TP_IP_PARAM */ |
776 | ||
1ddfd641 MD |
777 | /* |
778 | * Using twice size for filter stack data to hold size and pointer for | |
779 | * each field (worse case). For integers, max size required is 64-bit. | |
780 | * Same for double-precision floats. Those fit within | |
781 | * 2*sizeof(unsigned long) for all supported architectures. | |
61ce3223 | 782 | * Perform UNION (||) of filter runtime list. |
1ddfd641 | 783 | */ |
f8021d08 CB |
784 | #undef _TRACEPOINT_EVENT_CLASS |
785 | #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
a8909ba5 PW |
786 | static lttng_ust_notrace \ |
787 | void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \ | |
788 | static \ | |
789 | void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \ | |
1c324e59 | 790 | { \ |
ba99fbe2 | 791 | struct lttng_ust_event_common *__event = (struct lttng_ust_event_common *) __tp_data; \ |
1c324e59 | 792 | size_t __dynamic_len_idx = 0; \ |
75026e9f | 793 | const size_t __num_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name) - 1; \ |
d71b57b9 | 794 | union { \ |
75026e9f | 795 | size_t __dynamic_len[__num_fields]; \ |
ba99fbe2 | 796 | char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \ |
d71b57b9 | 797 | } __stackvar; \ |
1c324e59 | 798 | int __ret; \ |
a2e4d05e | 799 | bool __interpreter_stack_prepared = false; \ |
1c324e59 MD |
800 | \ |
801 | if (0) \ | |
802 | (void) __dynamic_len_idx; /* don't warn if unused */ \ | |
ba99fbe2 MD |
803 | switch (__event->type) { \ |
804 | case LTTNG_UST_EVENT_TYPE_RECORDER: \ | |
805 | { \ | |
806 | struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \ | |
e7bc0ef6 MD |
807 | struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \ |
808 | struct lttng_ust_channel_common *__chan_common = __chan->parent; \ | |
ba99fbe2 | 809 | \ |
e7bc0ef6 | 810 | if (!_TP_SESSION_CHECK(session, __chan_common->session)) \ |
ba99fbe2 | 811 | return; \ |
e7bc0ef6 | 812 | if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->session->active))) \ |
ba99fbe2 | 813 | return; \ |
e7bc0ef6 | 814 | if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->enabled))) \ |
ba99fbe2 MD |
815 | return; \ |
816 | break; \ | |
817 | } \ | |
818 | case LTTNG_UST_EVENT_TYPE_NOTIFIER: \ | |
819 | break; \ | |
820 | } \ | |
821 | if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \ | |
1c324e59 | 822 | return; \ |
1b436e01 MD |
823 | if (caa_unlikely(!TP_RCU_LINK_TEST())) \ |
824 | return; \ | |
a2e4d05e | 825 | if (caa_unlikely(CMM_ACCESS_ONCE(__event->eval_filter))) { \ |
ba99fbe2 | 826 | __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \ |
f488575f | 827 | _TP_ARGS_DATA_VAR(_args)); \ |
a2e4d05e MD |
828 | __interpreter_stack_prepared = true; \ |
829 | if (caa_likely(__event->run_filter(__event, \ | |
830 | __stackvar.__interpreter_stack_data, NULL) != LTTNG_UST_EVENT_FILTER_ACCEPT)) \ | |
61ce3223 | 831 | return; \ |
1ddfd641 | 832 | } \ |
ba99fbe2 MD |
833 | switch (__event->type) { \ |
834 | case LTTNG_UST_EVENT_TYPE_RECORDER: \ | |
835 | { \ | |
836 | size_t __event_len, __event_align; \ | |
837 | struct lttng_ust_event_recorder *__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \ | |
e7bc0ef6 | 838 | struct lttng_ust_channel_buffer *__chan = __event_recorder->chan; \ |
ba99fbe2 | 839 | struct lttng_ust_lib_ring_buffer_ctx __ctx; \ |
ba99fbe2 MD |
840 | \ |
841 | __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \ | |
842 | _TP_ARGS_DATA_VAR(_args)); \ | |
843 | __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \ | |
8936b6c0 MD |
844 | lttng_ust_lib_ring_buffer_ctx_init(&__ctx, __event_recorder, __event_len, __event_align, \ |
845 | _TP_IP_PARAM(TP_IP_PARAM)); \ | |
846 | __ret = __chan->ops->event_reserve(&__ctx); \ | |
ba99fbe2 MD |
847 | if (__ret < 0) \ |
848 | return; \ | |
849 | _fields \ | |
850 | __chan->ops->event_commit(&__ctx); \ | |
851 | break; \ | |
852 | } \ | |
853 | case LTTNG_UST_EVENT_TYPE_NOTIFIER: \ | |
854 | { \ | |
855 | struct lttng_ust_event_notifier *__event_notifier = (struct lttng_ust_event_notifier *) __event->child; \ | |
a2e4d05e MD |
856 | struct lttng_ust_notification_ctx __notif_ctx; \ |
857 | \ | |
858 | __notif_ctx.struct_size = sizeof(struct lttng_ust_notification_ctx); \ | |
859 | __notif_ctx.eval_capture = CMM_ACCESS_ONCE(__event_notifier->eval_capture); \ | |
ba99fbe2 | 860 | \ |
a2e4d05e | 861 | if (caa_unlikely(!__interpreter_stack_prepared && __notif_ctx.eval_capture)) \ |
ba99fbe2 MD |
862 | __event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \ |
863 | _TP_ARGS_DATA_VAR(_args)); \ | |
864 | \ | |
865 | __event_notifier->notification_send(__event_notifier, \ | |
a2e4d05e MD |
866 | __stackvar.__interpreter_stack_data, \ |
867 | &__notif_ctx); \ | |
ba99fbe2 MD |
868 | break; \ |
869 | } \ | |
870 | } \ | |
1c324e59 MD |
871 | } |
872 | ||
873 | #include TRACEPOINT_INCLUDE | |
874 | ||
875 | #undef __get_dynamic_len | |
876 | ||
68755429 MD |
877 | /* |
878 | * Stage 5.1 of tracepoint event generation. | |
879 | * | |
880 | * Create probe signature | |
881 | */ | |
882 | ||
883 | /* Reset all macros within TRACEPOINT_EVENT */ | |
884 | #include <lttng/ust-tracepoint-event-reset.h> | |
885 | ||
886 | #undef TP_ARGS | |
2eda209b | 887 | #define TP_ARGS(...) __VA_ARGS__ |
9eb06182 MD |
888 | |
889 | #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__ | |
68755429 | 890 | |
f8021d08 CB |
891 | #undef _TRACEPOINT_EVENT_CLASS |
892 | #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ | |
ff82b7c1 | 893 | static const char __tp_event_signature___##_provider##___##_name[] = \ |
9eb06182 | 894 | _TP_EXTRACT_STRING2(_args); |
68755429 MD |
895 | |
896 | #include TRACEPOINT_INCLUDE | |
897 | ||
9eb06182 MD |
898 | #undef _TP_EXTRACT_STRING2 |
899 | ||
05ceaafd | 900 | /* |
882a56d7 | 901 | * Stage 6 of tracepoint event generation. |
1c324e59 | 902 | * |
df854e41 MD |
903 | * Tracepoint loglevel mapping definition generation. We generate a |
904 | * symbol for each mapping for a provider/event to ensure at most a 1 to | |
905 | * 1 mapping between events and loglevels. If the symbol is repeated, | |
906 | * the compiler will complain. | |
05ceaafd MD |
907 | */ |
908 | ||
909 | /* Reset all macros within TRACEPOINT_EVENT */ | |
910 | #include <lttng/ust-tracepoint-event-reset.h> | |
911 | ||
4ea4f80e MD |
912 | /* |
913 | * Declare _loglevel___##__provider##___##__name as non-static, with | |
914 | * hidden visibility for c++ handling of weakref. We do a weakref to the | |
915 | * symbol in a later stage, which requires that the symbol is not | |
916 | * mangled. | |
917 | */ | |
918 | #ifdef __cplusplus | |
919 | #define LTTNG_TP_EXTERN_C extern "C" | |
920 | #else | |
921 | #define LTTNG_TP_EXTERN_C | |
922 | #endif | |
923 | ||
05ceaafd | 924 | #undef TRACEPOINT_LOGLEVEL |
457a6b58 MD |
925 | #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \ |
926 | static const int _loglevel_value___##__provider##___##__name = __loglevel; \ | |
4ea4f80e MD |
927 | LTTNG_TP_EXTERN_C const int *_loglevel___##__provider##___##__name \ |
928 | __attribute__((visibility("hidden"))) = \ | |
457a6b58 | 929 | &_loglevel_value___##__provider##___##__name; |
df854e41 MD |
930 | |
931 | #include TRACEPOINT_INCLUDE | |
932 | ||
4ea4f80e | 933 | #undef LTTNG_TP_EXTERN_C |
4ea4f80e | 934 | |
6ddc916d MD |
935 | /* |
936 | * Stage 6.1 of tracepoint event generation. | |
937 | * | |
938 | * Tracepoint UML URI info. | |
939 | */ | |
940 | ||
941 | /* Reset all macros within TRACEPOINT_EVENT */ | |
942 | #include <lttng/ust-tracepoint-event-reset.h> | |
943 | ||
4ea4f80e MD |
944 | /* |
945 | * Declare _model_emf_uri___##__provider##___##__name as non-static, | |
946 | * with hidden visibility for c++ handling of weakref. We do a weakref | |
947 | * to the symbol in a later stage, which requires that the symbol is not | |
948 | * mangled. | |
949 | */ | |
950 | #ifdef __cplusplus | |
951 | #define LTTNG_TP_EXTERN_C extern "C" | |
952 | #else | |
953 | #define LTTNG_TP_EXTERN_C | |
954 | #endif | |
955 | ||
6ddc916d MD |
956 | #undef TRACEPOINT_MODEL_EMF_URI |
957 | #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \ | |
4ea4f80e | 958 | LTTNG_TP_EXTERN_C const char *_model_emf_uri___##__provider##___##__name \ |
082802f9 | 959 | __attribute__((visibility("hidden"))) = __uri; \ |
6ddc916d MD |
960 | |
961 | #include TRACEPOINT_INCLUDE | |
962 | ||
4ea4f80e | 963 | #undef LTTNG_TP_EXTERN_C |
4ea4f80e | 964 | |
5b4c6da4 MD |
965 | /* |
966 | * Stage 7.0 of tracepoint event generation. | |
967 | * | |
968 | * Declare toplevel descriptor for the whole probe. | |
969 | * Unlike C, C++ does not allow tentative definitions. Therefore, we | |
970 | * need to explicitly declare the variable with "extern", using hidden | |
971 | * visibility to keep this symbol from being exported to the global | |
972 | * symbol table. | |
973 | */ | |
974 | ||
975 | extern struct lttng_ust_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER) | |
976 | __attribute__((visibility("hidden"))); | |
977 | ||
df854e41 | 978 | /* |
882a56d7 | 979 | * Stage 7.1 of tracepoint event generation. |
df854e41 MD |
980 | * |
981 | * Create events description structures. We use a weakref because | |
982 | * loglevels are optional. If not declared, the event will point to the | |
983 | * a loglevel that contains NULL. | |
984 | */ | |
985 | ||
986 | /* Reset all macros within TRACEPOINT_EVENT */ | |
987 | #include <lttng/ust-tracepoint-event-reset.h> | |
988 | ||
f8021d08 CB |
989 | #undef _TRACEPOINT_EVENT_INSTANCE |
990 | #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \ | |
882a56d7 MD |
991 | static const int * \ |
992 | __ref_loglevel___##_provider##___##_name \ | |
993 | __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \ | |
6ddc916d MD |
994 | static const char * \ |
995 | __ref_model_emf_uri___##_provider##___##_name \ | |
996 | __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\ | |
a084756d | 997 | static struct lttng_ust_event_desc __event_desc___##_provider##_##_name = { \ |
dc11f93f | 998 | .struct_size = sizeof(struct lttng_ust_event_desc), \ |
5b4c6da4 MD |
999 | .event_name = #_name, \ |
1000 | .probe_desc = &__probe_desc___##_provider, \ | |
dc11f93f | 1001 | .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template, \ |
46d52200 ZT |
1002 | .ctx = NULL, \ |
1003 | .fields = __event_fields___##_provider##___##_template, \ | |
1c80c909 | 1004 | .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template) - 1, \ |
882a56d7 | 1005 | .loglevel = &__ref_loglevel___##_provider##___##_name, \ |
68755429 | 1006 | .signature = __tp_event_signature___##_provider##___##_template, \ |
dc11f93f | 1007 | .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \ |
df854e41 MD |
1008 | }; |
1009 | ||
1010 | #include TRACEPOINT_INCLUDE | |
05ceaafd | 1011 | |
df854e41 | 1012 | /* |
882a56d7 | 1013 | * Stage 7.2 of tracepoint event generation. |
df854e41 MD |
1014 | * |
1015 | * Create array of events. | |
1016 | */ | |
1017 | ||
1018 | /* Reset all macros within TRACEPOINT_EVENT */ | |
1019 | #include <lttng/ust-tracepoint-event-reset.h> | |
1020 | ||
f8021d08 CB |
1021 | #undef _TRACEPOINT_EVENT_INSTANCE |
1022 | #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \ | |
df854e41 MD |
1023 | &__event_desc___##_provider##_##_name, |
1024 | ||
a084756d | 1025 | static struct lttng_ust_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = { |
05ceaafd | 1026 | #include TRACEPOINT_INCLUDE |
1c80c909 | 1027 | NULL, /* Dummy, C99 forbids 0-len array. */ |
05ceaafd MD |
1028 | }; |
1029 | ||
df854e41 | 1030 | |
05ceaafd | 1031 | /* |
882a56d7 | 1032 | * Stage 8 of tracepoint event generation. |
05ceaafd MD |
1033 | * |
1034 | * Create a toplevel descriptor for the whole probe. | |
1035 | */ | |
1036 | ||
5b4c6da4 | 1037 | struct lttng_ust_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER) = { |
dc11f93f | 1038 | .struct_size = sizeof(struct lttng_ust_probe_desc), |
5b4c6da4 | 1039 | .provider_name = __tp_stringify(TRACEPOINT_PROVIDER), |
05ceaafd | 1040 | .event_desc = _TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER), |
1c80c909 | 1041 | .nr_events = _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)) - 1, |
46d52200 ZT |
1042 | .head = { NULL, NULL }, |
1043 | .lazy_init_head = { NULL, NULL }, | |
1044 | .lazy = 0, | |
71d31690 MD |
1045 | .major = LTTNG_UST_PROVIDER_MAJOR, |
1046 | .minor = LTTNG_UST_PROVIDER_MINOR, | |
05ceaafd MD |
1047 | }; |
1048 | ||
f0cc794d MD |
1049 | static int _TP_COMBINE_TOKENS(__probe_register_refcount___, TRACEPOINT_PROVIDER); |
1050 | ||
05ceaafd | 1051 | /* |
882a56d7 | 1052 | * Stage 9 of tracepoint event generation. |
05ceaafd | 1053 | * |
1c324e59 | 1054 | * Register/unregister probes at module load/unload. |
628e1d81 MD |
1055 | * |
1056 | * Generate the constructor as an externally visible symbol for use when | |
1057 | * linking the probe statically. | |
f0cc794d MD |
1058 | * |
1059 | * Register refcount is protected by libc dynamic loader mutex. | |
1c324e59 MD |
1060 | */ |
1061 | ||
1062 | /* Reset all macros within TRACEPOINT_EVENT */ | |
1063 | #include <lttng/ust-tracepoint-event-reset.h> | |
a8909ba5 PW |
1064 | static void lttng_ust_notrace __attribute__((constructor)) |
1065 | _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void); | |
1066 | static void | |
1c324e59 MD |
1067 | _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void) |
1068 | { | |
1069 | int ret; | |
1070 | ||
f0cc794d MD |
1071 | if (_TP_COMBINE_TOKENS(__probe_register_refcount___, |
1072 | TRACEPOINT_PROVIDER)++) { | |
1073 | return; | |
1074 | } | |
e8bd1da7 MD |
1075 | /* |
1076 | * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a | |
1077 | * static inline function that ensures every probe PROVIDER | |
1078 | * argument match the provider within which they appear. It | |
1079 | * calls empty static inline functions, and therefore has no | |
1080 | * runtime effect. However, if it detects an error, a linker | |
1081 | * error will appear. | |
1082 | */ | |
1083 | _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(); | |
dc11f93f | 1084 | ret = lttng_ust_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER)); |
7d381d6e | 1085 | if (ret) { |
0fdd0b89 | 1086 | fprintf(stderr, "LTTng-UST: Error (%d) while registering tracepoint probe.\n", ret); |
7d381d6e MD |
1087 | abort(); |
1088 | } | |
1c324e59 MD |
1089 | } |
1090 | ||
a8909ba5 PW |
1091 | static void lttng_ust_notrace __attribute__((destructor)) |
1092 | _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void); | |
1093 | static void | |
1c324e59 MD |
1094 | _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void) |
1095 | { | |
f0cc794d MD |
1096 | if (--_TP_COMBINE_TOKENS(__probe_register_refcount___, |
1097 | TRACEPOINT_PROVIDER)) { | |
1098 | return; | |
1099 | } | |
dc11f93f | 1100 | lttng_ust_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER)); |
1c324e59 | 1101 | } |
628e1d81 | 1102 | |
6c8cfec7 MD |
1103 | int _TP_COMBINE_TOKENS(__tracepoint_provider_, TRACEPOINT_PROVIDER) |
1104 | __attribute__((visibility("default"))); |