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