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