lib: decouple variant FC option names from selector FC mapping names
[babeltrace.git] / src / plugins / lttng-utils / debug-info / trace-ir-metadata-field-class-copy.c
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
27 #define BT_COMP_LOG_SELF_COMP (md_maps->self_comp)
28 #define BT_LOG_OUTPUT_LEVEL (md_maps->log_level)
29 #define BT_LOG_TAG "PLUGIN/FLT.LTTNG-UTILS.DEBUG-INFO/TRACE-IR-META-FC-COPY"
30 #include "plugins/comp-logging.h"
31
32 #include "common/assert.h"
33 #include "common/common.h"
34 #include "compat/compiler.h"
35 #include <babeltrace2/babeltrace.h>
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
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)
48 {
49 uint64_t i, fp_item_count;
50 const bt_field_class *curr_fc;
51
52 BT_ASSERT(bt_field_class_get_type(fc) == BT_FIELD_CLASS_TYPE_STRUCTURE);
53 BT_COMP_LOGD("Walking field path on field class: fp-addr=%p, fc-addr=%p",
54 fp, fc);
55
56 fp_item_count = bt_field_path_get_item_count(fp);
57 curr_fc = fc;
58 for (i = 0; i < fp_item_count; i++) {
59 bt_field_class_type fc_type = bt_field_class_get_type(curr_fc);
60 const bt_field_path_item *fp_item =
61 bt_field_path_borrow_item_by_index_const(fp, i);
62
63 switch (fc_type) {
64 case BT_FIELD_CLASS_TYPE_STRUCTURE:
65 {
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));
73 curr_fc = bt_field_class_structure_member_borrow_field_class_const(
74 member);
75 break;
76 }
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:
80 {
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));
88 curr_fc = bt_field_class_variant_option_borrow_field_class_const(
89 option);
90 break;
91 }
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 }
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;
115 bt_scope fp_scope;
116
117 BT_COMP_LOGD("Resolving field path: fp-addr=%p", fp);
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) {
123 case BT_SCOPE_PACKET_CONTEXT:
124 fc = walk_field_path(md_maps, fp,
125 fc_resolving_ctx->packet_context);
126 break;
127 case BT_SCOPE_EVENT_COMMON_CONTEXT:
128 fc = walk_field_path(md_maps, fp,
129 fc_resolving_ctx->event_common_context);
130 break;
131 case BT_SCOPE_EVENT_SPECIFIC_CONTEXT:
132 fc = walk_field_path(md_maps, fp,
133 fc_resolving_ctx->event_specific_context);
134 break;
135 case BT_SCOPE_EVENT_PAYLOAD:
136 fc = walk_field_path(md_maps, fp,
137 fc_resolving_ctx->event_payload);
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 {
162 BT_COMP_LOGD("Copying content of unsigned integer field class: "
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
168 BT_COMP_LOGD("Copied content of unsigned integer field class: "
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 {
180 BT_COMP_LOGD("Copying content of signed integer field class: "
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
186 BT_COMP_LOGD("Copied content of signed integer field class: "
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
201 BT_COMP_LOGD("Copying content of unsigned enumeration field class: "
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;
212 const bt_integer_range_set_unsigned *range_set;
213 const bt_field_class_unsigned_enumeration_mapping *u_mapping;
214 const bt_field_class_enumeration_mapping *mapping;
215
216 u_mapping = bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const(
217 in_field_class, i);
218 mapping = bt_field_class_unsigned_enumeration_mapping_as_mapping_const(
219 u_mapping);
220 label = bt_field_class_enumeration_mapping_get_label(mapping);
221 range_set = bt_field_class_unsigned_enumeration_mapping_borrow_ranges_const(
222 u_mapping);
223 ret = bt_field_class_unsigned_enumeration_add_mapping(
224 out_field_class, label, range_set);
225 if (ret) {
226 goto error;
227 }
228 }
229
230 BT_COMP_LOGD("Copied content of unsigned enumeration field class: "
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
247 BT_COMP_LOGD("Copying content of signed enumeration field class: "
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;
259 const bt_integer_range_set_signed *range_set;
260 const bt_field_class_signed_enumeration_mapping *s_mapping;
261 const bt_field_class_enumeration_mapping *mapping;
262
263 s_mapping = bt_field_class_signed_enumeration_borrow_mapping_by_index_const(
264 in_field_class, i);
265 mapping = bt_field_class_signed_enumeration_mapping_as_mapping_const(
266 s_mapping);
267 label = bt_field_class_enumeration_mapping_get_label(mapping);
268 range_set = bt_field_class_signed_enumeration_mapping_borrow_ranges_const(
269 s_mapping);
270 ret = bt_field_class_signed_enumeration_add_mapping(
271 out_field_class, label, range_set);
272 if (ret) {
273 goto error;
274 }
275 }
276
277 BT_COMP_LOGD("Copied content of signed enumeration field class: "
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 {
291 BT_COMP_LOGD("Copying content of real field class: "
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
298 BT_COMP_LOGD("Copied content real field class: in-fc-addr=%p, "
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;
311 int ret = 0;
312
313 BT_COMP_LOGD("Copying content of structure field class: "
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++) {
322 const bt_field_class_structure_member *member;
323 const char *member_name;
324 const bt_field_class *member_fc;
325 bt_field_class *out_member_field_class;
326
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);
332 BT_COMP_LOGD("Copying structure field class's field: "
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) {
340 BT_COMP_LOGE("Cannot copy structure field class's field: "
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
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) {
356 BT_COMP_LOGE("Cannot append structure field class's field: "
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
366 BT_COMP_LOGD("Copied structure field class: original-fc-addr=%p, copy-fc-addr=%p",
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 {
379 bt_field_class *out_tag_field_class = NULL;
380 uint64_t i, variant_option_count;
381 bt_field_class_type fc_type = bt_field_class_get_type(in_field_class);
382 int ret = 0;
383
384 BT_COMP_LOGD("Copying content of variant field class: "
385 "in-fc-addr=%p, out-fc-addr=%p",
386 in_field_class, out_field_class);
387 variant_option_count =
388 bt_field_class_variant_get_option_count(in_field_class);
389 for (i = 0; i < variant_option_count; i++) {
390 const bt_field_class *option_fc;
391 const char *option_name;
392 bt_field_class *out_option_field_class;
393 const bt_field_class_variant_option *option;
394
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);
400 out_option_field_class = create_field_class_copy_internal(
401 md_maps, option_fc);
402 if (!out_option_field_class) {
403 BT_COMP_LOGE_STR("Cannot copy field class.");
404 ret = -1;
405 goto error;
406 }
407 ret = copy_field_class_content_internal(md_maps, option_fc,
408 out_option_field_class);
409 if (ret) {
410 BT_COMP_LOGE_STR("Error copying content of option variant "
411 "field class'");
412 goto error;
413 }
414
415 if (fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR) {
416 const bt_field_class_variant_with_unsigned_selector_option *spec_opt =
417 bt_field_class_variant_with_unsigned_selector_borrow_option_by_index_const(
418 in_field_class, i);
419 const bt_integer_range_set_unsigned *ranges =
420 bt_field_class_variant_with_unsigned_selector_option_borrow_ranges_const(
421 spec_opt);
422
423 if (bt_field_class_variant_with_unsigned_selector_append_option(
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) {
433 const bt_field_class_variant_with_signed_selector_option *spec_opt =
434 bt_field_class_variant_with_signed_selector_borrow_option_by_index_const(
435 in_field_class, i);
436 const bt_integer_range_set_signed *ranges =
437 bt_field_class_variant_with_signed_selector_option_borrow_ranges_const(
438 spec_opt);
439
440 if (bt_field_class_variant_with_signed_selector_append_option(
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 }
461 }
462 }
463
464 BT_COMP_LOGD("Copied content of variant field class: in-fc-addr=%p, "
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 {
477 BT_COMP_LOGD("Copying content of static array field class: in-fc-addr=%p, "
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 */
483 BT_COMP_LOGD("Copied content of static array field class: in-fc-addr=%p, "
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 {
495 const bt_field_class *len_fc;
496 const bt_field_path *len_fp;
497 bt_field_class *out_len_field_class;
498 int ret = 0;
499
500 BT_COMP_LOGD("Copying content of dynamic array field class: "
501 "in-fc-addr=%p, out-fc-addr=%p",
502 in_field_class, out_field_class);
503
504 len_fp = bt_field_class_dynamic_array_borrow_length_field_path_const(
505 in_field_class);
506
507 if (len_fp) {
508 BT_COMP_LOGD("Copying dynamic array length field class using "
509 "field path: in-len-fp=%p", len_fp);
510 len_fc = resolve_field_path_to_field_class(
511 len_fp, md_maps);
512 out_len_field_class = g_hash_table_lookup(
513 md_maps->field_class_map, len_fc);
514 if (!out_len_field_class) {
515 BT_COMP_LOGE_STR("Cannot find the output matching length"
516 "field class.");
517 ret = -1;
518 goto error;
519 }
520
521 if (bt_field_class_dynamic_array_set_length_field_class(
522 out_field_class, out_len_field_class) !=
523 BT_FIELD_CLASS_DYNAMIC_ARRAY_SET_LENGTH_FIELD_CLASS_STATUS_OK) {
524 BT_COMP_LOGE_STR("Cannot set dynamic array field class' "
525 "length field class.");
526 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_len_field_class);
527 ret = -1;
528 goto error;
529 }
530 }
531
532 BT_COMP_LOGD("Copied dynamic array field class: in-fc-addr=%p, "
533 "out-fc-addr=%p", in_field_class, out_field_class);
534
535 error:
536 return ret;
537 }
538
539 static inline
540 int field_class_string_copy(struct trace_ir_metadata_maps *md_maps,
541 const bt_field_class *in_field_class,
542 bt_field_class *out_field_class)
543 {
544 BT_COMP_LOGD("Copying content of string field class: in-fc-addr=%p, "
545 "out-fc-addr=%p", in_field_class, out_field_class);
546 /*
547 * There is no content to copy. Keep this function call anyway for
548 * logging purposes.
549 */
550 BT_COMP_LOGD("Copied content of string field class: in-fc-addr=%p, "
551 "out-fc-addr=%p", in_field_class, out_field_class);
552
553 return 0;
554 }
555
556 static
557 bt_field_class *copy_field_class_array_element(struct trace_ir_metadata_maps *md_maps,
558 const bt_field_class *in_elem_fc)
559 {
560 int ret;
561 bt_field_class *out_elem_fc =
562 create_field_class_copy_internal(md_maps, in_elem_fc);
563 if (!out_elem_fc) {
564 BT_COMP_LOGE("Error creating output elem field class "
565 "from input elem field class for static array: "
566 "in-fc-addr=%p", in_elem_fc);
567 goto error;
568 }
569
570 ret = copy_field_class_content_internal(md_maps, in_elem_fc, out_elem_fc);
571 if (ret) {
572 BT_COMP_LOGE("Error creating output elem field class "
573 "from input elem field class for static array: "
574 "in-fc-addr=%p", in_elem_fc);
575 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_elem_fc);
576 goto error;
577 }
578
579 error:
580 return out_elem_fc;
581 }
582
583 BT_HIDDEN
584 bt_field_class *create_field_class_copy_internal(struct trace_ir_metadata_maps *md_maps,
585 const bt_field_class *in_field_class)
586 {
587 bt_field_class *out_field_class = NULL;
588 bt_field_class_type fc_type = bt_field_class_get_type(in_field_class);
589
590 BT_COMP_LOGD("Creating bare field class based on field class: in-fc-addr=%p",
591 in_field_class);
592
593 switch (fc_type) {
594 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER:
595 out_field_class = bt_field_class_unsigned_integer_create(
596 md_maps->output_trace_class);
597 break;
598 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER:
599 out_field_class = bt_field_class_signed_integer_create(
600 md_maps->output_trace_class);
601 break;
602 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION:
603 out_field_class = bt_field_class_unsigned_enumeration_create(
604 md_maps->output_trace_class);
605 break;
606 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
607 out_field_class = bt_field_class_signed_enumeration_create(
608 md_maps->output_trace_class);
609 break;
610 case BT_FIELD_CLASS_TYPE_REAL:
611 out_field_class = bt_field_class_real_create(
612 md_maps->output_trace_class);
613 break;
614 case BT_FIELD_CLASS_TYPE_STRING:
615 out_field_class = bt_field_class_string_create(
616 md_maps->output_trace_class);
617 break;
618 case BT_FIELD_CLASS_TYPE_STRUCTURE:
619 out_field_class = bt_field_class_structure_create(
620 md_maps->output_trace_class);
621 break;
622 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
623 {
624 const bt_field_class *in_elem_fc =
625 bt_field_class_array_borrow_element_field_class_const(
626 in_field_class);
627 uint64_t array_len =
628 bt_field_class_static_array_get_length(in_field_class);
629
630 bt_field_class *out_elem_fc = copy_field_class_array_element(
631 md_maps, in_elem_fc);
632 if (!out_elem_fc) {
633 out_field_class = NULL;
634 goto error;
635 }
636
637 out_field_class = bt_field_class_static_array_create(
638 md_maps->output_trace_class,
639 out_elem_fc, array_len);
640 break;
641 }
642 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY:
643 {
644 const bt_field_class *in_elem_fc =
645 bt_field_class_array_borrow_element_field_class_const(
646 in_field_class);
647
648 bt_field_class *out_elem_fc = copy_field_class_array_element(
649 md_maps, in_elem_fc);
650 if (!out_elem_fc) {
651 out_field_class = NULL;
652 goto error;
653 }
654
655 out_field_class = bt_field_class_dynamic_array_create(
656 md_maps->output_trace_class,
657 out_elem_fc);
658 break;
659 }
660 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR:
661 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR:
662 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR:
663 {
664 bt_field_class *out_sel_fc = NULL;
665
666 if (fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR ||
667 fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR) {
668 const bt_field_class *in_sel_fc;
669 const bt_field_path *sel_fp =
670 bt_field_class_variant_with_selector_borrow_selector_field_path_const(
671 in_field_class);
672
673 BT_ASSERT(sel_fp);
674 in_sel_fc = resolve_field_path_to_field_class(sel_fp,
675 md_maps);
676 BT_ASSERT(in_sel_fc);
677 out_sel_fc = g_hash_table_lookup(
678 md_maps->field_class_map, in_sel_fc);
679 BT_ASSERT(out_sel_fc);
680 }
681
682 out_field_class = bt_field_class_variant_create(
683 md_maps->output_trace_class, out_sel_fc);
684 break;
685 }
686 default:
687 abort();
688 }
689
690 /*
691 * Add mapping from in_field_class to out_field_class. This simplifies
692 * the resolution of field paths in variant and dynamic array field
693 * classes.
694 */
695 g_hash_table_insert(md_maps->field_class_map,
696 (gpointer) in_field_class, out_field_class);
697
698 error:
699 if(out_field_class){
700 BT_COMP_LOGD("Created bare field class based on field class: in-fc-addr=%p, "
701 "out-fc-addr=%p", in_field_class, out_field_class);
702 } else {
703 BT_COMP_LOGE("Error creating output field class from input field "
704 "class: in-fc-addr=%p", in_field_class);
705 }
706
707 return out_field_class;
708 }
709
710 BT_HIDDEN
711 int copy_field_class_content_internal(
712 struct trace_ir_metadata_maps *md_maps,
713 const bt_field_class *in_field_class,
714 bt_field_class *out_field_class)
715 {
716 int ret = 0;
717 switch(bt_field_class_get_type(in_field_class)) {
718 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER:
719 ret = field_class_unsigned_integer_copy(md_maps,
720 in_field_class, out_field_class);
721 break;
722 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER:
723 ret = field_class_signed_integer_copy(md_maps,
724 in_field_class, out_field_class);
725 break;
726 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION:
727 ret = field_class_unsigned_enumeration_copy(md_maps,
728 in_field_class, out_field_class);
729 break;
730 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
731 ret = field_class_signed_enumeration_copy(md_maps,
732 in_field_class, out_field_class);
733 break;
734 case BT_FIELD_CLASS_TYPE_REAL:
735 ret = field_class_real_copy(md_maps,
736 in_field_class, out_field_class);
737 break;
738 case BT_FIELD_CLASS_TYPE_STRING:
739 ret = field_class_string_copy(md_maps,
740 in_field_class, out_field_class);
741 break;
742 case BT_FIELD_CLASS_TYPE_STRUCTURE:
743 ret = field_class_structure_copy(md_maps,
744 in_field_class, out_field_class);
745 break;
746 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
747 ret = field_class_static_array_copy(md_maps,
748 in_field_class, out_field_class);
749 break;
750 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY:
751 ret = field_class_dynamic_array_copy(md_maps,
752 in_field_class, out_field_class);
753 break;
754 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR:
755 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR:
756 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR:
757 ret = field_class_variant_copy(md_maps,
758 in_field_class, out_field_class);
759 break;
760 default:
761 abort();
762 }
763
764 return ret;
765 }
This page took 0.05396 seconds and 4 git commands to generate.