| 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 "logging/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 | if (fc_type == BT_FIELD_CLASS_TYPE_STRUCTURE) { |
| 64 | const bt_field_class_structure_member *member; |
| 65 | |
| 66 | BT_ASSERT(bt_field_path_item_get_type(fp_item) == |
| 67 | BT_FIELD_PATH_ITEM_TYPE_INDEX); |
| 68 | member = bt_field_class_structure_borrow_member_by_index_const( |
| 69 | curr_fc, |
| 70 | bt_field_path_item_index_get_index(fp_item)); |
| 71 | curr_fc = bt_field_class_structure_member_borrow_field_class_const( |
| 72 | member); |
| 73 | } else if (bt_field_class_type_is(fc_type, BT_FIELD_CLASS_TYPE_OPTION)) { |
| 74 | BT_ASSERT(bt_field_path_item_get_type(fp_item) == |
| 75 | BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT); |
| 76 | curr_fc = bt_field_class_option_borrow_field_class_const( |
| 77 | curr_fc); |
| 78 | |
| 79 | } else if (bt_field_class_type_is(fc_type, BT_FIELD_CLASS_TYPE_VARIANT)) { |
| 80 | const bt_field_class_variant_option *option; |
| 81 | |
| 82 | BT_ASSERT(bt_field_path_item_get_type(fp_item) == |
| 83 | BT_FIELD_PATH_ITEM_TYPE_INDEX); |
| 84 | option = bt_field_class_variant_borrow_option_by_index_const( |
| 85 | curr_fc, |
| 86 | bt_field_path_item_index_get_index(fp_item)); |
| 87 | curr_fc = bt_field_class_variant_option_borrow_field_class_const( |
| 88 | option); |
| 89 | break; |
| 90 | } else if (bt_field_class_type_is(fc_type, BT_FIELD_CLASS_TYPE_ARRAY)) { |
| 91 | BT_ASSERT(bt_field_path_item_get_type(fp_item) == |
| 92 | BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT); |
| 93 | curr_fc = bt_field_class_array_borrow_element_field_class_const( |
| 94 | curr_fc); |
| 95 | break; |
| 96 | } else { |
| 97 | abort(); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | return curr_fc; |
| 102 | } |
| 103 | |
| 104 | static |
| 105 | const bt_field_class *resolve_field_path_to_field_class(const bt_field_path *fp, |
| 106 | struct trace_ir_metadata_maps *md_maps) |
| 107 | { |
| 108 | struct field_class_resolving_context *fc_resolving_ctx; |
| 109 | const bt_field_class *fc; |
| 110 | bt_field_path_scope fp_scope; |
| 111 | |
| 112 | BT_COMP_LOGD("Resolving field path: fp-addr=%p", fp); |
| 113 | |
| 114 | fc_resolving_ctx = md_maps->fc_resolving_ctx; |
| 115 | fp_scope = bt_field_path_get_root_scope(fp); |
| 116 | |
| 117 | switch (fp_scope) { |
| 118 | case BT_FIELD_PATH_SCOPE_PACKET_CONTEXT: |
| 119 | fc = walk_field_path(md_maps, fp, |
| 120 | fc_resolving_ctx->packet_context); |
| 121 | break; |
| 122 | case BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT: |
| 123 | fc = walk_field_path(md_maps, fp, |
| 124 | fc_resolving_ctx->event_common_context); |
| 125 | break; |
| 126 | case BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT: |
| 127 | fc = walk_field_path(md_maps, fp, |
| 128 | fc_resolving_ctx->event_specific_context); |
| 129 | break; |
| 130 | case BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD: |
| 131 | fc = walk_field_path(md_maps, fp, |
| 132 | fc_resolving_ctx->event_payload); |
| 133 | break; |
| 134 | default: |
| 135 | abort(); |
| 136 | } |
| 137 | |
| 138 | return fc; |
| 139 | } |
| 140 | |
| 141 | static inline |
| 142 | void field_class_integer_set_props(const bt_field_class *input_fc, |
| 143 | bt_field_class *output_fc) |
| 144 | { |
| 145 | bt_field_class_integer_set_preferred_display_base(output_fc, |
| 146 | bt_field_class_integer_get_preferred_display_base(input_fc)); |
| 147 | bt_field_class_integer_set_field_value_range(output_fc, |
| 148 | bt_field_class_integer_get_field_value_range(input_fc)); |
| 149 | } |
| 150 | |
| 151 | static inline |
| 152 | enum debug_info_trace_ir_mapping_status field_class_bool_copy( |
| 153 | struct trace_ir_metadata_maps *md_maps, |
| 154 | const bt_field_class *in_field_class, |
| 155 | bt_field_class *out_field_class) |
| 156 | { |
| 157 | BT_COMP_LOGD("Copying content of boolean field class: " |
| 158 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 159 | /* |
| 160 | * There is no content to copy. Keep this function call anyway for |
| 161 | * logging purposes. |
| 162 | */ |
| 163 | BT_COMP_LOGD("Copied content of boolean field class: " |
| 164 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 165 | return DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; |
| 166 | } |
| 167 | |
| 168 | static inline |
| 169 | enum debug_info_trace_ir_mapping_status field_class_bit_array_copy( |
| 170 | struct trace_ir_metadata_maps *md_maps, |
| 171 | const bt_field_class *in_field_class, |
| 172 | bt_field_class *out_field_class) |
| 173 | { |
| 174 | BT_COMP_LOGD("Copying content of bit array field class: " |
| 175 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 176 | /* |
| 177 | * There is no content to copy. Keep this function call anyway for |
| 178 | * logging purposes. |
| 179 | */ |
| 180 | BT_COMP_LOGD("Copied content of bit array field class: " |
| 181 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 182 | return DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; |
| 183 | } |
| 184 | |
| 185 | static inline |
| 186 | enum debug_info_trace_ir_mapping_status field_class_unsigned_integer_copy( |
| 187 | struct trace_ir_metadata_maps *md_maps, |
| 188 | const bt_field_class *in_field_class, |
| 189 | bt_field_class *out_field_class) |
| 190 | { |
| 191 | BT_COMP_LOGD("Copying content of unsigned integer field class: " |
| 192 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 193 | |
| 194 | field_class_integer_set_props(in_field_class, out_field_class); |
| 195 | |
| 196 | BT_COMP_LOGD("Copied content of unsigned integer field class: " |
| 197 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 198 | return DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; |
| 199 | } |
| 200 | |
| 201 | static inline |
| 202 | enum debug_info_trace_ir_mapping_status field_class_signed_integer_copy( |
| 203 | struct trace_ir_metadata_maps *md_maps, |
| 204 | const bt_field_class *in_field_class, |
| 205 | bt_field_class *out_field_class) |
| 206 | { |
| 207 | BT_COMP_LOGD("Copying content of signed integer field class: " |
| 208 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 209 | |
| 210 | field_class_integer_set_props(in_field_class, out_field_class); |
| 211 | |
| 212 | BT_COMP_LOGD("Copied content of signed integer field class: " |
| 213 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 214 | return DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; |
| 215 | } |
| 216 | |
| 217 | BT_HIDDEN |
| 218 | enum debug_info_trace_ir_mapping_status field_class_unsigned_enumeration_copy( |
| 219 | struct trace_ir_metadata_maps *md_maps, |
| 220 | const bt_field_class *in_field_class, |
| 221 | bt_field_class *out_field_class) |
| 222 | { |
| 223 | enum debug_info_trace_ir_mapping_status status; |
| 224 | uint64_t i, enum_mapping_count; |
| 225 | |
| 226 | BT_COMP_LOGD("Copying content of unsigned enumeration field class: " |
| 227 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 228 | |
| 229 | /* Copy properties of the inner integer. */ |
| 230 | field_class_integer_set_props(in_field_class, out_field_class); |
| 231 | |
| 232 | /* Copy all enumeration entries. */ |
| 233 | enum_mapping_count = bt_field_class_enumeration_get_mapping_count( |
| 234 | in_field_class); |
| 235 | for (i = 0; i < enum_mapping_count; i++) { |
| 236 | const char *label; |
| 237 | const bt_integer_range_set_unsigned *range_set; |
| 238 | const bt_field_class_enumeration_unsigned_mapping *u_mapping; |
| 239 | const bt_field_class_enumeration_mapping *mapping; |
| 240 | enum bt_field_class_enumeration_add_mapping_status add_mapping_status; |
| 241 | |
| 242 | u_mapping = bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const( |
| 243 | in_field_class, i); |
| 244 | mapping = bt_field_class_enumeration_unsigned_mapping_as_mapping_const( |
| 245 | u_mapping); |
| 246 | label = bt_field_class_enumeration_mapping_get_label(mapping); |
| 247 | range_set = bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const( |
| 248 | u_mapping); |
| 249 | add_mapping_status = bt_field_class_enumeration_unsigned_add_mapping( |
| 250 | out_field_class, label, range_set); |
| 251 | if (add_mapping_status != BT_FIELD_CLASS_ENUMERATION_ADD_MAPPING_STATUS_OK) { |
| 252 | status = (int) add_mapping_status; |
| 253 | goto end; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | BT_COMP_LOGD("Copied content of unsigned enumeration field class: " |
| 258 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 259 | |
| 260 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; |
| 261 | end: |
| 262 | return status; |
| 263 | } |
| 264 | |
| 265 | static inline |
| 266 | enum debug_info_trace_ir_mapping_status field_class_signed_enumeration_copy( |
| 267 | struct trace_ir_metadata_maps *md_maps, |
| 268 | const bt_field_class *in_field_class, |
| 269 | bt_field_class *out_field_class) |
| 270 | { |
| 271 | enum debug_info_trace_ir_mapping_status status; |
| 272 | uint64_t i, enum_mapping_count; |
| 273 | |
| 274 | BT_COMP_LOGD("Copying content of signed enumeration field class: " |
| 275 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 276 | |
| 277 | /* Copy properties of the inner integer. */ |
| 278 | field_class_integer_set_props(in_field_class, out_field_class); |
| 279 | |
| 280 | /* Copy all enumeration entries. */ |
| 281 | enum_mapping_count = |
| 282 | bt_field_class_enumeration_get_mapping_count(in_field_class); |
| 283 | for (i = 0; i < enum_mapping_count; i++) { |
| 284 | const char *label; |
| 285 | const bt_integer_range_set_signed *range_set; |
| 286 | const bt_field_class_enumeration_signed_mapping *s_mapping; |
| 287 | const bt_field_class_enumeration_mapping *mapping; |
| 288 | enum bt_field_class_enumeration_add_mapping_status add_mapping_status; |
| 289 | |
| 290 | s_mapping = bt_field_class_enumeration_signed_borrow_mapping_by_index_const( |
| 291 | in_field_class, i); |
| 292 | mapping = bt_field_class_enumeration_signed_mapping_as_mapping_const( |
| 293 | s_mapping); |
| 294 | label = bt_field_class_enumeration_mapping_get_label(mapping); |
| 295 | range_set = bt_field_class_enumeration_signed_mapping_borrow_ranges_const( |
| 296 | s_mapping); |
| 297 | add_mapping_status = bt_field_class_enumeration_signed_add_mapping( |
| 298 | out_field_class, label, range_set); |
| 299 | if (add_mapping_status != BT_FIELD_CLASS_ENUMERATION_ADD_MAPPING_STATUS_OK) { |
| 300 | status = (int) add_mapping_status; |
| 301 | goto end; |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | BT_COMP_LOGD("Copied content of signed enumeration field class: " |
| 306 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 307 | |
| 308 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; |
| 309 | end: |
| 310 | return status; |
| 311 | } |
| 312 | |
| 313 | static inline |
| 314 | enum debug_info_trace_ir_mapping_status field_class_single_precision_real_copy( |
| 315 | struct trace_ir_metadata_maps *md_maps, |
| 316 | const bt_field_class *in_field_class, |
| 317 | bt_field_class *out_field_class) |
| 318 | { |
| 319 | BT_COMP_LOGD("Copying content of single-precision real field class: " |
| 320 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 321 | |
| 322 | BT_COMP_LOGD("Copied content single-precision real field class:" |
| 323 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 324 | |
| 325 | return DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; |
| 326 | } |
| 327 | |
| 328 | static inline |
| 329 | enum debug_info_trace_ir_mapping_status field_class_double_precision_real_copy( |
| 330 | struct trace_ir_metadata_maps *md_maps, |
| 331 | const bt_field_class *in_field_class, |
| 332 | bt_field_class *out_field_class) |
| 333 | { |
| 334 | BT_COMP_LOGD("Copying content of double-precision real field class: " |
| 335 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 336 | |
| 337 | BT_COMP_LOGD("Copied content double-precision real field class:" |
| 338 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 339 | |
| 340 | return DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; |
| 341 | } |
| 342 | |
| 343 | static inline |
| 344 | enum debug_info_trace_ir_mapping_status field_class_structure_copy( |
| 345 | struct trace_ir_metadata_maps *md_maps, |
| 346 | const bt_field_class *in_field_class, |
| 347 | bt_field_class *out_field_class) |
| 348 | { |
| 349 | bt_self_component *self_comp = md_maps->self_comp; |
| 350 | uint64_t i, struct_member_count; |
| 351 | enum debug_info_trace_ir_mapping_status status; |
| 352 | |
| 353 | BT_COMP_LOGD("Copying content of structure field class: " |
| 354 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 355 | /* Get the number of member in that struct. */ |
| 356 | struct_member_count = |
| 357 | bt_field_class_structure_get_member_count(in_field_class); |
| 358 | |
| 359 | /* Iterate over all the members of the struct. */ |
| 360 | for (i = 0; i < struct_member_count; i++) { |
| 361 | enum bt_field_class_structure_append_member_status append_member_status; |
| 362 | const bt_field_class_structure_member *in_member; |
| 363 | bt_field_class_structure_member *out_member; |
| 364 | const char *member_name; |
| 365 | const bt_field_class *in_member_fc; |
| 366 | bt_field_class *out_member_fc; |
| 367 | |
| 368 | in_member = bt_field_class_structure_borrow_member_by_index_const( |
| 369 | in_field_class, i); |
| 370 | in_member_fc = bt_field_class_structure_member_borrow_field_class_const( |
| 371 | in_member); |
| 372 | member_name = bt_field_class_structure_member_get_name(in_member); |
| 373 | BT_COMP_LOGD("Copying structure field class's member: " |
| 374 | "index=%" PRId64 ", member-fc-addr=%p, member-name=\"%s\"", |
| 375 | i, in_member_fc, member_name); |
| 376 | |
| 377 | out_member_fc = create_field_class_copy(md_maps, in_member_fc); |
| 378 | if (!out_member_fc) { |
| 379 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot copy structure field class's member: " |
| 380 | "index=%" PRId64 ", in-member-fc-addr=%p, " |
| 381 | "member-name=\"%s\"", i, in_member_fc, |
| 382 | member_name); |
| 383 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; |
| 384 | goto end; |
| 385 | } |
| 386 | |
| 387 | status = copy_field_class_content(md_maps, in_member_fc, |
| 388 | out_member_fc); |
| 389 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
| 390 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot copy content of structure field class's member: " |
| 391 | "index=%" PRId64 ", in-member-fc-addr=%p, " |
| 392 | "member-name=\"%s\"", i, in_member_fc, |
| 393 | member_name); |
| 394 | BT_FIELD_CLASS_PUT_REF_AND_RESET(out_member_fc); |
| 395 | goto end; |
| 396 | } |
| 397 | |
| 398 | append_member_status = bt_field_class_structure_append_member(out_field_class, |
| 399 | member_name, out_member_fc); |
| 400 | if (append_member_status != |
| 401 | BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { |
| 402 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot append structure field class's field: " |
| 403 | "index=%" PRId64 ", field-fc-addr=%p, " |
| 404 | "field-name=\"%s\"", i, in_member_fc, |
| 405 | member_name); |
| 406 | BT_FIELD_CLASS_PUT_REF_AND_RESET(out_member_fc); |
| 407 | status = (int) append_member_status; |
| 408 | goto end; |
| 409 | } |
| 410 | |
| 411 | out_member = bt_field_class_structure_borrow_member_by_index( |
| 412 | out_field_class, i); |
| 413 | BT_ASSERT(out_member); |
| 414 | |
| 415 | /* |
| 416 | * Safe to use the same value object because it's frozen |
| 417 | * at this point. |
| 418 | */ |
| 419 | bt_field_class_structure_member_set_user_attributes( |
| 420 | out_member, |
| 421 | bt_field_class_structure_member_borrow_user_attributes_const( |
| 422 | in_member)); |
| 423 | } |
| 424 | |
| 425 | BT_COMP_LOGD("Copied structure field class: original-fc-addr=%p, copy-fc-addr=%p", |
| 426 | in_field_class, out_field_class); |
| 427 | |
| 428 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; |
| 429 | end: |
| 430 | return status; |
| 431 | } |
| 432 | |
| 433 | static inline |
| 434 | enum debug_info_trace_ir_mapping_status field_class_variant_copy( |
| 435 | struct trace_ir_metadata_maps *md_maps, |
| 436 | const bt_field_class *in_field_class, |
| 437 | bt_field_class *out_field_class) |
| 438 | { |
| 439 | bt_self_component *self_comp = md_maps->self_comp; |
| 440 | enum debug_info_trace_ir_mapping_status status; |
| 441 | bt_field_class *out_tag_field_class = NULL; |
| 442 | uint64_t i, variant_option_count; |
| 443 | bt_field_class_type fc_type = bt_field_class_get_type(in_field_class); |
| 444 | |
| 445 | BT_COMP_LOGD("Copying content of variant field class: " |
| 446 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 447 | variant_option_count = |
| 448 | bt_field_class_variant_get_option_count(in_field_class); |
| 449 | for (i = 0; i < variant_option_count; i++) { |
| 450 | const bt_field_class *in_option_fc; |
| 451 | const char *option_name; |
| 452 | bt_field_class *out_option_fc; |
| 453 | const bt_field_class_variant_option *in_option; |
| 454 | bt_field_class_variant_option *out_option; |
| 455 | |
| 456 | in_option = bt_field_class_variant_borrow_option_by_index_const( |
| 457 | in_field_class, i); |
| 458 | in_option_fc = bt_field_class_variant_option_borrow_field_class_const( |
| 459 | in_option); |
| 460 | option_name = bt_field_class_variant_option_get_name(in_option); |
| 461 | |
| 462 | out_option_fc = create_field_class_copy_internal( |
| 463 | md_maps, in_option_fc); |
| 464 | if (!out_option_fc) { |
| 465 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot copy variant option field class: " |
| 466 | "in-option-fc=%p, in-option-name=\"%s\"", |
| 467 | in_option_fc, option_name); |
| 468 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; |
| 469 | goto end; |
| 470 | } |
| 471 | |
| 472 | status = copy_field_class_content_internal(md_maps, in_option_fc, |
| 473 | out_option_fc); |
| 474 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
| 475 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error copying content of variant option field class: " |
| 476 | "in-option-fc=%p, in-option-name=\"%s\"", |
| 477 | in_option_fc, option_name); |
| 478 | BT_FIELD_CLASS_PUT_REF_AND_RESET(out_option_fc); |
| 479 | goto end; |
| 480 | } |
| 481 | |
| 482 | if (fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD) { |
| 483 | const bt_field_class_variant_with_selector_field_integer_unsigned_option *spec_opt = |
| 484 | bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_index_const( |
| 485 | in_field_class, i); |
| 486 | const bt_integer_range_set_unsigned *ranges = |
| 487 | bt_field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const( |
| 488 | spec_opt); |
| 489 | enum bt_field_class_variant_with_selector_field_integer_append_option_status append_opt_status = |
| 490 | bt_field_class_variant_with_selector_field_integer_unsigned_append_option( |
| 491 | out_field_class, option_name, |
| 492 | out_option_fc, ranges); |
| 493 | |
| 494 | if (append_opt_status != |
| 495 | BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_FIELD_APPEND_OPTION_STATUS_OK) { |
| 496 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot append option to variant field class with unsigned integer selector" |
| 497 | "out-fc-addr=%p, out-option-fc-addr=%p, " |
| 498 | "out-option-name=\"%s\"", out_field_class, |
| 499 | out_option_fc, option_name); |
| 500 | BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class); |
| 501 | status = (int) append_opt_status; |
| 502 | goto end; |
| 503 | } |
| 504 | } else if (fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD) { |
| 505 | const bt_field_class_variant_with_selector_field_integer_signed_option *spec_opt = |
| 506 | bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_index_const( |
| 507 | in_field_class, i); |
| 508 | const bt_integer_range_set_signed *ranges = |
| 509 | bt_field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const( |
| 510 | spec_opt); |
| 511 | |
| 512 | enum bt_field_class_variant_with_selector_field_integer_append_option_status append_opt_status = |
| 513 | bt_field_class_variant_with_selector_field_integer_signed_append_option( |
| 514 | out_field_class, option_name, |
| 515 | out_option_fc, ranges); |
| 516 | if (append_opt_status != |
| 517 | BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_FIELD_APPEND_OPTION_STATUS_OK) { |
| 518 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot append option to variant field class with signed integer selector" |
| 519 | "out-fc-addr=%p, out-option-fc-addr=%p, " |
| 520 | "out-option-name=\"%s\"", out_field_class, |
| 521 | out_option_fc, option_name); |
| 522 | BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class); |
| 523 | status = (int) append_opt_status; |
| 524 | goto end; |
| 525 | } |
| 526 | } else { |
| 527 | BT_ASSERT(fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD); |
| 528 | |
| 529 | enum bt_field_class_variant_without_selector_append_option_status append_opt_status = |
| 530 | bt_field_class_variant_without_selector_append_option( |
| 531 | out_field_class, option_name, |
| 532 | out_option_fc); |
| 533 | if (append_opt_status != |
| 534 | BT_FIELD_CLASS_VARIANT_WITHOUT_SELECTOR_FIELD_APPEND_OPTION_STATUS_OK) { |
| 535 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot append option to variant field class" |
| 536 | "out-fc-addr=%p, out-option-fc-addr=%p, " |
| 537 | "out-option-name=\"%s\"", out_field_class, |
| 538 | out_option_fc, option_name); |
| 539 | BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class); |
| 540 | status = (int) append_opt_status; |
| 541 | goto end; |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | out_option = bt_field_class_variant_borrow_option_by_index( |
| 546 | out_field_class, i); |
| 547 | BT_ASSERT(out_option); |
| 548 | |
| 549 | /* |
| 550 | * Safe to use the same value object because it's frozen |
| 551 | * at this point. |
| 552 | */ |
| 553 | bt_field_class_variant_option_set_user_attributes( |
| 554 | out_option, |
| 555 | bt_field_class_variant_option_borrow_user_attributes_const( |
| 556 | in_option)); |
| 557 | } |
| 558 | |
| 559 | BT_COMP_LOGD("Copied content of variant field class: in-fc-addr=%p, " |
| 560 | "out-fc-addr=%p", in_field_class, out_field_class); |
| 561 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; |
| 562 | end: |
| 563 | return status; |
| 564 | } |
| 565 | |
| 566 | static inline |
| 567 | enum debug_info_trace_ir_mapping_status field_class_static_array_copy( |
| 568 | struct trace_ir_metadata_maps *md_maps, |
| 569 | const bt_field_class *in_field_class, |
| 570 | bt_field_class *out_field_class) |
| 571 | { |
| 572 | BT_COMP_LOGD("Copying content of static array field class: in-fc-addr=%p, " |
| 573 | "out-fc-addr=%p", in_field_class, out_field_class); |
| 574 | /* |
| 575 | * There is no content to copy. Keep this function call anyway for |
| 576 | * logging purposes. |
| 577 | */ |
| 578 | BT_COMP_LOGD("Copied content of static array field class: in-fc-addr=%p, " |
| 579 | "out-fc-addr=%p", in_field_class, out_field_class); |
| 580 | |
| 581 | return DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; |
| 582 | } |
| 583 | |
| 584 | static inline |
| 585 | enum debug_info_trace_ir_mapping_status field_class_dynamic_array_copy( |
| 586 | struct trace_ir_metadata_maps *md_maps, |
| 587 | const bt_field_class *in_field_class, |
| 588 | bt_field_class *out_field_class) |
| 589 | { |
| 590 | BT_COMP_LOGD("Copying content of dynamic array field class: " |
| 591 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 592 | /* |
| 593 | * There is no content to copy. Keep this function call anyway for |
| 594 | * logging purposes. |
| 595 | */ |
| 596 | BT_COMP_LOGD("Copied content of dynamic array field class: " |
| 597 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 598 | |
| 599 | return DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; |
| 600 | } |
| 601 | |
| 602 | static inline |
| 603 | enum debug_info_trace_ir_mapping_status field_class_option_copy( |
| 604 | struct trace_ir_metadata_maps *md_maps, |
| 605 | const bt_field_class *in_field_class, |
| 606 | bt_field_class *out_field_class) |
| 607 | { |
| 608 | BT_COMP_LOGD("Copying content of option field class: " |
| 609 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 610 | |
| 611 | if (bt_field_class_get_type(out_field_class) == |
| 612 | BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD) { |
| 613 | bt_field_class_option_with_selector_field_bool_set_selector_is_reversed( |
| 614 | out_field_class, |
| 615 | bt_field_class_option_with_selector_field_bool_selector_is_reversed( |
| 616 | in_field_class)); |
| 617 | } |
| 618 | |
| 619 | BT_COMP_LOGD("Copied content of option field class: " |
| 620 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 621 | |
| 622 | return DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; |
| 623 | } |
| 624 | |
| 625 | static inline |
| 626 | enum debug_info_trace_ir_mapping_status field_class_string_copy( |
| 627 | struct trace_ir_metadata_maps *md_maps, |
| 628 | const bt_field_class *in_field_class, |
| 629 | bt_field_class *out_field_class) |
| 630 | { |
| 631 | BT_COMP_LOGD("Copying content of string field class: in-fc-addr=%p, " |
| 632 | "out-fc-addr=%p", in_field_class, out_field_class); |
| 633 | /* |
| 634 | * There is no content to copy. Keep this function call anyway for |
| 635 | * logging purposes. |
| 636 | */ |
| 637 | BT_COMP_LOGD("Copied content of string field class: in-fc-addr=%p, " |
| 638 | "out-fc-addr=%p", in_field_class, out_field_class); |
| 639 | |
| 640 | return DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; |
| 641 | } |
| 642 | |
| 643 | static |
| 644 | bt_field_class *copy_field_class_array_element( |
| 645 | struct trace_ir_metadata_maps *md_maps, |
| 646 | const bt_field_class *in_elem_fc) |
| 647 | { |
| 648 | bt_self_component *self_comp = md_maps->self_comp; |
| 649 | bt_field_class *out_elem_fc = |
| 650 | create_field_class_copy_internal(md_maps, in_elem_fc); |
| 651 | if (!out_elem_fc) { |
| 652 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 653 | "Error creating output elem field class from input elem field class for static array: " |
| 654 | "in-fc-addr=%p", in_elem_fc); |
| 655 | goto end; |
| 656 | } |
| 657 | |
| 658 | if (copy_field_class_content_internal(md_maps, in_elem_fc, out_elem_fc) != |
| 659 | DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
| 660 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 661 | "Error creating output elem field class from input elem field class for static array: " |
| 662 | "in-fc-addr=%p", in_elem_fc); |
| 663 | BT_FIELD_CLASS_PUT_REF_AND_RESET(out_elem_fc); |
| 664 | goto end; |
| 665 | } |
| 666 | |
| 667 | end: |
| 668 | return out_elem_fc; |
| 669 | } |
| 670 | |
| 671 | BT_HIDDEN |
| 672 | bt_field_class *create_field_class_copy_internal( |
| 673 | struct trace_ir_metadata_maps *md_maps, |
| 674 | const bt_field_class *in_field_class) |
| 675 | { |
| 676 | bt_self_component *self_comp = md_maps->self_comp; |
| 677 | enum debug_info_trace_ir_mapping_status status; |
| 678 | bt_field_class *out_field_class = NULL; |
| 679 | bt_field_class_type fc_type = bt_field_class_get_type(in_field_class); |
| 680 | |
| 681 | BT_COMP_LOGD("Creating bare field class based on field class: in-fc-addr=%p", |
| 682 | in_field_class); |
| 683 | |
| 684 | switch (fc_type) { |
| 685 | case BT_FIELD_CLASS_TYPE_BOOL: |
| 686 | out_field_class = bt_field_class_bool_create( |
| 687 | md_maps->output_trace_class); |
| 688 | break; |
| 689 | case BT_FIELD_CLASS_TYPE_BIT_ARRAY: |
| 690 | out_field_class = bt_field_class_bit_array_create( |
| 691 | md_maps->output_trace_class, |
| 692 | bt_field_class_bit_array_get_length( |
| 693 | in_field_class)); |
| 694 | break; |
| 695 | case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER: |
| 696 | out_field_class = bt_field_class_integer_unsigned_create( |
| 697 | md_maps->output_trace_class); |
| 698 | break; |
| 699 | case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER: |
| 700 | out_field_class = bt_field_class_integer_signed_create( |
| 701 | md_maps->output_trace_class); |
| 702 | break; |
| 703 | case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: |
| 704 | out_field_class = bt_field_class_enumeration_unsigned_create( |
| 705 | md_maps->output_trace_class); |
| 706 | break; |
| 707 | case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION: |
| 708 | out_field_class = bt_field_class_enumeration_signed_create( |
| 709 | md_maps->output_trace_class); |
| 710 | break; |
| 711 | case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL: |
| 712 | out_field_class = bt_field_class_real_single_precision_create( |
| 713 | md_maps->output_trace_class); |
| 714 | break; |
| 715 | case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL: |
| 716 | out_field_class = bt_field_class_real_double_precision_create( |
| 717 | md_maps->output_trace_class); |
| 718 | break; |
| 719 | case BT_FIELD_CLASS_TYPE_STRING: |
| 720 | out_field_class = bt_field_class_string_create( |
| 721 | md_maps->output_trace_class); |
| 722 | break; |
| 723 | case BT_FIELD_CLASS_TYPE_STRUCTURE: |
| 724 | out_field_class = bt_field_class_structure_create( |
| 725 | md_maps->output_trace_class); |
| 726 | break; |
| 727 | case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: |
| 728 | { |
| 729 | const bt_field_class *in_elem_fc = |
| 730 | bt_field_class_array_borrow_element_field_class_const( |
| 731 | in_field_class); |
| 732 | uint64_t array_len = bt_field_class_array_static_get_length( |
| 733 | in_field_class); |
| 734 | |
| 735 | bt_field_class *out_elem_fc = copy_field_class_array_element( |
| 736 | md_maps, in_elem_fc); |
| 737 | if (!out_elem_fc) { |
| 738 | out_field_class = NULL; |
| 739 | goto error; |
| 740 | } |
| 741 | |
| 742 | out_field_class = bt_field_class_array_static_create( |
| 743 | md_maps->output_trace_class, |
| 744 | out_elem_fc, array_len); |
| 745 | break; |
| 746 | } |
| 747 | default: |
| 748 | break; |
| 749 | } |
| 750 | |
| 751 | if (bt_field_class_type_is(fc_type, |
| 752 | BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY)) { |
| 753 | const bt_field_class *in_elem_fc = |
| 754 | bt_field_class_array_borrow_element_field_class_const( |
| 755 | in_field_class); |
| 756 | bt_field_class *out_length_fc = NULL; |
| 757 | bt_field_class *out_elem_fc = copy_field_class_array_element( |
| 758 | md_maps, in_elem_fc); |
| 759 | |
| 760 | if (!out_elem_fc) { |
| 761 | out_field_class = NULL; |
| 762 | goto error; |
| 763 | } |
| 764 | |
| 765 | if (fc_type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD) { |
| 766 | const bt_field_path *length_fp = |
| 767 | bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const( |
| 768 | in_field_class); |
| 769 | const bt_field_class *in_length_fc = |
| 770 | resolve_field_path_to_field_class(length_fp, |
| 771 | md_maps); |
| 772 | |
| 773 | BT_ASSERT(in_length_fc); |
| 774 | out_length_fc = g_hash_table_lookup(md_maps->field_class_map, |
| 775 | in_length_fc); |
| 776 | BT_ASSERT(out_length_fc); |
| 777 | } |
| 778 | |
| 779 | out_field_class = bt_field_class_array_dynamic_create( |
| 780 | md_maps->output_trace_class, out_elem_fc, out_length_fc); |
| 781 | } else if (bt_field_class_type_is(fc_type, BT_FIELD_CLASS_TYPE_OPTION)) { |
| 782 | const bt_field_class *in_content_fc = |
| 783 | bt_field_class_option_borrow_field_class_const( |
| 784 | in_field_class); |
| 785 | bt_field_class *out_selector_fc = NULL; |
| 786 | bt_field_class *out_content_fc; |
| 787 | |
| 788 | out_content_fc = create_field_class_copy_internal( |
| 789 | md_maps, in_content_fc); |
| 790 | if (!out_content_fc) { |
| 791 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 792 | "Cannot copy option's content field class: " |
| 793 | "in-content-fc-addr=%p", in_content_fc); |
| 794 | goto error; |
| 795 | } |
| 796 | |
| 797 | status = copy_field_class_content_internal(md_maps, |
| 798 | in_content_fc, out_content_fc); |
| 799 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
| 800 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 801 | "Error copying content of option's content field class: " |
| 802 | "in-content-fc-addr=%p, out-content-fc-addr=%p", |
| 803 | in_content_fc, out_content_fc); |
| 804 | BT_FIELD_CLASS_PUT_REF_AND_RESET(out_content_fc); |
| 805 | goto error; |
| 806 | } |
| 807 | |
| 808 | if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD) { |
| 809 | out_field_class = |
| 810 | bt_field_class_option_without_selector_create( |
| 811 | md_maps->output_trace_class, |
| 812 | out_content_fc); |
| 813 | } else { |
| 814 | const bt_field_path *in_selector_fp = |
| 815 | bt_field_class_option_with_selector_field_borrow_selector_field_path_const( |
| 816 | in_field_class); |
| 817 | const bt_field_class *in_selector_fc; |
| 818 | |
| 819 | BT_ASSERT(in_selector_fp); |
| 820 | in_selector_fc = resolve_field_path_to_field_class( |
| 821 | in_selector_fp, md_maps); |
| 822 | BT_ASSERT(in_selector_fc); |
| 823 | out_selector_fc = g_hash_table_lookup( |
| 824 | md_maps->field_class_map, in_selector_fc); |
| 825 | BT_ASSERT(out_selector_fc); |
| 826 | |
| 827 | if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD) { |
| 828 | out_field_class = |
| 829 | bt_field_class_option_with_selector_field_bool_create( |
| 830 | md_maps->output_trace_class, |
| 831 | out_content_fc, out_selector_fc); |
| 832 | } else if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD) { |
| 833 | const bt_integer_range_set_unsigned *ranges = |
| 834 | bt_field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const( |
| 835 | in_field_class); |
| 836 | |
| 837 | BT_ASSERT(ranges); |
| 838 | out_field_class = |
| 839 | bt_field_class_option_with_selector_field_integer_unsigned_create( |
| 840 | md_maps->output_trace_class, |
| 841 | out_content_fc, out_selector_fc, |
| 842 | ranges); |
| 843 | } else if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD) { |
| 844 | const bt_integer_range_set_signed *ranges = |
| 845 | bt_field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const( |
| 846 | in_field_class); |
| 847 | |
| 848 | BT_ASSERT(ranges); |
| 849 | out_field_class = |
| 850 | bt_field_class_option_with_selector_field_integer_signed_create( |
| 851 | md_maps->output_trace_class, |
| 852 | out_content_fc, out_selector_fc, |
| 853 | ranges); |
| 854 | } |
| 855 | } |
| 856 | } else if (bt_field_class_type_is(fc_type, |
| 857 | BT_FIELD_CLASS_TYPE_VARIANT)) { |
| 858 | bt_field_class *out_sel_fc = NULL; |
| 859 | |
| 860 | if (bt_field_class_type_is(fc_type, |
| 861 | BT_FIELD_CLASS_TYPE_VARIANT_WITH_SELECTOR_FIELD)) { |
| 862 | const bt_field_class *in_sel_fc; |
| 863 | const bt_field_path *sel_fp = |
| 864 | bt_field_class_variant_with_selector_field_borrow_selector_field_path_const( |
| 865 | in_field_class); |
| 866 | |
| 867 | BT_ASSERT(sel_fp); |
| 868 | in_sel_fc = resolve_field_path_to_field_class(sel_fp, |
| 869 | md_maps); |
| 870 | BT_ASSERT(in_sel_fc); |
| 871 | out_sel_fc = g_hash_table_lookup( |
| 872 | md_maps->field_class_map, in_sel_fc); |
| 873 | BT_ASSERT(out_sel_fc); |
| 874 | } |
| 875 | |
| 876 | out_field_class = bt_field_class_variant_create( |
| 877 | md_maps->output_trace_class, out_sel_fc); |
| 878 | } |
| 879 | |
| 880 | /* |
| 881 | * Add mapping from in_field_class to out_field_class. This simplifies |
| 882 | * the resolution of field paths in variant and dynamic array field |
| 883 | * classes. |
| 884 | */ |
| 885 | BT_ASSERT(out_field_class); |
| 886 | g_hash_table_insert(md_maps->field_class_map, |
| 887 | (gpointer) in_field_class, out_field_class); |
| 888 | |
| 889 | error: |
| 890 | if(out_field_class){ |
| 891 | BT_COMP_LOGD("Created bare field class based on field class: in-fc-addr=%p, " |
| 892 | "out-fc-addr=%p", in_field_class, out_field_class); |
| 893 | } else { |
| 894 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 895 | "Error creating output field class from input field class: " |
| 896 | "in-fc-addr=%p", in_field_class); |
| 897 | } |
| 898 | |
| 899 | return out_field_class; |
| 900 | } |
| 901 | |
| 902 | BT_HIDDEN |
| 903 | enum debug_info_trace_ir_mapping_status copy_field_class_content_internal( |
| 904 | struct trace_ir_metadata_maps *md_maps, |
| 905 | const bt_field_class *in_field_class, |
| 906 | bt_field_class *out_field_class) |
| 907 | { |
| 908 | enum debug_info_trace_ir_mapping_status status; |
| 909 | bt_field_class_type in_fc_type = |
| 910 | bt_field_class_get_type(in_field_class); |
| 911 | |
| 912 | /* |
| 913 | * Safe to use the same value object because it's frozen at this |
| 914 | * point. |
| 915 | */ |
| 916 | bt_field_class_set_user_attributes(out_field_class, |
| 917 | bt_field_class_borrow_user_attributes_const(in_field_class)); |
| 918 | |
| 919 | if (in_fc_type == BT_FIELD_CLASS_TYPE_BOOL) { |
| 920 | status = field_class_bool_copy(md_maps, |
| 921 | in_field_class, out_field_class); |
| 922 | } else if (in_fc_type == BT_FIELD_CLASS_TYPE_BIT_ARRAY) { |
| 923 | status = field_class_bit_array_copy(md_maps, |
| 924 | in_field_class, out_field_class); |
| 925 | } else if (in_fc_type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER) { |
| 926 | status = field_class_unsigned_integer_copy(md_maps, |
| 927 | in_field_class, out_field_class); |
| 928 | } else if (in_fc_type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER) { |
| 929 | status = field_class_signed_integer_copy(md_maps, |
| 930 | in_field_class, out_field_class); |
| 931 | } else if (in_fc_type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION) { |
| 932 | status = field_class_unsigned_enumeration_copy(md_maps, |
| 933 | in_field_class, out_field_class); |
| 934 | } else if (in_fc_type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION) { |
| 935 | status = field_class_signed_enumeration_copy(md_maps, |
| 936 | in_field_class, out_field_class); |
| 937 | } else if (in_fc_type == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL) { |
| 938 | status = field_class_single_precision_real_copy(md_maps, |
| 939 | in_field_class, out_field_class); |
| 940 | } else if (in_fc_type == BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL) { |
| 941 | status = field_class_double_precision_real_copy(md_maps, |
| 942 | in_field_class, out_field_class); |
| 943 | } else if (in_fc_type == BT_FIELD_CLASS_TYPE_STRING) { |
| 944 | status = field_class_string_copy(md_maps, |
| 945 | in_field_class, out_field_class); |
| 946 | } else if (in_fc_type == BT_FIELD_CLASS_TYPE_STRUCTURE) { |
| 947 | status = field_class_structure_copy(md_maps, |
| 948 | in_field_class, out_field_class); |
| 949 | } else if (in_fc_type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY) { |
| 950 | status = field_class_static_array_copy(md_maps, |
| 951 | in_field_class, out_field_class); |
| 952 | } else if (bt_field_class_type_is(in_fc_type, |
| 953 | BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY)) { |
| 954 | status = field_class_dynamic_array_copy(md_maps, |
| 955 | in_field_class, out_field_class); |
| 956 | } else if (bt_field_class_type_is(in_fc_type, |
| 957 | BT_FIELD_CLASS_TYPE_OPTION)) { |
| 958 | status = field_class_option_copy(md_maps, |
| 959 | in_field_class, out_field_class); |
| 960 | } else if (bt_field_class_type_is(in_fc_type, |
| 961 | BT_FIELD_CLASS_TYPE_VARIANT)) { |
| 962 | status = field_class_variant_copy(md_maps, |
| 963 | in_field_class, out_field_class); |
| 964 | } else { |
| 965 | abort(); |
| 966 | } |
| 967 | |
| 968 | return status; |
| 969 | } |