Commit | Line | Data |
---|---|---|
58f6d595 FD |
1 | /* |
2 | * Babeltrace - Trace IR metadata object copy | |
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 | * 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 self_comp |
a07aba4f | 28 | #define BT_LOG_OUTPUT_LEVEL log_level |
b03487ab | 29 | #define BT_LOG_TAG "PLUGIN/FLT.LTTNG-UTILS.DEBUG-INFO/TRACE-IR-META-COPY" |
475e740e | 30 | #include "plugins/comp-logging.h" |
58f6d595 FD |
31 | |
32 | #include <inttypes.h> | |
33 | #include <stdint.h> | |
34 | ||
57952005 | 35 | #include "common/assert.h" |
58f6d595 FD |
36 | |
37 | #include "trace-ir-metadata-copy.h" | |
38 | #include "trace-ir-metadata-field-class-copy.h" | |
39 | #include "utils.h" | |
40 | ||
41 | BT_HIDDEN | |
42 | int copy_trace_class_content(const bt_trace_class *in_trace_class, | |
475e740e PP |
43 | bt_trace_class *out_trace_class, bt_logging_level log_level, |
44 | bt_self_component *self_comp) | |
58f6d595 | 45 | { |
475e740e | 46 | BT_COMP_LOGD("Copying content of trace class: in-tc-addr=%p, out-tc-addr=%p", |
58f6d595 FD |
47 | in_trace_class, out_trace_class); |
48 | ||
49 | /* Use the same stream class ids as in the origin trace class. */ | |
50 | bt_trace_class_set_assigns_automatic_stream_class_id(out_trace_class, | |
51 | BT_FALSE); | |
475e740e | 52 | BT_COMP_LOGD("Copied content of trace class: in-tc-addr=%p, out-tc-addr=%p", |
58f6d595 | 53 | in_trace_class, out_trace_class); |
cd03c43c | 54 | return 0; |
58f6d595 FD |
55 | } |
56 | ||
57 | static | |
58 | int copy_clock_class_content(const bt_clock_class *in_clock_class, | |
475e740e PP |
59 | bt_clock_class *out_clock_class, bt_logging_level log_level, |
60 | bt_self_component *self_comp) | |
58f6d595 | 61 | { |
58f6d595 FD |
62 | const char *clock_class_name, *clock_class_description; |
63 | int64_t seconds; | |
64 | uint64_t cycles; | |
65 | bt_uuid in_uuid; | |
66 | int ret = 0; | |
67 | ||
475e740e | 68 | BT_COMP_LOGD("Copying content of clock class: in-cc-addr=%p, out-cc-addr=%p", |
58f6d595 FD |
69 | in_clock_class, out_clock_class); |
70 | ||
71 | clock_class_name = bt_clock_class_get_name(in_clock_class); | |
72 | ||
73 | if (clock_class_name) { | |
fb25b9e3 PP |
74 | if (bt_clock_class_set_name(out_clock_class, clock_class_name) |
75 | != BT_CLOCK_CLASS_SET_NAME_STATUS_OK) { | |
475e740e | 76 | BT_COMP_LOGE("Error setting clock class' name cc-addr=%p, name=%p", |
58f6d595 FD |
77 | out_clock_class, clock_class_name); |
78 | out_clock_class = NULL; | |
79 | ret = -1; | |
80 | goto error; | |
81 | } | |
82 | } | |
83 | ||
84 | clock_class_description = bt_clock_class_get_description(in_clock_class); | |
85 | ||
86 | if (clock_class_description) { | |
fb25b9e3 PP |
87 | if (bt_clock_class_set_description(out_clock_class, |
88 | clock_class_description) != | |
89 | BT_CLOCK_CLASS_SET_DESCRIPTION_STATUS_OK) { | |
475e740e | 90 | BT_COMP_LOGE("Error setting clock class' description cc-addr=%p, " |
58f6d595 FD |
91 | "name=%p", out_clock_class, clock_class_description); |
92 | out_clock_class = NULL; | |
93 | ret = -1; | |
94 | goto error; | |
95 | } | |
96 | } | |
97 | ||
98 | in_uuid = bt_clock_class_get_uuid(in_clock_class); | |
99 | if (in_uuid) { | |
100 | bt_clock_class_set_uuid(out_clock_class, in_uuid); | |
101 | } | |
102 | ||
103 | bt_clock_class_set_frequency(out_clock_class, | |
104 | bt_clock_class_get_frequency(in_clock_class)); | |
105 | bt_clock_class_set_precision(out_clock_class, | |
106 | bt_clock_class_get_precision(in_clock_class)); | |
107 | bt_clock_class_get_offset(in_clock_class, &seconds, &cycles); | |
108 | bt_clock_class_set_offset(out_clock_class, seconds, cycles); | |
109 | bt_clock_class_set_origin_is_unix_epoch(out_clock_class, | |
110 | bt_clock_class_origin_is_unix_epoch(in_clock_class)); | |
111 | ||
475e740e | 112 | BT_COMP_LOGD("Copied content of clock class: in-cc-addr=%p, out-cc-addr=%p", |
58f6d595 FD |
113 | in_clock_class, out_clock_class); |
114 | ||
115 | error: | |
116 | return ret; | |
117 | } | |
118 | ||
119 | static | |
120 | bt_clock_class *borrow_mapped_clock_class( | |
121 | struct trace_ir_metadata_maps *md_maps, | |
122 | const bt_clock_class *in_clock_class) | |
123 | { | |
124 | BT_ASSERT(md_maps); | |
125 | BT_ASSERT(in_clock_class); | |
126 | ||
127 | return g_hash_table_lookup(md_maps->clock_class_map, | |
128 | (gpointer) in_clock_class); | |
129 | } | |
130 | ||
131 | static | |
132 | bt_clock_class *create_new_mapped_clock_class( | |
133 | bt_self_component *self_comp, | |
134 | struct trace_ir_metadata_maps *md_maps, | |
135 | const bt_clock_class *in_clock_class) | |
136 | { | |
137 | bt_clock_class *out_clock_class; | |
138 | int ret; | |
a07aba4f | 139 | bt_logging_level log_level = md_maps->log_level; |
58f6d595 | 140 | |
475e740e | 141 | BT_COMP_LOGD("Creating new mapped clock class: in-cc-addr=%p", |
58f6d595 FD |
142 | in_clock_class); |
143 | ||
144 | BT_ASSERT(md_maps); | |
145 | BT_ASSERT(in_clock_class); | |
146 | ||
147 | BT_ASSERT(!borrow_mapped_clock_class(md_maps, in_clock_class)); | |
148 | ||
149 | out_clock_class = bt_clock_class_create(self_comp); | |
150 | if (!out_clock_class) { | |
475e740e | 151 | BT_COMP_LOGE_STR("Cannot create clock class"); |
58f6d595 FD |
152 | goto end; |
153 | } | |
154 | /* If not, create a new one and add it to the mapping. */ | |
a07aba4f | 155 | ret = copy_clock_class_content(in_clock_class, out_clock_class, |
475e740e | 156 | log_level, self_comp); |
58f6d595 | 157 | if (ret) { |
475e740e | 158 | BT_COMP_LOGE_STR("Cannot copy clock class"); |
58f6d595 FD |
159 | goto end; |
160 | } | |
161 | ||
162 | g_hash_table_insert(md_maps->clock_class_map, | |
163 | (gpointer) in_clock_class, out_clock_class); | |
164 | ||
475e740e | 165 | BT_COMP_LOGD("Created new mapped clock class: in-cc-addr=%p, out-cc-addr=%p", |
58f6d595 FD |
166 | in_clock_class, out_clock_class); |
167 | end: | |
168 | return out_clock_class; | |
169 | } | |
170 | ||
171 | BT_HIDDEN | |
172 | int copy_stream_class_content(struct trace_ir_maps *ir_maps, | |
173 | const bt_stream_class *in_stream_class, | |
174 | bt_stream_class *out_stream_class) | |
175 | { | |
176 | struct trace_ir_metadata_maps *md_maps; | |
177 | const bt_clock_class *in_clock_class; | |
178 | bt_clock_class *out_clock_class; | |
179 | const bt_field_class *in_packet_context_fc, *in_common_context_fc; | |
180 | bt_field_class *out_packet_context_fc, *out_common_context_fc; | |
58f6d595 FD |
181 | const char *in_name; |
182 | int ret = 0; | |
a07aba4f | 183 | bt_logging_level log_level = ir_maps->log_level; |
475e740e | 184 | bt_self_component *self_comp = ir_maps->self_comp; |
58f6d595 | 185 | |
475e740e | 186 | BT_COMP_LOGD("Copying content of stream class: in-sc-addr=%p, out-sc-addr=%p", |
58f6d595 FD |
187 | in_stream_class, out_stream_class); |
188 | ||
189 | md_maps = borrow_metadata_maps_from_input_stream_class(ir_maps, in_stream_class); | |
190 | in_clock_class = bt_stream_class_borrow_default_clock_class_const( | |
191 | in_stream_class); | |
192 | ||
193 | if (in_clock_class) { | |
194 | /* Copy the clock class. */ | |
195 | out_clock_class = | |
196 | borrow_mapped_clock_class(md_maps, in_clock_class); | |
197 | if (!out_clock_class) { | |
198 | out_clock_class = create_new_mapped_clock_class( | |
199 | ir_maps->self_comp, md_maps, | |
200 | in_clock_class); | |
201 | } | |
202 | bt_stream_class_set_default_clock_class(out_stream_class, | |
203 | out_clock_class); | |
204 | ||
205 | } | |
206 | ||
5ef34326 | 207 | bt_stream_class_set_packets_have_beginning_default_clock_snapshot( |
34e13c22 | 208 | out_stream_class, |
5ef34326 | 209 | bt_stream_class_packets_have_beginning_default_clock_snapshot( |
34e13c22 | 210 | in_stream_class)); |
5ef34326 | 211 | bt_stream_class_set_packets_have_end_default_clock_snapshot( |
34e13c22 | 212 | out_stream_class, |
5ef34326 | 213 | bt_stream_class_packets_have_end_default_clock_snapshot( |
34e13c22 | 214 | in_stream_class)); |
77037b2b PP |
215 | bt_stream_class_set_supports_discarded_events( |
216 | out_stream_class, | |
217 | bt_stream_class_supports_discarded_events(in_stream_class), | |
218 | bt_stream_class_discarded_events_have_default_clock_snapshots( | |
219 | in_stream_class)); | |
220 | bt_stream_class_set_supports_discarded_packets( | |
221 | out_stream_class, | |
222 | bt_stream_class_supports_discarded_packets(in_stream_class), | |
223 | bt_stream_class_discarded_packets_have_default_clock_snapshots( | |
224 | in_stream_class)); | |
34e13c22 | 225 | |
58f6d595 FD |
226 | in_name = bt_stream_class_get_name(in_stream_class); |
227 | if (in_name) { | |
fb25b9e3 PP |
228 | if (bt_stream_class_set_name(out_stream_class, in_name) != |
229 | BT_STREAM_CLASS_SET_NAME_STATUS_OK) { | |
475e740e | 230 | BT_COMP_LOGE("Error set stream class name: out-sc-addr=%p, " |
58f6d595 FD |
231 | "name=%s", out_stream_class, in_name); |
232 | ret = -1; | |
233 | goto error; | |
234 | } | |
235 | } | |
236 | ||
237 | bt_stream_class_set_assigns_automatic_stream_id(out_stream_class, | |
238 | BT_FALSE); | |
239 | bt_stream_class_set_assigns_automatic_event_class_id(out_stream_class, | |
240 | BT_FALSE); | |
241 | ||
242 | /* | |
243 | * Add the input packet context field class to the context to | |
244 | * resolution in the further steps. | |
245 | */ | |
246 | in_packet_context_fc = | |
247 | bt_stream_class_borrow_packet_context_field_class_const( | |
248 | in_stream_class); | |
249 | md_maps->fc_resolving_ctx->packet_context = | |
250 | in_packet_context_fc; | |
251 | ||
252 | if (in_packet_context_fc) { | |
253 | /* Copy packet context. */ | |
254 | out_packet_context_fc = create_field_class_copy( | |
255 | md_maps, in_packet_context_fc); | |
256 | ||
257 | ret = copy_field_class_content(md_maps, | |
258 | in_packet_context_fc, out_packet_context_fc); | |
259 | if (ret) { | |
260 | ret = -1; | |
261 | goto error; | |
262 | } | |
263 | ||
fb25b9e3 PP |
264 | if (bt_stream_class_set_packet_context_field_class( |
265 | out_stream_class, out_packet_context_fc) != | |
266 | BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_OK) { | |
475e740e | 267 | BT_COMP_LOGE("Error setting stream class' packet context " |
58f6d595 FD |
268 | "field class: sc-addr=%p, packet-fc-addr=%p", |
269 | out_stream_class, out_packet_context_fc); | |
270 | ret = -1; | |
271 | goto error; | |
272 | } | |
273 | } | |
274 | ||
275 | /* | |
276 | * Add the input common context field class to the context to | |
277 | * resolution in the further steps. | |
278 | */ | |
279 | in_common_context_fc = | |
280 | bt_stream_class_borrow_event_common_context_field_class_const( | |
281 | in_stream_class); | |
282 | md_maps->fc_resolving_ctx->event_common_context = | |
283 | in_common_context_fc; | |
284 | ||
285 | if (in_common_context_fc) { | |
286 | /* Copy common context. */ | |
287 | /* TODO: I find it a bit awkward to have this special function | |
288 | * here to add the debug-info field class. I would like to | |
289 | * abstract that.*/ | |
290 | out_common_context_fc = create_field_class_copy( | |
291 | md_maps, in_common_context_fc); | |
292 | ||
293 | ret = copy_event_common_context_field_class_content( | |
294 | md_maps, ir_maps->debug_info_field_class_name, | |
295 | in_common_context_fc, out_common_context_fc); | |
296 | if (ret) { | |
297 | goto error; | |
298 | } | |
299 | ||
fb25b9e3 PP |
300 | if (bt_stream_class_set_event_common_context_field_class( |
301 | out_stream_class, out_common_context_fc) != | |
302 | BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_OK) { | |
475e740e | 303 | BT_COMP_LOGE("Error setting stream class' packet context " |
58f6d595 FD |
304 | "field class: sc-addr=%p, packet-fc-addr=%p", |
305 | out_stream_class, out_common_context_fc); | |
306 | ret = -1; | |
307 | goto error; | |
308 | } | |
309 | } | |
310 | ||
311 | /* Set packet snapshot boolean fields. */ | |
475e740e | 312 | BT_COMP_LOGD("Copied content of stream class: in-sc-addr=%p, out-sc-addr=%p", |
58f6d595 FD |
313 | in_stream_class, out_stream_class); |
314 | error: | |
315 | return ret; | |
316 | } | |
317 | ||
318 | BT_HIDDEN | |
319 | int copy_event_class_content(struct trace_ir_maps *ir_maps, | |
320 | const bt_event_class *in_event_class, | |
321 | bt_event_class *out_event_class) | |
322 | { | |
323 | struct trace_ir_metadata_maps *md_maps; | |
324 | const char *in_event_class_name, *in_emf_uri; | |
325 | bt_property_availability prop_avail; | |
a07aba4f | 326 | bt_event_class_log_level ec_log_level; |
58f6d595 FD |
327 | bt_field_class *out_specific_context_fc, *out_payload_fc; |
328 | const bt_field_class *in_event_specific_context, *in_event_payload; | |
329 | int ret = 0; | |
a07aba4f | 330 | bt_logging_level log_level = ir_maps->log_level; |
475e740e | 331 | bt_self_component *self_comp = ir_maps->self_comp; |
58f6d595 | 332 | |
475e740e | 333 | BT_COMP_LOGD("Copying content of event class: in-ec-addr=%p, out-ec-addr=%p", |
58f6d595 FD |
334 | in_event_class, out_event_class); |
335 | ||
336 | /* Copy event class name. */ | |
337 | in_event_class_name = bt_event_class_get_name(in_event_class); | |
338 | if (in_event_class_name) { | |
fb25b9e3 PP |
339 | if (bt_event_class_set_name(out_event_class, |
340 | in_event_class_name) != | |
341 | BT_EVENT_CLASS_SET_NAME_STATUS_OK) { | |
475e740e | 342 | BT_COMP_LOGE("Error setting event class' name: ec-addr=%p, " |
58f6d595 FD |
343 | "name=%s", out_event_class, in_event_class_name); |
344 | ret = -1; | |
345 | goto error; | |
346 | } | |
347 | } | |
348 | ||
349 | /* Copy event class loglevel. */ | |
a07aba4f PP |
350 | prop_avail = bt_event_class_get_log_level(in_event_class, |
351 | &ec_log_level); | |
58f6d595 FD |
352 | if (prop_avail == BT_PROPERTY_AVAILABILITY_AVAILABLE) { |
353 | bt_event_class_set_log_level(out_event_class, | |
a07aba4f | 354 | ec_log_level); |
58f6d595 FD |
355 | } |
356 | ||
357 | /* Copy event class emf uri. */ | |
358 | in_emf_uri = bt_event_class_get_emf_uri(in_event_class); | |
359 | if (in_emf_uri) { | |
fb25b9e3 PP |
360 | if (bt_event_class_set_emf_uri(out_event_class, in_emf_uri) != |
361 | BT_EVENT_CLASS_SET_EMF_URI_STATUS_OK) { | |
475e740e | 362 | BT_COMP_LOGE("Error setting event class' emf uri: ec-addr=%p, " |
58f6d595 FD |
363 | "emf uri=%s", out_event_class, in_emf_uri); |
364 | ret = -1; | |
365 | goto error; | |
366 | } | |
367 | } | |
368 | ||
369 | md_maps = borrow_metadata_maps_from_input_event_class(ir_maps, in_event_class); | |
370 | /* | |
371 | * Add the input event class' specific ctx to te | |
372 | * context. | |
373 | */ | |
374 | in_event_specific_context = | |
375 | bt_event_class_borrow_specific_context_field_class_const( | |
376 | in_event_class); | |
377 | ||
378 | md_maps->fc_resolving_ctx->event_specific_context = | |
379 | in_event_specific_context; | |
380 | ||
381 | if (in_event_specific_context) { | |
382 | /* Copy the specific context of this event class. */ | |
383 | out_specific_context_fc = create_field_class_copy(md_maps, | |
384 | in_event_specific_context); | |
385 | ||
abf710c7 | 386 | ret = copy_field_class_content(md_maps, |
58f6d595 FD |
387 | in_event_specific_context, out_specific_context_fc); |
388 | if (ret) { | |
389 | goto error; | |
390 | } | |
391 | /* | |
392 | * Add the output specific context to the output event | |
393 | * class. | |
394 | */ | |
fb25b9e3 PP |
395 | if (bt_event_class_set_specific_context_field_class( |
396 | out_event_class, out_specific_context_fc) != | |
397 | BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_OK) { | |
475e740e | 398 | BT_COMP_LOGE("Error setting event class' specific context " |
58f6d595 FD |
399 | "field class: ec-addr=%p, ctx-fc-addr=%p", |
400 | out_event_class, out_specific_context_fc); | |
401 | ret = -1; | |
402 | goto error; | |
403 | } | |
404 | } | |
405 | ||
406 | /* | |
407 | * Add the input event class' payload field class to | |
408 | * the context. | |
409 | */ | |
410 | in_event_payload = bt_event_class_borrow_payload_field_class_const( | |
411 | in_event_class); | |
412 | ||
413 | md_maps->fc_resolving_ctx->event_payload = in_event_payload; | |
414 | ||
415 | if (in_event_payload) { | |
416 | /* Copy the payload of this event class. */ | |
417 | out_payload_fc = create_field_class_copy(md_maps, | |
418 | in_event_payload); | |
abf710c7 | 419 | ret = copy_field_class_content(md_maps, |
58f6d595 FD |
420 | in_event_payload, out_payload_fc); |
421 | if (ret) { | |
422 | goto error; | |
423 | } | |
424 | ||
425 | /* Add the output payload to the output event class. */ | |
fb25b9e3 PP |
426 | if (bt_event_class_set_payload_field_class( |
427 | out_event_class, out_payload_fc) != | |
428 | BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_OK) { | |
475e740e | 429 | BT_COMP_LOGE("Error setting event class' payload " |
58f6d595 FD |
430 | "field class: ec-addr=%p, payload-fc-addr=%p", |
431 | out_event_class, out_payload_fc); | |
432 | ret = -1; | |
433 | goto error; | |
434 | } | |
435 | } | |
436 | ||
475e740e | 437 | BT_COMP_LOGD("Copied content of event class: in-ec-addr=%p, out-ec-addr=%p", |
58f6d595 FD |
438 | in_event_class, out_event_class); |
439 | error: | |
440 | return ret; | |
441 | } | |
442 | ||
443 | BT_HIDDEN | |
444 | int copy_event_common_context_field_class_content( | |
445 | struct trace_ir_metadata_maps *md_maps, | |
446 | const char *debug_info_fc_name, | |
447 | const bt_field_class *in_field_class, | |
448 | bt_field_class *out_field_class) | |
449 | { | |
58f6d595 FD |
450 | bt_field_class *debug_field_class = NULL, *bin_field_class = NULL, |
451 | *func_field_class = NULL, *src_field_class = NULL; | |
452 | int ret = 0; | |
a07aba4f | 453 | bt_logging_level log_level = md_maps->log_level; |
475e740e | 454 | bt_self_component *self_comp = md_maps->self_comp; |
58f6d595 | 455 | |
475e740e | 456 | BT_COMP_LOGD("Copying content of event common context field class: " |
58f6d595 FD |
457 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
458 | ||
459 | /* Copy the content of the input common context. */ | |
460 | ret = copy_field_class_content(md_maps, in_field_class, out_field_class); | |
461 | if (ret) { | |
462 | goto error; | |
463 | } | |
464 | ||
465 | /* | |
466 | * If this event common context has the necessary fields to compute the | |
467 | * debug information append the debug-info field class to the event | |
468 | * common context. | |
469 | */ | |
470 | if (is_event_common_ctx_dbg_info_compatible(in_field_class, debug_info_fc_name)) { | |
471 | /* | |
472 | * The struct field and 3 sub-fields are not stored in the | |
473 | * field class map because they don't have input equivalent. | |
474 | * We need to put our reference each of these field classes | |
475 | * once they are added to their respective containing field | |
476 | * classes. | |
477 | */ | |
478 | debug_field_class = bt_field_class_structure_create( | |
479 | md_maps->output_trace_class); | |
480 | if (!debug_field_class) { | |
475e740e | 481 | BT_COMP_LOGE_STR("Failed to create debug_info structure."); |
58f6d595 FD |
482 | ret = -1; |
483 | goto error; | |
484 | } | |
485 | ||
486 | bin_field_class = bt_field_class_string_create( | |
487 | md_maps->output_trace_class); | |
488 | if (!bin_field_class) { | |
475e740e | 489 | BT_COMP_LOGE_STR("Failed to create string for field=bin."); |
58f6d595 FD |
490 | ret = -1; |
491 | goto error; | |
492 | } | |
493 | ||
494 | func_field_class = bt_field_class_string_create( | |
495 | md_maps->output_trace_class); | |
496 | if (!func_field_class) { | |
475e740e | 497 | BT_COMP_LOGE_STR("Failed to create string for field=func."); |
58f6d595 FD |
498 | ret = -1; |
499 | goto error; | |
500 | } | |
501 | ||
502 | src_field_class = bt_field_class_string_create( | |
503 | md_maps->output_trace_class); | |
504 | if (!src_field_class) { | |
475e740e | 505 | BT_COMP_LOGE_STR("Failed to create string for field=src."); |
58f6d595 FD |
506 | ret = -1; |
507 | goto error; | |
508 | } | |
509 | ||
fb25b9e3 PP |
510 | if (bt_field_class_structure_append_member( |
511 | debug_field_class, "bin", bin_field_class) != | |
512 | BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { | |
475e740e | 513 | BT_COMP_LOGE_STR("Failed to add a field to debug_info " |
58f6d595 FD |
514 | "struct: field=bin."); |
515 | ret = -1; | |
516 | goto error; | |
517 | } | |
518 | BT_FIELD_CLASS_PUT_REF_AND_RESET(bin_field_class); | |
519 | ||
fb25b9e3 PP |
520 | if (bt_field_class_structure_append_member( |
521 | debug_field_class, "func", func_field_class) != | |
522 | BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { | |
475e740e | 523 | BT_COMP_LOGE_STR("Failed to add a field to debug_info " |
58f6d595 FD |
524 | "struct: field=func."); |
525 | ret = -1; | |
526 | goto error; | |
527 | } | |
528 | BT_FIELD_CLASS_PUT_REF_AND_RESET(func_field_class); | |
529 | ||
fb25b9e3 PP |
530 | if (bt_field_class_structure_append_member( |
531 | debug_field_class, "src", src_field_class) != | |
532 | BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { | |
475e740e | 533 | BT_COMP_LOGE_STR("Failed to add a field to debug_info " |
58f6d595 FD |
534 | "struct: field=src."); |
535 | ret = -1; | |
536 | goto error; | |
537 | } | |
538 | BT_FIELD_CLASS_PUT_REF_AND_RESET(src_field_class); | |
539 | ||
540 | /*Add the filled debug-info field class to the common context. */ | |
fb25b9e3 PP |
541 | if (bt_field_class_structure_append_member(out_field_class, |
542 | debug_info_fc_name, debug_field_class) != | |
543 | BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { | |
475e740e | 544 | BT_COMP_LOGE_STR("Failed to add debug_info field to " |
58f6d595 FD |
545 | "event common context."); |
546 | ret = -1; | |
547 | goto error; | |
548 | } | |
549 | BT_FIELD_CLASS_PUT_REF_AND_RESET(debug_field_class); | |
550 | } | |
475e740e | 551 | BT_COMP_LOGD("Copied content of event common context field class: " |
58f6d595 FD |
552 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
553 | goto end; | |
554 | ||
555 | error: | |
556 | if (debug_field_class) { | |
557 | bt_field_class_put_ref(debug_field_class); | |
558 | } | |
559 | if (bin_field_class) { | |
560 | bt_field_class_put_ref(bin_field_class); | |
561 | } | |
562 | if (func_field_class) { | |
563 | bt_field_class_put_ref(func_field_class); | |
564 | } | |
565 | if (src_field_class) { | |
566 | bt_field_class_put_ref(src_field_class); | |
567 | } | |
568 | end: | |
569 | return ret; | |
570 | } | |
571 | ||
572 | BT_HIDDEN | |
573 | bt_field_class *create_field_class_copy(struct trace_ir_metadata_maps *md_maps, | |
574 | const bt_field_class *in_field_class) | |
575 | { | |
576 | return create_field_class_copy_internal(md_maps, in_field_class); | |
577 | } | |
578 | ||
579 | BT_HIDDEN | |
580 | int copy_field_class_content(struct trace_ir_metadata_maps *md_maps, | |
581 | const bt_field_class *in_field_class, | |
582 | bt_field_class *out_field_class) | |
583 | { | |
584 | return copy_field_class_content_internal(md_maps, in_field_class, | |
585 | out_field_class); | |
586 | } |