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