Commit | Line | Data |
---|---|---|
ca9f27f3 FD |
1 | /* |
2 | * Babeltrace - Trace IR field copy | |
3 | * | |
4 | * Copyright (c) 2015-2019 EfficiOS Inc. and Linux Foundation | |
5 | * Copyright (c) 2018 Philippe Proulx <pproulx@efficios.com> | |
6 | * Copyright (c) 2019 Francis Deslauriers <francis.deslauriers@efficios.com> | |
7 | * | |
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
9 | * of this software and associated documentation files (the "Software"), to deal | |
10 | * in the Software without restriction, including without limitation the rights | |
11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
12 | * copies of the Software, and to permit persons to whom the Software is | |
13 | * furnished to do so, subject to the following conditions: | |
14 | * | |
15 | * The above copyright notice and this permission notice shall be included in | |
16 | * all copies or substantial portions of the Software. | |
17 | * | |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
24 | * SOFTWARE. | |
25 | */ | |
26 | ||
91bc8451 | 27 | #define BT_COMP_LOG_SELF_COMP (md_maps->self_comp) |
3a3d15f3 | 28 | #define BT_LOG_OUTPUT_LEVEL (md_maps->log_level) |
350ad6c1 | 29 | #define BT_LOG_TAG "PLUGIN/FLT.LTTNG-UTILS.DEBUG-INFO/TRACE-IR-META-FC-COPY" |
d9c39b0a | 30 | #include "logging/comp-logging.h" |
ca9f27f3 | 31 | |
578e048b MJ |
32 | #include "common/assert.h" |
33 | #include "common/common.h" | |
34 | #include "compat/compiler.h" | |
3fadfbc0 | 35 | #include <babeltrace2/babeltrace.h> |
ca9f27f3 FD |
36 | |
37 | #include "trace-ir-metadata-copy.h" | |
38 | #include "trace-ir-metadata-field-class-copy.h" | |
39 | ||
40 | /* | |
41 | * This fonction walks througth the nested structures field class to resolve a | |
42 | * field path object. A field path is made of indexes inside possibly nested | |
43 | * structures ultimately leading to a field class. | |
44 | */ | |
45 | static | |
3a3d15f3 PP |
46 | const bt_field_class *walk_field_path(struct trace_ir_metadata_maps *md_maps, |
47 | const bt_field_path *fp, const bt_field_class *fc) | |
ca9f27f3 | 48 | { |
66ddcddf | 49 | uint64_t i, fp_item_count; |
ca9f27f3 FD |
50 | const bt_field_class *curr_fc; |
51 | ||
52 | BT_ASSERT(bt_field_class_get_type(fc) == BT_FIELD_CLASS_TYPE_STRUCTURE); | |
91bc8451 | 53 | BT_COMP_LOGD("Walking field path on field class: fp-addr=%p, fc-addr=%p", |
ca9f27f3 FD |
54 | fp, fc); |
55 | ||
66ddcddf | 56 | fp_item_count = bt_field_path_get_item_count(fp); |
ca9f27f3 | 57 | curr_fc = fc; |
66ddcddf | 58 | for (i = 0; i < fp_item_count; i++) { |
ca9f27f3 | 59 | bt_field_class_type fc_type = bt_field_class_get_type(curr_fc); |
66ddcddf PP |
60 | const bt_field_path_item *fp_item = |
61 | bt_field_path_borrow_item_by_index_const(fp, i); | |
ca9f27f3 FD |
62 | |
63 | switch (fc_type) { | |
64 | case BT_FIELD_CLASS_TYPE_STRUCTURE: | |
1e6fd1d7 | 65 | { |
66ddcddf PP |
66 | const bt_field_class_structure_member *member; |
67 | ||
68 | BT_ASSERT(bt_field_path_item_get_type(fp_item) == | |
69 | BT_FIELD_PATH_ITEM_TYPE_INDEX); | |
70 | member = bt_field_class_structure_borrow_member_by_index_const( | |
71 | curr_fc, | |
72 | bt_field_path_item_index_get_index(fp_item)); | |
1e6fd1d7 PP |
73 | curr_fc = bt_field_class_structure_member_borrow_field_class_const( |
74 | member); | |
ca9f27f3 | 75 | break; |
1e6fd1d7 | 76 | } |
45c51519 PP |
77 | case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR: |
78 | case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR: | |
79 | case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR: | |
1e6fd1d7 | 80 | { |
66ddcddf PP |
81 | const bt_field_class_variant_option *option; |
82 | ||
83 | BT_ASSERT(bt_field_path_item_get_type(fp_item) == | |
84 | BT_FIELD_PATH_ITEM_TYPE_INDEX); | |
85 | option = bt_field_class_variant_borrow_option_by_index_const( | |
86 | curr_fc, | |
87 | bt_field_path_item_index_get_index(fp_item)); | |
1e6fd1d7 PP |
88 | curr_fc = bt_field_class_variant_option_borrow_field_class_const( |
89 | option); | |
ca9f27f3 | 90 | break; |
1e6fd1d7 | 91 | } |
66ddcddf PP |
92 | case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: |
93 | case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY: | |
94 | { | |
95 | BT_ASSERT(bt_field_path_item_get_type(fp_item) == | |
96 | BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT); | |
97 | curr_fc = bt_field_class_array_borrow_element_field_class_const( | |
98 | curr_fc); | |
99 | break; | |
100 | } | |
ca9f27f3 FD |
101 | default: |
102 | abort(); | |
103 | } | |
104 | } | |
105 | ||
106 | return curr_fc; | |
107 | } | |
108 | ||
109 | static | |
110 | const bt_field_class *resolve_field_path_to_field_class(const bt_field_path *fp, | |
111 | struct trace_ir_metadata_maps *md_maps) | |
112 | { | |
113 | struct field_class_resolving_context *fc_resolving_ctx; | |
114 | const bt_field_class *fc; | |
e7ceb9df | 115 | bt_field_path_scope fp_scope; |
ca9f27f3 | 116 | |
91bc8451 | 117 | BT_COMP_LOGD("Resolving field path: fp-addr=%p", fp); |
ca9f27f3 FD |
118 | |
119 | fc_resolving_ctx = md_maps->fc_resolving_ctx; | |
120 | fp_scope = bt_field_path_get_root_scope(fp); | |
121 | ||
122 | switch (fp_scope) { | |
e7ceb9df | 123 | case BT_FIELD_PATH_SCOPE_PACKET_CONTEXT: |
3a3d15f3 PP |
124 | fc = walk_field_path(md_maps, fp, |
125 | fc_resolving_ctx->packet_context); | |
ca9f27f3 | 126 | break; |
e7ceb9df | 127 | case BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT: |
3a3d15f3 PP |
128 | fc = walk_field_path(md_maps, fp, |
129 | fc_resolving_ctx->event_common_context); | |
ca9f27f3 | 130 | break; |
e7ceb9df | 131 | case BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT: |
3a3d15f3 PP |
132 | fc = walk_field_path(md_maps, fp, |
133 | fc_resolving_ctx->event_specific_context); | |
ca9f27f3 | 134 | break; |
e7ceb9df | 135 | case BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD: |
3a3d15f3 PP |
136 | fc = walk_field_path(md_maps, fp, |
137 | fc_resolving_ctx->event_payload); | |
ca9f27f3 FD |
138 | break; |
139 | default: | |
140 | abort(); | |
141 | } | |
142 | ||
143 | return fc; | |
144 | } | |
145 | ||
146 | static inline | |
147 | void field_class_integer_set_props(const bt_field_class *input_fc, | |
148 | bt_field_class *output_fc) | |
149 | { | |
150 | bt_field_class_integer_set_preferred_display_base(output_fc, | |
151 | bt_field_class_integer_get_preferred_display_base(input_fc)); | |
152 | bt_field_class_integer_set_field_value_range(output_fc, | |
153 | bt_field_class_integer_get_field_value_range(input_fc)); | |
154 | } | |
155 | ||
156 | static inline | |
157 | int field_class_unsigned_integer_copy( | |
158 | struct trace_ir_metadata_maps *md_maps, | |
159 | const bt_field_class *in_field_class, | |
160 | bt_field_class *out_field_class) | |
161 | { | |
91bc8451 | 162 | BT_COMP_LOGD("Copying content of unsigned integer field class: " |
ca9f27f3 FD |
163 | "in-fc-addr=%p, out-fc-addr=%p", |
164 | in_field_class, out_field_class); | |
165 | ||
166 | field_class_integer_set_props(in_field_class, out_field_class); | |
167 | ||
91bc8451 | 168 | BT_COMP_LOGD("Copied content of unsigned integer field class: " |
ca9f27f3 FD |
169 | "in-fc-addr=%p, out-fc-addr=%p", |
170 | in_field_class, out_field_class); | |
171 | return 0; | |
172 | } | |
173 | ||
174 | static inline | |
175 | int field_class_signed_integer_copy( | |
176 | struct trace_ir_metadata_maps *md_maps, | |
177 | const bt_field_class *in_field_class, | |
178 | bt_field_class *out_field_class) | |
179 | { | |
91bc8451 | 180 | BT_COMP_LOGD("Copying content of signed integer field class: " |
ca9f27f3 FD |
181 | "in-fc-addr=%p, out-fc-addr=%p", |
182 | in_field_class, out_field_class); | |
183 | ||
184 | field_class_integer_set_props(in_field_class, out_field_class); | |
185 | ||
91bc8451 | 186 | BT_COMP_LOGD("Copied content of signed integer field class: " |
ca9f27f3 FD |
187 | "in-fc-addr=%p, out-fc-addr=%p", |
188 | in_field_class, out_field_class); | |
189 | return 0; | |
190 | } | |
191 | ||
192 | BT_HIDDEN | |
193 | int field_class_unsigned_enumeration_copy( | |
194 | struct trace_ir_metadata_maps *md_maps, | |
195 | const bt_field_class *in_field_class, | |
196 | bt_field_class *out_field_class) | |
197 | { | |
198 | uint64_t i, enum_mapping_count; | |
199 | int ret = 0; | |
200 | ||
91bc8451 | 201 | BT_COMP_LOGD("Copying content of unsigned enumeration field class: " |
ca9f27f3 FD |
202 | "in-fc-addr=%p, out-fc-addr=%p", |
203 | in_field_class, out_field_class); | |
204 | ||
205 | /* Copy properties of the inner integer. */ | |
206 | field_class_integer_set_props(in_field_class, out_field_class); | |
207 | ||
208 | /* Copy all enumeration entries. */ | |
209 | enum_mapping_count = bt_field_class_enumeration_get_mapping_count(in_field_class); | |
210 | for (i = 0; i < enum_mapping_count; i++) { | |
211 | const char *label; | |
45c51519 | 212 | const bt_integer_range_set_unsigned *range_set; |
9c08c816 | 213 | const bt_field_class_enumeration_unsigned_mapping *u_mapping; |
8f3ccfbc | 214 | const bt_field_class_enumeration_mapping *mapping; |
ca9f27f3 | 215 | |
9c08c816 | 216 | u_mapping = bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const( |
8f3ccfbc | 217 | in_field_class, i); |
9c08c816 | 218 | mapping = bt_field_class_enumeration_unsigned_mapping_as_mapping_const( |
8f3ccfbc | 219 | u_mapping); |
45c51519 | 220 | label = bt_field_class_enumeration_mapping_get_label(mapping); |
9c08c816 | 221 | range_set = bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const( |
45c51519 | 222 | u_mapping); |
9c08c816 | 223 | ret = bt_field_class_enumeration_unsigned_add_mapping( |
45c51519 PP |
224 | out_field_class, label, range_set); |
225 | if (ret) { | |
226 | goto error; | |
ca9f27f3 FD |
227 | } |
228 | } | |
229 | ||
91bc8451 | 230 | BT_COMP_LOGD("Copied content of unsigned enumeration field class: " |
ca9f27f3 FD |
231 | "in-fc-addr=%p, out-fc-addr=%p", |
232 | in_field_class, out_field_class); | |
233 | ||
234 | error: | |
235 | return ret; | |
236 | } | |
237 | ||
238 | static inline | |
239 | int field_class_signed_enumeration_copy( | |
240 | struct trace_ir_metadata_maps *md_maps, | |
241 | const bt_field_class *in_field_class, | |
242 | bt_field_class *out_field_class) | |
243 | { | |
244 | uint64_t i, enum_mapping_count; | |
245 | int ret = 0; | |
246 | ||
91bc8451 | 247 | BT_COMP_LOGD("Copying content of signed enumeration field class: " |
ca9f27f3 FD |
248 | "in-fc-addr=%p, out-fc-addr=%p", |
249 | in_field_class, out_field_class); | |
250 | ||
251 | /* Copy properties of the inner integer. */ | |
252 | field_class_integer_set_props(in_field_class, out_field_class); | |
253 | ||
254 | /* Copy all enumeration entries. */ | |
255 | enum_mapping_count = | |
256 | bt_field_class_enumeration_get_mapping_count(in_field_class); | |
257 | for (i = 0; i < enum_mapping_count; i++) { | |
258 | const char *label; | |
45c51519 | 259 | const bt_integer_range_set_signed *range_set; |
9c08c816 | 260 | const bt_field_class_enumeration_signed_mapping *s_mapping; |
8f3ccfbc | 261 | const bt_field_class_enumeration_mapping *mapping; |
ca9f27f3 | 262 | |
9c08c816 | 263 | s_mapping = bt_field_class_enumeration_signed_borrow_mapping_by_index_const( |
8f3ccfbc | 264 | in_field_class, i); |
9c08c816 | 265 | mapping = bt_field_class_enumeration_signed_mapping_as_mapping_const( |
45c51519 PP |
266 | s_mapping); |
267 | label = bt_field_class_enumeration_mapping_get_label(mapping); | |
9c08c816 | 268 | range_set = bt_field_class_enumeration_signed_mapping_borrow_ranges_const( |
45c51519 | 269 | s_mapping); |
9c08c816 | 270 | ret = bt_field_class_enumeration_signed_add_mapping( |
45c51519 PP |
271 | out_field_class, label, range_set); |
272 | if (ret) { | |
273 | goto error; | |
ca9f27f3 FD |
274 | } |
275 | } | |
276 | ||
91bc8451 | 277 | BT_COMP_LOGD("Copied content of signed enumeration field class: " |
ca9f27f3 FD |
278 | "in-fc-addr=%p, out-fc-addr=%p", |
279 | in_field_class, out_field_class); | |
280 | ||
281 | error: | |
282 | return ret; | |
283 | } | |
284 | ||
285 | static inline | |
286 | int field_class_real_copy( | |
287 | struct trace_ir_metadata_maps *md_maps, | |
288 | const bt_field_class *in_field_class, | |
289 | bt_field_class *out_field_class) | |
290 | { | |
91bc8451 | 291 | BT_COMP_LOGD("Copying content of real field class: " |
ca9f27f3 FD |
292 | "in-fc-addr=%p, out-fc-addr=%p", |
293 | in_field_class, out_field_class); | |
294 | ||
295 | bt_field_class_real_set_is_single_precision(out_field_class, | |
296 | bt_field_class_real_is_single_precision(in_field_class)); | |
297 | ||
91bc8451 | 298 | BT_COMP_LOGD("Copied content real field class: in-fc-addr=%p, " |
ca9f27f3 FD |
299 | "out-fc-addr=%p", in_field_class, out_field_class); |
300 | ||
301 | return 0; | |
302 | } | |
303 | ||
304 | static inline | |
305 | int field_class_structure_copy( | |
306 | struct trace_ir_metadata_maps *md_maps, | |
307 | const bt_field_class *in_field_class, | |
308 | bt_field_class *out_field_class) | |
309 | { | |
310 | uint64_t i, struct_member_count; | |
ca9f27f3 FD |
311 | int ret = 0; |
312 | ||
91bc8451 | 313 | BT_COMP_LOGD("Copying content of structure field class: " |
ca9f27f3 FD |
314 | "in-fc-addr=%p, out-fc-addr=%p", |
315 | in_field_class, out_field_class); | |
316 | /* Get the number of member in that struct. */ | |
317 | struct_member_count = | |
318 | bt_field_class_structure_get_member_count(in_field_class); | |
319 | ||
320 | /* Iterate over all the members of the struct. */ | |
321 | for (i = 0; i < struct_member_count; i++) { | |
1e6fd1d7 | 322 | const bt_field_class_structure_member *member; |
ca9f27f3 FD |
323 | const char *member_name; |
324 | const bt_field_class *member_fc; | |
325 | bt_field_class *out_member_field_class; | |
326 | ||
1e6fd1d7 PP |
327 | member = bt_field_class_structure_borrow_member_by_index_const( |
328 | in_field_class, i); | |
329 | member_fc = bt_field_class_structure_member_borrow_field_class_const( | |
330 | member); | |
331 | member_name = bt_field_class_structure_member_get_name(member); | |
91bc8451 | 332 | BT_COMP_LOGD("Copying structure field class's field: " |
ca9f27f3 FD |
333 | "index=%" PRId64 ", " |
334 | "member-fc-addr=%p, field-name=\"%s\"", | |
335 | i, member_fc, member_name); | |
336 | ||
337 | out_member_field_class = create_field_class_copy(md_maps, | |
338 | member_fc); | |
339 | if (!out_member_field_class) { | |
91bc8451 | 340 | BT_COMP_LOGE("Cannot copy structure field class's field: " |
ca9f27f3 FD |
341 | "index=%" PRId64 ", " |
342 | "field-fc-addr=%p, field-name=\"%s\"", | |
343 | i, member_fc, member_name); | |
344 | ret = -1; | |
345 | goto error; | |
346 | } | |
347 | ret = copy_field_class_content(md_maps, member_fc, | |
348 | out_member_field_class); | |
349 | if (ret) { | |
350 | goto error; | |
351 | } | |
352 | ||
d24d5663 PP |
353 | if (bt_field_class_structure_append_member(out_field_class, |
354 | member_name, out_member_field_class) != | |
355 | BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { | |
91bc8451 | 356 | BT_COMP_LOGE("Cannot append structure field class's field: " |
ca9f27f3 FD |
357 | "index=%" PRId64 ", " |
358 | "field-fc-addr=%p, field-name=\"%s\"", | |
359 | i, member_fc, member_name); | |
360 | BT_FIELD_CLASS_PUT_REF_AND_RESET(out_member_field_class); | |
361 | ret = -1; | |
362 | goto error; | |
363 | } | |
364 | } | |
365 | ||
91bc8451 | 366 | BT_COMP_LOGD("Copied structure field class: original-fc-addr=%p, copy-fc-addr=%p", |
ca9f27f3 FD |
367 | in_field_class, out_field_class); |
368 | ||
369 | error: | |
370 | return ret; | |
371 | } | |
372 | ||
373 | static inline | |
374 | int field_class_variant_copy( | |
375 | struct trace_ir_metadata_maps *md_maps, | |
376 | const bt_field_class *in_field_class, | |
377 | bt_field_class *out_field_class) | |
378 | { | |
1ec009b2 | 379 | bt_field_class *out_tag_field_class = NULL; |
ca9f27f3 | 380 | uint64_t i, variant_option_count; |
45c51519 | 381 | bt_field_class_type fc_type = bt_field_class_get_type(in_field_class); |
ca9f27f3 FD |
382 | int ret = 0; |
383 | ||
91bc8451 | 384 | BT_COMP_LOGD("Copying content of variant field class: " |
ca9f27f3 FD |
385 | "in-fc-addr=%p, out-fc-addr=%p", |
386 | in_field_class, out_field_class); | |
ca9f27f3 FD |
387 | variant_option_count = |
388 | bt_field_class_variant_get_option_count(in_field_class); | |
389 | for (i = 0; i < variant_option_count; i++) { | |
1e6fd1d7 | 390 | const bt_field_class *option_fc; |
ca9f27f3 FD |
391 | const char *option_name; |
392 | bt_field_class *out_option_field_class; | |
1e6fd1d7 | 393 | const bt_field_class_variant_option *option; |
ca9f27f3 | 394 | |
1e6fd1d7 PP |
395 | option = bt_field_class_variant_borrow_option_by_index_const( |
396 | in_field_class, i); | |
397 | option_fc = bt_field_class_variant_option_borrow_field_class_const( | |
398 | option); | |
399 | option_name = bt_field_class_variant_option_get_name(option); | |
ca9f27f3 | 400 | out_option_field_class = create_field_class_copy_internal( |
1e6fd1d7 | 401 | md_maps, option_fc); |
ca9f27f3 | 402 | if (!out_option_field_class) { |
91bc8451 | 403 | BT_COMP_LOGE_STR("Cannot copy field class."); |
ca9f27f3 FD |
404 | ret = -1; |
405 | goto error; | |
406 | } | |
1e6fd1d7 | 407 | ret = copy_field_class_content_internal(md_maps, option_fc, |
ca9f27f3 FD |
408 | out_option_field_class); |
409 | if (ret) { | |
91bc8451 | 410 | BT_COMP_LOGE_STR("Error copying content of option variant " |
ca9f27f3 FD |
411 | "field class'"); |
412 | goto error; | |
413 | } | |
414 | ||
45c51519 | 415 | if (fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR) { |
9c08c816 PP |
416 | const bt_field_class_variant_with_selector_unsigned_option *spec_opt = |
417 | bt_field_class_variant_with_selector_unsigned_borrow_option_by_index_const( | |
45c51519 PP |
418 | in_field_class, i); |
419 | const bt_integer_range_set_unsigned *ranges = | |
9c08c816 | 420 | bt_field_class_variant_with_selector_unsigned_option_borrow_ranges_const( |
45c51519 PP |
421 | spec_opt); |
422 | ||
9c08c816 | 423 | if (bt_field_class_variant_with_selector_unsigned_append_option( |
45c51519 PP |
424 | out_field_class, option_name, |
425 | out_option_field_class, ranges) != | |
426 | BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_APPEND_OPTION_STATUS_OK) { | |
427 | BT_COMP_LOGE_STR("Cannot append option to variant field class with unsigned selector'"); | |
428 | BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class); | |
429 | ret = -1; | |
430 | goto error; | |
431 | } | |
432 | } else if (fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR) { | |
9c08c816 PP |
433 | const bt_field_class_variant_with_selector_signed_option *spec_opt = |
434 | bt_field_class_variant_with_selector_signed_borrow_option_by_index_const( | |
45c51519 PP |
435 | in_field_class, i); |
436 | const bt_integer_range_set_signed *ranges = | |
9c08c816 | 437 | bt_field_class_variant_with_selector_signed_option_borrow_ranges_const( |
45c51519 PP |
438 | spec_opt); |
439 | ||
9c08c816 | 440 | if (bt_field_class_variant_with_selector_signed_append_option( |
45c51519 PP |
441 | out_field_class, option_name, |
442 | out_option_field_class, ranges) != | |
443 | BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_APPEND_OPTION_STATUS_OK) { | |
444 | BT_COMP_LOGE_STR("Cannot append option to variant field class with signed selector'"); | |
445 | BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class); | |
446 | ret = -1; | |
447 | goto error; | |
448 | } | |
449 | } else { | |
450 | BT_ASSERT(fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR); | |
451 | ||
452 | if (bt_field_class_variant_without_selector_append_option( | |
453 | out_field_class, option_name, | |
454 | out_option_field_class) != | |
455 | BT_FIELD_CLASS_VARIANT_WITHOUT_SELECTOR_APPEND_OPTION_STATUS_OK) { | |
456 | BT_COMP_LOGE_STR("Cannot append option to variant field class'"); | |
457 | BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class); | |
458 | ret = -1; | |
459 | goto error; | |
460 | } | |
ca9f27f3 FD |
461 | } |
462 | } | |
463 | ||
91bc8451 | 464 | BT_COMP_LOGD("Copied content of variant field class: in-fc-addr=%p, " |
ca9f27f3 FD |
465 | "out-fc-addr=%p", in_field_class, out_field_class); |
466 | ||
467 | error: | |
468 | return ret; | |
469 | } | |
470 | ||
471 | static inline | |
472 | int field_class_static_array_copy( | |
473 | struct trace_ir_metadata_maps *md_maps, | |
474 | const bt_field_class *in_field_class, | |
475 | bt_field_class *out_field_class) | |
476 | { | |
91bc8451 | 477 | BT_COMP_LOGD("Copying content of static array field class: in-fc-addr=%p, " |
ca9f27f3 FD |
478 | "out-fc-addr=%p", in_field_class, out_field_class); |
479 | /* | |
480 | * There is no content to copy. Keep this function call anyway for | |
481 | * logging purposes. | |
482 | */ | |
91bc8451 | 483 | BT_COMP_LOGD("Copied content of static array field class: in-fc-addr=%p, " |
ca9f27f3 FD |
484 | "out-fc-addr=%p", in_field_class, out_field_class); |
485 | ||
486 | return 0; | |
487 | } | |
488 | ||
489 | static inline | |
490 | int field_class_dynamic_array_copy( | |
491 | struct trace_ir_metadata_maps *md_maps, | |
492 | const bt_field_class *in_field_class, | |
493 | bt_field_class *out_field_class) | |
494 | { | |
91bc8451 | 495 | BT_COMP_LOGD("Copying content of dynamic array field class: " |
ca9f27f3 FD |
496 | "in-fc-addr=%p, out-fc-addr=%p", |
497 | in_field_class, out_field_class); | |
498 | ||
1367bc7c PP |
499 | /* |
500 | * There is no content to copy. Keep this function call anyway for | |
501 | * logging purposes. | |
502 | */ | |
91bc8451 | 503 | BT_COMP_LOGD("Copied dynamic array field class: in-fc-addr=%p, " |
ca9f27f3 FD |
504 | "out-fc-addr=%p", in_field_class, out_field_class); |
505 | ||
1367bc7c | 506 | return 0; |
ca9f27f3 FD |
507 | } |
508 | ||
509 | static inline | |
510 | int field_class_string_copy(struct trace_ir_metadata_maps *md_maps, | |
511 | const bt_field_class *in_field_class, | |
512 | bt_field_class *out_field_class) | |
513 | { | |
91bc8451 | 514 | BT_COMP_LOGD("Copying content of string field class: in-fc-addr=%p, " |
ca9f27f3 FD |
515 | "out-fc-addr=%p", in_field_class, out_field_class); |
516 | /* | |
517 | * There is no content to copy. Keep this function call anyway for | |
518 | * logging purposes. | |
519 | */ | |
91bc8451 | 520 | BT_COMP_LOGD("Copied content of string field class: in-fc-addr=%p, " |
ca9f27f3 FD |
521 | "out-fc-addr=%p", in_field_class, out_field_class); |
522 | ||
523 | return 0; | |
524 | } | |
525 | ||
526 | static | |
527 | bt_field_class *copy_field_class_array_element(struct trace_ir_metadata_maps *md_maps, | |
528 | const bt_field_class *in_elem_fc) | |
529 | { | |
530 | int ret; | |
531 | bt_field_class *out_elem_fc = | |
532 | create_field_class_copy_internal(md_maps, in_elem_fc); | |
533 | if (!out_elem_fc) { | |
91bc8451 | 534 | BT_COMP_LOGE("Error creating output elem field class " |
ca9f27f3 FD |
535 | "from input elem field class for static array: " |
536 | "in-fc-addr=%p", in_elem_fc); | |
537 | goto error; | |
538 | } | |
539 | ||
540 | ret = copy_field_class_content_internal(md_maps, in_elem_fc, out_elem_fc); | |
541 | if (ret) { | |
91bc8451 | 542 | BT_COMP_LOGE("Error creating output elem field class " |
ca9f27f3 FD |
543 | "from input elem field class for static array: " |
544 | "in-fc-addr=%p", in_elem_fc); | |
545 | BT_FIELD_CLASS_PUT_REF_AND_RESET(out_elem_fc); | |
546 | goto error; | |
547 | } | |
548 | ||
549 | error: | |
550 | return out_elem_fc; | |
551 | } | |
552 | ||
553 | BT_HIDDEN | |
554 | bt_field_class *create_field_class_copy_internal(struct trace_ir_metadata_maps *md_maps, | |
555 | const bt_field_class *in_field_class) | |
556 | { | |
557 | bt_field_class *out_field_class = NULL; | |
45c51519 | 558 | bt_field_class_type fc_type = bt_field_class_get_type(in_field_class); |
ca9f27f3 | 559 | |
91bc8451 | 560 | BT_COMP_LOGD("Creating bare field class based on field class: in-fc-addr=%p", |
ca9f27f3 FD |
561 | in_field_class); |
562 | ||
45c51519 | 563 | switch (fc_type) { |
ca9f27f3 | 564 | case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER: |
9c08c816 | 565 | out_field_class = bt_field_class_integer_unsigned_create( |
ca9f27f3 FD |
566 | md_maps->output_trace_class); |
567 | break; | |
568 | case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER: | |
9c08c816 | 569 | out_field_class = bt_field_class_integer_signed_create( |
ca9f27f3 FD |
570 | md_maps->output_trace_class); |
571 | break; | |
572 | case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: | |
9c08c816 | 573 | out_field_class = bt_field_class_enumeration_unsigned_create( |
ca9f27f3 FD |
574 | md_maps->output_trace_class); |
575 | break; | |
576 | case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION: | |
9c08c816 | 577 | out_field_class = bt_field_class_enumeration_signed_create( |
ca9f27f3 FD |
578 | md_maps->output_trace_class); |
579 | break; | |
580 | case BT_FIELD_CLASS_TYPE_REAL: | |
581 | out_field_class = bt_field_class_real_create( | |
582 | md_maps->output_trace_class); | |
583 | break; | |
584 | case BT_FIELD_CLASS_TYPE_STRING: | |
585 | out_field_class = bt_field_class_string_create( | |
586 | md_maps->output_trace_class); | |
587 | break; | |
588 | case BT_FIELD_CLASS_TYPE_STRUCTURE: | |
589 | out_field_class = bt_field_class_structure_create( | |
590 | md_maps->output_trace_class); | |
591 | break; | |
592 | case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: | |
593 | { | |
594 | const bt_field_class *in_elem_fc = | |
595 | bt_field_class_array_borrow_element_field_class_const( | |
596 | in_field_class); | |
597 | uint64_t array_len = | |
9c08c816 | 598 | bt_field_class_array_static_get_length(in_field_class); |
ca9f27f3 FD |
599 | |
600 | bt_field_class *out_elem_fc = copy_field_class_array_element( | |
601 | md_maps, in_elem_fc); | |
602 | if (!out_elem_fc) { | |
603 | out_field_class = NULL; | |
604 | goto error; | |
605 | } | |
606 | ||
9c08c816 | 607 | out_field_class = bt_field_class_array_static_create( |
ca9f27f3 FD |
608 | md_maps->output_trace_class, |
609 | out_elem_fc, array_len); | |
610 | break; | |
611 | } | |
612 | case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY: | |
613 | { | |
614 | const bt_field_class *in_elem_fc = | |
615 | bt_field_class_array_borrow_element_field_class_const( | |
616 | in_field_class); | |
1367bc7c | 617 | const bt_field_path *length_fp = |
9c08c816 | 618 | bt_field_class_array_dynamic_borrow_length_field_path_const( |
1367bc7c PP |
619 | in_field_class); |
620 | bt_field_class *out_length_fc = NULL; | |
ca9f27f3 FD |
621 | |
622 | bt_field_class *out_elem_fc = copy_field_class_array_element( | |
1367bc7c | 623 | md_maps, in_elem_fc); |
ca9f27f3 FD |
624 | if (!out_elem_fc) { |
625 | out_field_class = NULL; | |
626 | goto error; | |
627 | } | |
628 | ||
1367bc7c PP |
629 | if (length_fp) { |
630 | const bt_field_class *in_length_fc = | |
631 | resolve_field_path_to_field_class(length_fp, | |
632 | md_maps); | |
633 | ||
634 | BT_ASSERT(in_length_fc); | |
635 | out_length_fc = g_hash_table_lookup(md_maps->field_class_map, | |
636 | in_length_fc); | |
637 | BT_ASSERT(out_length_fc); | |
638 | } | |
639 | ||
9c08c816 | 640 | out_field_class = bt_field_class_array_dynamic_create( |
ca9f27f3 | 641 | md_maps->output_trace_class, |
1367bc7c | 642 | out_elem_fc, out_length_fc); |
ca9f27f3 FD |
643 | break; |
644 | } | |
45c51519 PP |
645 | case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR: |
646 | case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR: | |
647 | case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR: | |
648 | { | |
649 | bt_field_class *out_sel_fc = NULL; | |
650 | ||
651 | if (fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR || | |
652 | fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR) { | |
653 | const bt_field_class *in_sel_fc; | |
654 | const bt_field_path *sel_fp = | |
655 | bt_field_class_variant_with_selector_borrow_selector_field_path_const( | |
656 | in_field_class); | |
657 | ||
658 | BT_ASSERT(sel_fp); | |
659 | in_sel_fc = resolve_field_path_to_field_class(sel_fp, | |
660 | md_maps); | |
661 | BT_ASSERT(in_sel_fc); | |
662 | out_sel_fc = g_hash_table_lookup( | |
663 | md_maps->field_class_map, in_sel_fc); | |
664 | BT_ASSERT(out_sel_fc); | |
665 | } | |
666 | ||
ca9f27f3 | 667 | out_field_class = bt_field_class_variant_create( |
45c51519 | 668 | md_maps->output_trace_class, out_sel_fc); |
ca9f27f3 | 669 | break; |
45c51519 | 670 | } |
ca9f27f3 FD |
671 | default: |
672 | abort(); | |
673 | } | |
674 | ||
675 | /* | |
676 | * Add mapping from in_field_class to out_field_class. This simplifies | |
677 | * the resolution of field paths in variant and dynamic array field | |
678 | * classes. | |
679 | */ | |
680 | g_hash_table_insert(md_maps->field_class_map, | |
681 | (gpointer) in_field_class, out_field_class); | |
682 | ||
683 | error: | |
684 | if(out_field_class){ | |
91bc8451 | 685 | BT_COMP_LOGD("Created bare field class based on field class: in-fc-addr=%p, " |
ca9f27f3 FD |
686 | "out-fc-addr=%p", in_field_class, out_field_class); |
687 | } else { | |
91bc8451 | 688 | BT_COMP_LOGE("Error creating output field class from input field " |
ca9f27f3 FD |
689 | "class: in-fc-addr=%p", in_field_class); |
690 | } | |
691 | ||
692 | return out_field_class; | |
693 | } | |
694 | ||
695 | BT_HIDDEN | |
696 | int copy_field_class_content_internal( | |
697 | struct trace_ir_metadata_maps *md_maps, | |
698 | const bt_field_class *in_field_class, | |
699 | bt_field_class *out_field_class) | |
700 | { | |
701 | int ret = 0; | |
702 | switch(bt_field_class_get_type(in_field_class)) { | |
703 | case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER: | |
704 | ret = field_class_unsigned_integer_copy(md_maps, | |
705 | in_field_class, out_field_class); | |
706 | break; | |
707 | case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER: | |
708 | ret = field_class_signed_integer_copy(md_maps, | |
709 | in_field_class, out_field_class); | |
710 | break; | |
711 | case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: | |
712 | ret = field_class_unsigned_enumeration_copy(md_maps, | |
713 | in_field_class, out_field_class); | |
714 | break; | |
715 | case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION: | |
716 | ret = field_class_signed_enumeration_copy(md_maps, | |
717 | in_field_class, out_field_class); | |
718 | break; | |
719 | case BT_FIELD_CLASS_TYPE_REAL: | |
720 | ret = field_class_real_copy(md_maps, | |
721 | in_field_class, out_field_class); | |
722 | break; | |
723 | case BT_FIELD_CLASS_TYPE_STRING: | |
724 | ret = field_class_string_copy(md_maps, | |
725 | in_field_class, out_field_class); | |
726 | break; | |
727 | case BT_FIELD_CLASS_TYPE_STRUCTURE: | |
728 | ret = field_class_structure_copy(md_maps, | |
729 | in_field_class, out_field_class); | |
730 | break; | |
731 | case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: | |
732 | ret = field_class_static_array_copy(md_maps, | |
733 | in_field_class, out_field_class); | |
734 | break; | |
735 | case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY: | |
736 | ret = field_class_dynamic_array_copy(md_maps, | |
737 | in_field_class, out_field_class); | |
738 | break; | |
45c51519 PP |
739 | case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR: |
740 | case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR: | |
741 | case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR: | |
ca9f27f3 FD |
742 | ret = field_class_variant_copy(md_maps, |
743 | in_field_class, out_field_class); | |
744 | break; | |
745 | default: | |
746 | abort(); | |
747 | } | |
748 | ||
749 | return ret; | |
750 | } |