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