Commit | Line | Data |
---|---|---|
ca9f27f3 FD |
1 | /* |
2 | * Babeltrace - Trace IR data object copy | |
3 | * | |
4 | * Copyright (c) 2015-2019 EfficiOS Inc. and Linux Foundation | |
5 | * Copyright (c) 2019 Francis Deslauriers <francis.deslauriers@efficios.com> | |
6 | * | |
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
8 | * of this software and associated documentation files (the "Software"), to deal | |
9 | * in the Software without restriction, including without limitation the rights | |
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
11 | * copies of the Software, and to permit persons to whom the Software is | |
12 | * furnished to do so, subject to the following conditions: | |
13 | * | |
14 | * The above copyright notice and this permission notice shall be included in | |
15 | * all copies or substantial portions of the Software. | |
16 | * | |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
23 | * SOFTWARE. | |
24 | */ | |
25 | ||
91bc8451 | 26 | #define BT_COMP_LOG_SELF_COMP self_comp |
3a3d15f3 | 27 | #define BT_LOG_OUTPUT_LEVEL log_level |
350ad6c1 | 28 | #define BT_LOG_TAG "PLUGIN/FLT.LTTNG-UTILS.DEBUG-INFO/TRACE-IR-DATA-COPY" |
d9c39b0a | 29 | #include "logging/comp-logging.h" |
ca9f27f3 FD |
30 | |
31 | #include <inttypes.h> | |
32 | #include <stdint.h> | |
33 | ||
578e048b | 34 | #include "common/assert.h" |
ca9f27f3 FD |
35 | |
36 | #include "trace-ir-data-copy.h" | |
37 | ||
38 | BT_HIDDEN | |
3b34b490 FD |
39 | enum debug_info_trace_ir_mapping_status copy_trace_content( |
40 | const bt_trace *in_trace, bt_trace *out_trace, | |
91bc8451 | 41 | bt_logging_level log_level, bt_self_component *self_comp) |
ca9f27f3 | 42 | { |
3b34b490 | 43 | enum debug_info_trace_ir_mapping_status status; |
ca9f27f3 | 44 | const char *trace_name; |
335a2da5 | 45 | uint64_t i, env_field_count; |
ca9f27f3 | 46 | |
91bc8451 | 47 | BT_COMP_LOGD("Copying content of trace: in-t-addr=%p, out-t-addr=%p", |
ca9f27f3 | 48 | in_trace, out_trace); |
3b34b490 | 49 | |
ca9f27f3 | 50 | trace_name = bt_trace_get_name(in_trace); |
3b34b490 | 51 | |
ca9f27f3 FD |
52 | /* Copy the trace name. */ |
53 | if (trace_name) { | |
3b34b490 FD |
54 | bt_trace_set_name_status set_name_status = |
55 | bt_trace_set_name(out_trace, trace_name); | |
56 | if (set_name_status != BT_TRACE_SET_NAME_STATUS_OK) { | |
57 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot set trace's name: " | |
58 | "out-t-addr=%p, name=\"%s\"", out_trace, | |
59 | trace_name); | |
60 | status = (int) set_name_status; | |
ca9f27f3 FD |
61 | goto end; |
62 | } | |
63 | } | |
64 | ||
ce45f74a PP |
65 | /* |
66 | * Safe to use the same value object because it's frozen at this | |
67 | * point. | |
68 | */ | |
69 | bt_trace_set_user_attributes(out_trace, | |
70 | bt_trace_borrow_user_attributes_const(in_trace)); | |
71 | ||
335a2da5 | 72 | /* |
3b34b490 | 73 | * Do not copy the trace UUID as the trace may be modified and should |
335a2da5 PP |
74 | * no longer have the same UUID. |
75 | */ | |
76 | ||
77 | /* | |
78 | * Go over all the entries in the environment section of the | |
79 | * trace and copy the content to the new trace. | |
80 | */ | |
81 | env_field_count = bt_trace_get_environment_entry_count(in_trace); | |
82 | for (i = 0; i < env_field_count; i++) { | |
83 | const char *value_name; | |
84 | const bt_value *value = NULL; | |
85 | bt_trace_set_environment_entry_status set_env_status; | |
86 | ||
87 | bt_trace_borrow_environment_entry_by_index_const( | |
88 | in_trace, i, &value_name, &value); | |
89 | ||
90 | BT_COMP_LOGD("Copying trace environnement entry: " | |
3b34b490 | 91 | "index=%" PRId64 ", value-addr=%p, value-name=\"%s\"", |
335a2da5 PP |
92 | i, value, value_name); |
93 | ||
94 | BT_ASSERT(value_name); | |
95 | BT_ASSERT(value); | |
96 | ||
97 | if (bt_value_is_signed_integer(value)) { | |
bc463d34 FD |
98 | set_env_status = bt_trace_set_environment_entry_integer( |
99 | out_trace, value_name, | |
100 | bt_value_integer_signed_get( value)); | |
335a2da5 | 101 | } else if (bt_value_is_string(value)) { |
bc463d34 FD |
102 | set_env_status = bt_trace_set_environment_entry_string( |
103 | out_trace, value_name, | |
104 | bt_value_string_get(value)); | |
335a2da5 PP |
105 | } else { |
106 | abort(); | |
107 | } | |
108 | ||
bc463d34 | 109 | if (set_env_status != BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_OK) { |
3b34b490 FD |
110 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot copy trace's environment: " |
111 | "out-t-addr=%p, name=\"%s\"", | |
335a2da5 | 112 | out_trace, trace_name); |
3b34b490 | 113 | status = (int) set_env_status; |
335a2da5 PP |
114 | goto end; |
115 | } | |
116 | } | |
117 | ||
91bc8451 | 118 | BT_COMP_LOGD("Copied content of trace: in-t-addr=%p, out-t-addr=%p", |
3b34b490 FD |
119 | in_trace, out_trace); |
120 | ||
121 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; | |
ca9f27f3 | 122 | end: |
3b34b490 | 123 | return status; |
ca9f27f3 FD |
124 | } |
125 | ||
126 | BT_HIDDEN | |
3b34b490 FD |
127 | enum debug_info_trace_ir_mapping_status copy_stream_content( |
128 | const bt_stream *in_stream, bt_stream *out_stream, | |
91bc8451 | 129 | bt_logging_level log_level, bt_self_component *self_comp) |
ca9f27f3 | 130 | { |
3b34b490 | 131 | enum debug_info_trace_ir_mapping_status status; |
ca9f27f3 | 132 | const char *stream_name; |
ca9f27f3 | 133 | |
91bc8451 | 134 | BT_COMP_LOGD("Copying content of stream: in-s-addr=%p, out-s-addr=%p", |
ca9f27f3 FD |
135 | in_stream, out_stream); |
136 | ||
ca9f27f3 | 137 | stream_name = bt_stream_get_name(in_stream); |
3b34b490 | 138 | |
ca9f27f3 | 139 | if (stream_name) { |
3b34b490 FD |
140 | bt_stream_set_name_status set_name_status = |
141 | bt_stream_set_name(out_stream, stream_name); | |
142 | if (set_name_status != BT_STREAM_SET_NAME_STATUS_OK) { | |
143 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot set stream's name: " | |
144 | "stream-addr=%p, name=\"%s\"", out_stream, | |
145 | stream_name); | |
146 | status = (int) set_name_status; | |
ca9f27f3 FD |
147 | goto end; |
148 | } | |
149 | } | |
150 | ||
ce45f74a PP |
151 | /* |
152 | * Safe to use the same value object because it's frozen at this | |
153 | * point. | |
154 | */ | |
155 | bt_stream_set_user_attributes(out_stream, | |
156 | bt_stream_borrow_user_attributes_const(in_stream)); | |
3b34b490 | 157 | |
91bc8451 | 158 | BT_COMP_LOGD("Copied content of stream: in-s-addr=%p, out-s-addr=%p", |
3b34b490 FD |
159 | in_stream, out_stream); |
160 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; | |
ca9f27f3 | 161 | end: |
3b34b490 | 162 | return status; |
ca9f27f3 FD |
163 | } |
164 | ||
165 | BT_HIDDEN | |
3b34b490 FD |
166 | enum debug_info_trace_ir_mapping_status copy_packet_content( |
167 | const bt_packet *in_packet, bt_packet *out_packet, | |
91bc8451 | 168 | bt_logging_level log_level, bt_self_component *self_comp) |
ca9f27f3 | 169 | { |
3b34b490 | 170 | enum debug_info_trace_ir_mapping_status status; |
ca9f27f3 FD |
171 | const bt_field *in_context_field; |
172 | bt_field *out_context_field; | |
173 | ||
91bc8451 | 174 | BT_COMP_LOGD("Copying content of packet: in-p-addr=%p, out-p-addr=%p", |
ca9f27f3 FD |
175 | in_packet, out_packet); |
176 | ||
177 | /* Copy context field. */ | |
178 | in_context_field = bt_packet_borrow_context_field_const(in_packet); | |
179 | if (in_context_field) { | |
180 | out_context_field = bt_packet_borrow_context_field(out_packet); | |
181 | BT_ASSERT(out_context_field); | |
3b34b490 | 182 | status = copy_field_content(in_context_field, out_context_field, |
91bc8451 | 183 | log_level, self_comp); |
3b34b490 FD |
184 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
185 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot copy context field: " | |
186 | "in-ctx-f-addr=%p, out-ctx-f-addr=%p", | |
187 | in_context_field, out_context_field); | |
188 | goto end; | |
189 | } | |
ca9f27f3 FD |
190 | } |
191 | ||
91bc8451 | 192 | BT_COMP_LOGD("Copied content of packet: in-p-addr=%p, out-p-addr=%p", |
ca9f27f3 | 193 | in_packet, out_packet); |
3b34b490 FD |
194 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; |
195 | end: | |
196 | return status; | |
ca9f27f3 FD |
197 | } |
198 | ||
199 | BT_HIDDEN | |
3b34b490 FD |
200 | enum debug_info_trace_ir_mapping_status copy_event_content( |
201 | const bt_event *in_event, bt_event *out_event, | |
91bc8451 | 202 | bt_logging_level log_level, bt_self_component *self_comp) |
ca9f27f3 | 203 | { |
3b34b490 | 204 | enum debug_info_trace_ir_mapping_status status; |
ca9f27f3 FD |
205 | const bt_field *in_common_ctx_field, *in_specific_ctx_field, |
206 | *in_payload_field; | |
207 | bt_field *out_common_ctx_field, *out_specific_ctx_field, | |
208 | *out_payload_field; | |
209 | ||
91bc8451 | 210 | BT_COMP_LOGD("Copying content of event: in-e-addr=%p, out-e-addr=%p", |
ca9f27f3 FD |
211 | in_event, out_event); |
212 | in_common_ctx_field = | |
213 | bt_event_borrow_common_context_field_const(in_event); | |
214 | if (in_common_ctx_field) { | |
215 | out_common_ctx_field = | |
216 | bt_event_borrow_common_context_field(out_event); | |
98b15851 | 217 | BT_ASSERT_DBG(out_common_ctx_field); |
3b34b490 FD |
218 | |
219 | status = copy_field_content(in_common_ctx_field, | |
91bc8451 | 220 | out_common_ctx_field, log_level, self_comp); |
3b34b490 FD |
221 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
222 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot copy common context field: " | |
223 | "in-comm-ctx-f-addr=%p, out-comm-ctx-f-addr=%p", | |
224 | in_common_ctx_field, out_common_ctx_field); | |
225 | goto end; | |
226 | } | |
ca9f27f3 FD |
227 | } |
228 | ||
229 | in_specific_ctx_field = | |
230 | bt_event_borrow_specific_context_field_const(in_event); | |
231 | if (in_specific_ctx_field) { | |
232 | out_specific_ctx_field = | |
233 | bt_event_borrow_specific_context_field(out_event); | |
98b15851 | 234 | BT_ASSERT_DBG(out_specific_ctx_field); |
3b34b490 FD |
235 | |
236 | status = copy_field_content(in_specific_ctx_field, | |
91bc8451 | 237 | out_specific_ctx_field, log_level, self_comp); |
3b34b490 FD |
238 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
239 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot copy specific context field: " | |
240 | "in-spec-ctx-f-addr=%p, out-spec-ctx-f-addr=%p", | |
241 | in_specific_ctx_field, out_specific_ctx_field); | |
242 | goto end; | |
243 | } | |
ca9f27f3 FD |
244 | } |
245 | ||
246 | in_payload_field = bt_event_borrow_payload_field_const(in_event); | |
247 | if (in_payload_field) { | |
248 | out_payload_field = bt_event_borrow_payload_field(out_event); | |
98b15851 | 249 | BT_ASSERT_DBG(out_payload_field); |
3b34b490 FD |
250 | |
251 | status = copy_field_content(in_payload_field, | |
91bc8451 | 252 | out_payload_field, log_level, self_comp); |
3b34b490 FD |
253 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
254 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot copy payloat field: " | |
255 | "in-payload-f-addr=%p, out-payload-f-addr=%p", | |
256 | in_payload_field, out_payload_field); | |
257 | goto end; | |
258 | } | |
ca9f27f3 FD |
259 | } |
260 | ||
91bc8451 | 261 | BT_COMP_LOGD("Copied content of event: in-e-addr=%p, out-e-addr=%p", |
ca9f27f3 | 262 | in_event, out_event); |
3b34b490 FD |
263 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; |
264 | end: | |
265 | return status; | |
ca9f27f3 FD |
266 | } |
267 | ||
268 | BT_HIDDEN | |
3b34b490 FD |
269 | enum debug_info_trace_ir_mapping_status copy_field_content( |
270 | const bt_field *in_field, bt_field *out_field, | |
91bc8451 | 271 | bt_logging_level log_level, bt_self_component *self_comp) |
ca9f27f3 | 272 | { |
3b34b490 | 273 | enum debug_info_trace_ir_mapping_status status; |
ca9f27f3 FD |
274 | bt_field_class_type in_fc_type, out_fc_type; |
275 | ||
276 | in_fc_type = bt_field_get_class_type(in_field); | |
277 | out_fc_type = bt_field_get_class_type(out_field); | |
98b15851 | 278 | BT_ASSERT_DBG(in_fc_type == out_fc_type); |
ca9f27f3 | 279 | |
ef267d12 | 280 | BT_COMP_LOGT("Copying content of field: in-f-addr=%p, out-f-addr=%p", |
ca9f27f3 | 281 | in_field, out_field); |
ebdb6693 PP |
282 | |
283 | if (in_fc_type == BT_FIELD_CLASS_TYPE_BOOL) { | |
f7cfbcc3 PP |
284 | bt_field_bool_set_value(out_field, |
285 | bt_field_bool_get_value(in_field)); | |
ebdb6693 | 286 | } else if (in_fc_type == BT_FIELD_CLASS_TYPE_BIT_ARRAY) { |
dc7ac074 PP |
287 | bt_field_bit_array_set_value_as_integer(out_field, |
288 | bt_field_bit_array_get_value_as_integer(in_field)); | |
ebdb6693 PP |
289 | } else if (bt_field_class_type_is(in_fc_type, |
290 | BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER)) { | |
9c08c816 | 291 | bt_field_integer_unsigned_set_value(out_field, |
3b34b490 | 292 | bt_field_integer_unsigned_get_value(in_field)); |
ebdb6693 PP |
293 | } else if (bt_field_class_type_is(in_fc_type, |
294 | BT_FIELD_CLASS_TYPE_SIGNED_INTEGER)) { | |
9c08c816 | 295 | bt_field_integer_signed_set_value(out_field, |
3b34b490 | 296 | bt_field_integer_signed_get_value(in_field)); |
ebdb6693 | 297 | } else if (in_fc_type == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL) { |
fe4df857 | 298 | bt_field_real_single_precision_set_value(out_field, |
3b34b490 | 299 | bt_field_real_single_precision_get_value(in_field)); |
ebdb6693 | 300 | } else if (in_fc_type == BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL) { |
fe4df857 | 301 | bt_field_real_double_precision_set_value(out_field, |
3b34b490 | 302 | bt_field_real_double_precision_get_value(in_field)); |
ebdb6693 | 303 | } else if (in_fc_type == BT_FIELD_CLASS_TYPE_STRING) { |
ca9f27f3 | 304 | const char *str = bt_field_string_get_value(in_field); |
3b34b490 | 305 | bt_field_string_set_value_status set_value_status = |
d24d5663 | 306 | bt_field_string_set_value(out_field, str); |
3b34b490 FD |
307 | if (set_value_status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) { |
308 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot set string field's value: " | |
309 | "out-str-f-addr=%p, str=\"%s\"" PRId64, | |
ca9f27f3 | 310 | out_field, str); |
3b34b490 FD |
311 | status = (int) set_value_status; |
312 | goto end; | |
ca9f27f3 | 313 | } |
ebdb6693 | 314 | } else if (in_fc_type == BT_FIELD_CLASS_TYPE_STRUCTURE) { |
ca9f27f3 FD |
315 | uint64_t i, nb_member_struct; |
316 | const bt_field *in_member_field; | |
317 | bt_field *out_member_field; | |
1e6fd1d7 | 318 | const bt_field_class *in_field_class; |
ca9f27f3 FD |
319 | const char *in_member_name; |
320 | ||
321 | in_field_class = bt_field_borrow_class_const(in_field); | |
322 | nb_member_struct = bt_field_class_structure_get_member_count( | |
3b34b490 | 323 | in_field_class); |
ca9f27f3 FD |
324 | |
325 | /* | |
326 | * Iterate over the fields by names in the input field to avoid | |
327 | * problem if the struct fields are not in the same order after | |
328 | * the debug-info was added. | |
329 | */ | |
330 | for (i = 0; i < nb_member_struct; i++) { | |
1e6fd1d7 PP |
331 | const bt_field_class_structure_member *member = |
332 | bt_field_class_structure_borrow_member_by_index_const( | |
333 | in_field_class, i); | |
ca9f27f3 | 334 | |
1e6fd1d7 PP |
335 | in_member_name = |
336 | bt_field_class_structure_member_get_name( | |
337 | member); | |
ca9f27f3 FD |
338 | in_member_field = |
339 | bt_field_structure_borrow_member_field_by_name_const( | |
bc463d34 | 340 | in_field, in_member_name); |
ca9f27f3 FD |
341 | out_member_field = |
342 | bt_field_structure_borrow_member_field_by_name( | |
bc463d34 | 343 | out_field, in_member_name); |
ca9f27f3 | 344 | |
3b34b490 | 345 | status = copy_field_content(in_member_field, |
91bc8451 | 346 | out_member_field, log_level, self_comp); |
3b34b490 FD |
347 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
348 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, | |
349 | "Cannot copy struct member field: " | |
350 | "out-struct-f-addr=%p, " | |
351 | "out-struct-member-f-addr=%p, " | |
352 | "member-name=\"%s\"", | |
353 | out_field, out_member_field, | |
354 | in_member_name); | |
355 | goto end; | |
356 | } | |
ca9f27f3 | 357 | } |
ebdb6693 PP |
358 | } else if (bt_field_class_type_is(in_fc_type, |
359 | BT_FIELD_CLASS_TYPE_ARRAY)) { | |
ca9f27f3 FD |
360 | const bt_field *in_element_field; |
361 | bt_field *out_element_field; | |
362 | uint64_t i, array_len; | |
9c08c816 | 363 | bt_field_array_dynamic_set_length_status set_len_status; |
ca9f27f3 FD |
364 | |
365 | array_len = bt_field_array_get_length(in_field); | |
366 | ||
ebdb6693 PP |
367 | if (bt_field_class_type_is(in_fc_type, |
368 | BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY)) { | |
9c08c816 | 369 | set_len_status = bt_field_array_dynamic_set_length( |
d24d5663 PP |
370 | out_field, array_len); |
371 | if (set_len_status != | |
372 | BT_FIELD_DYNAMIC_ARRAY_SET_LENGTH_STATUS_OK) { | |
3b34b490 FD |
373 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
374 | "Cannot set dynamic array field's length field: " | |
375 | "out-arr-f-addr=%p, arr-length=%" PRIu64, | |
376 | out_field, array_len); | |
377 | status = (int) set_len_status; | |
378 | goto end; | |
ca9f27f3 FD |
379 | } |
380 | } | |
381 | ||
382 | for (i = 0; i < array_len; i++) { | |
383 | in_element_field = | |
384 | bt_field_array_borrow_element_field_by_index_const( | |
d24d5663 | 385 | in_field, i); |
ca9f27f3 FD |
386 | out_element_field = |
387 | bt_field_array_borrow_element_field_by_index( | |
d24d5663 | 388 | out_field, i); |
3b34b490 FD |
389 | status = copy_field_content(in_element_field, |
390 | out_element_field, log_level, self_comp); | |
391 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { | |
392 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, | |
393 | "Cannot copy element field: " | |
394 | "out-arr-f-addr=%p, out-arr-elem-f-addr=%p", | |
395 | out_field, out_element_field); | |
396 | goto end; | |
397 | } | |
ca9f27f3 | 398 | } |
ebdb6693 PP |
399 | } else if (bt_field_class_type_is(in_fc_type, |
400 | BT_FIELD_CLASS_TYPE_OPTION)) { | |
f29ef814 PP |
401 | const bt_field *in_option_field; |
402 | bt_field *out_option_field; | |
403 | ||
404 | in_option_field = bt_field_option_borrow_field_const(in_field); | |
405 | ||
406 | if (in_option_field) { | |
407 | bt_field_option_set_has_field(out_field, BT_TRUE); | |
408 | out_option_field = bt_field_option_borrow_field( | |
409 | out_field); | |
98b15851 | 410 | BT_ASSERT_DBG(out_option_field); |
3b34b490 | 411 | status = copy_field_content(in_option_field, out_option_field, |
f29ef814 | 412 | log_level, self_comp); |
3b34b490 FD |
413 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
414 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, | |
415 | "Cannot copy option field: " | |
416 | "out-opt-f-addr=%p, out-opt-field-f-addr=%p", | |
417 | out_field, out_option_field); | |
418 | goto end; | |
419 | } | |
f29ef814 PP |
420 | } else { |
421 | bt_field_option_set_has_field(out_field, BT_FALSE); | |
422 | } | |
ebdb6693 PP |
423 | } else if (bt_field_class_type_is(in_fc_type, |
424 | BT_FIELD_CLASS_TYPE_VARIANT)) { | |
45c51519 | 425 | bt_field_variant_select_option_field_by_index_status sel_opt_status; |
ca9f27f3 FD |
426 | uint64_t in_selected_option_idx; |
427 | const bt_field *in_option_field; | |
428 | bt_field *out_option_field; | |
429 | ||
430 | in_selected_option_idx = | |
431 | bt_field_variant_get_selected_option_field_index( | |
bc463d34 | 432 | in_field); |
45c51519 | 433 | sel_opt_status = bt_field_variant_select_option_field_by_index(out_field, |
bc463d34 | 434 | in_selected_option_idx); |
d24d5663 PP |
435 | if (sel_opt_status != |
436 | BT_FIELD_VARIANT_SELECT_OPTION_FIELD_STATUS_OK) { | |
3b34b490 FD |
437 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
438 | "Cannot select variant field's option field: " | |
439 | "out-var-f-addr=%p, opt-index=%" PRId64, | |
ca9f27f3 | 440 | out_field, in_selected_option_idx); |
3b34b490 FD |
441 | status = (int) sel_opt_status; |
442 | goto end; | |
ca9f27f3 FD |
443 | } |
444 | ||
445 | in_option_field = bt_field_variant_borrow_selected_option_field_const(in_field); | |
446 | out_option_field = bt_field_variant_borrow_selected_option_field(out_field); | |
447 | ||
3b34b490 | 448 | status = copy_field_content(in_option_field, out_option_field, |
91bc8451 | 449 | log_level, self_comp); |
3b34b490 FD |
450 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
451 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, | |
452 | "Cannot copy element field: " | |
453 | "out-var-f-addr=%p, out-opt-f-addr=%p", | |
454 | out_field, out_option_field); | |
455 | goto end; | |
456 | } | |
ebdb6693 | 457 | } else { |
ca9f27f3 FD |
458 | abort(); |
459 | } | |
ebdb6693 | 460 | |
ef267d12 | 461 | BT_COMP_LOGT("Copied content of field: in-f-addr=%p, out-f-addr=%p", |
ca9f27f3 | 462 | in_field, out_field); |
3b34b490 FD |
463 | |
464 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; | |
465 | end: | |
466 | return status; | |
ca9f27f3 | 467 | } |