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