Fix: move compat macros for tracepoint probes to ust-tracepoint-event.h
[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>
0b4b8811 13#include <lttng/ust-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>
4849bc7a 18#include <lttng/ust-api-compat.h>
44c72f10 19#include <string.h>
f3b06377
MD
20#include <lttng/ust-api-compat.h>
21
22#if LTTNG_UST_COMPAT_API(0)
23#define TP_FIELDS LTTNG_UST_TP_FIELDS
24
25#define ctf_integer lttng_ust_field_integer
26#define ctf_integer_hex lttng_ust_field_integer_hex
27#define ctf_integer_network lttng_ust_field_integer_network
28#define ctf_integer_network_hex lttng_ust_field_integer_network_hex
29#define ctf_integer_nowrite lttng_ust_field_integer_nowrite
30
31#define ctf_float lttng_ust_field_float
32#define ctf_float_nowrite lttng_ust_field_float_nowrite
33
34#define ctf_array lttng_ust_field_array
35#define ctf_array_hex lttng_ust_field_array_hex
36#define ctf_array_network lttng_ust_field_array_network
37#define ctf_array_network_hex lttng_ust_field_array_network_hex
38#define ctf_array_text lttng_ust_field_array_text
39#define ctf_array_nowrite lttng_ust_field_array_nowrite
40#define ctf_array_nowrite_hex lttng_ust_field_array_nowrite_hex
41#define ctf_array_network_nowrite lttng_ust_field_array_network_nowrite
42#define ctf_array_network_nowrite_hex lttng_ust_field_array_network_nowrite_hex
43#define ctf_array_text_nowrite lttng_ust_field_array_text_nowrite
44
45#define ctf_sequence lttng_ust_field_sequence
46#define ctf_sequence_hex lttng_ust_field_sequence_hex
47#define ctf_sequence_network lttng_ust_field_sequence_network
48#define ctf_sequence_network_hex lttng_ust_field_sequence_network_hex
49#define ctf_sequence_text lttng_ust_field_sequence_text
50#define ctf_sequence_nowrite lttng_ust_field_sequence_nowrite
51#define ctf_sequence_nowrite_hex lttng_ust_field_sequence_nowrite_hex
52#define ctf_sequence_network_nowrite lttng_ust_field_sequence_network_nowrite
53#define ctf_sequence_network_nowrite_hex lttng_ust_field_sequence_network_nowrite_hex
54#define ctf_sequence_text_nowrite lttng_ust_field_sequence_text_nowrite
55
56#define ctf_string lttng_ust_field_string
57#define ctf_string_nowrite lttng_ust_field_string_nowrite
58
59#define ctf_unused lttng_ust_field_unused
60#define ctf_unused_nowrite lttng_ust_field_unused_nowrite
61
62#define ctf_enum lttng_ust_field_enum
63#define ctf_enum_nowrite lttng_ust_field_enum_nowrite
64#define ctf_enum_value lttng_ust_field_enum_value
65#define ctf_enum_range lttng_ust_field_enum_range
66#define ctf_enum_auto lttng_ust_field_enum_auto
67#endif /* #if LTTNG_UST_COMPAT_API(0) */
1c324e59 68
ee0889a3 69#define LTTNG_UST__NULL_STRING "(null)"
24a39530 70
1c324e59 71/*
7f2f82c3 72 * LTTNG_UST_TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
1c324e59
MD
73 * same arguments and having the same field layout.
74 *
7f2f82c3 75 * LTTNG_UST_TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
1c324e59
MD
76 * its own provider and name. It refers to a class (template).
77 *
7f2f82c3 78 * LTTNG_UST_TRACEPOINT_EVENT declared both a class and an instance and does a
1c324e59
MD
79 * direct mapping from the instance to the class.
80 */
81
7f2f82c3
MJ
82#undef LTTNG_UST_TRACEPOINT_EVENT
83#define LTTNG_UST_TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
84 LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, \
6eddcb06
MJ
85 LTTNG_UST__TP_PARAMS(_args), \
86 LTTNG_UST__TP_PARAMS(_fields)) \
7f2f82c3 87 LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
6eddcb06 88 LTTNG_UST__TP_PARAMS(_args))
1c324e59 89
7f2f82c3
MJ
90#undef LTTNG_UST_TRACEPOINT_EVENT_CLASS
91#define LTTNG_UST_TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
6eddcb06 92 LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, LTTNG_UST__TP_PARAMS(_args), LTTNG_UST__TP_PARAMS(_fields))
f8021d08 93
7f2f82c3
MJ
94#undef LTTNG_UST_TRACEPOINT_EVENT_INSTANCE
95#define LTTNG_UST_TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
6eddcb06 96 LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, LTTNG_UST__TP_PARAMS(_args))
f8021d08 97
1c324e59 98/* Helpers */
ca6ed78d 99#define LTTNG_UST__TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
1c324e59 100
1210ca90 101#define lttng_ust__tp_max_t(type, x, y) \
1c324e59 102 ({ \
1210ca90
MJ
103 type lttng_ust__max1 = (x); \
104 type lttng_ust__max2 = (y); \
105 lttng_ust__max1 > lttng_ust__max2 ? lttng_ust__max1: lttng_ust__max2; \
1c324e59
MD
106 })
107
108/*
109 * Stage 0 of tracepoint event generation.
110 *
7f2f82c3 111 * Check that each LTTNG_UST_TRACEPOINT_EVENT provider argument match the
5b393d64 112 * LTTNG_UST_TRACEPOINT_PROVIDER by creating dummy callbacks.
1c324e59
MD
113 */
114
7f2f82c3 115/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1c324e59
MD
116#include <lttng/ust-tracepoint-event-reset.h>
117
106ff4da 118static inline
5b393d64 119void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_mismatch_, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
106ff4da 120 lttng_ust_notrace;
1c324e59 121static inline
5b393d64 122void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_mismatch_, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
1c324e59
MD
123{
124}
125
7f2f82c3
MJ
126#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
127#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
0274f7f2 128 lttng_ust_tracepoint_provider_mismatch_##_provider();
1c324e59 129
7f2f82c3
MJ
130#undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
131#define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
0274f7f2 132 lttng_ust_tracepoint_provider_mismatch_##_provider();
1c324e59 133
106ff4da 134static inline
5b393d64 135void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
106ff4da 136 lttng_ust_notrace;
e8bd1da7 137static inline
5b393d64 138void LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
1c324e59 139{
bb71a8ea 140#include LTTNG_UST_TRACEPOINT_INCLUDE
1c324e59
MD
141}
142
f56cd1d5
MD
143/*
144 * Stage 0.1 of tracepoint event generation.
145 *
7f2f82c3 146 * Check that each LTTNG_UST_TRACEPOINT_EVENT provider:name does not exceed the
f56cd1d5
MD
147 * tracepoint name length limit.
148 */
149
7f2f82c3 150/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
f56cd1d5
MD
151#include <lttng/ust-tracepoint-event-reset.h>
152
7f2f82c3
MJ
153#undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
154#define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
81b16412 155 lttng_ust_tracepoint_validate_name_len(_provider, _name);
f56cd1d5 156
bb71a8ea 157#include LTTNG_UST_TRACEPOINT_INCLUDE
f56cd1d5 158
c75c0422
MD
159/*
160 * Stage 0.2 of tracepoint event generation.
161 *
162 * Create dummy trace prototypes for each event class, and for each used
163 * template. This will allow checking whether the prototypes from the
164 * class and the instance using the class actually match.
165 */
166
7f2f82c3 167/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
c75c0422
MD
168#include <lttng/ust-tracepoint-event-reset.h>
169
cadfcbfc
MJ
170#undef LTTNG_UST_TP_ARGS
171#define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
c75c0422 172
7f2f82c3
MJ
173#undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
174#define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
bfcc2759 175void lttng_ust__event_template_proto___##_provider##___##_template(LTTNG_UST__TP_ARGS_DATA_PROTO(_args));
c75c0422 176
7f2f82c3
MJ
177#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
178#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
bfcc2759 179void lttng_ust__event_template_proto___##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args));
c75c0422 180
bb71a8ea 181#include LTTNG_UST_TRACEPOINT_INCLUDE
c75c0422 182
c785c634
MD
183/*
184 * Stage 0.9 of tracepoint event generation
185 *
186 * Unfolding the enums
187 */
188#include <lttng/ust-tracepoint-event-reset.h>
189
190/* Enumeration entry (single value) */
78684808
MJ
191#undef lttng_ust_field_enum_value
192#define lttng_ust_field_enum_value(_string, _value) \
5defa774 193 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \
891d6b55 194 .struct_size = sizeof(struct lttng_ust_enum_entry), \
a6f80644 195 .start = { \
eae3c729 196 .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
a6f80644 197 (long long) (_value) : (_value), \
eae3c729 198 .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \
a6f80644
MD
199 }, \
200 .end = { \
eae3c729 201 .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
a6f80644 202 (long long) (_value) : (_value), \
eae3c729 203 .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \
a6f80644
MD
204 }, \
205 .string = (_string), \
891d6b55 206 }),
c785c634
MD
207
208/* Enumeration entry (range) */
78684808
MJ
209#undef lttng_ust_field_enum_range
210#define lttng_ust_field_enum_range(_string, _range_start, _range_end) \
5defa774 211 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \
891d6b55 212 .struct_size = sizeof(struct lttng_ust_enum_entry), \
a6f80644 213 .start = { \
eae3c729 214 .value = lttng_ust_is_signed_type(__typeof__(_range_start)) ? \
a6f80644 215 (long long) (_range_start) : (_range_start), \
eae3c729 216 .signedness = lttng_ust_is_signed_type(__typeof__(_range_start)), \
a6f80644
MD
217 }, \
218 .end = { \
eae3c729 219 .value = lttng_ust_is_signed_type(__typeof__(_range_end)) ? \
a6f80644 220 (long long) (_range_end) : (_range_end), \
eae3c729 221 .signedness = lttng_ust_is_signed_type(__typeof__(_range_end)), \
a6f80644
MD
222 }, \
223 .string = (_string), \
891d6b55 224 }),
c785c634 225
3e762260 226/* Enumeration entry (automatic value; follows the rules of CTF) */
78684808
MJ
227#undef lttng_ust_field_enum_auto
228#define lttng_ust_field_enum_auto(_string) \
5defa774 229 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_enum_entry, { \
891d6b55 230 .struct_size = sizeof(struct lttng_ust_enum_entry), \
3e762260
PP
231 .start = { \
232 .value = -1ULL, \
233 .signedness = 0, \
234 }, \
235 .end = { \
236 .value = -1ULL, \
237 .signedness = 0, \
238 }, \
239 .string = (_string), \
1a37a873 240 .options = LTTNG_UST_ENUM_ENTRY_OPTION_IS_AUTO, \
891d6b55 241 }),
3e762260 242
4849bc7a
MJ
243#undef LTTNG_UST_TP_ENUM_VALUES
244#define LTTNG_UST_TP_ENUM_VALUES(...) \
c785c634
MD
245 __VA_ARGS__
246
4849bc7a
MJ
247#if LTTNG_UST_COMPAT_API(0)
248# undef TP_ENUM_VALUES
249# define TP_ENUM_VALUES LTTNG_UST_TP_ENUM_VALUES
250#endif /* #if LTTNG_UST_COMPAT_API(0) */
251
2ebf164b
MJ
252#undef LTTNG_UST_TRACEPOINT_ENUM
253#define LTTNG_UST_TRACEPOINT_ENUM(_provider, _name, _values) \
3d33ca1d 254 const struct lttng_ust_enum_entry * const __enum_values__##_provider##_##_name[] = { \
c785c634 255 _values \
78684808 256 lttng_ust_field_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \
c785c634 257 };
bb71a8ea 258#include LTTNG_UST_TRACEPOINT_INCLUDE
2df82195
FD
259
260/*
261 * Stage 0.9.1
262 * Verifying array and sequence elements are of an integer type.
263 */
264
7f2f82c3 265/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
2df82195
FD
266#include <lttng/ust-tracepoint-event-reset.h>
267#include <lttng/ust-tracepoint-event-write.h>
268#include <lttng/ust-tracepoint-event-nowrite.h>
269
10937ee5
MJ
270#undef lttng_ust__field_array_encoded
271#define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, \
2df82195
FD
272 _length, _encoding, _nowrite, \
273 _elem_type_base) \
10937ee5 274 lttng_ust_field_array_element_type_is_supported(_type, _item);
2df82195 275
1d188af9
MJ
276#undef lttng_ust__field_sequence_encoded
277#define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, \
2df82195
FD
278 _length_type, _src_length, _encoding, _nowrite, \
279 _elem_type_base) \
10937ee5 280 lttng_ust_field_array_element_type_is_supported(_type, _item);
2df82195 281
efa14d16
MJ
282#undef LTTNG_UST_TP_FIELDS
283#define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
2df82195 284
7f2f82c3
MJ
285#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
286#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
2df82195 287 _fields
c785c634 288
bb71a8ea 289#include LTTNG_UST_TRACEPOINT_INCLUDE
c785c634 290
1c324e59
MD
291/*
292 * Stage 1 of tracepoint event generation.
293 *
294 * Create event field type metadata section.
295 * Each event produce an array of fields.
296 */
297
7f2f82c3 298/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1c324e59 299#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3
MD
300#include <lttng/ust-tracepoint-event-write.h>
301#include <lttng/ust-tracepoint-event-nowrite.h>
1c324e59 302
b4064f28
MJ
303#undef lttng_ust__field_integer_ext
304#define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
5defa774 305 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
25cff019
MD
306 .struct_size = sizeof(struct lttng_ust_event_field), \
307 .name = #_item, \
a084756d 308 .type = lttng_ust_type_integer_define(_type, _byte_order, _base), \
25cff019
MD
309 .nowrite = _nowrite, \
310 .nofilter = 0, \
311 }),
1c324e59 312
891226fc
MJ
313#undef lttng_ust__field_float
314#define lttng_ust__field_float(_type, _item, _src, _nowrite) \
5defa774 315 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
25cff019
MD
316 .struct_size = sizeof(struct lttng_ust_event_field), \
317 .name = #_item, \
a084756d 318 .type = lttng_ust_type_float_define(_type), \
25cff019
MD
319 .nowrite = _nowrite, \
320 .nofilter = 0, \
321 }),
1c324e59 322
10937ee5
MJ
323#undef lttng_ust__field_array_encoded
324#define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, \
f3ec4cb5
MD
325 _length, _encoding, _nowrite, \
326 _elem_type_base) \
5defa774 327 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
25cff019
MD
328 .struct_size = sizeof(struct lttng_ust_event_field), \
329 .name = #_item, \
5defa774 330 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_array, { \
a084756d
MD
331 .parent = { \
332 .type = lttng_ust_type_array, \
333 }, \
334 .struct_size = sizeof(struct lttng_ust_type_array), \
335 .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \
336 .length = _length, \
337 .alignment = 0, \
338 .encoding = lttng_ust_string_encoding_##_encoding, \
339 }), \
25cff019
MD
340 .nowrite = _nowrite, \
341 .nofilter = 0, \
342 }),
1c324e59 343
1d188af9
MJ
344#undef lttng_ust__field_sequence_encoded
345#define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, \
f968510a
PP
346 _length_type, _src_length, _encoding, _nowrite, \
347 _elem_type_base) \
5defa774 348 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
25cff019
MD
349 .struct_size = sizeof(struct lttng_ust_event_field), \
350 .name = "_" #_item "_length", \
baa8acf3 351 .type = lttng_ust_type_integer_define(_length_type, LTTNG_UST_BYTE_ORDER, 10), \
25cff019
MD
352 .nowrite = _nowrite, \
353 .nofilter = 1, \
354 }), \
5defa774 355 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
25cff019
MD
356 .struct_size = sizeof(struct lttng_ust_event_field), \
357 .name = #_item, \
5defa774 358 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_sequence, { \
a084756d
MD
359 .parent = { \
360 .type = lttng_ust_type_sequence, \
1c324e59 361 }, \
a084756d
MD
362 .struct_size = sizeof(struct lttng_ust_type_sequence), \
363 .length_name = "_" #_item "_length", \
364 .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \
365 .alignment = 0, \
366 .encoding = lttng_ust_string_encoding_##_encoding, \
367 }), \
25cff019
MD
368 .nowrite = _nowrite, \
369 .nofilter = 0, \
370 }),
1c324e59 371
3202f63a
MJ
372#undef lttng_ust__field_string
373#define lttng_ust__field_string(_item, _src, _nowrite) \
5defa774 374 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
25cff019
MD
375 .struct_size = sizeof(struct lttng_ust_event_field), \
376 .name = #_item, \
5defa774 377 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_string, { \
a084756d
MD
378 .parent = { \
379 .type = lttng_ust_type_string, \
46d52200 380 }, \
a084756d
MD
381 .struct_size = sizeof(struct lttng_ust_type_string), \
382 .encoding = lttng_ust_string_encoding_UTF8, \
383 }), \
25cff019
MD
384 .nowrite = _nowrite, \
385 .nofilter = 0, \
386 }),
1c324e59 387
ddde62ca
MJ
388#undef lttng_ust__field_unused
389#define lttng_ust__field_unused(_src)
5152f6df 390
78684808
MJ
391#undef lttng_ust__field_enum
392#define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
5defa774 393 LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field, { \
25cff019 394 .struct_size = sizeof(struct lttng_ust_event_field), \
c785c634 395 .name = #_item, \
5defa774 396 .type = (const struct lttng_ust_type_common *) LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_type_enum, { \
a084756d
MD
397 .parent = { \
398 .type = lttng_ust_type_enum, \
c785c634 399 }, \
a084756d
MD
400 .struct_size = sizeof(struct lttng_ust_type_enum), \
401 .desc = &__enum_##_provider##_##_name, \
baa8acf3 402 .container_type = lttng_ust_type_integer_define(_type, LTTNG_UST_BYTE_ORDER, 10), \
a084756d 403 }), \
c785c634 404 .nowrite = _nowrite, \
25cff019
MD
405 .nofilter = 0, \
406 }),
c785c634 407
efa14d16
MJ
408#undef LTTNG_UST_TP_FIELDS
409#define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
1c324e59 410
7f2f82c3
MJ
411#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
412#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
bfcc2759 413 static const struct lttng_ust_event_field * const lttng_ust__event_fields___##_provider##___##_name[] = { \
1c324e59 414 _fields \
b4064f28 415 lttng_ust_field_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \
1c324e59
MD
416 };
417
2ebf164b
MJ
418#undef LTTNG_UST_TRACEPOINT_ENUM
419#define LTTNG_UST_TRACEPOINT_ENUM(_provider, _name, _values) \
4e48b5d2 420 static const struct lttng_ust_enum_desc __enum_##_provider##_##_name = { \
a084756d 421 .struct_size = sizeof(struct lttng_ust_enum_desc), \
c785c634
MD
422 .name = #_provider "_" #_name, \
423 .entries = __enum_values__##_provider##_##_name, \
ca6ed78d 424 .nr_entries = LTTNG_UST__TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \
c785c634
MD
425 };
426
bb71a8ea 427#include LTTNG_UST_TRACEPOINT_INCLUDE
1c324e59
MD
428
429/*
430 * Stage 2 of tracepoint event generation.
431 *
432 * Create probe callback prototypes.
433 */
434
7f2f82c3 435/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1c324e59
MD
436#include <lttng/ust-tracepoint-event-reset.h>
437
cadfcbfc
MJ
438#undef LTTNG_UST_TP_ARGS
439#define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
1c324e59 440
7f2f82c3
MJ
441#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
442#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
bfcc2759 443static void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args));
1c324e59 444
bb71a8ea 445#include LTTNG_UST_TRACEPOINT_INCLUDE
1c324e59
MD
446
447/*
c785c634 448 * Stage 3.0 of tracepoint event generation.
1c324e59 449 *
1c324e59
MD
450 * Create static inline function that calculates event size.
451 */
452
7f2f82c3 453/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1c324e59 454#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3 455#include <lttng/ust-tracepoint-event-write.h>
1c324e59 456
b4064f28
MJ
457#undef lttng_ust__field_integer_ext
458#define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
5152f6df
MJ
459 if (0) \
460 (void) (_src); /* Unused */ \
b5457df5 461 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
1c324e59
MD
462 __event_len += sizeof(_type);
463
891226fc
MJ
464#undef lttng_ust__field_float
465#define lttng_ust__field_float(_type, _item, _src, _nowrite) \
5152f6df
MJ
466 if (0) \
467 (void) (_src); /* Unused */ \
b5457df5 468 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
1c324e59
MD
469 __event_len += sizeof(_type);
470
10937ee5
MJ
471#undef lttng_ust__field_array_encoded
472#define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, _encoding, \
f3ec4cb5 473 _nowrite, _elem_type_base) \
5152f6df
MJ
474 if (0) \
475 (void) (_src); /* Unused */ \
b5457df5 476 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
1c324e59
MD
477 __event_len += sizeof(_type) * (_length);
478
1d188af9
MJ
479#undef lttng_ust__field_sequence_encoded
480#define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
f968510a 481 _src_length, _encoding, _nowrite, _elem_type_base) \
5152f6df
MJ
482 if (0) \
483 (void) (_src); /* Unused */ \
b5457df5 484 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_length_type)); \
1c324e59 485 __event_len += sizeof(_length_type); \
b5457df5 486 __event_len += lttng_ust_ring_buffer_align(__event_len, lttng_ust_rb_alignof(_type)); \
1c324e59
MD
487 __dynamic_len[__dynamic_len_idx] = (_src_length); \
488 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
489 __dynamic_len_idx++;
490
3202f63a
MJ
491#undef lttng_ust__field_string
492#define lttng_ust__field_string(_item, _src, _nowrite) \
24a39530 493 __event_len += __dynamic_len[__dynamic_len_idx++] = \
ee0889a3 494 strlen((_src) ? (_src) : LTTNG_UST__NULL_STRING) + 1;
1c324e59 495
ddde62ca
MJ
496#undef lttng_ust__field_unused
497#define lttng_ust__field_unused(_src) \
5152f6df
MJ
498 if (0) \
499 (void) (_src); /* Unused */
500
78684808
MJ
501#undef lttng_ust__field_enum
502#define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
b4064f28 503 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
c785c634 504
cadfcbfc
MJ
505#undef LTTNG_UST_TP_ARGS
506#define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
1c324e59 507
efa14d16
MJ
508#undef LTTNG_UST_TP_FIELDS
509#define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
1c324e59 510
7f2f82c3
MJ
511#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
512#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
106ff4da 513static inline \
bfcc2759 514size_t lttng_ust__event_get_size__##_provider##___##_name(size_t *__dynamic_len, LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
106ff4da 515 lttng_ust_notrace; \
a8909ba5 516static inline \
bfcc2759 517size_t lttng_ust__event_get_size__##_provider##___##_name( \
5152f6df 518 size_t *__dynamic_len __attribute__((__unused__)), \
6eddcb06 519 LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
1c324e59
MD
520{ \
521 size_t __event_len = 0; \
5152f6df 522 unsigned int __dynamic_len_idx __attribute__((__unused__)) = 0; \
1c324e59
MD
523 \
524 if (0) \
5152f6df
MJ
525 (void) __tp_data; /* don't warn if unused */ \
526 \
1c324e59
MD
527 _fields \
528 return __event_len; \
529}
530
bb71a8ea 531#include LTTNG_UST_TRACEPOINT_INCLUDE
1c324e59 532
1ddfd641
MD
533/*
534 * Stage 3.1 of tracepoint event generation.
535 *
536 * Create static inline function that layout the filter stack data.
4774c8f3 537 * We make both write and nowrite data available to the filter.
1ddfd641
MD
538 */
539
7f2f82c3 540/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1ddfd641 541#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3
MD
542#include <lttng/ust-tracepoint-event-write.h>
543#include <lttng/ust-tracepoint-event-nowrite.h>
1ddfd641 544
b4064f28
MJ
545#undef lttng_ust__field_integer_ext
546#define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
eae3c729 547 if (lttng_ust_is_signed_type(_type)) { \
3ebeea0d
MD
548 int64_t __ctf_tmp_int64; \
549 switch (sizeof(_type)) { \
550 case 1: \
551 { \
552 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
553 __ctf_tmp_int64 = (int64_t) __tmp.v; \
554 break; \
555 } \
556 case 2: \
557 { \
558 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
baa8acf3
MJ
559 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
560 __tmp.v = lttng_ust_bswap_16(__tmp.v); \
3ebeea0d
MD
561 __ctf_tmp_int64 = (int64_t) __tmp.v; \
562 break; \
563 } \
564 case 4: \
565 { \
566 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
baa8acf3
MJ
567 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
568 __tmp.v = lttng_ust_bswap_32(__tmp.v); \
3ebeea0d
MD
569 __ctf_tmp_int64 = (int64_t) __tmp.v; \
570 break; \
571 } \
572 case 8: \
573 { \
574 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
baa8acf3
MJ
575 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
576 __tmp.v = lttng_ust_bswap_64(__tmp.v); \
3ebeea0d
MD
577 __ctf_tmp_int64 = (int64_t) __tmp.v; \
578 break; \
579 } \
580 default: \
581 abort(); \
582 }; \
fa099471
MD
583 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
584 } else { \
3ebeea0d
MD
585 uint64_t __ctf_tmp_uint64; \
586 switch (sizeof(_type)) { \
587 case 1: \
588 { \
589 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
590 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
591 break; \
592 } \
593 case 2: \
594 { \
595 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
baa8acf3
MJ
596 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
597 __tmp.v = lttng_ust_bswap_16(__tmp.v); \
3ebeea0d
MD
598 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
599 break; \
600 } \
601 case 4: \
602 { \
603 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
baa8acf3
MJ
604 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
605 __tmp.v = lttng_ust_bswap_32(__tmp.v); \
3ebeea0d
MD
606 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
607 break; \
608 } \
609 case 8: \
610 { \
611 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
baa8acf3
MJ
612 if (_byte_order != LTTNG_UST_BYTE_ORDER) \
613 __tmp.v = lttng_ust_bswap_64(__tmp.v); \
3ebeea0d
MD
614 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
615 break; \
616 } \
617 default: \
618 abort(); \
619 }; \
fa099471
MD
620 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
621 } \
1ddfd641
MD
622 __stack_data += sizeof(int64_t);
623
891226fc
MJ
624#undef lttng_ust__field_float
625#define lttng_ust__field_float(_type, _item, _src, _nowrite) \
fa099471
MD
626 { \
627 double __ctf_tmp_double = (double) (_type) (_src); \
628 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
629 __stack_data += sizeof(double); \
630 }
1ddfd641 631
10937ee5
MJ
632#undef lttng_ust__field_array_encoded
633#define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \
f3ec4cb5 634 _encoding, _nowrite, _elem_type_base) \
fa099471
MD
635 { \
636 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
59034aab 637 const void *__ctf_tmp_ptr = (_src); \
fa099471
MD
638 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
639 __stack_data += sizeof(unsigned long); \
b1239ad6
MD
640 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
641 __stack_data += sizeof(void *); \
fa099471 642 }
1ddfd641 643
1d188af9
MJ
644#undef lttng_ust__field_sequence_encoded
645#define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
f968510a 646 _src_length, _encoding, _nowrite, _elem_type_base) \
fa099471
MD
647 { \
648 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
59034aab 649 const void *__ctf_tmp_ptr = (_src); \
fa099471
MD
650 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
651 __stack_data += sizeof(unsigned long); \
b1239ad6
MD
652 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
653 __stack_data += sizeof(void *); \
fa099471 654 }
1ddfd641 655
3202f63a
MJ
656#undef lttng_ust__field_string
657#define lttng_ust__field_string(_item, _src, _nowrite) \
fa099471 658 { \
24a39530 659 const void *__ctf_tmp_ptr = \
ee0889a3 660 ((_src) ? (_src) : LTTNG_UST__NULL_STRING); \
b1239ad6
MD
661 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
662 __stack_data += sizeof(void *); \
fa099471 663 }
1ddfd641 664
ddde62ca
MJ
665#undef lttng_ust__field_unused
666#define lttng_ust__field_unused(_src) \
5152f6df
MJ
667 if (0) \
668 (void) (_src);
669
78684808
MJ
670#undef lttng_ust__field_enum
671#define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
b4064f28 672 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
c785c634 673
cadfcbfc
MJ
674#undef LTTNG_UST_TP_ARGS
675#define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
1ddfd641 676
efa14d16
MJ
677#undef LTTNG_UST_TP_FIELDS
678#define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
1ddfd641 679
7f2f82c3
MJ
680#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
681#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
1ddfd641 682static inline \
bfcc2759 683void lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(char *__stack_data,\
6eddcb06 684 LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
1ddfd641 685{ \
5152f6df
MJ
686 if (0) { \
687 (void) __tp_data; /* don't warn if unused */ \
688 (void) __stack_data; /* don't warn if unused */ \
689 } \
690 \
1ddfd641
MD
691 _fields \
692}
693
bb71a8ea 694#include LTTNG_UST_TRACEPOINT_INCLUDE
1ddfd641 695
1c324e59 696/*
df854e41 697 * Stage 4 of tracepoint event generation.
1c324e59
MD
698 *
699 * Create static inline function that calculates event payload alignment.
700 */
701
7f2f82c3 702/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1c324e59 703#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3 704#include <lttng/ust-tracepoint-event-write.h>
1c324e59 705
b4064f28
MJ
706#undef lttng_ust__field_integer_ext
707#define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
5152f6df
MJ
708 if (0) \
709 (void) (_src); /* Unused */ \
bfcc2759 710 lttng_ust__event_align = lttng_ust__tp_max_t(size_t, lttng_ust__event_align, lttng_ust_rb_alignof(_type));
1c324e59 711
891226fc
MJ
712#undef lttng_ust__field_float
713#define lttng_ust__field_float(_type, _item, _src, _nowrite) \
5152f6df
MJ
714 if (0) \
715 (void) (_src); /* Unused */ \
bfcc2759 716 lttng_ust__event_align = lttng_ust__tp_max_t(size_t, lttng_ust__event_align, lttng_ust_rb_alignof(_type));
1c324e59 717
10937ee5
MJ
718#undef lttng_ust__field_array_encoded
719#define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \
f3ec4cb5 720 _encoding, _nowrite, _elem_type_base) \
5152f6df
MJ
721 if (0) \
722 (void) (_src); /* Unused */ \
bfcc2759 723 lttng_ust__event_align = lttng_ust__tp_max_t(size_t, lttng_ust__event_align, lttng_ust_rb_alignof(_type));
1c324e59 724
1d188af9
MJ
725#undef lttng_ust__field_sequence_encoded
726#define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
f968510a 727 _src_length, _encoding, _nowrite, _elem_type_base) \
5152f6df
MJ
728 if (0) \
729 (void) (_src); /* Unused */ \
730 if (0) \
731 (void) (_src_length); /* Unused */ \
bfcc2759
MJ
732 lttng_ust__event_align = lttng_ust__tp_max_t(size_t, lttng_ust__event_align, lttng_ust_rb_alignof(_length_type)); \
733 lttng_ust__event_align = lttng_ust__tp_max_t(size_t, lttng_ust__event_align, lttng_ust_rb_alignof(_type));
1c324e59 734
3202f63a
MJ
735#undef lttng_ust__field_string
736#define lttng_ust__field_string(_item, _src, _nowrite) \
5152f6df
MJ
737 if (0) \
738 (void) (_src); /* Unused */
739
ddde62ca
MJ
740#undef lttng_ust__field_unused
741#define lttng_ust__field_unused(_src) \
5152f6df
MJ
742 if (0) \
743 (void) (_src); /* Unused */
1c324e59 744
78684808
MJ
745#undef lttng_ust__field_enum
746#define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
b4064f28 747 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
c785c634 748
cadfcbfc
MJ
749#undef LTTNG_UST_TP_ARGS
750#define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
1c324e59 751
efa14d16
MJ
752#undef LTTNG_UST_TP_FIELDS
753#define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
1c324e59 754
7f2f82c3
MJ
755#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
756#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
106ff4da 757static inline \
bfcc2759 758size_t lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(_args)) \
106ff4da 759 lttng_ust_notrace; \
1c324e59 760static inline \
bfcc2759 761size_t lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_PROTO(_args)) \
1c324e59 762{ \
bfcc2759 763 size_t lttng_ust__event_align = 1; \
1c324e59 764 _fields \
bfcc2759 765 return lttng_ust__event_align; \
1c324e59
MD
766}
767
bb71a8ea 768#include LTTNG_UST_TRACEPOINT_INCLUDE
1c324e59
MD
769
770
771/*
df854e41 772 * Stage 5 of tracepoint event generation.
1c324e59
MD
773 *
774 * Create the probe function. This function calls event size calculation
775 * and writes event data into the buffer.
776 */
777
7f2f82c3 778/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1c324e59 779#include <lttng/ust-tracepoint-event-reset.h>
4774c8f3 780#include <lttng/ust-tracepoint-event-write.h>
1c324e59 781
b4064f28
MJ
782#undef lttng_ust__field_integer_ext
783#define lttng_ust__field_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
1c324e59
MD
784 { \
785 _type __tmp = (_src); \
8936b6c0 786 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\
1c324e59
MD
787 }
788
891226fc
MJ
789#undef lttng_ust__field_float
790#define lttng_ust__field_float(_type, _item, _src, _nowrite) \
1c324e59
MD
791 { \
792 _type __tmp = (_src); \
8936b6c0 793 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp), lttng_ust_rb_alignof(__tmp));\
1c324e59
MD
794 }
795
10937ee5
MJ
796#undef lttng_ust__field_array_encoded
797#define lttng_ust__field_array_encoded(_type, _item, _src, _byte_order, _length, \
f3ec4cb5 798 _encoding, _nowrite, _elem_type_base) \
27927814 799 if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
8936b6c0 800 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length), lttng_ust_rb_alignof(_type)); \
27927814 801 else \
879f9b0a 802 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), _length); \
1c324e59 803
1d188af9
MJ
804#undef lttng_ust__field_sequence_encoded
805#define lttng_ust__field_sequence_encoded(_type, _item, _src, _byte_order, _length_type, \
f968510a 806 _src_length, _encoding, _nowrite, _elem_type_base) \
1c324e59 807 { \
d71b57b9 808 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
8936b6c0 809 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type), lttng_ust_rb_alignof(_length_type));\
1c324e59 810 } \
27927814
MD
811 if (lttng_ust_string_encoding_##_encoding == lttng_ust_string_encoding_none) \
812 __chan->ops->event_write(&__ctx, _src, \
bae1f483 813 sizeof(_type) * lttng_ust__get_dynamic_len(dest), lttng_ust_rb_alignof(_type)); \
27927814 814 else \
bae1f483 815 __chan->ops->event_pstrcpy_pad(&__ctx, (const char *) (_src), lttng_ust__get_dynamic_len(dest)); \
1c324e59 816
3202f63a
MJ
817#undef lttng_ust__field_string
818#define lttng_ust__field_string(_item, _src, _nowrite) \
24a39530
PP
819 { \
820 const char *__ctf_tmp_string = \
ee0889a3 821 ((_src) ? (_src) : LTTNG_UST__NULL_STRING); \
f9ec4a97 822 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
bae1f483 823 lttng_ust__get_dynamic_len(dest)); \
24a39530
PP
824 }
825
ddde62ca
MJ
826#undef lttng_ust__field_unused
827#define lttng_ust__field_unused(_src)
1c324e59 828
78684808
MJ
829#undef lttng_ust__field_enum
830#define lttng_ust__field_enum(_provider, _name, _type, _item, _src, _nowrite) \
b4064f28 831 lttng_ust__field_integer_ext(_type, _item, _src, LTTNG_UST_BYTE_ORDER, 10, _nowrite)
c785c634 832
1c324e59 833/* Beware: this get len actually consumes the len value */
bae1f483
MJ
834#undef lttng_ust__get_dynamic_len
835#define lttng_ust__get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
1c324e59 836
cadfcbfc
MJ
837#undef LTTNG_UST_TP_ARGS
838#define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
1c324e59 839
efa14d16
MJ
840#undef LTTNG_UST_TP_FIELDS
841#define LTTNG_UST_TP_FIELDS(...) __VA_ARGS__
1c324e59 842
95c25348
PW
843/*
844 * For state dump, check that "session" argument (mandatory) matches the
845 * session this event belongs to. Ensures that we write state dump data only
846 * into the started session, not into all sessions.
847 */
91fe3e13
MJ
848#undef LTTNG_UST__TP_SESSION_CHECK
849#ifdef LTTNG_UST_TP_SESSION_CHECK
850#define LTTNG_UST__TP_SESSION_CHECK(session, csession) (session == csession)
95c25348 851#else /* TP_SESSION_CHECK */
91fe3e13 852#define LTTNG_UST__TP_SESSION_CHECK(session, csession) 1
95c25348
PW
853#endif /* TP_SESSION_CHECK */
854
97904b41
MD
855/*
856 * Use of __builtin_return_address(0) sometimes seems to cause stack
857 * corruption on 32-bit PowerPC. Disable this feature on that
858 * architecture for now by always using the NULL value for the ip
859 * context.
860 */
c28c4a88
MJ
861#undef LTTNG_UST__TP_IP_PARAM
862
863#ifdef LTTNG_UST_TP_IP_PARAM
864#define LTTNG_UST__TP_IP_PARAM(x) (x)
5dadb547 865#else /* TP_IP_PARAM */
97904b41 866
2eba8e39 867#if defined(LTTNG_UST_ARCH_PPC) && !defined(LTTNG_UST_ARCH_PPC64)
c28c4a88 868#define LTTNG_UST__TP_IP_PARAM(x) NULL
2eba8e39 869#else
c28c4a88 870#define LTTNG_UST__TP_IP_PARAM(x) __builtin_return_address(0)
2eba8e39 871#endif
97904b41 872
5dadb547
MD
873#endif /* TP_IP_PARAM */
874
1ddfd641
MD
875/*
876 * Using twice size for filter stack data to hold size and pointer for
877 * each field (worse case). For integers, max size required is 64-bit.
878 * Same for double-precision floats. Those fit within
879 * 2*sizeof(unsigned long) for all supported architectures.
61ce3223 880 * Perform UNION (||) of filter runtime list.
1ddfd641 881 */
7f2f82c3
MJ
882#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
883#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
106ff4da 884static \
bfcc2759 885void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
106ff4da 886 lttng_ust_notrace; \
a8909ba5 887static \
bfcc2759 888void lttng_ust__event_probe__##_provider##___##_name(LTTNG_UST__TP_ARGS_DATA_PROTO(_args)) \
1c324e59 889{ \
ba99fbe2 890 struct lttng_ust_event_common *__event = (struct lttng_ust_event_common *) __tp_data; \
1c324e59 891 size_t __dynamic_len_idx = 0; \
bfcc2759 892 const size_t __num_fields = LTTNG_UST__TP_ARRAY_SIZE(lttng_ust__event_fields___##_provider##___##_name) - 1; \
d71b57b9 893 union { \
75026e9f 894 size_t __dynamic_len[__num_fields]; \
ba99fbe2 895 char __interpreter_stack_data[2 * sizeof(unsigned long) * __num_fields]; \
d71b57b9 896 } __stackvar; \
1c324e59 897 int __ret; \
a2e4d05e 898 bool __interpreter_stack_prepared = false; \
1c324e59
MD
899 \
900 if (0) \
901 (void) __dynamic_len_idx; /* don't warn if unused */ \
ba99fbe2
MD
902 switch (__event->type) { \
903 case LTTNG_UST_EVENT_TYPE_RECORDER: \
904 { \
bfcc2759
MJ
905 struct lttng_ust_event_recorder *lttng_ust__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
906 struct lttng_ust_channel_buffer *__chan = lttng_ust__event_recorder->chan; \
e7bc0ef6 907 struct lttng_ust_channel_common *__chan_common = __chan->parent; \
ba99fbe2 908 \
91fe3e13 909 if (!LTTNG_UST__TP_SESSION_CHECK(session, __chan_common->session)) \
ba99fbe2 910 return; \
e7bc0ef6 911 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->session->active))) \
ba99fbe2 912 return; \
e7bc0ef6 913 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan_common->enabled))) \
ba99fbe2
MD
914 return; \
915 break; \
916 } \
917 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
918 break; \
919 } \
920 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
1c324e59 921 return; \
251c9f75 922 if (caa_unlikely(!LTTNG_UST_TP_RCU_LINK_TEST())) \
1b436e01 923 return; \
a2e4d05e 924 if (caa_unlikely(CMM_ACCESS_ONCE(__event->eval_filter))) { \
bfcc2759 925 lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
6eddcb06 926 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
a2e4d05e
MD
927 __interpreter_stack_prepared = true; \
928 if (caa_likely(__event->run_filter(__event, \
929 __stackvar.__interpreter_stack_data, NULL) != LTTNG_UST_EVENT_FILTER_ACCEPT)) \
61ce3223 930 return; \
1ddfd641 931 } \
ba99fbe2
MD
932 switch (__event->type) { \
933 case LTTNG_UST_EVENT_TYPE_RECORDER: \
934 { \
bfcc2759
MJ
935 size_t __event_len, lttng_ust__event_align; \
936 struct lttng_ust_event_recorder *lttng_ust__event_recorder = (struct lttng_ust_event_recorder *) __event->child; \
937 struct lttng_ust_channel_buffer *__chan = lttng_ust__event_recorder->chan; \
b5457df5 938 struct lttng_ust_ring_buffer_ctx __ctx; \
ba99fbe2 939 \
bfcc2759 940 __event_len = lttng_ust__event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
6eddcb06 941 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
bfcc2759
MJ
942 lttng_ust__event_align = lttng_ust__event_get_align__##_provider##___##_name(LTTNG_UST__TP_ARGS_VAR(_args)); \
943 lttng_ust_ring_buffer_ctx_init(&__ctx, lttng_ust__event_recorder, __event_len, lttng_ust__event_align, \
c28c4a88 944 LTTNG_UST__TP_IP_PARAM(LTTNG_UST_TP_IP_PARAM)); \
8936b6c0 945 __ret = __chan->ops->event_reserve(&__ctx); \
ba99fbe2
MD
946 if (__ret < 0) \
947 return; \
948 _fields \
949 __chan->ops->event_commit(&__ctx); \
950 break; \
951 } \
952 case LTTNG_UST_EVENT_TYPE_NOTIFIER: \
953 { \
bfcc2759 954 struct lttng_ust_event_notifier *lttng_ust__event_notifier = (struct lttng_ust_event_notifier *) __event->child; \
a2e4d05e
MD
955 struct lttng_ust_notification_ctx __notif_ctx; \
956 \
957 __notif_ctx.struct_size = sizeof(struct lttng_ust_notification_ctx); \
bfcc2759 958 __notif_ctx.eval_capture = CMM_ACCESS_ONCE(lttng_ust__event_notifier->eval_capture); \
ba99fbe2 959 \
a2e4d05e 960 if (caa_unlikely(!__interpreter_stack_prepared && __notif_ctx.eval_capture)) \
bfcc2759 961 lttng_ust__event_prepare_interpreter_stack__##_provider##___##_name(__stackvar.__interpreter_stack_data, \
6eddcb06 962 LTTNG_UST__TP_ARGS_DATA_VAR(_args)); \
ba99fbe2 963 \
bfcc2759 964 lttng_ust__event_notifier->notification_send(lttng_ust__event_notifier, \
a2e4d05e
MD
965 __stackvar.__interpreter_stack_data, \
966 &__notif_ctx); \
ba99fbe2
MD
967 break; \
968 } \
969 } \
1c324e59
MD
970}
971
bb71a8ea 972#include LTTNG_UST_TRACEPOINT_INCLUDE
1c324e59 973
bae1f483 974#undef lttng_ust__get_dynamic_len
1c324e59 975
68755429
MD
976/*
977 * Stage 5.1 of tracepoint event generation.
978 *
979 * Create probe signature
980 */
981
7f2f82c3 982/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
68755429
MD
983#include <lttng/ust-tracepoint-event-reset.h>
984
cadfcbfc
MJ
985#undef LTTNG_UST_TP_ARGS
986#define LTTNG_UST_TP_ARGS(...) __VA_ARGS__
9eb06182 987
4a36f0f1 988#define LTTNG_UST__TP_EXTRACT_STRING2(...) #__VA_ARGS__
68755429 989
7f2f82c3
MJ
990#undef LTTNG_UST__TRACEPOINT_EVENT_CLASS
991#define LTTNG_UST__TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
ff82b7c1 992static const char __tp_event_signature___##_provider##___##_name[] = \
4a36f0f1 993 LTTNG_UST__TP_EXTRACT_STRING2(_args);
68755429 994
bb71a8ea 995#include LTTNG_UST_TRACEPOINT_INCLUDE
68755429 996
4a36f0f1 997#undef LTTNG_UST__TP_EXTRACT_STRING2
9eb06182 998
05ceaafd 999/*
882a56d7 1000 * Stage 6 of tracepoint event generation.
1c324e59 1001 *
df854e41
MD
1002 * Tracepoint loglevel mapping definition generation. We generate a
1003 * symbol for each mapping for a provider/event to ensure at most a 1 to
1004 * 1 mapping between events and loglevels. If the symbol is repeated,
1005 * the compiler will complain.
05ceaafd
MD
1006 */
1007
7f2f82c3 1008/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
05ceaafd
MD
1009#include <lttng/ust-tracepoint-event-reset.h>
1010
4ea4f80e
MD
1011/*
1012 * Declare _loglevel___##__provider##___##__name as non-static, with
1013 * hidden visibility for c++ handling of weakref. We do a weakref to the
1014 * symbol in a later stage, which requires that the symbol is not
1015 * mangled.
1016 */
1017#ifdef __cplusplus
fc6d7bef 1018#define LTTNG_UST_TP_EXTERN_C extern "C"
4ea4f80e 1019#else
fc6d7bef 1020#define LTTNG_UST_TP_EXTERN_C
4ea4f80e
MD
1021#endif
1022
612e9ce4
MJ
1023#undef LTTNG_UST_TRACEPOINT_LOGLEVEL
1024#define LTTNG_UST_TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
3d33ca1d
MD
1025static const int _loglevel_value___##__provider##___##__name = __loglevel; \
1026LTTNG_UST_TP_EXTERN_C const int * const _loglevel___##__provider##___##__name \
1027 __attribute__((visibility("hidden"))) = \
457a6b58 1028 &_loglevel_value___##__provider##___##__name;
df854e41 1029
bb71a8ea 1030#include LTTNG_UST_TRACEPOINT_INCLUDE
df854e41 1031
fc6d7bef 1032#undef LTTNG_UST_TP_EXTERN_C
4ea4f80e 1033
6ddc916d
MD
1034/*
1035 * Stage 6.1 of tracepoint event generation.
1036 *
1037 * Tracepoint UML URI info.
1038 */
1039
7f2f82c3 1040/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
6ddc916d
MD
1041#include <lttng/ust-tracepoint-event-reset.h>
1042
4ea4f80e
MD
1043/*
1044 * Declare _model_emf_uri___##__provider##___##__name as non-static,
1045 * with hidden visibility for c++ handling of weakref. We do a weakref
1046 * to the symbol in a later stage, which requires that the symbol is not
1047 * mangled.
1048 */
1049#ifdef __cplusplus
fc6d7bef 1050#define LTTNG_UST_TP_EXTERN_C extern "C"
4ea4f80e 1051#else
fc6d7bef 1052#define LTTNG_UST_TP_EXTERN_C
4ea4f80e
MD
1053#endif
1054
dbcc2f92
MJ
1055#undef LTTNG_UST_TRACEPOINT_MODEL_EMF_URI
1056#define LTTNG_UST_TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
3d33ca1d 1057LTTNG_UST_TP_EXTERN_C const char * const _model_emf_uri___##__provider##___##__name \
082802f9 1058 __attribute__((visibility("hidden"))) = __uri; \
6ddc916d 1059
bb71a8ea 1060#include LTTNG_UST_TRACEPOINT_INCLUDE
6ddc916d 1061
fc6d7bef 1062#undef LTTNG_UST_TP_EXTERN_C
4ea4f80e 1063
5b4c6da4
MD
1064/*
1065 * Stage 7.0 of tracepoint event generation.
1066 *
1067 * Declare toplevel descriptor for the whole probe.
1068 * Unlike C, C++ does not allow tentative definitions. Therefore, we
1069 * need to explicitly declare the variable with "extern", using hidden
1070 * visibility to keep this symbol from being exported to the global
1071 * symbol table.
1072 */
1073
c9201081 1074extern const struct lttng_ust_probe_desc LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___, LTTNG_UST_TRACEPOINT_PROVIDER)
5b4c6da4
MD
1075 __attribute__((visibility("hidden")));
1076
df854e41 1077/*
882a56d7 1078 * Stage 7.1 of tracepoint event generation.
df854e41
MD
1079 *
1080 * Create events description structures. We use a weakref because
3d33ca1d 1081 * loglevels are optional. If not declared, the event will point to
df854e41 1082 * a loglevel that contains NULL.
3d33ca1d
MD
1083 *
1084 * C++ requires that const objects have a user-declared default
1085 * constructor. However, in both C++ and C, weakref cannot be
1086 * initialized because it causes the weakref attribute to be ignored.
1087 * Therefore, the loglevel and model_emf_uri pointers are not const
1088 * to ensure C++ compilers default-initialize them.
df854e41
MD
1089 */
1090
7f2f82c3 1091/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
df854e41
MD
1092#include <lttng/ust-tracepoint-event-reset.h>
1093
7f2f82c3
MJ
1094#undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
1095#define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
882a56d7
MD
1096static const int * \
1097 __ref_loglevel___##_provider##___##_name \
1098 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
6ddc916d
MD
1099static const char * \
1100 __ref_model_emf_uri___##_provider##___##_name \
1101 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
bfcc2759 1102static const struct lttng_ust_event_desc lttng_ust__event_desc___##_provider##_##_name = { \
dc11f93f 1103 .struct_size = sizeof(struct lttng_ust_event_desc), \
5b4c6da4 1104 .event_name = #_name, \
c9201081 1105 .probe_desc = &lttng_ust__probe_desc___##_provider, \
bfcc2759
MJ
1106 .probe_callback = (void (*)(void)) &lttng_ust__event_probe__##_provider##___##_template, \
1107 .fields = lttng_ust__event_fields___##_provider##___##_template, \
1108 .nr_fields = LTTNG_UST__TP_ARRAY_SIZE(lttng_ust__event_fields___##_provider##___##_template) - 1, \
882a56d7 1109 .loglevel = &__ref_loglevel___##_provider##___##_name, \
68755429 1110 .signature = __tp_event_signature___##_provider##___##_template, \
dc11f93f 1111 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
df854e41
MD
1112};
1113
bb71a8ea 1114#include LTTNG_UST_TRACEPOINT_INCLUDE
05ceaafd 1115
df854e41 1116/*
882a56d7 1117 * Stage 7.2 of tracepoint event generation.
df854e41
MD
1118 *
1119 * Create array of events.
1120 */
1121
7f2f82c3 1122/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
df854e41
MD
1123#include <lttng/ust-tracepoint-event-reset.h>
1124
7f2f82c3
MJ
1125#undef LTTNG_UST__TRACEPOINT_EVENT_INSTANCE
1126#define LTTNG_UST__TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
bfcc2759 1127 &lttng_ust__event_desc___##_provider##_##_name,
df854e41 1128
bfcc2759 1129static const struct lttng_ust_event_desc * const LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__event_desc___, LTTNG_UST_TRACEPOINT_PROVIDER)[] = {
bb71a8ea 1130#include LTTNG_UST_TRACEPOINT_INCLUDE
1c80c909 1131 NULL, /* Dummy, C99 forbids 0-len array. */
05ceaafd
MD
1132};
1133
df854e41 1134
05ceaafd 1135/*
882a56d7 1136 * Stage 8 of tracepoint event generation.
05ceaafd
MD
1137 *
1138 * Create a toplevel descriptor for the whole probe.
1139 */
1140
c9201081 1141const struct lttng_ust_probe_desc LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___, LTTNG_UST_TRACEPOINT_PROVIDER) = {
dc11f93f 1142 .struct_size = sizeof(struct lttng_ust_probe_desc),
061fc37a 1143 .provider_name = lttng_ust__tp_stringify(LTTNG_UST_TRACEPOINT_PROVIDER),
bfcc2759
MJ
1144 .event_desc = LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__event_desc___, LTTNG_UST_TRACEPOINT_PROVIDER),
1145 .nr_events = LTTNG_UST__TP_ARRAY_SIZE(LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__event_desc___, LTTNG_UST_TRACEPOINT_PROVIDER)) - 1,
71d31690
MD
1146 .major = LTTNG_UST_PROVIDER_MAJOR,
1147 .minor = LTTNG_UST_PROVIDER_MINOR,
05ceaafd
MD
1148};
1149
03221919 1150static int LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___, LTTNG_UST_TRACEPOINT_PROVIDER);
f082dde9 1151static struct lttng_ust_registered_probe *LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER);
f0cc794d 1152
05ceaafd 1153/*
882a56d7 1154 * Stage 9 of tracepoint event generation.
05ceaafd 1155 *
1c324e59 1156 * Register/unregister probes at module load/unload.
628e1d81
MD
1157 *
1158 * Generate the constructor as an externally visible symbol for use when
1159 * linking the probe statically.
f0cc794d
MD
1160 *
1161 * Register refcount is protected by libc dynamic loader mutex.
1c324e59
MD
1162 */
1163
7f2f82c3 1164/* Reset all macros within LTTNG_UST_TRACEPOINT_EVENT */
1c324e59 1165#include <lttng/ust-tracepoint-event-reset.h>
465a0d04 1166static void
11bce056 1167LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
465a0d04 1168 lttng_ust_notrace __attribute__((constructor));
a8909ba5 1169static void
11bce056 1170LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_init__, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
1c324e59 1171{
4e48b5d2 1172 struct lttng_ust_registered_probe *reg_probe;
1c324e59 1173
03221919 1174 if (LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___,
5b393d64 1175 LTTNG_UST_TRACEPOINT_PROVIDER)++) {
f0cc794d
MD
1176 return;
1177 }
e8bd1da7 1178 /*
5b393d64 1179 * lttng_ust_tracepoint_provider_check_ ## LTTNG_UST_TRACEPOINT_PROVIDER() is a
e8bd1da7
MD
1180 * static inline function that ensures every probe PROVIDER
1181 * argument match the provider within which they appear. It
1182 * calls empty static inline functions, and therefore has no
1183 * runtime effect. However, if it detects an error, a linker
1184 * error will appear.
1185 */
5b393d64 1186 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_check_, LTTNG_UST_TRACEPOINT_PROVIDER)();
f082dde9 1187 assert(!LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER));
c9201081 1188 reg_probe = lttng_ust_probe_register(&LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_desc___, LTTNG_UST_TRACEPOINT_PROVIDER));
4e48b5d2
MD
1189 if (!reg_probe) {
1190 fprintf(stderr, "LTTng-UST: Error while registering tracepoint probe.\n");
7d381d6e
MD
1191 abort();
1192 }
f082dde9 1193 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER) = reg_probe;
1c324e59
MD
1194}
1195
c589eca2 1196static void
638ce920 1197LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
c589eca2 1198 lttng_ust_notrace __attribute__((destructor));
a8909ba5 1199static void
638ce920 1200LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__events_exit__, LTTNG_UST_TRACEPOINT_PROVIDER)(void)
1c324e59 1201{
03221919 1202 if (--LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_refcount___,
5b393d64 1203 LTTNG_UST_TRACEPOINT_PROVIDER)) {
f0cc794d
MD
1204 return;
1205 }
f082dde9
MJ
1206 lttng_ust_probe_unregister(LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER));
1207 LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust__probe_register_cookie___, LTTNG_UST_TRACEPOINT_PROVIDER) = NULL;
1c324e59 1208}
628e1d81 1209
5b393d64 1210int LTTNG_UST__TP_COMBINE_TOKENS(lttng_ust_tracepoint_provider_, LTTNG_UST_TRACEPOINT_PROVIDER)
1d18d519 1211 __attribute__((visibility("default")));
This page took 0.110885 seconds and 4 git commands to generate.