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