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