Output "(null)" when ctf_string()'s arg is NULL
[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 <stdio.h>
24 #include <stdlib.h>
25 #include <urcu/compiler.h>
26 #include <urcu/rculist.h>
27 #include <lttng/ust-events.h>
28 #include <lttng/ringbuffer-config.h>
29 #include <lttng/ust-compiler.h>
30 #include <lttng/tracepoint.h>
31 #include <string.h>
32
33 #define __LTTNG_UST_NULL_STRING "(null)"
34
35 #undef tp_list_for_each_entry_rcu
36 #define tp_list_for_each_entry_rcu(pos, head, member) \
37 for (pos = cds_list_entry(tp_rcu_dereference_bp((head)->next), __typeof__(*pos), member); \
38 &pos->member != (head); \
39 pos = cds_list_entry(tp_rcu_dereference_bp(pos->member.next), __typeof__(*pos), member))
40
41 /*
42 * TRACEPOINT_EVENT_CLASS declares a class of tracepoints receiving the
43 * same arguments and having the same field layout.
44 *
45 * TRACEPOINT_EVENT_INSTANCE declares an instance of a tracepoint, with
46 * its own provider and name. It refers to a class (template).
47 *
48 * TRACEPOINT_EVENT declared both a class and an instance and does a
49 * direct mapping from the instance to the class.
50 */
51
52 #undef TRACEPOINT_EVENT
53 #define TRACEPOINT_EVENT(_provider, _name, _args, _fields) \
54 TRACEPOINT_EVENT_CLASS(_provider, _name, \
55 _TP_PARAMS(_args), \
56 _TP_PARAMS(_fields)) \
57 TRACEPOINT_EVENT_INSTANCE(_provider, _name, _name, \
58 _TP_PARAMS(_args))
59
60 /* Helpers */
61 #define _TP_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
62
63 #define _tp_max_t(type, x, y) \
64 ({ \
65 type __max1 = (x); \
66 type __max2 = (y); \
67 __max1 > __max2 ? __max1: __max2; \
68 })
69
70 /*
71 * Stage 0 of tracepoint event generation.
72 *
73 * Check that each TRACEPOINT_EVENT provider argument match the
74 * TRACEPOINT_PROVIDER by creating dummy callbacks.
75 */
76
77 /* Reset all macros within TRACEPOINT_EVENT */
78 #include <lttng/ust-tracepoint-event-reset.h>
79
80 static inline lttng_ust_notrace
81 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void);
82 static inline
83 void _TP_COMBINE_TOKENS(__tracepoint_provider_mismatch_, TRACEPOINT_PROVIDER)(void)
84 {
85 }
86
87 #undef TRACEPOINT_EVENT_CLASS
88 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
89 __tracepoint_provider_mismatch_##_provider();
90
91 #undef TRACEPOINT_EVENT_INSTANCE
92 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
93 __tracepoint_provider_mismatch_##_provider();
94
95 static inline lttng_ust_notrace
96 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void);
97 static inline
98 void _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)(void)
99 {
100 #include TRACEPOINT_INCLUDE
101 }
102
103 /*
104 * Stage 0.1 of tracepoint event generation.
105 *
106 * Check that each TRACEPOINT_EVENT provider:name does not exceed the
107 * tracepoint name length limit.
108 */
109
110 /* Reset all macros within TRACEPOINT_EVENT */
111 #include <lttng/ust-tracepoint-event-reset.h>
112
113 #undef TRACEPOINT_EVENT_INSTANCE
114 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
115 static const char \
116 __tp_name_len_check##_provider##___##_name[LTTNG_UST_SYM_NAME_LEN] \
117 __attribute__((unused)) = \
118 #_provider ":" #_name;
119
120 #include TRACEPOINT_INCLUDE
121
122 /*
123 * Stage 0.9 of tracepoint event generation
124 *
125 * Unfolding the enums
126 */
127 #include <lttng/ust-tracepoint-event-reset.h>
128
129 /* Enumeration entry (single value) */
130 #undef ctf_enum_value
131 #define ctf_enum_value(_string, _value) \
132 { _value, _value, _string },
133
134 /* Enumeration entry (range) */
135 #undef ctf_enum_range
136 #define ctf_enum_range(_string, _range_start, _range_end) \
137 { _range_start, _range_end, _string },
138
139 #undef TP_ENUM_VALUES
140 #define TP_ENUM_VALUES(...) \
141 __VA_ARGS__
142
143 #undef TRACEPOINT_ENUM
144 #define TRACEPOINT_ENUM(_provider, _name, _values) \
145 const struct lttng_enum_entry __enum_values__##_provider##_##_name[] = { \
146 _values \
147 };
148
149 #include TRACEPOINT_INCLUDE
150
151 /*
152 * Stage 1 of tracepoint event generation.
153 *
154 * Create event field type metadata section.
155 * Each event produce an array of fields.
156 */
157
158 /* Reset all macros within TRACEPOINT_EVENT */
159 #include <lttng/ust-tracepoint-event-reset.h>
160 #include <lttng/ust-tracepoint-event-write.h>
161 #include <lttng/ust-tracepoint-event-nowrite.h>
162
163 #undef _ctf_integer_ext
164 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
165 { \
166 .name = #_item, \
167 .type = __type_integer(_type, _byte_order, _base, none),\
168 .nowrite = _nowrite, \
169 },
170
171 #undef _ctf_float
172 #define _ctf_float(_type, _item, _src, _nowrite) \
173 { \
174 .name = #_item, \
175 .type = __type_float(_type), \
176 .nowrite = _nowrite, \
177 },
178
179 #undef _ctf_array_encoded
180 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
181 { \
182 .name = #_item, \
183 .type = \
184 { \
185 .atype = atype_array, \
186 .u = \
187 { \
188 .array = \
189 { \
190 .elem_type = __type_integer(_type, BYTE_ORDER, 10, _encoding), \
191 .length = _length, \
192 } \
193 } \
194 }, \
195 .nowrite = _nowrite, \
196 },
197
198 #undef _ctf_sequence_encoded
199 #define _ctf_sequence_encoded(_type, _item, _src, \
200 _length_type, _src_length, _encoding, _nowrite, \
201 _elem_type_base) \
202 { \
203 .name = #_item, \
204 .type = \
205 { \
206 .atype = atype_sequence, \
207 .u = \
208 { \
209 .sequence = \
210 { \
211 .length_type = __type_integer(_length_type, BYTE_ORDER, 10, none), \
212 .elem_type = __type_integer(_type, BYTE_ORDER, _elem_type_base, _encoding), \
213 }, \
214 }, \
215 }, \
216 .nowrite = _nowrite, \
217 },
218
219 #undef _ctf_string
220 #define _ctf_string(_item, _src, _nowrite) \
221 { \
222 .name = #_item, \
223 .type = \
224 { \
225 .atype = atype_string, \
226 .u = \
227 { \
228 .basic = { .string = { .encoding = lttng_encode_UTF8 } } \
229 }, \
230 }, \
231 .nowrite = _nowrite, \
232 },
233
234 #undef _ctf_enum
235 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
236 { \
237 .name = #_item, \
238 .type = { \
239 .atype = atype_enum, \
240 .u = { \
241 .basic = { \
242 .enumeration = { \
243 .desc = &__enum_##_provider##_##_name, \
244 .container_type = { \
245 .size = sizeof(_type) * CHAR_BIT, \
246 .alignment = lttng_alignof(_type) * CHAR_BIT, \
247 .signedness = lttng_is_signed_type(_type), \
248 .reverse_byte_order = 0, \
249 .base = 10, \
250 .encoding = lttng_encode_none, \
251 }, \
252 }, \
253 }, \
254 }, \
255 }, \
256 .nowrite = _nowrite, \
257 },
258
259 #undef TP_FIELDS
260 #define TP_FIELDS(...) __VA_ARGS__ /* Only one used in this phase */
261
262 #undef TRACEPOINT_EVENT_CLASS
263 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
264 static const struct lttng_event_field __event_fields___##_provider##___##_name[] = { \
265 _fields \
266 };
267
268 #undef TRACEPOINT_ENUM
269 #define TRACEPOINT_ENUM(_provider, _name, _values) \
270 static const struct lttng_enum_desc __enum_##_provider##_##_name = { \
271 .name = #_provider "_" #_name, \
272 .entries = __enum_values__##_provider##_##_name, \
273 .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name), \
274 };
275
276 #include TRACEPOINT_INCLUDE
277
278 /*
279 * Stage 2 of tracepoint event generation.
280 *
281 * Create probe callback prototypes.
282 */
283
284 /* Reset all macros within TRACEPOINT_EVENT */
285 #include <lttng/ust-tracepoint-event-reset.h>
286
287 #undef TP_ARGS
288 #define TP_ARGS(...) __VA_ARGS__
289
290 #undef TRACEPOINT_EVENT_CLASS
291 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
292 static void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args));
293
294 #include TRACEPOINT_INCLUDE
295
296 /*
297 * Stage 3.0 of tracepoint event generation.
298 *
299 * Create static inline function that calculates event size.
300 */
301
302 /* Reset all macros within TRACEPOINT_EVENT */
303 #include <lttng/ust-tracepoint-event-reset.h>
304 #include <lttng/ust-tracepoint-event-write.h>
305
306 #undef _ctf_integer_ext
307 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
308 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
309 __event_len += sizeof(_type);
310
311 #undef _ctf_float
312 #define _ctf_float(_type, _item, _src, _nowrite) \
313 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
314 __event_len += sizeof(_type);
315
316 #undef _ctf_array_encoded
317 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
318 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
319 __event_len += sizeof(_type) * (_length);
320
321 #undef _ctf_sequence_encoded
322 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
323 _src_length, _encoding, _nowrite, _elem_type_base) \
324 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_length_type)); \
325 __event_len += sizeof(_length_type); \
326 __event_len += lib_ring_buffer_align(__event_len, lttng_alignof(_type)); \
327 __dynamic_len[__dynamic_len_idx] = (_src_length); \
328 __event_len += sizeof(_type) * __dynamic_len[__dynamic_len_idx]; \
329 __dynamic_len_idx++;
330
331 #undef _ctf_string
332 #define _ctf_string(_item, _src, _nowrite) \
333 __event_len += __dynamic_len[__dynamic_len_idx++] = \
334 strlen((_src) ? (_src) : __LTTNG_UST_NULL_STRING) + 1;
335
336 #undef _ctf_enum
337 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
338 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
339
340 #undef TP_ARGS
341 #define TP_ARGS(...) __VA_ARGS__
342
343 #undef TP_FIELDS
344 #define TP_FIELDS(...) __VA_ARGS__
345
346 #undef TRACEPOINT_EVENT_CLASS
347 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
348 static inline lttng_ust_notrace \
349 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)); \
350 static inline \
351 size_t __event_get_size__##_provider##___##_name(size_t *__dynamic_len, _TP_ARGS_DATA_PROTO(_args)) \
352 { \
353 size_t __event_len = 0; \
354 unsigned int __dynamic_len_idx = 0; \
355 \
356 if (0) \
357 (void) __dynamic_len_idx; /* don't warn if unused */ \
358 _fields \
359 return __event_len; \
360 }
361
362 #include TRACEPOINT_INCLUDE
363
364 /*
365 * Stage 3.1 of tracepoint event generation.
366 *
367 * Create static inline function that layout the filter stack data.
368 * We make both write and nowrite data available to the filter.
369 */
370
371 /* Reset all macros within TRACEPOINT_EVENT */
372 #include <lttng/ust-tracepoint-event-reset.h>
373 #include <lttng/ust-tracepoint-event-write.h>
374 #include <lttng/ust-tracepoint-event-nowrite.h>
375
376 #undef _ctf_integer_ext
377 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
378 if (lttng_is_signed_type(_type)) { \
379 int64_t __ctf_tmp_int64; \
380 switch (sizeof(_type)) { \
381 case 1: \
382 { \
383 union { _type t; int8_t v; } __tmp = { (_type) (_src) }; \
384 __ctf_tmp_int64 = (int64_t) __tmp.v; \
385 break; \
386 } \
387 case 2: \
388 { \
389 union { _type t; int16_t v; } __tmp = { (_type) (_src) }; \
390 __ctf_tmp_int64 = (int64_t) __tmp.v; \
391 break; \
392 } \
393 case 4: \
394 { \
395 union { _type t; int32_t v; } __tmp = { (_type) (_src) }; \
396 __ctf_tmp_int64 = (int64_t) __tmp.v; \
397 break; \
398 } \
399 case 8: \
400 { \
401 union { _type t; int64_t v; } __tmp = { (_type) (_src) }; \
402 __ctf_tmp_int64 = (int64_t) __tmp.v; \
403 break; \
404 } \
405 default: \
406 abort(); \
407 }; \
408 memcpy(__stack_data, &__ctf_tmp_int64, sizeof(int64_t)); \
409 } else { \
410 uint64_t __ctf_tmp_uint64; \
411 switch (sizeof(_type)) { \
412 case 1: \
413 { \
414 union { _type t; uint8_t v; } __tmp = { (_type) (_src) }; \
415 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
416 break; \
417 } \
418 case 2: \
419 { \
420 union { _type t; uint16_t v; } __tmp = { (_type) (_src) }; \
421 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
422 break; \
423 } \
424 case 4: \
425 { \
426 union { _type t; uint32_t v; } __tmp = { (_type) (_src) }; \
427 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
428 break; \
429 } \
430 case 8: \
431 { \
432 union { _type t; uint64_t v; } __tmp = { (_type) (_src) }; \
433 __ctf_tmp_uint64 = (uint64_t) __tmp.v; \
434 break; \
435 } \
436 default: \
437 abort(); \
438 }; \
439 memcpy(__stack_data, &__ctf_tmp_uint64, sizeof(uint64_t)); \
440 } \
441 __stack_data += sizeof(int64_t);
442
443 #undef _ctf_float
444 #define _ctf_float(_type, _item, _src, _nowrite) \
445 { \
446 double __ctf_tmp_double = (double) (_type) (_src); \
447 memcpy(__stack_data, &__ctf_tmp_double, sizeof(double)); \
448 __stack_data += sizeof(double); \
449 }
450
451 #undef _ctf_array_encoded
452 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
453 { \
454 unsigned long __ctf_tmp_ulong = (unsigned long) (_length); \
455 const void *__ctf_tmp_ptr = (_src); \
456 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
457 __stack_data += sizeof(unsigned long); \
458 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
459 __stack_data += sizeof(void *); \
460 }
461
462 #undef _ctf_sequence_encoded
463 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
464 _src_length, _encoding, _nowrite, _elem_type_base) \
465 { \
466 unsigned long __ctf_tmp_ulong = (unsigned long) (_src_length); \
467 const void *__ctf_tmp_ptr = (_src); \
468 memcpy(__stack_data, &__ctf_tmp_ulong, sizeof(unsigned long)); \
469 __stack_data += sizeof(unsigned long); \
470 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
471 __stack_data += sizeof(void *); \
472 }
473
474 #undef _ctf_string
475 #define _ctf_string(_item, _src, _nowrite) \
476 { \
477 const void *__ctf_tmp_ptr = \
478 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
479 memcpy(__stack_data, &__ctf_tmp_ptr, sizeof(void *)); \
480 __stack_data += sizeof(void *); \
481 }
482
483 #undef _ctf_enum
484 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
485 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
486
487 #undef TP_ARGS
488 #define TP_ARGS(...) __VA_ARGS__
489
490 #undef TP_FIELDS
491 #define TP_FIELDS(...) __VA_ARGS__
492
493 #undef TRACEPOINT_EVENT_CLASS
494 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
495 static inline \
496 void __event_prepare_filter_stack__##_provider##___##_name(char *__stack_data,\
497 _TP_ARGS_DATA_PROTO(_args)) \
498 { \
499 _fields \
500 }
501
502 #include TRACEPOINT_INCLUDE
503
504 /*
505 * Stage 4 of tracepoint event generation.
506 *
507 * Create static inline function that calculates event payload alignment.
508 */
509
510 /* Reset all macros within TRACEPOINT_EVENT */
511 #include <lttng/ust-tracepoint-event-reset.h>
512 #include <lttng/ust-tracepoint-event-write.h>
513
514 #undef _ctf_integer_ext
515 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
516 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
517
518 #undef _ctf_float
519 #define _ctf_float(_type, _item, _src, _nowrite) \
520 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
521
522 #undef _ctf_array_encoded
523 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
524 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
525
526 #undef _ctf_sequence_encoded
527 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
528 _src_length, _encoding, _nowrite, _elem_type_base) \
529 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_length_type)); \
530 __event_align = _tp_max_t(size_t, __event_align, lttng_alignof(_type));
531
532 #undef _ctf_string
533 #define _ctf_string(_item, _src, _nowrite)
534
535 #undef _ctf_enum
536 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
537 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
538
539 #undef TP_ARGS
540 #define TP_ARGS(...) __VA_ARGS__
541
542 #undef TP_FIELDS
543 #define TP_FIELDS(...) __VA_ARGS__
544
545 #undef TRACEPOINT_EVENT_CLASS
546 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
547 static inline lttng_ust_notrace \
548 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)); \
549 static inline \
550 size_t __event_get_align__##_provider##___##_name(_TP_ARGS_PROTO(_args)) \
551 { \
552 size_t __event_align = 1; \
553 _fields \
554 return __event_align; \
555 }
556
557 #include TRACEPOINT_INCLUDE
558
559
560 /*
561 * Stage 5 of tracepoint event generation.
562 *
563 * Create the probe function. This function calls event size calculation
564 * and writes event data into the buffer.
565 */
566
567 /* Reset all macros within TRACEPOINT_EVENT */
568 #include <lttng/ust-tracepoint-event-reset.h>
569 #include <lttng/ust-tracepoint-event-write.h>
570
571 #undef _ctf_integer_ext
572 #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \
573 { \
574 _type __tmp = (_src); \
575 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
576 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
577 }
578
579 #undef _ctf_float
580 #define _ctf_float(_type, _item, _src, _nowrite) \
581 { \
582 _type __tmp = (_src); \
583 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(__tmp));\
584 __chan->ops->event_write(&__ctx, &__tmp, sizeof(__tmp));\
585 }
586
587 #undef _ctf_array_encoded
588 #define _ctf_array_encoded(_type, _item, _src, _length, _encoding, _nowrite) \
589 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
590 __chan->ops->event_write(&__ctx, _src, sizeof(_type) * (_length));
591
592 #undef _ctf_sequence_encoded
593 #define _ctf_sequence_encoded(_type, _item, _src, _length_type, \
594 _src_length, _encoding, _nowrite, _elem_type_base) \
595 { \
596 _length_type __tmpl = __stackvar.__dynamic_len[__dynamic_len_idx]; \
597 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_length_type));\
598 __chan->ops->event_write(&__ctx, &__tmpl, sizeof(_length_type));\
599 } \
600 lib_ring_buffer_align_ctx(&__ctx, lttng_alignof(_type)); \
601 __chan->ops->event_write(&__ctx, _src, \
602 sizeof(_type) * __get_dynamic_len(dest));
603
604 /*
605 * __chan->ops->u.has_strcpy is a flag letting us know if the LTTng-UST
606 * tracepoint provider ABI implements event_strcpy. This dynamic check
607 * can be removed when the tracepoint provider ABI moves to 2.
608 */
609 #if (LTTNG_UST_PROVIDER_MAJOR > 1)
610 #error "Tracepoint probe provider major version has changed. Please remove dynamic check for has_strcpy."
611 #endif
612
613 #undef _ctf_string
614 #define _ctf_string(_item, _src, _nowrite) \
615 { \
616 const char *__ctf_tmp_string = \
617 ((_src) ? (_src) : __LTTNG_UST_NULL_STRING); \
618 lib_ring_buffer_align_ctx(&__ctx, \
619 lttng_alignof(*__ctf_tmp_string)); \
620 if (__chan->ops->u.has_strcpy) \
621 __chan->ops->event_strcpy(&__ctx, __ctf_tmp_string, \
622 __get_dynamic_len(dest)); \
623 else \
624 __chan->ops->event_write(&__ctx, __ctf_tmp_string, \
625 __get_dynamic_len(dest)); \
626 }
627
628
629 #undef _ctf_enum
630 #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \
631 _ctf_integer_ext(_type, _item, _src, BYTE_ORDER, 10, _nowrite)
632
633 /* Beware: this get len actually consumes the len value */
634 #undef __get_dynamic_len
635 #define __get_dynamic_len(field) __stackvar.__dynamic_len[__dynamic_len_idx++]
636
637 #undef TP_ARGS
638 #define TP_ARGS(...) __VA_ARGS__
639
640 #undef TP_FIELDS
641 #define TP_FIELDS(...) __VA_ARGS__
642
643 /*
644 * For state dump, check that "session" argument (mandatory) matches the
645 * session this event belongs to. Ensures that we write state dump data only
646 * into the started session, not into all sessions.
647 */
648 #undef _TP_SESSION_CHECK
649 #ifdef TP_SESSION_CHECK
650 #define _TP_SESSION_CHECK(session, csession) (session == csession)
651 #else /* TP_SESSION_CHECK */
652 #define _TP_SESSION_CHECK(session, csession) 1
653 #endif /* TP_SESSION_CHECK */
654
655 /*
656 * Use of __builtin_return_address(0) sometimes seems to cause stack
657 * corruption on 32-bit PowerPC. Disable this feature on that
658 * architecture for now by always using the NULL value for the ip
659 * context.
660 */
661 #undef _TP_IP_PARAM
662 #ifdef TP_IP_PARAM
663 #define _TP_IP_PARAM(x) (x)
664 #else /* TP_IP_PARAM */
665
666 #if defined(__PPC__) && !defined(__PPC64__)
667 #define _TP_IP_PARAM(x) NULL
668 #else /* #if defined(__PPC__) && !defined(__PPC64__) */
669 #define _TP_IP_PARAM(x) __builtin_return_address(0)
670 #endif /* #else #if defined(__PPC__) && !defined(__PPC64__) */
671
672 #endif /* TP_IP_PARAM */
673
674 /*
675 * Using twice size for filter stack data to hold size and pointer for
676 * each field (worse case). For integers, max size required is 64-bit.
677 * Same for double-precision floats. Those fit within
678 * 2*sizeof(unsigned long) for all supported architectures.
679 * Perform UNION (||) of filter runtime list.
680 */
681 #undef TRACEPOINT_EVENT_CLASS
682 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
683 static lttng_ust_notrace \
684 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)); \
685 static \
686 void __event_probe__##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args)) \
687 { \
688 struct lttng_event *__event = (struct lttng_event *) __tp_data; \
689 struct lttng_channel *__chan = __event->chan; \
690 struct lttng_ust_lib_ring_buffer_ctx __ctx; \
691 struct lttng_stack_ctx __lttng_ctx; \
692 size_t __event_len, __event_align; \
693 size_t __dynamic_len_idx = 0; \
694 union { \
695 size_t __dynamic_len[_TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
696 char __filter_stack_data[2 * sizeof(unsigned long) * _TP_ARRAY_SIZE(__event_fields___##_provider##___##_name)]; \
697 } __stackvar; \
698 int __ret; \
699 \
700 if (0) \
701 (void) __dynamic_len_idx; /* don't warn if unused */ \
702 if (!_TP_SESSION_CHECK(session, __chan->session)) \
703 return; \
704 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->session->active))) \
705 return; \
706 if (caa_unlikely(!CMM_ACCESS_ONCE(__chan->enabled))) \
707 return; \
708 if (caa_unlikely(!CMM_ACCESS_ONCE(__event->enabled))) \
709 return; \
710 if (caa_unlikely(!TP_RCU_LINK_TEST())) \
711 return; \
712 if (caa_unlikely(!cds_list_empty(&__event->bytecode_runtime_head))) { \
713 struct lttng_bytecode_runtime *bc_runtime; \
714 int __filter_record = __event->has_enablers_without_bytecode; \
715 \
716 __event_prepare_filter_stack__##_provider##___##_name(__stackvar.__filter_stack_data, \
717 _TP_ARGS_DATA_VAR(_args)); \
718 tp_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
719 if (caa_unlikely(bc_runtime->filter(bc_runtime, \
720 __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
721 __filter_record = 1; \
722 } \
723 if (caa_likely(!__filter_record)) \
724 return; \
725 } \
726 __event_len = __event_get_size__##_provider##___##_name(__stackvar.__dynamic_len, \
727 _TP_ARGS_DATA_VAR(_args)); \
728 __event_align = __event_get_align__##_provider##___##_name(_TP_ARGS_VAR(_args)); \
729 memset(&__lttng_ctx, 0, sizeof(__lttng_ctx)); \
730 __lttng_ctx.event = __event; \
731 __lttng_ctx.chan_ctx = tp_rcu_dereference_bp(__chan->ctx); \
732 __lttng_ctx.event_ctx = tp_rcu_dereference_bp(__event->ctx); \
733 lib_ring_buffer_ctx_init(&__ctx, __chan->chan, __event, __event_len, \
734 __event_align, -1, __chan->handle, &__lttng_ctx); \
735 __ctx.ip = _TP_IP_PARAM(TP_IP_PARAM); \
736 __ret = __chan->ops->event_reserve(&__ctx, __event->id); \
737 if (__ret < 0) \
738 return; \
739 _fields \
740 __chan->ops->event_commit(&__ctx); \
741 }
742
743 #include TRACEPOINT_INCLUDE
744
745 #undef __get_dynamic_len
746
747 /*
748 * Stage 5.1 of tracepoint event generation.
749 *
750 * Create probe signature
751 */
752
753 /* Reset all macros within TRACEPOINT_EVENT */
754 #include <lttng/ust-tracepoint-event-reset.h>
755
756 #undef TP_ARGS
757 #define TP_ARGS(...) __VA_ARGS__
758
759 #define _TP_EXTRACT_STRING2(...) #__VA_ARGS__
760
761 #undef TRACEPOINT_EVENT_CLASS
762 #define TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \
763 const char __tp_event_signature___##_provider##___##_name[] = \
764 _TP_EXTRACT_STRING2(_args);
765
766 #include TRACEPOINT_INCLUDE
767
768 #undef _TP_EXTRACT_STRING2
769
770 /*
771 * Stage 6 of tracepoint event generation.
772 *
773 * Tracepoint loglevel mapping definition generation. We generate a
774 * symbol for each mapping for a provider/event to ensure at most a 1 to
775 * 1 mapping between events and loglevels. If the symbol is repeated,
776 * the compiler will complain.
777 */
778
779 /* Reset all macros within TRACEPOINT_EVENT */
780 #include <lttng/ust-tracepoint-event-reset.h>
781
782 #undef TRACEPOINT_LOGLEVEL
783 #define TRACEPOINT_LOGLEVEL(__provider, __name, __loglevel) \
784 static const int _loglevel_value___##__provider##___##__name = __loglevel; \
785 static const int *_loglevel___##__provider##___##__name = \
786 &_loglevel_value___##__provider##___##__name;
787
788 #include TRACEPOINT_INCLUDE
789
790 /*
791 * Stage 6.1 of tracepoint event generation.
792 *
793 * Tracepoint UML URI info.
794 */
795
796 /* Reset all macros within TRACEPOINT_EVENT */
797 #include <lttng/ust-tracepoint-event-reset.h>
798
799 #undef TRACEPOINT_MODEL_EMF_URI
800 #define TRACEPOINT_MODEL_EMF_URI(__provider, __name, __uri) \
801 static const char *_model_emf_uri___##__provider##___##__name = __uri;
802
803 #include TRACEPOINT_INCLUDE
804
805 /*
806 * Stage 7.1 of tracepoint event generation.
807 *
808 * Create events description structures. We use a weakref because
809 * loglevels are optional. If not declared, the event will point to the
810 * a loglevel that contains NULL.
811 */
812
813 /* Reset all macros within TRACEPOINT_EVENT */
814 #include <lttng/ust-tracepoint-event-reset.h>
815
816 #undef TRACEPOINT_EVENT_INSTANCE
817 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
818 static const int * \
819 __ref_loglevel___##_provider##___##_name \
820 __attribute__((weakref ("_loglevel___" #_provider "___" #_name))); \
821 static const char * \
822 __ref_model_emf_uri___##_provider##___##_name \
823 __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\
824 const struct lttng_event_desc __event_desc___##_provider##_##_name = { \
825 .name = #_provider ":" #_name, \
826 .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template,\
827 .ctx = NULL, \
828 .fields = __event_fields___##_provider##___##_template, \
829 .nr_fields = _TP_ARRAY_SIZE(__event_fields___##_provider##___##_template), \
830 .loglevel = &__ref_loglevel___##_provider##___##_name, \
831 .signature = __tp_event_signature___##_provider##___##_template, \
832 .u = { \
833 .ext = { \
834 .model_emf_uri = &__ref_model_emf_uri___##_provider##___##_name, \
835 }, \
836 }, \
837 };
838
839 #include TRACEPOINT_INCLUDE
840
841 /*
842 * Stage 7.2 of tracepoint event generation.
843 *
844 * Create array of events.
845 */
846
847 /* Reset all macros within TRACEPOINT_EVENT */
848 #include <lttng/ust-tracepoint-event-reset.h>
849
850 #undef TRACEPOINT_EVENT_INSTANCE
851 #define TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \
852 &__event_desc___##_provider##_##_name,
853
854 static const struct lttng_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = {
855 #include TRACEPOINT_INCLUDE
856 };
857
858
859 /*
860 * Stage 8 of tracepoint event generation.
861 *
862 * Create a toplevel descriptor for the whole probe.
863 */
864
865 /* non-const because list head will be modified when registered. */
866 static struct lttng_probe_desc _TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER) = {
867 .provider = __tp_stringify(TRACEPOINT_PROVIDER),
868 .event_desc = _TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER),
869 .nr_events = _TP_ARRAY_SIZE(_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)),
870 .head = { NULL, NULL },
871 .lazy_init_head = { NULL, NULL },
872 .lazy = 0,
873 .major = LTTNG_UST_PROVIDER_MAJOR,
874 .minor = LTTNG_UST_PROVIDER_MINOR,
875 };
876
877 static int _TP_COMBINE_TOKENS(__probe_register_refcount___, TRACEPOINT_PROVIDER);
878
879 /*
880 * Stage 9 of tracepoint event generation.
881 *
882 * Register/unregister probes at module load/unload.
883 *
884 * Generate the constructor as an externally visible symbol for use when
885 * linking the probe statically.
886 *
887 * Register refcount is protected by libc dynamic loader mutex.
888 */
889
890 /* Reset all macros within TRACEPOINT_EVENT */
891 #include <lttng/ust-tracepoint-event-reset.h>
892 static void lttng_ust_notrace __attribute__((constructor))
893 _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void);
894 static void
895 _TP_COMBINE_TOKENS(__lttng_events_init__, TRACEPOINT_PROVIDER)(void)
896 {
897 int ret;
898
899 if (_TP_COMBINE_TOKENS(__probe_register_refcount___,
900 TRACEPOINT_PROVIDER)++) {
901 return;
902 }
903 /*
904 * __tracepoint_provider_check_ ## TRACEPOINT_PROVIDER() is a
905 * static inline function that ensures every probe PROVIDER
906 * argument match the provider within which they appear. It
907 * calls empty static inline functions, and therefore has no
908 * runtime effect. However, if it detects an error, a linker
909 * error will appear.
910 */
911 _TP_COMBINE_TOKENS(__tracepoint_provider_check_, TRACEPOINT_PROVIDER)();
912 ret = lttng_probe_register(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER));
913 if (ret) {
914 fprintf(stderr, "LTTng-UST: Error (%d) while registering tracepoint probe. Duplicate registration of tracepoint probes having the same name is not allowed.\n", ret);
915 abort();
916 }
917 }
918
919 static void lttng_ust_notrace __attribute__((destructor))
920 _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void);
921 static void
922 _TP_COMBINE_TOKENS(__lttng_events_exit__, TRACEPOINT_PROVIDER)(void)
923 {
924 if (--_TP_COMBINE_TOKENS(__probe_register_refcount___,
925 TRACEPOINT_PROVIDER)) {
926 return;
927 }
928 lttng_probe_unregister(&_TP_COMBINE_TOKENS(__probe_desc___, TRACEPOINT_PROVIDER));
929 }
930
931 int _TP_COMBINE_TOKENS(__tracepoint_provider_, TRACEPOINT_PROVIDER);
This page took 0.048114 seconds and 5 git commands to generate.