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