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