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