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