| 1 | /* |
| 2 | * SPDX-License-Identifier: MIT |
| 3 | * |
| 4 | * Copyright (c) 2015 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 | * Babeltrace - Trace IR metadata object copy |
| 9 | */ |
| 10 | |
| 11 | #define BT_COMP_LOG_SELF_COMP self_comp |
| 12 | #define BT_LOG_OUTPUT_LEVEL log_level |
| 13 | #define BT_LOG_TAG "PLUGIN/FLT.LTTNG-UTILS.DEBUG-INFO/TRACE-IR-META-COPY" |
| 14 | #include "logging/comp-logging.h" |
| 15 | |
| 16 | #include <inttypes.h> |
| 17 | #include <stdint.h> |
| 18 | |
| 19 | #include "common/assert.h" |
| 20 | |
| 21 | #include "trace-ir-metadata-copy.h" |
| 22 | #include "trace-ir-metadata-field-class-copy.h" |
| 23 | #include "utils.h" |
| 24 | |
| 25 | BT_HIDDEN |
| 26 | enum debug_info_trace_ir_mapping_status copy_trace_class_content( |
| 27 | struct trace_ir_maps *ir_maps, |
| 28 | const bt_trace_class *in_trace_class, |
| 29 | bt_trace_class *out_trace_class, |
| 30 | bt_logging_level log_level, bt_self_component *self_comp) |
| 31 | { |
| 32 | enum debug_info_trace_ir_mapping_status status; |
| 33 | uint64_t sc_number, sc_idx; |
| 34 | |
| 35 | BT_COMP_LOGD("Copying content of trace class: in-tc-addr=%p, out-tc-addr=%p", |
| 36 | in_trace_class, out_trace_class); |
| 37 | |
| 38 | /* |
| 39 | * Safe to use the same value object because it's frozen at this |
| 40 | * point. |
| 41 | */ |
| 42 | bt_trace_class_set_user_attributes(out_trace_class, |
| 43 | bt_trace_class_borrow_user_attributes_const(in_trace_class)); |
| 44 | |
| 45 | /* Use the same stream class ids as in the origin trace class. */ |
| 46 | bt_trace_class_set_assigns_automatic_stream_class_id(out_trace_class, |
| 47 | BT_FALSE); |
| 48 | |
| 49 | /* Copy stream classes contained in the trace class. */ |
| 50 | sc_number = bt_trace_class_get_stream_class_count(in_trace_class); |
| 51 | for (sc_idx = 0; sc_idx < sc_number; sc_idx++) { |
| 52 | bt_stream_class *out_stream_class; |
| 53 | const bt_stream_class *in_stream_class = |
| 54 | bt_trace_class_borrow_stream_class_by_index_const( |
| 55 | in_trace_class, sc_idx); |
| 56 | |
| 57 | out_stream_class = trace_ir_mapping_borrow_mapped_stream_class( |
| 58 | ir_maps, in_stream_class); |
| 59 | if (!out_stream_class) { |
| 60 | out_stream_class = trace_ir_mapping_create_new_mapped_stream_class( |
| 61 | ir_maps, in_stream_class); |
| 62 | if (!out_stream_class) { |
| 63 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; |
| 64 | goto end; |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | BT_COMP_LOGD("Copied content of trace class: in-tc-addr=%p, out-tc-addr=%p", |
| 70 | in_trace_class, out_trace_class); |
| 71 | |
| 72 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; |
| 73 | end: |
| 74 | return status; |
| 75 | } |
| 76 | |
| 77 | static |
| 78 | enum debug_info_trace_ir_mapping_status copy_clock_class_content( |
| 79 | const bt_clock_class *in_clock_class, |
| 80 | bt_clock_class *out_clock_class, bt_logging_level log_level, |
| 81 | bt_self_component *self_comp) |
| 82 | { |
| 83 | enum debug_info_trace_ir_mapping_status status; |
| 84 | const char *clock_class_name, *clock_class_description; |
| 85 | int64_t seconds; |
| 86 | uint64_t cycles; |
| 87 | bt_uuid in_uuid; |
| 88 | |
| 89 | BT_COMP_LOGD("Copying content of clock class: in-cc-addr=%p, out-cc-addr=%p", |
| 90 | in_clock_class, out_clock_class); |
| 91 | |
| 92 | clock_class_name = bt_clock_class_get_name(in_clock_class); |
| 93 | |
| 94 | if (clock_class_name) { |
| 95 | enum bt_clock_class_set_name_status set_name_status = |
| 96 | bt_clock_class_set_name(out_clock_class, clock_class_name); |
| 97 | if (set_name_status != BT_CLOCK_CLASS_SET_NAME_STATUS_OK) { |
| 98 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 99 | "Error setting clock class' name: " |
| 100 | "cc-addr=%p, name=%s", out_clock_class, |
| 101 | clock_class_name); |
| 102 | status = (int) set_name_status; |
| 103 | goto end; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | /* |
| 108 | * Safe to use the same value object because it's frozen at this |
| 109 | * point. |
| 110 | */ |
| 111 | bt_clock_class_set_user_attributes(out_clock_class, |
| 112 | bt_clock_class_borrow_user_attributes_const(in_clock_class)); |
| 113 | |
| 114 | clock_class_description = bt_clock_class_get_description(in_clock_class); |
| 115 | |
| 116 | if (clock_class_description) { |
| 117 | enum bt_clock_class_set_description_status set_desc_status = |
| 118 | bt_clock_class_set_description(out_clock_class, clock_class_description); |
| 119 | if (set_desc_status!= BT_CLOCK_CLASS_SET_DESCRIPTION_STATUS_OK) { |
| 120 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 121 | "Error setting clock class' description: " |
| 122 | "cc-addr=%p, cc-desc=%s", out_clock_class, |
| 123 | clock_class_description); |
| 124 | status = (int) set_desc_status; |
| 125 | goto end; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | in_uuid = bt_clock_class_get_uuid(in_clock_class); |
| 130 | if (in_uuid) { |
| 131 | bt_clock_class_set_uuid(out_clock_class, in_uuid); |
| 132 | } |
| 133 | |
| 134 | bt_clock_class_set_frequency(out_clock_class, |
| 135 | bt_clock_class_get_frequency(in_clock_class)); |
| 136 | bt_clock_class_set_precision(out_clock_class, |
| 137 | bt_clock_class_get_precision(in_clock_class)); |
| 138 | bt_clock_class_get_offset(in_clock_class, &seconds, &cycles); |
| 139 | bt_clock_class_set_offset(out_clock_class, seconds, cycles); |
| 140 | bt_clock_class_set_origin_is_unix_epoch(out_clock_class, |
| 141 | bt_clock_class_origin_is_unix_epoch(in_clock_class)); |
| 142 | |
| 143 | BT_COMP_LOGD("Copied content of clock class: in-cc-addr=%p, out-cc-addr=%p", |
| 144 | in_clock_class, out_clock_class); |
| 145 | |
| 146 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; |
| 147 | end: |
| 148 | return status; |
| 149 | } |
| 150 | |
| 151 | static |
| 152 | bt_clock_class *borrow_mapped_clock_class( |
| 153 | struct trace_ir_metadata_maps *md_maps, |
| 154 | const bt_clock_class *in_clock_class) |
| 155 | { |
| 156 | BT_ASSERT_DBG(md_maps); |
| 157 | BT_ASSERT_DBG(in_clock_class); |
| 158 | |
| 159 | return g_hash_table_lookup(md_maps->clock_class_map, |
| 160 | (gpointer) in_clock_class); |
| 161 | } |
| 162 | |
| 163 | static |
| 164 | bt_clock_class *create_new_mapped_clock_class(bt_self_component *self_comp, |
| 165 | struct trace_ir_metadata_maps *md_maps, |
| 166 | const bt_clock_class *in_clock_class) |
| 167 | { |
| 168 | enum debug_info_trace_ir_mapping_status status; |
| 169 | bt_clock_class *out_clock_class; |
| 170 | bt_logging_level log_level = md_maps->log_level; |
| 171 | |
| 172 | BT_COMP_LOGD("Creating new mapped clock class: in-cc-addr=%p", |
| 173 | in_clock_class); |
| 174 | |
| 175 | BT_ASSERT(md_maps); |
| 176 | BT_ASSERT(in_clock_class); |
| 177 | |
| 178 | BT_ASSERT(!borrow_mapped_clock_class(md_maps, in_clock_class)); |
| 179 | |
| 180 | out_clock_class = bt_clock_class_create(self_comp); |
| 181 | if (!out_clock_class) { |
| 182 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 183 | "Cannot create clock class"); |
| 184 | goto end; |
| 185 | } |
| 186 | /* If not, create a new one and add it to the mapping. */ |
| 187 | status = copy_clock_class_content(in_clock_class, out_clock_class, |
| 188 | log_level, self_comp); |
| 189 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
| 190 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 191 | "Cannot copy clock class"); |
| 192 | BT_CLOCK_CLASS_PUT_REF_AND_RESET(out_clock_class); |
| 193 | goto end; |
| 194 | } |
| 195 | |
| 196 | g_hash_table_insert(md_maps->clock_class_map, |
| 197 | (gpointer) in_clock_class, out_clock_class); |
| 198 | |
| 199 | BT_COMP_LOGD("Created new mapped clock class: in-cc-addr=%p, out-cc-addr=%p", |
| 200 | in_clock_class, out_clock_class); |
| 201 | end: |
| 202 | return out_clock_class; |
| 203 | } |
| 204 | |
| 205 | BT_HIDDEN |
| 206 | enum debug_info_trace_ir_mapping_status copy_stream_class_content( |
| 207 | struct trace_ir_maps *ir_maps, |
| 208 | const bt_stream_class *in_stream_class, |
| 209 | bt_stream_class *out_stream_class) |
| 210 | { |
| 211 | enum debug_info_trace_ir_mapping_status status; |
| 212 | struct trace_ir_metadata_maps *md_maps; |
| 213 | const bt_clock_class *in_clock_class; |
| 214 | bt_clock_class *out_clock_class; |
| 215 | const bt_field_class *in_packet_context_fc, *in_common_context_fc; |
| 216 | bt_field_class *out_packet_context_fc, *out_common_context_fc; |
| 217 | const char *in_name; |
| 218 | uint64_t ec_number, ec_idx; |
| 219 | bt_logging_level log_level = ir_maps->log_level; |
| 220 | bt_self_component *self_comp = ir_maps->self_comp; |
| 221 | |
| 222 | BT_COMP_LOGD("Copying content of stream class: in-sc-addr=%p, out-sc-addr=%p", |
| 223 | in_stream_class, out_stream_class); |
| 224 | |
| 225 | md_maps = borrow_metadata_maps_from_input_stream_class(ir_maps, in_stream_class); |
| 226 | in_clock_class = bt_stream_class_borrow_default_clock_class_const( |
| 227 | in_stream_class); |
| 228 | |
| 229 | if (in_clock_class) { |
| 230 | enum bt_stream_class_set_default_clock_class_status set_def_cc_status; |
| 231 | /* Copy the clock class. */ |
| 232 | out_clock_class = borrow_mapped_clock_class(md_maps, |
| 233 | in_clock_class); |
| 234 | if (!out_clock_class) { |
| 235 | out_clock_class = create_new_mapped_clock_class( |
| 236 | ir_maps->self_comp, md_maps, in_clock_class); |
| 237 | if (!out_clock_class) { |
| 238 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; |
| 239 | goto end; |
| 240 | } |
| 241 | } |
| 242 | set_def_cc_status = bt_stream_class_set_default_clock_class( |
| 243 | out_stream_class, out_clock_class); |
| 244 | if (set_def_cc_status != BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK) { |
| 245 | status = (int) set_def_cc_status; |
| 246 | goto end; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | /* |
| 251 | * Safe to use the same value object because it's frozen at this |
| 252 | * point. |
| 253 | */ |
| 254 | bt_stream_class_set_user_attributes(out_stream_class, |
| 255 | bt_stream_class_borrow_user_attributes_const(in_stream_class)); |
| 256 | |
| 257 | bt_stream_class_set_supports_packets( |
| 258 | out_stream_class, |
| 259 | bt_stream_class_supports_packets(in_stream_class), |
| 260 | bt_stream_class_packets_have_beginning_default_clock_snapshot( |
| 261 | in_stream_class), |
| 262 | bt_stream_class_packets_have_end_default_clock_snapshot( |
| 263 | in_stream_class)); |
| 264 | bt_stream_class_set_supports_discarded_events( |
| 265 | out_stream_class, |
| 266 | bt_stream_class_supports_discarded_events(in_stream_class), |
| 267 | bt_stream_class_discarded_events_have_default_clock_snapshots( |
| 268 | in_stream_class)); |
| 269 | bt_stream_class_set_supports_discarded_packets( |
| 270 | out_stream_class, |
| 271 | bt_stream_class_supports_discarded_packets(in_stream_class), |
| 272 | bt_stream_class_discarded_packets_have_default_clock_snapshots( |
| 273 | in_stream_class)); |
| 274 | |
| 275 | in_name = bt_stream_class_get_name(in_stream_class); |
| 276 | if (in_name) { |
| 277 | enum bt_stream_class_set_name_status set_name_status = |
| 278 | bt_stream_class_set_name(out_stream_class, in_name); |
| 279 | if (set_name_status != BT_STREAM_CLASS_SET_NAME_STATUS_OK) { |
| 280 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 281 | "Error set stream class name: " |
| 282 | "out-sc-addr=%p, name=%s", out_stream_class, |
| 283 | in_name); |
| 284 | status = (int) set_name_status; |
| 285 | goto end; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | bt_stream_class_set_assigns_automatic_stream_id(out_stream_class, |
| 290 | BT_FALSE); |
| 291 | bt_stream_class_set_assigns_automatic_event_class_id(out_stream_class, |
| 292 | BT_FALSE); |
| 293 | |
| 294 | /* |
| 295 | * Add the input packet context field class to the context to |
| 296 | * resolution in the further steps. |
| 297 | */ |
| 298 | in_packet_context_fc = |
| 299 | bt_stream_class_borrow_packet_context_field_class_const( |
| 300 | in_stream_class); |
| 301 | md_maps->fc_resolving_ctx->packet_context = |
| 302 | in_packet_context_fc; |
| 303 | |
| 304 | if (in_packet_context_fc) { |
| 305 | enum bt_stream_class_set_field_class_status set_fc_status; |
| 306 | /* Copy packet context. */ |
| 307 | out_packet_context_fc = create_field_class_copy(md_maps, |
| 308 | in_packet_context_fc); |
| 309 | |
| 310 | status = copy_field_class_content(md_maps, in_packet_context_fc, |
| 311 | out_packet_context_fc); |
| 312 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
| 313 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 314 | "Error copying stream class' packet context field class: " |
| 315 | "in-packet-ctx-fc-addr=%p, out-packet-ctx-fc-addr=%p", |
| 316 | in_packet_context_fc, out_packet_context_fc); |
| 317 | goto end; |
| 318 | } |
| 319 | |
| 320 | set_fc_status = bt_stream_class_set_packet_context_field_class( |
| 321 | out_stream_class, out_packet_context_fc); |
| 322 | if (set_fc_status != BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_OK) { |
| 323 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 324 | "Error setting stream class' packet context field class: " |
| 325 | "out-sc-addr=%p, out-packet-ctx-fc-addr=%p", |
| 326 | out_stream_class, out_packet_context_fc); |
| 327 | status = (int) set_fc_status; |
| 328 | goto end; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | /* |
| 333 | * Add the input common context field class to the context to |
| 334 | * resolution in the further steps. |
| 335 | */ |
| 336 | in_common_context_fc = |
| 337 | bt_stream_class_borrow_event_common_context_field_class_const( |
| 338 | in_stream_class); |
| 339 | md_maps->fc_resolving_ctx->event_common_context = in_common_context_fc; |
| 340 | |
| 341 | if (in_common_context_fc) { |
| 342 | enum bt_stream_class_set_field_class_status set_fc_status; |
| 343 | /* Copy common context. */ |
| 344 | /* TODO: I find it a bit awkward to have this special function |
| 345 | * here to add the debug-info field class. I would like to |
| 346 | * abstract that.*/ |
| 347 | out_common_context_fc = create_field_class_copy(md_maps, |
| 348 | in_common_context_fc); |
| 349 | status = copy_event_common_context_field_class_content(md_maps, |
| 350 | ir_maps->debug_info_field_class_name, |
| 351 | in_common_context_fc, out_common_context_fc); |
| 352 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
| 353 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 354 | "Error copying stream class' common context field class: " |
| 355 | "in-comm-ctx-fc-addr=%p, out-comm-ctx-fc-addr=%p", |
| 356 | in_common_context_fc, out_common_context_fc); |
| 357 | goto end; |
| 358 | } |
| 359 | |
| 360 | set_fc_status = bt_stream_class_set_event_common_context_field_class( |
| 361 | out_stream_class, out_common_context_fc); |
| 362 | if (set_fc_status != BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_OK) { |
| 363 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 364 | "Error setting stream class' common context field class: " |
| 365 | "out-sc-addr=%p, out-comm-ctx-fc-addr=%p", |
| 366 | out_stream_class, out_common_context_fc); |
| 367 | status = (int) set_fc_status; |
| 368 | goto end; |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | /* Copy event classes contained in the stream class. */ |
| 373 | ec_number = bt_stream_class_get_event_class_count(in_stream_class); |
| 374 | for (ec_idx = 0; ec_idx < ec_number; ec_idx++) { |
| 375 | bt_event_class *out_event_class; |
| 376 | const bt_event_class *in_event_class = |
| 377 | bt_stream_class_borrow_event_class_by_id_const( |
| 378 | in_stream_class, ec_idx); |
| 379 | out_event_class = trace_ir_mapping_borrow_mapped_event_class( |
| 380 | ir_maps, in_event_class); |
| 381 | if (!out_event_class) { |
| 382 | /* |
| 383 | * We don't need the new event_class yet. We simply |
| 384 | * want to create it and keep it in the map. |
| 385 | */ |
| 386 | out_event_class = trace_ir_mapping_create_new_mapped_event_class( |
| 387 | ir_maps, in_event_class); |
| 388 | if (!out_event_class) { |
| 389 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; |
| 390 | goto end; |
| 391 | } |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | BT_COMP_LOGD("Copied content of stream class: in-sc-addr=%p, out-sc-addr=%p", |
| 396 | in_stream_class, out_stream_class); |
| 397 | |
| 398 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; |
| 399 | end: |
| 400 | return status; |
| 401 | } |
| 402 | |
| 403 | BT_HIDDEN |
| 404 | enum debug_info_trace_ir_mapping_status copy_event_class_content( |
| 405 | struct trace_ir_maps *ir_maps, |
| 406 | const bt_event_class *in_event_class, |
| 407 | bt_event_class *out_event_class) |
| 408 | { |
| 409 | enum debug_info_trace_ir_mapping_status status; |
| 410 | struct trace_ir_metadata_maps *md_maps; |
| 411 | const char *in_event_class_name, *in_emf_uri; |
| 412 | bt_property_availability prop_avail; |
| 413 | bt_event_class_log_level ec_log_level; |
| 414 | bt_field_class *out_specific_context_fc, *out_payload_fc; |
| 415 | const bt_field_class *in_event_specific_context, *in_event_payload; |
| 416 | bt_logging_level log_level = ir_maps->log_level; |
| 417 | bt_self_component *self_comp = ir_maps->self_comp; |
| 418 | |
| 419 | BT_COMP_LOGD("Copying content of event class: in-ec-addr=%p, out-ec-addr=%p", |
| 420 | in_event_class, out_event_class); |
| 421 | |
| 422 | /* Copy event class name. */ |
| 423 | in_event_class_name = bt_event_class_get_name(in_event_class); |
| 424 | if (in_event_class_name) { |
| 425 | enum bt_event_class_set_name_status set_name_status = |
| 426 | bt_event_class_set_name(out_event_class, in_event_class_name); |
| 427 | if (set_name_status != BT_EVENT_CLASS_SET_NAME_STATUS_OK) { |
| 428 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error setting event class' name: ec-addr=%p, " |
| 429 | "name=%s", out_event_class, in_event_class_name); |
| 430 | status = (int) set_name_status; |
| 431 | goto end; |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | /* |
| 436 | * Safe to use the same value object because it's frozen at this |
| 437 | * point. |
| 438 | */ |
| 439 | bt_event_class_set_user_attributes(out_event_class, |
| 440 | bt_event_class_borrow_user_attributes_const(in_event_class)); |
| 441 | |
| 442 | /* Copy event class loglevel. */ |
| 443 | prop_avail = bt_event_class_get_log_level(in_event_class, |
| 444 | &ec_log_level); |
| 445 | if (prop_avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) { |
| 446 | bt_event_class_set_log_level(out_event_class, ec_log_level); |
| 447 | } |
| 448 | |
| 449 | /* Copy event class emf uri. */ |
| 450 | in_emf_uri = bt_event_class_get_emf_uri(in_event_class); |
| 451 | if (in_emf_uri) { |
| 452 | enum bt_event_class_set_emf_uri_status set_emf_status = |
| 453 | bt_event_class_set_emf_uri(out_event_class, in_emf_uri); |
| 454 | if (set_emf_status != BT_EVENT_CLASS_SET_EMF_URI_STATUS_OK) { |
| 455 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 456 | "Error setting event class' emf uri: " |
| 457 | "out-ec-addr=%p, emf-uri=\"%s\"", |
| 458 | out_event_class, in_emf_uri); |
| 459 | status = (int) set_emf_status; |
| 460 | goto end; |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | md_maps = borrow_metadata_maps_from_input_event_class(ir_maps, |
| 465 | in_event_class); |
| 466 | /* |
| 467 | * Add the input event class' specific ctx to te |
| 468 | * context. |
| 469 | */ |
| 470 | in_event_specific_context = |
| 471 | bt_event_class_borrow_specific_context_field_class_const( |
| 472 | in_event_class); |
| 473 | |
| 474 | md_maps->fc_resolving_ctx->event_specific_context = |
| 475 | in_event_specific_context; |
| 476 | |
| 477 | if (in_event_specific_context) { |
| 478 | enum bt_event_class_set_field_class_status set_fc_status; |
| 479 | /* Copy the specific context of this event class. */ |
| 480 | out_specific_context_fc = create_field_class_copy(md_maps, |
| 481 | in_event_specific_context); |
| 482 | |
| 483 | status = copy_field_class_content(md_maps, |
| 484 | in_event_specific_context, out_specific_context_fc); |
| 485 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
| 486 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 487 | "Error copying event class' specific context field class:" |
| 488 | "in-spec-ctx-fc-addr=%p, out-spec-ctx-fc-addr=%p", |
| 489 | in_event_specific_context, out_specific_context_fc); |
| 490 | goto end; |
| 491 | } |
| 492 | /* |
| 493 | * Add the output specific context to the output event |
| 494 | * class. |
| 495 | */ |
| 496 | set_fc_status = bt_event_class_set_specific_context_field_class( |
| 497 | out_event_class, out_specific_context_fc); |
| 498 | if (set_fc_status != BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_OK) { |
| 499 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 500 | "Error setting event class' specific context field class:" |
| 501 | "out-ec-addr=%p, out-spec-ctx-fc-addr=%p", |
| 502 | out_event_class, out_specific_context_fc); |
| 503 | status = (int) set_fc_status; |
| 504 | goto end; |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | /* |
| 509 | * Add the input event class' payload field class to |
| 510 | * the context. |
| 511 | */ |
| 512 | in_event_payload = bt_event_class_borrow_payload_field_class_const( |
| 513 | in_event_class); |
| 514 | |
| 515 | md_maps->fc_resolving_ctx->event_payload = in_event_payload; |
| 516 | |
| 517 | if (in_event_payload) { |
| 518 | enum bt_event_class_set_field_class_status set_fc_status; |
| 519 | /* Copy the payload of this event class. */ |
| 520 | out_payload_fc = create_field_class_copy(md_maps, |
| 521 | in_event_payload); |
| 522 | status = copy_field_class_content(md_maps, in_event_payload, |
| 523 | out_payload_fc); |
| 524 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
| 525 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 526 | "Error copying event class' specific context field class:" |
| 527 | "in-payload-fc-addr=%p, out-payload-fc-addr=%p", |
| 528 | in_event_payload, out_payload_fc); |
| 529 | goto end; |
| 530 | } |
| 531 | |
| 532 | /* Add the output payload to the output event class. */ |
| 533 | set_fc_status = bt_event_class_set_payload_field_class( |
| 534 | out_event_class, out_payload_fc); |
| 535 | if (set_fc_status != BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_OK) { |
| 536 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error setting event class' payload field class: " |
| 537 | "out-ec-addr=%p, out-payload-fc-addr=%p", |
| 538 | out_event_class, out_payload_fc); |
| 539 | status = (int) set_fc_status; |
| 540 | goto end; |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | BT_COMP_LOGD("Copied content of event class: in-ec-addr=%p, out-ec-addr=%p", |
| 545 | in_event_class, out_event_class); |
| 546 | |
| 547 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; |
| 548 | end: |
| 549 | return status; |
| 550 | } |
| 551 | |
| 552 | BT_HIDDEN |
| 553 | enum debug_info_trace_ir_mapping_status |
| 554 | copy_event_common_context_field_class_content( |
| 555 | struct trace_ir_metadata_maps *md_maps, |
| 556 | const char *debug_info_fc_name, |
| 557 | const bt_field_class *in_field_class, |
| 558 | bt_field_class *out_field_class) |
| 559 | { |
| 560 | enum debug_info_trace_ir_mapping_status status; |
| 561 | bt_field_class *debug_field_class = NULL, *bin_field_class = NULL, |
| 562 | *func_field_class = NULL, *src_field_class = NULL; |
| 563 | bt_logging_level log_level = md_maps->log_level; |
| 564 | bt_self_component *self_comp = md_maps->self_comp; |
| 565 | |
| 566 | BT_COMP_LOGD("Copying content of event common context field class: " |
| 567 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 568 | |
| 569 | /* Copy the content of the input common context. */ |
| 570 | status = copy_field_class_content(md_maps, in_field_class, out_field_class); |
| 571 | if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { |
| 572 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 573 | "Error copying content of event common context field class: " |
| 574 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, |
| 575 | out_field_class); |
| 576 | goto error; |
| 577 | } |
| 578 | |
| 579 | /* |
| 580 | * If this event common context has the necessary fields to compute the |
| 581 | * debug information append the debug-info field class to the event |
| 582 | * common context. |
| 583 | */ |
| 584 | if (is_event_common_ctx_dbg_info_compatible(in_field_class, debug_info_fc_name)) { |
| 585 | enum bt_field_class_structure_append_member_status append_member_status; |
| 586 | /* |
| 587 | * The struct field and 3 sub-fields are not stored in the |
| 588 | * field class map because they don't have input equivalent. |
| 589 | * We need to put our reference each of these field classes |
| 590 | * once they are added to their respective containing field |
| 591 | * classes. |
| 592 | */ |
| 593 | debug_field_class = bt_field_class_structure_create( |
| 594 | md_maps->output_trace_class); |
| 595 | if (!debug_field_class) { |
| 596 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 597 | "Failed to create debug_info structure."); |
| 598 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; |
| 599 | goto error; |
| 600 | } |
| 601 | |
| 602 | bin_field_class = bt_field_class_string_create( |
| 603 | md_maps->output_trace_class); |
| 604 | if (!bin_field_class) { |
| 605 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 606 | "Failed to create string for field=\"bin\"."); |
| 607 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; |
| 608 | goto error; |
| 609 | } |
| 610 | |
| 611 | func_field_class = bt_field_class_string_create( |
| 612 | md_maps->output_trace_class); |
| 613 | if (!func_field_class) { |
| 614 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 615 | "Failed to create string for field=\"func\"."); |
| 616 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; |
| 617 | goto error; |
| 618 | } |
| 619 | |
| 620 | src_field_class = bt_field_class_string_create( |
| 621 | md_maps->output_trace_class); |
| 622 | if (!src_field_class) { |
| 623 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 624 | "Failed to create string for field=\"src\"."); |
| 625 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; |
| 626 | goto error; |
| 627 | } |
| 628 | |
| 629 | append_member_status = bt_field_class_structure_append_member( |
| 630 | debug_field_class, "bin", bin_field_class); |
| 631 | if (append_member_status != |
| 632 | BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { |
| 633 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 634 | "Failed to add a field to debug_info struct: " |
| 635 | "field=\"bin\"."); |
| 636 | status = (int) append_member_status; |
| 637 | goto error; |
| 638 | } |
| 639 | BT_FIELD_CLASS_PUT_REF_AND_RESET(bin_field_class); |
| 640 | |
| 641 | append_member_status = bt_field_class_structure_append_member( |
| 642 | debug_field_class, "func", func_field_class); |
| 643 | if (append_member_status != |
| 644 | BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { |
| 645 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 646 | "Failed to add a field to debug_info struct: " |
| 647 | "field=\"func\"."); |
| 648 | status = (int) append_member_status; |
| 649 | goto error; |
| 650 | } |
| 651 | BT_FIELD_CLASS_PUT_REF_AND_RESET(func_field_class); |
| 652 | |
| 653 | append_member_status = bt_field_class_structure_append_member( |
| 654 | debug_field_class, "src", src_field_class); |
| 655 | if (append_member_status != |
| 656 | BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { |
| 657 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 658 | "Failed to add a field to debug_info struct: " |
| 659 | "field=\"src\"."); |
| 660 | status = (int) append_member_status; |
| 661 | goto error; |
| 662 | } |
| 663 | BT_FIELD_CLASS_PUT_REF_AND_RESET(src_field_class); |
| 664 | |
| 665 | /*Add the filled debug-info field class to the common context. */ |
| 666 | append_member_status = bt_field_class_structure_append_member( |
| 667 | out_field_class, debug_info_fc_name, debug_field_class); |
| 668 | if (append_member_status != |
| 669 | BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { |
| 670 | BT_COMP_LOGE_APPEND_CAUSE(self_comp, |
| 671 | "Failed to add debug_info field to event common context."); |
| 672 | status = (int) append_member_status; |
| 673 | goto error; |
| 674 | } |
| 675 | BT_FIELD_CLASS_PUT_REF_AND_RESET(debug_field_class); |
| 676 | } |
| 677 | BT_COMP_LOGD("Copied content of event common context field class: " |
| 678 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
| 679 | |
| 680 | status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; |
| 681 | goto end; |
| 682 | |
| 683 | error: |
| 684 | if (debug_field_class) { |
| 685 | bt_field_class_put_ref(debug_field_class); |
| 686 | } |
| 687 | if (bin_field_class) { |
| 688 | bt_field_class_put_ref(bin_field_class); |
| 689 | } |
| 690 | if (func_field_class) { |
| 691 | bt_field_class_put_ref(func_field_class); |
| 692 | } |
| 693 | if (src_field_class) { |
| 694 | bt_field_class_put_ref(src_field_class); |
| 695 | } |
| 696 | end: |
| 697 | return status; |
| 698 | } |
| 699 | |
| 700 | BT_HIDDEN |
| 701 | bt_field_class *create_field_class_copy(struct trace_ir_metadata_maps *md_maps, |
| 702 | const bt_field_class *in_field_class) |
| 703 | { |
| 704 | return create_field_class_copy_internal(md_maps, in_field_class); |
| 705 | } |
| 706 | |
| 707 | BT_HIDDEN |
| 708 | enum debug_info_trace_ir_mapping_status copy_field_class_content( |
| 709 | struct trace_ir_metadata_maps *md_maps, |
| 710 | const bt_field_class *in_field_class, |
| 711 | bt_field_class *out_field_class) |
| 712 | { |
| 713 | return copy_field_class_content_internal(md_maps, in_field_class, |
| 714 | out_field_class); |
| 715 | } |