Fix: ctf-writer: null dereference in bt_ctf_trace_common_add_stream_class
[babeltrace.git] / src / ctf-writer / trace.c
CommitLineData
8deee039
PP
1/*
2 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
b03487ab 24#define BT_LOG_TAG "CTF-WRITER/TRACE"
bf436657 25#include "logging.h"
8deee039 26
086dc475 27#include <inttypes.h>
969c1d8a 28#include <stdbool.h>
086dc475
PP
29#include <stdint.h>
30#include <stdlib.h>
31#include <string.h>
32
3996bc53
PP
33#include <babeltrace2-ctf-writer/event.h>
34#include <babeltrace2-ctf-writer/object.h>
35#include <babeltrace2-ctf-writer/utils.h>
57952005
MJ
36#include <babeltrace2/types.h>
37
38#include "common/assert.h"
39#include "compat/compiler.h"
40#include "compat/endian.h"
41
42#include "attributes.h"
43#include "clock-class.h"
44#include "clock.h"
45#include "event-class.h"
46#include "event.h"
47#include "field-types.h"
48#include "field-wrapper.h"
49#include "functor.h"
50#include "stream-class.h"
51#include "stream.h"
52#include "trace.h"
53#include "utils.h"
54#include "validation.h"
55#include "values.h"
56#include "visitor.h"
57#include "writer.h"
58
086dc475
PP
59#define DEFAULT_IDENTIFIER_SIZE 128
60#define DEFAULT_METADATA_STRING_SIZE 4096
61
62BT_HIDDEN
63int bt_ctf_trace_common_initialize(struct bt_ctf_trace_common *trace,
c2606e2f 64 bt_ctf_object_release_func release_func)
086dc475
PP
65{
66 int ret = 0;
67
68 BT_LOGD_STR("Initializing common trace object.");
69 trace->native_byte_order = BT_CTF_BYTE_ORDER_UNSPECIFIED;
c2606e2f 70 bt_ctf_object_init_shared_with_parent(&trace->base, release_func);
086dc475 71 trace->clock_classes = g_ptr_array_new_with_free_func(
c2606e2f 72 (GDestroyNotify) bt_ctf_object_put_ref);
086dc475
PP
73 if (!trace->clock_classes) {
74 BT_LOGE_STR("Failed to allocate one GPtrArray.");
75 goto error;
76 }
77
78 trace->streams = g_ptr_array_new_with_free_func(
c2606e2f 79 (GDestroyNotify) bt_ctf_object_try_spec_release);
086dc475
PP
80 if (!trace->streams) {
81 BT_LOGE_STR("Failed to allocate one GPtrArray.");
82 goto error;
83 }
84
85 trace->stream_classes = g_ptr_array_new_with_free_func(
c2606e2f 86 (GDestroyNotify) bt_ctf_object_try_spec_release);
086dc475
PP
87 if (!trace->stream_classes) {
88 BT_LOGE_STR("Failed to allocate one GPtrArray.");
89 goto error;
90 }
91
92 /* Create the environment array object */
93 trace->environment = bt_ctf_attributes_create();
94 if (!trace->environment) {
95 BT_LOGE_STR("Cannot create empty attributes object.");
96 goto error;
97 }
98
99 BT_LOGD("Initialized common trace object: addr=%p", trace);
100 goto end;
101
102error:
103 ret = -1;
104
105end:
106 return ret;
107}
108
109BT_HIDDEN
110void bt_ctf_trace_common_finalize(struct bt_ctf_trace_common *trace)
111{
112 BT_LOGD("Finalizing common trace object: addr=%p, name=\"%s\"",
113 trace, bt_ctf_trace_common_get_name(trace));
114
115 if (trace->environment) {
116 BT_LOGD_STR("Destroying environment attributes.");
117 bt_ctf_attributes_destroy(trace->environment);
118 }
119
120 if (trace->name) {
121 g_string_free(trace->name, TRUE);
122 }
123
124 if (trace->clock_classes) {
125 BT_LOGD_STR("Putting clock classes.");
126 g_ptr_array_free(trace->clock_classes, TRUE);
127 }
128
129 if (trace->streams) {
130 BT_LOGD_STR("Destroying streams.");
131 g_ptr_array_free(trace->streams, TRUE);
132 }
133
134 if (trace->stream_classes) {
135 BT_LOGD_STR("Destroying stream classes.");
136 g_ptr_array_free(trace->stream_classes, TRUE);
137 }
138
139 BT_LOGD_STR("Putting packet header field type.");
c2606e2f 140 bt_ctf_object_put_ref(trace->packet_header_field_type);
086dc475
PP
141}
142
143BT_HIDDEN
144int bt_ctf_trace_common_set_name(struct bt_ctf_trace_common *trace, const char *name)
145{
146 int ret = 0;
147
148 if (!trace) {
149 BT_LOGW_STR("Invalid parameter: trace is NULL.");
150 ret = -1;
151 goto end;
152 }
153
154 if (!name) {
155 BT_LOGW_STR("Invalid parameter: name is NULL.");
156 ret = -1;
157 goto end;
158 }
159
160 if (trace->frozen) {
161 BT_LOGW("Invalid parameter: trace is frozen: "
162 "addr=%p, name=\"%s\"",
163 trace, bt_ctf_trace_common_get_name(trace));
164 ret = -1;
165 goto end;
166 }
167
168 trace->name = trace->name ? g_string_assign(trace->name, name) :
169 g_string_new(name);
170 if (!trace->name) {
171 BT_LOGE_STR("Failed to allocate one GString.");
172 ret = -1;
173 goto end;
174 }
175
c9ecaa78 176 BT_LOGT("Set trace's name: addr=%p, name=\"%s\"", trace, name);
086dc475
PP
177
178end:
179 return ret;
180}
181
182BT_HIDDEN
183int bt_ctf_trace_common_set_uuid(struct bt_ctf_trace_common *trace,
d126826c 184 const uint8_t *uuid)
086dc475
PP
185{
186 int ret = 0;
187
188 if (!trace) {
189 BT_LOGW_STR("Invalid parameter: trace is NULL.");
190 ret = -1;
191 goto end;
192 }
193
194 if (!uuid) {
195 BT_LOGW_STR("Invalid parameter: UUID is NULL.");
196 ret = -1;
197 goto end;
198 }
199
200 if (trace->frozen) {
201 BT_LOGW("Invalid parameter: trace is frozen: "
202 "addr=%p, name=\"%s\"",
203 trace, bt_ctf_trace_common_get_name(trace));
204 ret = -1;
205 goto end;
206 }
207
d126826c 208 bt_uuid_copy(trace->uuid, uuid);
d7279670 209 trace->uuid_set = BT_CTF_TRUE;
c9ecaa78 210 BT_LOGT("Set trace's UUID: addr=%p, name=\"%s\", "
d126826c 211 "uuid=\"" BT_UUID_FMT "\"",
086dc475 212 trace, bt_ctf_trace_common_get_name(trace),
d126826c 213 BT_UUID_FMT_VALUES(uuid));
086dc475
PP
214
215end:
216 return ret;
217}
218
219BT_HIDDEN
220int bt_ctf_trace_common_set_environment_field(struct bt_ctf_trace_common *trace,
c2606e2f 221 const char *name, struct bt_ctf_private_value *value)
086dc475
PP
222{
223 int ret = 0;
224
225 if (!trace) {
226 BT_LOGW_STR("Invalid parameter: trace is NULL.");
227 ret = -1;
228 goto end;
229 }
230
231 if (!name) {
232 BT_LOGW_STR("Invalid parameter: name is NULL.");
233 ret = -1;
234 goto end;
235 }
236
237 if (!value) {
238 BT_LOGW_STR("Invalid parameter: value is NULL.");
239 ret = -1;
240 goto end;
241 }
242
243 if (!bt_ctf_identifier_is_valid(name)) {
244 BT_LOGW("Invalid parameter: environment field's name is not a valid CTF identifier: "
245 "trace-addr=%p, trace-name=\"%s\", "
246 "env-name=\"%s\"",
247 trace, bt_ctf_trace_common_get_name(trace), name);
248 ret = -1;
249 goto end;
250 }
251
c2606e2f
PP
252 if (!bt_ctf_value_is_integer(bt_ctf_private_value_as_value(value)) &&
253 !bt_ctf_value_is_string(bt_ctf_private_value_as_value(value))) {
086dc475
PP
254 BT_LOGW("Invalid parameter: environment field's value is not an integer or string value: "
255 "trace-addr=%p, trace-name=\"%s\", "
256 "env-name=\"%s\", env-value-type=%s",
257 trace, bt_ctf_trace_common_get_name(trace), name,
b5401f8b 258 bt_ctf_value_type_string(
c2606e2f
PP
259 bt_ctf_value_get_type(
260 bt_ctf_private_value_as_value(value))));
086dc475
PP
261 ret = -1;
262 goto end;
263 }
264
265 if (trace->frozen) {
266 /*
267 * New environment fields may be added to a frozen trace,
268 * but existing fields may not be changed.
269 *
270 * The object passed is frozen like all other attributes.
271 */
c2606e2f 272 struct bt_ctf_private_value *attribute =
086dc475
PP
273 bt_ctf_attributes_borrow_field_value_by_name(
274 trace->environment, name);
275
276 if (attribute) {
277 BT_LOGW("Invalid parameter: trace is frozen and environment field already exists with this name: "
278 "trace-addr=%p, trace-name=\"%s\", "
279 "env-name=\"%s\"",
280 trace, bt_ctf_trace_common_get_name(trace), name);
281 ret = -1;
282 goto end;
283 }
284
c2606e2f 285 bt_ctf_value_freeze(bt_ctf_private_value_as_value(value));
086dc475
PP
286 }
287
288 ret = bt_ctf_attributes_set_field_value(trace->environment, name,
289 value);
290 if (ret) {
291 BT_LOGE("Cannot set environment field's value: "
292 "trace-addr=%p, trace-name=\"%s\", "
293 "env-name=\"%s\"",
294 trace, bt_ctf_trace_common_get_name(trace), name);
295 } else {
c9ecaa78 296 BT_LOGT("Set environment field's value: "
086dc475
PP
297 "trace-addr=%p, trace-name=\"%s\", "
298 "env-name=\"%s\", value-addr=%p",
299 trace, bt_ctf_trace_common_get_name(trace), name, value);
300 }
301
302end:
303 return ret;
304}
305
306BT_HIDDEN
307int bt_ctf_trace_common_set_environment_field_string(struct bt_ctf_trace_common *trace,
308 const char *name, const char *value)
309{
310 int ret = 0;
c2606e2f 311 struct bt_ctf_private_value *env_value_string_obj = NULL;
086dc475
PP
312
313 if (!value) {
314 BT_LOGW_STR("Invalid parameter: value is NULL.");
315 ret = -1;
316 goto end;
317 }
318
c2606e2f 319 env_value_string_obj = bt_ctf_private_value_string_create_init(value);
086dc475
PP
320 if (!env_value_string_obj) {
321 BT_LOGE_STR("Cannot create string value object.");
322 ret = -1;
323 goto end;
324 }
325
326 /* bt_ctf_trace_common_set_environment_field() logs errors */
327 ret = bt_ctf_trace_common_set_environment_field(trace, name,
328 env_value_string_obj);
329
330end:
c2606e2f 331 bt_ctf_object_put_ref(env_value_string_obj);
086dc475
PP
332 return ret;
333}
334
335BT_HIDDEN
336int bt_ctf_trace_common_set_environment_field_integer(
337 struct bt_ctf_trace_common *trace, const char *name, int64_t value)
338{
339 int ret = 0;
c2606e2f 340 struct bt_ctf_private_value *env_value_integer_obj = NULL;
086dc475 341
c2606e2f 342 env_value_integer_obj = bt_ctf_private_value_integer_create_init(value);
086dc475
PP
343 if (!env_value_integer_obj) {
344 BT_LOGE_STR("Cannot create integer value object.");
345 ret = -1;
346 goto end;
347 }
348
349 /* bt_ctf_trace_common_set_environment_field() logs errors */
350 ret = bt_ctf_trace_common_set_environment_field(trace, name,
351 env_value_integer_obj);
352
353end:
c2606e2f 354 bt_ctf_object_put_ref(env_value_integer_obj);
086dc475
PP
355 return ret;
356}
357
358BT_HIDDEN
359int bt_ctf_trace_common_add_clock_class(struct bt_ctf_trace_common *trace,
360 struct bt_ctf_clock_class *clock_class)
361{
362 int ret = 0;
363
364 if (!trace) {
365 BT_LOGW_STR("Invalid parameter: trace is NULL.");
366 ret = -1;
367 goto end;
368 }
369
370 if (!bt_ctf_clock_class_is_valid(clock_class)) {
371 BT_LOGW("Invalid parameter: clock class is invalid: "
372 "trace-addr=%p, trace-name=\"%s\", "
373 "clock-class-addr=%p, clock-class-name=\"%s\"",
374 trace, bt_ctf_trace_common_get_name(trace),
375 clock_class, bt_ctf_clock_class_get_name(clock_class));
376 ret = -1;
377 goto end;
378 }
379
380 /* Check for duplicate clock classes */
381 if (bt_ctf_trace_common_has_clock_class(trace, clock_class)) {
382 BT_LOGW("Invalid parameter: clock class already exists in trace: "
383 "trace-addr=%p, trace-name=\"%s\", "
384 "clock-class-addr=%p, clock-class-name=\"%s\"",
385 trace, bt_ctf_trace_common_get_name(trace),
386 clock_class, bt_ctf_clock_class_get_name(clock_class));
387 ret = -1;
388 goto end;
389 }
390
c2606e2f 391 bt_ctf_object_get_ref(clock_class);
086dc475
PP
392 g_ptr_array_add(trace->clock_classes, clock_class);
393
394 if (trace->frozen) {
c9ecaa78 395 BT_LOGT_STR("Freezing added clock class because trace is frozen.");
086dc475
PP
396 bt_ctf_clock_class_freeze(clock_class);
397 }
398
c9ecaa78 399 BT_LOGT("Added clock class to trace: "
086dc475
PP
400 "trace-addr=%p, trace-name=\"%s\", "
401 "clock-class-addr=%p, clock-class-name=\"%s\"",
402 trace, bt_ctf_trace_common_get_name(trace),
403 clock_class, bt_ctf_clock_class_get_name(clock_class));
404
405end:
406 return ret;
407}
408
409static
410bool packet_header_field_type_is_valid(struct bt_ctf_trace_common *trace,
411 struct bt_ctf_field_type_common *packet_header_type)
412{
413 int ret;
414 bool is_valid = true;
415 struct bt_ctf_field_type_common *field_type = NULL;
416
417 if (!packet_header_type) {
418 /*
419 * No packet header field type: trace must have only
420 * one stream. At this point the stream class being
421 * added is not part of the trace yet, so we validate
422 * that the trace contains no stream classes yet.
423 */
424 if (trace->stream_classes->len >= 1) {
425 BT_LOGW_STR("Invalid packet header field type: "
426 "packet header field type does not exist but there's more than one stream class in the trace.");
427 goto invalid;
428 }
429
430 /* No packet header field type: valid at this point */
431 goto end;
432 }
433
434 /* Packet header field type, if it exists, must be a structure */
435 if (packet_header_type->id != BT_CTF_FIELD_TYPE_ID_STRUCT) {
436 BT_LOGW("Invalid packet header field type: must be a structure field type if it exists: "
437 "ft-addr=%p, ft-id=%s",
438 packet_header_type,
439 bt_ctf_field_type_id_string(packet_header_type->id));
440 goto invalid;
441 }
442
443 /*
444 * If there's a `magic` field, it must be a 32-bit unsigned
445 * integer field type. Also it must be the first field of the
446 * packet header field type.
447 */
448 field_type = bt_ctf_field_type_common_structure_borrow_field_type_by_name(
449 packet_header_type, "magic");
450 if (field_type) {
451 const char *field_name;
452
453 if (field_type->id != BT_CTF_FIELD_TYPE_ID_INTEGER) {
454 BT_LOGW("Invalid packet header field type: `magic` field must be an integer field type: "
455 "magic-ft-addr=%p, magic-ft-id=%s",
456 field_type,
457 bt_ctf_field_type_id_string(field_type->id));
458 goto invalid;
459 }
460
461 if (bt_ctf_field_type_common_integer_is_signed(field_type)) {
462 BT_LOGW("Invalid packet header field type: `magic` field must be an unsigned integer field type: "
463 "magic-ft-addr=%p", field_type);
464 goto invalid;
465 }
466
467 if (bt_ctf_field_type_common_integer_get_size(field_type) != 32) {
468 BT_LOGW("Invalid packet header field type: `magic` field must be a 32-bit unsigned integer field type: "
469 "magic-ft-addr=%p, magic-ft-size=%u",
470 field_type,
471 bt_ctf_field_type_common_integer_get_size(field_type));
472 goto invalid;
473 }
474
475 ret = bt_ctf_field_type_common_structure_borrow_field_by_index(
476 packet_header_type, &field_name, NULL, 0);
ec4a3354 477 BT_ASSERT_DBG(ret == 0);
086dc475
PP
478
479 if (strcmp(field_name, "magic") != 0) {
480 BT_LOGW("Invalid packet header field type: `magic` field must be the first field: "
481 "magic-ft-addr=%p, first-field-name=\"%s\"",
482 field_type, field_name);
483 goto invalid;
484 }
485 }
486
487 /*
488 * If there's a `uuid` field, it must be an array field type of
489 * length 16 with an 8-bit unsigned integer element field type.
490 */
491 field_type = bt_ctf_field_type_common_structure_borrow_field_type_by_name(
492 packet_header_type, "uuid");
493 if (field_type) {
494 struct bt_ctf_field_type_common *elem_ft;
495
496 if (field_type->id != BT_CTF_FIELD_TYPE_ID_ARRAY) {
497 BT_LOGW("Invalid packet header field type: `uuid` field must be an array field type: "
498 "uuid-ft-addr=%p, uuid-ft-id=%s",
499 field_type,
500 bt_ctf_field_type_id_string(field_type->id));
501 goto invalid;
502 }
503
504 if (bt_ctf_field_type_common_array_get_length(field_type) != 16) {
505 BT_LOGW("Invalid packet header field type: `uuid` array field type's length must be 16: "
506 "uuid-ft-addr=%p, uuid-ft-length=%" PRId64,
507 field_type,
508 bt_ctf_field_type_common_array_get_length(field_type));
509 goto invalid;
510 }
511
512 elem_ft = bt_ctf_field_type_common_array_borrow_element_field_type(field_type);
ec4a3354 513 BT_ASSERT_DBG(elem_ft);
086dc475
PP
514
515 if (elem_ft->id != BT_CTF_FIELD_TYPE_ID_INTEGER) {
516 BT_LOGW("Invalid packet header field type: `uuid` field's element field type must be an integer field type: "
517 "elem-ft-addr=%p, elem-ft-id=%s",
518 elem_ft,
519 bt_ctf_field_type_id_string(elem_ft->id));
520 goto invalid;
521 }
522
523 if (bt_ctf_field_type_common_integer_is_signed(elem_ft)) {
524 BT_LOGW("Invalid packet header field type: `uuid` field's element field type must be an unsigned integer field type: "
525 "elem-ft-addr=%p", elem_ft);
526 goto invalid;
527 }
528
529 if (bt_ctf_field_type_common_integer_get_size(elem_ft) != 8) {
530 BT_LOGW("Invalid packet header field type: `uuid` field's element field type must be an 8-bit unsigned integer field type: "
531 "elem-ft-addr=%p, elem-ft-size=%u",
532 elem_ft,
533 bt_ctf_field_type_common_integer_get_size(elem_ft));
534 goto invalid;
535 }
536 }
537
538 /*
539 * The `stream_id` field must exist if there's more than one
540 * stream classes in the trace.
541 */
542 field_type = bt_ctf_field_type_common_structure_borrow_field_type_by_name(
543 packet_header_type, "stream_id");
544
545 if (!field_type && trace->stream_classes->len >= 1) {
546 BT_LOGW_STR("Invalid packet header field type: "
547 "`stream_id` field does not exist but there's more than one stream class in the trace.");
548 goto invalid;
549 }
550
551 /*
552 * If there's a `stream_id` field, it must be an unsigned
553 * integer field type.
554 */
555 if (field_type) {
556 if (field_type->id != BT_CTF_FIELD_TYPE_ID_INTEGER) {
557 BT_LOGW("Invalid packet header field type: `stream_id` field must be an integer field type: "
558 "stream-id-ft-addr=%p, stream-id-ft-id=%s",
559 field_type,
560 bt_ctf_field_type_id_string(field_type->id));
561 goto invalid;
562 }
563
564 if (bt_ctf_field_type_common_integer_is_signed(field_type)) {
565 BT_LOGW("Invalid packet header field type: `stream_id` field must be an unsigned integer field type: "
566 "stream-id-ft-addr=%p", field_type);
567 goto invalid;
568 }
569 }
570
571 /*
572 * If there's a `packet_seq_num` field, it must be an unsigned
573 * integer field type.
574 */
575 field_type = bt_ctf_field_type_common_structure_borrow_field_type_by_name(
576 packet_header_type, "packet_seq_num");
577 if (field_type) {
578 if (field_type->id != BT_CTF_FIELD_TYPE_ID_INTEGER) {
579 BT_LOGW("Invalid packet header field type: `packet_seq_num` field must be an integer field type: "
580 "stream-id-ft-addr=%p, packet-seq-num-ft-id=%s",
581 field_type,
582 bt_ctf_field_type_id_string(field_type->id));
583 goto invalid;
584 }
585
586 if (bt_ctf_field_type_common_integer_is_signed(field_type)) {
587 BT_LOGW("Invalid packet header field type: `packet_seq_num` field must be an unsigned integer field type: "
588 "packet-seq-num-ft-addr=%p", field_type);
589 goto invalid;
590 }
591 }
592
593 goto end;
594
595invalid:
596 is_valid = false;
597
598end:
599 return is_valid;
600}
601
602static
603bool packet_context_field_type_is_valid(struct bt_ctf_trace_common *trace,
604 struct bt_ctf_stream_class_common *stream_class,
605 struct bt_ctf_field_type_common *packet_context_type,
606 bool check_ts_begin_end_mapped)
607{
608 bool is_valid = true;
609 struct bt_ctf_field_type_common *field_type = NULL;
610
611 if (!packet_context_type) {
612 /* No packet context field type: valid at this point */
613 goto end;
614 }
615
616 /* Packet context field type, if it exists, must be a structure */
617 if (packet_context_type->id != BT_CTF_FIELD_TYPE_ID_STRUCT) {
618 BT_LOGW("Invalid packet context field type: must be a structure field type if it exists: "
619 "ft-addr=%p, ft-id=%s",
620 packet_context_type,
621 bt_ctf_field_type_id_string(packet_context_type->id));
622 goto invalid;
623 }
624
625 /*
626 * If there's a `packet_size` field, it must be an unsigned
627 * integer field type.
628 */
629 field_type = bt_ctf_field_type_common_structure_borrow_field_type_by_name(
630 packet_context_type, "packet_size");
631 if (field_type) {
632 if (field_type->id != BT_CTF_FIELD_TYPE_ID_INTEGER) {
633 BT_LOGW("Invalid packet context field type: `packet_size` field must be an integer field type: "
634 "packet-size-ft-addr=%p, packet-size-ft-id=%s",
635 field_type,
636 bt_ctf_field_type_id_string(field_type->id));
637 goto invalid;
638 }
639
640 if (bt_ctf_field_type_common_integer_is_signed(field_type)) {
641 BT_LOGW("Invalid packet context field type: `packet_size` field must be an unsigned integer field type: "
642 "packet-size-ft-addr=%p", field_type);
643 goto invalid;
644 }
645 }
646
647 /*
648 * If there's a `content_size` field, it must be an unsigned
649 * integer field type.
650 */
651 field_type = bt_ctf_field_type_common_structure_borrow_field_type_by_name(
652 packet_context_type, "content_size");
653 if (field_type) {
654 if (field_type->id != BT_CTF_FIELD_TYPE_ID_INTEGER) {
655 BT_LOGW("Invalid packet context field type: `content_size` field must be an integer field type: "
656 "content-size-ft-addr=%p, content-size-ft-id=%s",
657 field_type,
658 bt_ctf_field_type_id_string(field_type->id));
659 goto invalid;
660 }
661
662 if (bt_ctf_field_type_common_integer_is_signed(field_type)) {
663 BT_LOGW("Invalid packet context field type: `content_size` field must be an unsigned integer field type: "
664 "content-size-ft-addr=%p", field_type);
665 goto invalid;
666 }
667 }
668
669 /*
670 * If there's a `events_discarded` field, it must be an unsigned
671 * integer field type.
672 */
673 field_type = bt_ctf_field_type_common_structure_borrow_field_type_by_name(
674 packet_context_type, "events_discarded");
675 if (field_type) {
676 if (field_type->id != BT_CTF_FIELD_TYPE_ID_INTEGER) {
677 BT_LOGW("Invalid packet context field type: `events_discarded` field must be an integer field type: "
678 "events-discarded-ft-addr=%p, events-discarded-ft-id=%s",
679 field_type,
680 bt_ctf_field_type_id_string(field_type->id));
681 goto invalid;
682 }
683
684 if (bt_ctf_field_type_common_integer_is_signed(field_type)) {
685 BT_LOGW("Invalid packet context field type: `events_discarded` field must be an unsigned integer field type: "
686 "events-discarded-ft-addr=%p", field_type);
687 goto invalid;
688 }
689 }
690
691 /*
692 * If there's a `timestamp_begin` field, it must be an unsigned
693 * integer field type. Also, if the trace is not a CTF writer's
694 * trace, then we cannot automatically set the mapped clock
695 * class of this field, so it must have a mapped clock class.
696 */
697 field_type = bt_ctf_field_type_common_structure_borrow_field_type_by_name(
698 packet_context_type, "timestamp_begin");
699 if (field_type) {
700 if (field_type->id != BT_CTF_FIELD_TYPE_ID_INTEGER) {
701 BT_LOGW("Invalid packet context field type: `timestamp_begin` field must be an integer field type: "
702 "timestamp-begin-ft-addr=%p, timestamp-begin-ft-id=%s",
703 field_type,
704 bt_ctf_field_type_id_string(field_type->id));
705 goto invalid;
706 }
707
708 if (bt_ctf_field_type_common_integer_is_signed(field_type)) {
709 BT_LOGW("Invalid packet context field type: `timestamp_begin` field must be an unsigned integer field type: "
710 "timestamp-begin-ft-addr=%p", field_type);
711 goto invalid;
712 }
713
714 if (check_ts_begin_end_mapped) {
715 struct bt_ctf_clock_class *clock_class =
716 bt_ctf_field_type_common_integer_borrow_mapped_clock_class(
717 field_type);
718
719 if (!clock_class) {
720 BT_LOGW("Invalid packet context field type: `timestamp_begin` field must be mapped to a clock class: "
721 "timestamp-begin-ft-addr=%p", field_type);
722 goto invalid;
723 }
724 }
725 }
8deee039 726
086dc475
PP
727 /*
728 * If there's a `timestamp_end` field, it must be an unsigned
729 * integer field type. Also, if the trace is not a CTF writer's
730 * trace, then we cannot automatically set the mapped clock
731 * class of this field, so it must have a mapped clock class.
732 */
733 field_type = bt_ctf_field_type_common_structure_borrow_field_type_by_name(
734 packet_context_type, "timestamp_end");
735 if (field_type) {
736 if (field_type->id != BT_CTF_FIELD_TYPE_ID_INTEGER) {
737 BT_LOGW("Invalid packet context field type: `timestamp_end` field must be an integer field type: "
738 "timestamp-end-ft-addr=%p, timestamp-end-ft-id=%s",
739 field_type,
740 bt_ctf_field_type_id_string(field_type->id));
741 goto invalid;
742 }
743
744 if (bt_ctf_field_type_common_integer_is_signed(field_type)) {
745 BT_LOGW("Invalid packet context field type: `timestamp_end` field must be an unsigned integer field type: "
746 "timestamp-end-ft-addr=%p", field_type);
747 goto invalid;
748 }
749
750 if (check_ts_begin_end_mapped) {
751 struct bt_ctf_clock_class *clock_class =
752 bt_ctf_field_type_common_integer_borrow_mapped_clock_class(
753 field_type);
754
755 if (!clock_class) {
756 BT_LOGW("Invalid packet context field type: `timestamp_end` field must be mapped to a clock class: "
757 "timestamp-end-ft-addr=%p", field_type);
758 goto invalid;
759 }
760 }
761 }
762
763 goto end;
764
765invalid:
766 is_valid = false;
767
768end:
769 return is_valid;
770}
771
772static
773bool event_header_field_type_is_valid(struct bt_ctf_trace_common *trace,
774 struct bt_ctf_stream_class_common *stream_class,
775 struct bt_ctf_field_type_common *event_header_type)
776{
777 bool is_valid = true;
778 struct bt_ctf_field_type_common *field_type = NULL;
779
780 /*
781 * We do not validate that the `timestamp` field exists here
782 * because CTF does not require this exact name to be mapped to
783 * a clock class.
784 */
785
786 if (!event_header_type) {
787 /*
788 * No event header field type: stream class must have
789 * only one event class.
790 */
791 if (bt_ctf_stream_class_common_get_event_class_count(stream_class) > 1) {
792 BT_LOGW_STR("Invalid event header field type: "
793 "event header field type does not exist but there's more than one event class in the stream class.");
794 goto invalid;
795 }
796
797 /* No event header field type: valid at this point */
798 goto end;
799 }
800
801 /* Event header field type, if it exists, must be a structure */
802 if (event_header_type->id != BT_CTF_FIELD_TYPE_ID_STRUCT) {
803 BT_LOGW("Invalid event header field type: must be a structure field type if it exists: "
804 "ft-addr=%p, ft-id=%s",
805 event_header_type,
806 bt_ctf_field_type_id_string(event_header_type->id));
807 goto invalid;
808 }
809
810 /*
811 * If there's an `id` field, it must be an unsigned integer
812 * field type or an enumeration field type with an unsigned
813 * integer container field type.
814 */
815 field_type = bt_ctf_field_type_common_structure_borrow_field_type_by_name(
816 event_header_type, "id");
817 if (field_type) {
818 struct bt_ctf_field_type_common *int_ft;
819
820 if (field_type->id == BT_CTF_FIELD_TYPE_ID_INTEGER) {
821 int_ft = field_type;
822 } else if (field_type->id == BT_CTF_FIELD_TYPE_ID_ENUM) {
823 int_ft = bt_ctf_field_type_common_enumeration_borrow_container_field_type(
824 field_type);
825 } else {
826 BT_LOGW("Invalid event header field type: `id` field must be an integer or enumeration field type: "
827 "id-ft-addr=%p, id-ft-id=%s",
828 field_type,
829 bt_ctf_field_type_id_string(field_type->id));
830 goto invalid;
831 }
832
ec4a3354 833 BT_ASSERT_DBG(int_ft);
086dc475
PP
834 if (bt_ctf_field_type_common_integer_is_signed(int_ft)) {
835 BT_LOGW("Invalid event header field type: `id` field must be an unsigned integer or enumeration field type: "
836 "id-ft-addr=%p", int_ft);
837 goto invalid;
838 }
839 }
840
841 goto end;
842
843invalid:
844 is_valid = false;
845
846end:
847 return is_valid;
848}
849
850static
851int check_packet_header_type_has_no_clock_class(struct bt_ctf_trace_common *trace)
852{
853 int ret = 0;
854
855 if (trace->packet_header_field_type) {
856 struct bt_ctf_clock_class *clock_class = NULL;
857
858 ret = bt_ctf_field_type_common_validate_single_clock_class(
859 trace->packet_header_field_type,
860 &clock_class);
c2606e2f 861 bt_ctf_object_put_ref(clock_class);
086dc475
PP
862 if (ret || clock_class) {
863 BT_LOGW("Trace's packet header field type cannot "
864 "contain a field type which is mapped to "
865 "a clock class: "
866 "trace-addr=%p, trace-name=\"%s\", "
867 "clock-class-name=\"%s\"",
868 trace, bt_ctf_trace_common_get_name(trace),
869 clock_class ?
870 bt_ctf_clock_class_get_name(clock_class) :
871 NULL);
872 ret = -1;
873 }
874 }
875
876 return ret;
877}
878
879BT_HIDDEN
880int bt_ctf_trace_common_add_stream_class(struct bt_ctf_trace_common *trace,
881 struct bt_ctf_stream_class_common *stream_class,
882 bt_ctf_validation_flag_copy_field_type_func copy_field_type_func,
883 struct bt_ctf_clock_class *init_expected_clock_class,
884 int (*map_clock_classes_func)(struct bt_ctf_stream_class_common *stream_class,
885 struct bt_ctf_field_type_common *packet_context_field_type,
886 struct bt_ctf_field_type_common *event_header_field_type),
887 bool check_ts_begin_end_mapped)
888{
889 int ret;
890 int64_t i;
891 int64_t stream_id;
892 struct bt_ctf_validation_output trace_sc_validation_output = { 0 };
893 struct bt_ctf_validation_output *ec_validation_outputs = NULL;
894 const enum bt_ctf_validation_flag trace_sc_validation_flags =
895 BT_CTF_VALIDATION_FLAG_TRACE |
896 BT_CTF_VALIDATION_FLAG_STREAM;
897 const enum bt_ctf_validation_flag ec_validation_flags =
898 BT_CTF_VALIDATION_FLAG_EVENT;
899 struct bt_ctf_field_type_common *packet_header_type = NULL;
900 struct bt_ctf_field_type_common *packet_context_type = NULL;
901 struct bt_ctf_field_type_common *event_header_type = NULL;
902 struct bt_ctf_field_type_common *stream_event_ctx_type = NULL;
1564e3dc 903 int64_t event_class_count = 0;
086dc475
PP
904 struct bt_ctf_trace_common *current_parent_trace = NULL;
905 struct bt_ctf_clock_class *expected_clock_class =
c2606e2f 906 bt_ctf_object_get_ref(init_expected_clock_class);
086dc475 907
ec4a3354 908 BT_ASSERT_DBG(copy_field_type_func);
086dc475
PP
909
910 if (!trace) {
911 BT_LOGW_STR("Invalid parameter: trace is NULL.");
912 ret = -1;
913 goto end;
914 }
915
916 if (!stream_class) {
917 BT_LOGW_STR("Invalid parameter: stream class is NULL.");
918 ret = -1;
919 goto end;
920 }
921
922 BT_LOGD("Adding stream class to trace: "
923 "trace-addr=%p, trace-name=\"%s\", "
924 "stream-class-addr=%p, stream-class-name=\"%s\", "
925 "stream-class-id=%" PRId64,
926 trace, bt_ctf_trace_common_get_name(trace),
927 stream_class, bt_ctf_stream_class_common_get_name(stream_class),
928 bt_ctf_stream_class_common_get_id(stream_class));
929
930 current_parent_trace = bt_ctf_stream_class_common_borrow_trace(stream_class);
931 if (current_parent_trace) {
932 /* Stream class is already associated to a trace, abort. */
933 BT_LOGW("Invalid parameter: stream class is already part of a trace: "
934 "stream-class-trace-addr=%p, "
935 "stream-class-trace-name=\"%s\"",
936 current_parent_trace,
937 bt_ctf_trace_common_get_name(current_parent_trace));
938 ret = -1;
939 goto end;
940 }
941
942 event_class_count =
943 bt_ctf_stream_class_common_get_event_class_count(stream_class);
ec4a3354 944 BT_ASSERT_DBG(event_class_count >= 0);
086dc475
PP
945
946 if (!stream_class->frozen) {
947 /*
948 * Stream class is not frozen yet. Validate that the
949 * stream class contains at most a single clock class
950 * because the previous
951 * bt_ctf_stream_class_common_add_event_class() calls did
952 * not make this validation since the stream class's
953 * direct field types (packet context, event header,
954 * event context) could change afterwards. This stream
955 * class is about to be frozen and those field types
956 * won't be changed if this function succeeds.
957 *
958 * At this point we're also sure that the stream class's
959 * clock, if any, has the same class as the stream
960 * class's expected clock class, if any. This is why, if
961 * bt_ctf_stream_class_common_validate_single_clock_class()
962 * succeeds below, the call to
963 * bt_ctf_stream_class_map_clock_class() at the end of this
964 * function is safe because it maps to the same, single
965 * clock class.
966 */
967 ret = bt_ctf_stream_class_common_validate_single_clock_class(
968 stream_class, &expected_clock_class);
969 if (ret) {
970 BT_LOGW("Invalid parameter: stream class or one of its "
971 "event classes contains a field type which is "
972 "not recursively mapped to the expected "
973 "clock class: "
974 "stream-class-addr=%p, "
975 "stream-class-id=%" PRId64 ", "
976 "stream-class-name=\"%s\", "
977 "expected-clock-class-addr=%p, "
978 "expected-clock-class-name=\"%s\"",
979 stream_class, bt_ctf_stream_class_common_get_id(stream_class),
980 bt_ctf_stream_class_common_get_name(stream_class),
981 expected_clock_class,
982 expected_clock_class ?
983 bt_ctf_clock_class_get_name(expected_clock_class) :
984 NULL);
985 goto end;
986 }
987 }
988
989 ret = check_packet_header_type_has_no_clock_class(trace);
990 if (ret) {
991 /* check_packet_header_type_has_no_clock_class() logs errors */
992 goto end;
993 }
994
995 /*
996 * We're about to freeze both the trace and the stream class.
997 * Also, each event class contained in this stream class are
998 * already frozen.
999 *
1000 * This trace, this stream class, and all its event classes
1001 * should be valid at this point.
1002 *
1003 * Validate trace and stream class first, then each event
1004 * class of this stream class can be validated individually.
1005 */
1006 packet_header_type =
1007 bt_ctf_trace_common_borrow_packet_header_field_type(trace);
1008 packet_context_type =
1009 bt_ctf_stream_class_common_borrow_packet_context_field_type(stream_class);
1010 event_header_type =
1011 bt_ctf_stream_class_common_borrow_event_header_field_type(stream_class);
1012 stream_event_ctx_type =
1013 bt_ctf_stream_class_common_borrow_event_context_field_type(stream_class);
1014
1015 BT_LOGD("Validating trace and stream class field types.");
1016 ret = bt_ctf_validate_class_types(trace->environment,
1017 packet_header_type, packet_context_type, event_header_type,
1018 stream_event_ctx_type, NULL, NULL, trace->valid,
1019 stream_class->valid, 1, &trace_sc_validation_output,
1020 trace_sc_validation_flags, copy_field_type_func);
1021
1022 if (ret) {
1023 /*
1024 * This means something went wrong during the validation
1025 * process, not that the objects are invalid.
1026 */
1027 BT_LOGE("Failed to validate trace and stream class field types: "
1028 "ret=%d", ret);
1029 goto end;
1030 }
1031
1032 if ((trace_sc_validation_output.valid_flags &
1033 trace_sc_validation_flags) !=
1034 trace_sc_validation_flags) {
1035 /* Invalid trace/stream class */
1036 BT_LOGW("Invalid trace or stream class field types: "
1037 "valid-flags=0x%x",
1038 trace_sc_validation_output.valid_flags);
1039 ret = -1;
1040 goto end;
1041 }
1042
1043 if (event_class_count > 0) {
1044 ec_validation_outputs = g_new0(struct bt_ctf_validation_output,
1045 event_class_count);
1046 if (!ec_validation_outputs) {
1047 BT_LOGE_STR("Failed to allocate one validation output structure.");
1048 ret = -1;
1049 goto end;
1050 }
1051 }
1052
1053 /* Validate each event class individually */
1054 for (i = 0; i < event_class_count; i++) {
1055 struct bt_ctf_event_class_common *event_class =
1056 bt_ctf_stream_class_common_borrow_event_class_by_index(
1057 stream_class, i);
1058 struct bt_ctf_field_type_common *event_context_type = NULL;
1059 struct bt_ctf_field_type_common *event_payload_type = NULL;
1060
1061 event_context_type =
1062 bt_ctf_event_class_common_borrow_context_field_type(
1063 event_class);
1064 event_payload_type =
1065 bt_ctf_event_class_common_borrow_payload_field_type(
1066 event_class);
1067
1068 /*
1069 * It is important to use the field types returned by
1070 * the previous trace and stream class validation here
1071 * because copies could have been made.
1072 */
1073 BT_LOGD("Validating event class's field types: "
1074 "addr=%p, name=\"%s\", id=%" PRId64,
1075 event_class, bt_ctf_event_class_common_get_name(event_class),
1076 bt_ctf_event_class_common_get_id(event_class));
1077 ret = bt_ctf_validate_class_types(trace->environment,
1078 trace_sc_validation_output.packet_header_type,
1079 trace_sc_validation_output.packet_context_type,
1080 trace_sc_validation_output.event_header_type,
1081 trace_sc_validation_output.stream_event_ctx_type,
1082 event_context_type, event_payload_type,
1083 1, 1, event_class->valid, &ec_validation_outputs[i],
1084 ec_validation_flags, copy_field_type_func);
1085
1086 if (ret) {
1087 BT_LOGE("Failed to validate event class field types: "
1088 "ret=%d", ret);
1089 goto end;
1090 }
1091
1092 if ((ec_validation_outputs[i].valid_flags &
1093 ec_validation_flags) != ec_validation_flags) {
1094 /* Invalid event class */
1095 BT_LOGW("Invalid event class field types: "
1096 "valid-flags=0x%x",
1097 ec_validation_outputs[i].valid_flags);
1098 ret = -1;
1099 goto end;
1100 }
1101 }
1102
1103 stream_id = bt_ctf_stream_class_common_get_id(stream_class);
1104 if (stream_id < 0) {
1105 stream_id = trace->next_stream_id++;
1106 if (stream_id < 0) {
1107 BT_LOGE_STR("No more stream class IDs available.");
1108 ret = -1;
1109 goto end;
1110 }
1111
1112 /* Try to assign a new stream id */
1113 for (i = 0; i < trace->stream_classes->len; i++) {
1114 if (stream_id == bt_ctf_stream_class_common_get_id(
1115 trace->stream_classes->pdata[i])) {
1116 /* Duplicate stream id found */
1117 BT_LOGW("Duplicate stream class ID: "
1118 "id=%" PRId64, (int64_t) stream_id);
1119 ret = -1;
1120 goto end;
1121 }
1122 }
1123
1124 if (bt_ctf_stream_class_common_set_id_no_check(stream_class,
1125 stream_id)) {
1126 /* TODO Should retry with a different stream id */
1127 BT_LOGE("Cannot set stream class's ID: "
1128 "id=%" PRId64, (int64_t) stream_id);
1129 ret = -1;
1130 goto end;
1131 }
1132 }
1133
1134 /*
1135 * At this point all the field types in the validation output
1136 * are valid. Validate the semantics of some scopes according to
1137 * the CTF specification.
1138 */
1139 if (!packet_header_field_type_is_valid(trace,
1140 trace_sc_validation_output.packet_header_type)) {
1141 BT_LOGW_STR("Invalid trace's packet header field type.");
1142 ret = -1;
1143 goto end;
1144 }
1145
1146 if (!packet_context_field_type_is_valid(trace,
1147 stream_class,
1148 trace_sc_validation_output.packet_context_type,
1149 check_ts_begin_end_mapped)) {
1150 BT_LOGW_STR("Invalid stream class's packet context field type.");
1151 ret = -1;
1152 goto end;
1153 }
1154
1155 if (!event_header_field_type_is_valid(trace,
1156 stream_class,
1157 trace_sc_validation_output.event_header_type)) {
1158 BT_LOGW_STR("Invalid steam class's event header field type.");
1159 ret = -1;
1160 goto end;
1161 }
1162
1163 /*
1164 * Now is the time to automatically map specific field types of
1165 * the stream class's packet context and event header field
1166 * types to the stream class's clock's class if they are not
1167 * mapped to a clock class yet. We do it here because we know
1168 * that after this point, everything is frozen so it won't be
1169 * possible for the user to modify the stream class's clock, or
1170 * to map those field types to other clock classes.
1171 */
1172 if (map_clock_classes_func) {
1173 if (map_clock_classes_func(stream_class,
1174 trace_sc_validation_output.packet_context_type,
1175 trace_sc_validation_output.event_header_type)) {
1176 /* map_clock_classes_func() logs errors */
1177 ret = -1;
1178 goto end;
1179 }
1180 }
1181
c2606e2f 1182 bt_ctf_object_set_parent(&stream_class->base, &trace->base);
086dc475
PP
1183 g_ptr_array_add(trace->stream_classes, stream_class);
1184
1185 /*
1186 * At this point we know that the function will be successful.
1187 * Therefore we can replace the trace and stream class field
1188 * types with what's in their validation output structure and
1189 * mark them as valid. We can also replace the field types of
1190 * all the event classes of the stream class and mark them as
1191 * valid.
1192 */
1193 bt_ctf_validation_replace_types(trace, stream_class, NULL,
1194 &trace_sc_validation_output, trace_sc_validation_flags);
1195 trace->valid = 1;
1196 stream_class->valid = 1;
1197
1198 /*
1199 * Put what was not moved in bt_ctf_validation_replace_types().
1200 */
1201 bt_ctf_validation_output_put_types(&trace_sc_validation_output);
1202
1203 for (i = 0; i < event_class_count; i++) {
1204 struct bt_ctf_event_class_common *event_class =
1205 bt_ctf_stream_class_common_borrow_event_class_by_index(
1206 stream_class, i);
1207
1208 bt_ctf_validation_replace_types(NULL, NULL, event_class,
1209 &ec_validation_outputs[i], ec_validation_flags);
1210 event_class->valid = 1;
1211
1212 /*
1213 * Put what was not moved in
1214 * bt_ctf_validation_replace_types().
1215 */
1216 bt_ctf_validation_output_put_types(&ec_validation_outputs[i]);
1217 }
1218
1219 /*
1220 * Freeze the trace and the stream class.
1221 */
1222 bt_ctf_stream_class_common_freeze(stream_class);
1223 bt_ctf_trace_common_freeze(trace);
1224
1225 /*
1226 * It is safe to set the stream class's unique clock class
1227 * now because the stream class is frozen.
1228 */
1229 if (expected_clock_class) {
c2606e2f 1230 BT_CTF_OBJECT_MOVE_REF(stream_class->clock_class, expected_clock_class);
086dc475
PP
1231 }
1232
1233 BT_LOGD("Added stream class to trace: "
1234 "trace-addr=%p, trace-name=\"%s\", "
1235 "stream-class-addr=%p, stream-class-name=\"%s\", "
1236 "stream-class-id=%" PRId64,
1237 trace, bt_ctf_trace_common_get_name(trace),
1238 stream_class, bt_ctf_stream_class_common_get_name(stream_class),
1239 bt_ctf_stream_class_common_get_id(stream_class));
1240
1241end:
1242 if (ret) {
1fdbadfc
JG
1243 if (stream_class) {
1244 bt_ctf_object_set_parent(&stream_class->base, NULL);
1245 }
086dc475
PP
1246
1247 if (ec_validation_outputs) {
1248 for (i = 0; i < event_class_count; i++) {
1249 bt_ctf_validation_output_put_types(
1250 &ec_validation_outputs[i]);
1251 }
1252 }
1253 }
1254
1255 g_free(ec_validation_outputs);
1256 bt_ctf_validation_output_put_types(&trace_sc_validation_output);
c2606e2f 1257 bt_ctf_object_put_ref(expected_clock_class);
086dc475
PP
1258 return ret;
1259}
1260
1261BT_HIDDEN
d7279670 1262bt_ctf_bool bt_ctf_trace_common_has_clock_class(struct bt_ctf_trace_common *trace,
086dc475
PP
1263 struct bt_ctf_clock_class *clock_class)
1264{
1265 struct bt_ctf_search_query query = { .value = clock_class, .found = 0 };
1266
ec4a3354
PP
1267 BT_ASSERT_DBG(trace);
1268 BT_ASSERT_DBG(clock_class);
086dc475
PP
1269
1270 g_ptr_array_foreach(trace->clock_classes, value_exists, &query);
1271 return query.found;
1272}
1273
1274BT_HIDDEN
1275int bt_ctf_trace_common_set_native_byte_order(struct bt_ctf_trace_common *trace,
1276 enum bt_ctf_byte_order byte_order, bool allow_unspecified)
1277{
1278 int ret = 0;
1279
1280 if (!trace) {
1281 BT_LOGW_STR("Invalid parameter: trace is NULL.");
1282 ret = -1;
1283 goto end;
1284 }
1285
1286 if (trace->frozen) {
1287 BT_LOGW("Invalid parameter: trace is frozen: "
1288 "addr=%p, name=\"%s\"",
1289 trace, bt_ctf_trace_common_get_name(trace));
1290 ret = -1;
1291 goto end;
1292 }
1293
1294 if (byte_order == BT_CTF_BYTE_ORDER_UNSPECIFIED && !allow_unspecified) {
1295 BT_LOGW("Invalid parameter: BT_CTF_BYTE_ORDER_UNSPECIFIED byte order is not allowed: "
1296 "addr=%p, name=\"%s\"",
1297 trace, bt_ctf_trace_common_get_name(trace));
1298 ret = -1;
1299 goto end;
1300 }
1301
1302 if (byte_order != BT_CTF_BYTE_ORDER_LITTLE_ENDIAN &&
1303 byte_order != BT_CTF_BYTE_ORDER_BIG_ENDIAN &&
1304 byte_order != BT_CTF_BYTE_ORDER_NETWORK) {
1305 BT_LOGW("Invalid parameter: invalid byte order: "
1306 "addr=%p, name=\"%s\", bo=%s",
1307 trace, bt_ctf_trace_common_get_name(trace),
1308 bt_ctf_byte_order_string(byte_order));
1309 ret = -1;
1310 goto end;
1311 }
1312
1313 trace->native_byte_order = byte_order;
c9ecaa78 1314 BT_LOGT("Set trace's native byte order: "
086dc475
PP
1315 "addr=%p, name=\"%s\", bo=%s",
1316 trace, bt_ctf_trace_common_get_name(trace),
1317 bt_ctf_byte_order_string(byte_order));
1318
1319end:
1320 return ret;
1321}
1322
1323BT_HIDDEN
1324int bt_ctf_trace_common_set_packet_header_field_type(struct bt_ctf_trace_common *trace,
1325 struct bt_ctf_field_type_common *packet_header_type)
1326{
1327 int ret = 0;
1328
1329 if (!trace) {
1330 BT_LOGW_STR("Invalid parameter: trace is NULL.");
1331 ret = -1;
1332 goto end;
1333 }
1334
1335 if (trace->frozen) {
1336 BT_LOGW("Invalid parameter: trace is frozen: "
1337 "addr=%p, name=\"%s\"",
1338 trace, bt_ctf_trace_common_get_name(trace));
1339 ret = -1;
1340 goto end;
1341 }
1342
1343 /* packet_header_type must be a structure. */
1344 if (packet_header_type &&
1345 packet_header_type->id != BT_CTF_FIELD_TYPE_ID_STRUCT) {
1346 BT_LOGW("Invalid parameter: packet header field type must be a structure field type if it exists: "
1347 "addr=%p, name=\"%s\", ft-addr=%p, ft-id=%s",
1348 trace, bt_ctf_trace_common_get_name(trace),
1349 packet_header_type,
1350 bt_ctf_field_type_id_string(packet_header_type->id));
1351 ret = -1;
1352 goto end;
1353 }
1354
c2606e2f
PP
1355 bt_ctf_object_put_ref(trace->packet_header_field_type);
1356 trace->packet_header_field_type = bt_ctf_object_get_ref(packet_header_type);
c9ecaa78 1357 BT_LOGT("Set trace's packet header field type: "
086dc475
PP
1358 "addr=%p, name=\"%s\", packet-context-ft-addr=%p",
1359 trace, bt_ctf_trace_common_get_name(trace), packet_header_type);
1360end:
1361 return ret;
1362}
1363
1364static
1365int64_t get_stream_class_count(void *element)
1366{
1367 return bt_ctf_trace_get_stream_class_count(
1368 (struct bt_ctf_trace *) element);
1369}
1370
1371static
1372void *get_stream_class(void *element, int i)
1373{
1374 return bt_ctf_trace_get_stream_class_by_index(
1375 (struct bt_ctf_trace *) element, i);
1376}
1377
1378static
1379int visit_stream_class(void *object, bt_ctf_visitor visitor,void *data)
1380{
1381 return bt_ctf_stream_class_visit(object, visitor, data);
1382}
1383
1384int bt_ctf_trace_visit(struct bt_ctf_trace *trace,
1385 bt_ctf_visitor visitor, void *data)
1386{
1387 int ret;
1388 struct bt_ctf_visitor_object obj = {
1389 .object = trace,
1390 .type = BT_CTF_VISITOR_OBJECT_TYPE_TRACE
1391 };
1392
1393 if (!trace) {
1394 BT_LOGW_STR("Invalid parameter: trace is NULL.");
1395 ret = -1;
1396 goto end;
1397 }
1398
1399 if (!visitor) {
1400 BT_LOGW_STR("Invalid parameter: visitor is NULL.");
1401 ret = -1;
1402 goto end;
1403 }
1404
c9ecaa78 1405 BT_LOGT("Visiting trace: addr=%p, name=\"%s\"",
086dc475 1406 trace, bt_ctf_trace_get_name(trace));
7b33a0e0 1407 ret = bt_ctf_visitor_helper(&obj, get_stream_class_count,
086dc475
PP
1408 get_stream_class, visit_stream_class, visitor, data);
1409end:
1410 return ret;
1411}
8deee039
PP
1412
1413static
c2606e2f 1414void bt_ctf_trace_destroy(struct bt_ctf_object *obj)
8deee039
PP
1415{
1416 struct bt_ctf_trace *trace = (void *) obj;
1417
1418 BT_LOGD("Destroying CTF writer trace object: addr=%p, name=\"%s\"",
1419 trace, bt_ctf_trace_get_name(trace));
086dc475 1420 bt_ctf_trace_common_finalize(BT_CTF_TO_COMMON(trace));
8deee039
PP
1421 g_free(trace);
1422}
1423
1424BT_HIDDEN
1425struct bt_ctf_trace *bt_ctf_trace_create(void)
1426{
1427 struct bt_ctf_trace *trace = NULL;
1428 int ret;
1429
1430 BT_LOGD_STR("Creating CTF writer trace object.");
1431 trace = g_new0(struct bt_ctf_trace, 1);
1432 if (!trace) {
1433 BT_LOGE_STR("Failed to allocate one CTF writer trace.");
1434 goto error;
1435 }
1436
086dc475 1437 ret = bt_ctf_trace_common_initialize(BT_CTF_TO_COMMON(trace),
8deee039
PP
1438 bt_ctf_trace_destroy);
1439 if (ret) {
086dc475 1440 /* bt_ctf_trace_common_initialize() logs errors */
8deee039
PP
1441 goto error;
1442 }
1443
1444 BT_LOGD("Created CTF writer trace object: addr=%p", trace);
1445 return trace;
1446
1447error:
c2606e2f 1448 BT_CTF_OBJECT_PUT_REF_AND_RESET(trace);
8deee039
PP
1449 return trace;
1450}
1451
d126826c 1452const uint8_t *bt_ctf_trace_get_uuid(struct bt_ctf_trace *trace)
8deee039 1453{
086dc475 1454 return bt_ctf_trace_common_get_uuid(BT_CTF_TO_COMMON(trace));
8deee039
PP
1455}
1456
1457int bt_ctf_trace_set_uuid(struct bt_ctf_trace *trace,
d126826c 1458 const uint8_t *uuid)
8deee039 1459{
086dc475 1460 return bt_ctf_trace_common_set_uuid(BT_CTF_TO_COMMON(trace), uuid);
8deee039
PP
1461}
1462
8deee039
PP
1463int bt_ctf_trace_set_environment_field_string(struct bt_ctf_trace *trace,
1464 const char *name, const char *value)
1465{
086dc475 1466 return bt_ctf_trace_common_set_environment_field_string(BT_CTF_TO_COMMON(trace),
8deee039
PP
1467 name, value);
1468}
1469
1470int bt_ctf_trace_set_environment_field_integer(
1471 struct bt_ctf_trace *trace, const char *name, int64_t value)
1472{
086dc475
PP
1473 return bt_ctf_trace_common_set_environment_field_integer(
1474 BT_CTF_TO_COMMON(trace), name, value);
8deee039
PP
1475}
1476
1477int64_t bt_ctf_trace_get_environment_field_count(struct bt_ctf_trace *trace)
1478{
086dc475 1479 return bt_ctf_trace_common_get_environment_field_count(BT_CTF_TO_COMMON(trace));
8deee039
PP
1480}
1481
1482const char *
1483bt_ctf_trace_get_environment_field_name_by_index(struct bt_ctf_trace *trace,
1484 uint64_t index)
1485{
086dc475
PP
1486 return bt_ctf_trace_common_get_environment_field_name_by_index(
1487 BT_CTF_TO_COMMON(trace), index);
8deee039
PP
1488}
1489
c2606e2f 1490struct bt_ctf_value *bt_ctf_trace_get_environment_field_value_by_index(
8deee039
PP
1491 struct bt_ctf_trace *trace, uint64_t index)
1492{
c2606e2f 1493 return bt_ctf_object_get_ref(bt_ctf_trace_common_borrow_environment_field_value_by_index(
086dc475 1494 BT_CTF_TO_COMMON(trace), index));
8deee039
PP
1495}
1496
c2606e2f 1497struct bt_ctf_value *bt_ctf_trace_get_environment_field_value_by_name(
8deee039
PP
1498 struct bt_ctf_trace *trace, const char *name)
1499{
c2606e2f 1500 return bt_ctf_object_get_ref(bt_ctf_trace_common_borrow_environment_field_value_by_name(
086dc475 1501 BT_CTF_TO_COMMON(trace), name));
8deee039
PP
1502}
1503
086dc475 1504BT_HIDDEN
8deee039
PP
1505int bt_ctf_trace_add_clock_class(struct bt_ctf_trace *trace,
1506 struct bt_ctf_clock_class *clock_class)
1507{
086dc475 1508 return bt_ctf_trace_common_add_clock_class(BT_CTF_TO_COMMON(trace),
8deee039
PP
1509 (void *) clock_class);
1510}
1511
086dc475 1512BT_HIDDEN
8deee039
PP
1513int64_t bt_ctf_trace_get_clock_class_count(struct bt_ctf_trace *trace)
1514{
086dc475 1515 return bt_ctf_trace_common_get_clock_class_count(BT_CTF_TO_COMMON(trace));
8deee039
PP
1516}
1517
086dc475 1518BT_HIDDEN
8deee039
PP
1519struct bt_ctf_clock_class *bt_ctf_trace_get_clock_class_by_index(
1520 struct bt_ctf_trace *trace, uint64_t index)
1521{
c2606e2f 1522 return bt_ctf_object_get_ref(bt_ctf_trace_common_borrow_clock_class_by_index(
086dc475 1523 BT_CTF_TO_COMMON(trace), index));
8deee039
PP
1524}
1525
1526static
086dc475
PP
1527int map_clock_classes_func(struct bt_ctf_stream_class_common *stream_class,
1528 struct bt_ctf_field_type_common *packet_context_type,
1529 struct bt_ctf_field_type_common *event_header_type)
8deee039
PP
1530{
1531 int ret = bt_ctf_stream_class_map_clock_class(
086dc475
PP
1532 BT_CTF_FROM_COMMON(stream_class),
1533 BT_CTF_FROM_COMMON(packet_context_type),
1534 BT_CTF_FROM_COMMON(event_header_type));
8deee039
PP
1535
1536 if (ret) {
1537 BT_LOGW_STR("Cannot automatically map selected stream class's field types to stream class's clock's class.");
1538 }
1539
1540 return ret;
1541}
1542
1543int bt_ctf_trace_add_stream_class(struct bt_ctf_trace *trace,
1544 struct bt_ctf_stream_class *stream_class)
1545{
1546 int ret = 0;
086dc475 1547 struct bt_ctf_clock_class *expected_clock_class = NULL;
8deee039
PP
1548
1549 if (!trace) {
1550 BT_LOGW_STR("Invalid parameter: trace is NULL.");
1551 ret = -1;
1552 goto end;
1553 }
1554
1555 if (!stream_class) {
1556 BT_LOGW_STR("Invalid parameter: stream class is NULL.");
1557 ret = -1;
1558 goto end;
1559 }
1560
1561 if (stream_class->clock) {
1562 struct bt_ctf_clock_class *stream_clock_class =
1563 stream_class->clock->clock_class;
1564
1565 /*
1566 * Make sure this clock was also added to the
1567 * trace (potentially through its CTF writer
1568 * owner).
1569 */
1570 size_t i;
1571
1572 for (i = 0; i < trace->common.clock_classes->len; i++) {
1573 if (trace->common.clock_classes->pdata[i] ==
1574 stream_clock_class) {
1575 /* Found! */
1576 break;
1577 }
1578 }
1579
1580 if (i == trace->common.clock_classes->len) {
1581 /* Not found */
1582 BT_LOGW("Stream class's clock's class is not part of the trace: "
1583 "clock-class-addr=%p, clock-class-name=\"%s\"",
1584 stream_clock_class,
086dc475 1585 bt_ctf_clock_class_get_name(stream_clock_class));
8deee039
PP
1586 ret = -1;
1587 goto end;
1588 }
1589
1590 if (stream_class->common.clock_class &&
1591 stream_class->common.clock_class !=
086dc475 1592 stream_class->clock->clock_class) {
8deee039
PP
1593 /*
1594 * Stream class already has an expected clock
1595 * class, but it does not match its clock's
1596 * class.
1597 */
1598 BT_LOGW("Invalid parameter: stream class's clock's "
1599 "class does not match stream class's "
1600 "expected clock class: "
1601 "stream-class-addr=%p, "
1602 "stream-class-id=%" PRId64 ", "
1603 "stream-class-name=\"%s\", "
1604 "expected-clock-class-addr=%p, "
1605 "expected-clock-class-name=\"%s\"",
1606 stream_class,
1607 bt_ctf_stream_class_get_id(stream_class),
1608 bt_ctf_stream_class_get_name(stream_class),
1609 stream_class->common.clock_class,
086dc475 1610 bt_ctf_clock_class_get_name(stream_class->common.clock_class));
8deee039
PP
1611 } else if (!stream_class->common.clock_class) {
1612 /*
1613 * Set expected clock class to stream class's
1614 * clock's class.
1615 */
086dc475 1616 expected_clock_class = stream_class->clock->clock_class;
8deee039
PP
1617 }
1618 }
1619
1620
086dc475
PP
1621 ret = bt_ctf_trace_common_add_stream_class(BT_CTF_TO_COMMON(trace),
1622 BT_CTF_TO_COMMON(stream_class),
1623 (bt_ctf_validation_flag_copy_field_type_func) bt_ctf_field_type_copy,
8deee039
PP
1624 expected_clock_class, map_clock_classes_func,
1625 false);
1626
1627end:
1628 return ret;
1629}
1630
1631int64_t bt_ctf_trace_get_stream_count(struct bt_ctf_trace *trace)
1632{
086dc475 1633 return bt_ctf_trace_common_get_stream_count(BT_CTF_TO_COMMON(trace));
8deee039
PP
1634}
1635
1636struct bt_ctf_stream *bt_ctf_trace_get_stream_by_index(
1637 struct bt_ctf_trace *trace, uint64_t index)
1638{
c2606e2f 1639 return bt_ctf_object_get_ref(bt_ctf_trace_common_borrow_stream_by_index(
086dc475 1640 BT_CTF_TO_COMMON(trace), index));
8deee039
PP
1641}
1642
1643int64_t bt_ctf_trace_get_stream_class_count(struct bt_ctf_trace *trace)
1644{
086dc475 1645 return bt_ctf_trace_common_get_stream_class_count(BT_CTF_TO_COMMON(trace));
8deee039
PP
1646}
1647
1648struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class_by_index(
1649 struct bt_ctf_trace *trace, uint64_t index)
1650{
c2606e2f 1651 return bt_ctf_object_get_ref(bt_ctf_trace_common_borrow_stream_class_by_index(
086dc475 1652 BT_CTF_TO_COMMON(trace), index));
8deee039
PP
1653}
1654
1655struct bt_ctf_stream_class *bt_ctf_trace_get_stream_class_by_id(
1656 struct bt_ctf_trace *trace, uint64_t id)
1657{
c2606e2f 1658 return bt_ctf_object_get_ref(bt_ctf_trace_common_borrow_stream_class_by_id(
086dc475 1659 BT_CTF_TO_COMMON(trace), id));
8deee039
PP
1660}
1661
086dc475 1662BT_HIDDEN
8deee039
PP
1663struct bt_ctf_clock_class *bt_ctf_trace_get_clock_class_by_name(
1664 struct bt_ctf_trace *trace, const char *name)
1665{
c2606e2f 1666 return bt_ctf_object_get_ref(
086dc475 1667 bt_ctf_trace_common_borrow_clock_class_by_name(BT_CTF_TO_COMMON(trace),
8deee039
PP
1668 name));
1669}
1670
1671static
1672int append_trace_metadata(struct bt_ctf_trace *trace,
1673 struct metadata_context *context)
1674{
d126826c 1675 uint8_t *uuid = trace->common.uuid;
8deee039
PP
1676 int ret = 0;
1677
086dc475
PP
1678 if (trace->common.native_byte_order == BT_CTF_BYTE_ORDER_NATIVE ||
1679 trace->common.native_byte_order == BT_CTF_BYTE_ORDER_UNSPECIFIED) {
8deee039
PP
1680 BT_LOGW("Invalid parameter: trace's byte order cannot be BT_CTF_BYTE_ORDER_NATIVE or BT_CTF_BYTE_ORDER_UNSPECIFIED at this point; "
1681 "set it with bt_ctf_trace_set_native_byte_order(): "
1682 "addr=%p, name=\"%s\"",
1683 trace, bt_ctf_trace_get_name(trace));
1684 ret = -1;
1685 goto end;
1686 }
1687
1688 g_string_append(context->string, "trace {\n");
1689 g_string_append(context->string, "\tmajor = 1;\n");
1690 g_string_append(context->string, "\tminor = 8;\n");
ec4a3354 1691 BT_ASSERT_DBG(trace->common.native_byte_order == BT_CTF_BYTE_ORDER_LITTLE_ENDIAN ||
086dc475
PP
1692 trace->common.native_byte_order == BT_CTF_BYTE_ORDER_BIG_ENDIAN ||
1693 trace->common.native_byte_order == BT_CTF_BYTE_ORDER_NETWORK);
8deee039
PP
1694
1695 if (trace->common.uuid_set) {
1696 g_string_append_printf(context->string,
d126826c
MJ
1697 "\tuuid = \"" BT_UUID_FMT "\";\n",
1698 BT_UUID_FMT_VALUES(uuid));
8deee039
PP
1699 }
1700
1701 g_string_append_printf(context->string, "\tbyte_order = %s;\n",
086dc475 1702 bt_ctf_get_byte_order_string(trace->common.native_byte_order));
8deee039
PP
1703
1704 if (trace->common.packet_header_field_type) {
1705 g_string_append(context->string, "\tpacket.header := ");
1706 context->current_indentation_level++;
1707 g_string_assign(context->field_name, "");
1708 BT_LOGD_STR("Serializing trace's packet header field type's metadata.");
1709 ret = bt_ctf_field_type_serialize_recursive(
1710 (void *) trace->common.packet_header_field_type,
1711 context);
1712 if (ret) {
1713 goto end;
1714 }
1715 context->current_indentation_level--;
1716 }
1717
1718 g_string_append(context->string, ";\n};\n\n");
1719end:
1720 return ret;
1721}
1722
1723static
1724void append_env_metadata(struct bt_ctf_trace *trace,
1725 struct metadata_context *context)
1726{
1727 int64_t i;
1728 int64_t env_size;
1729
086dc475 1730 env_size = bt_ctf_attributes_get_count(trace->common.environment);
8deee039
PP
1731 if (env_size <= 0) {
1732 return;
1733 }
1734
1735 g_string_append(context->string, "env {\n");
1736
1737 for (i = 0; i < env_size; i++) {
c2606e2f 1738 struct bt_ctf_private_value *env_field_value_obj = NULL;
8deee039
PP
1739 const char *entry_name;
1740
086dc475 1741 entry_name = bt_ctf_attributes_get_field_name(
8deee039 1742 trace->common.environment, i);
086dc475 1743 env_field_value_obj = bt_ctf_attributes_borrow_field_value(
8deee039
PP
1744 trace->common.environment, i);
1745
ec4a3354
PP
1746 BT_ASSERT_DBG(entry_name);
1747 BT_ASSERT_DBG(env_field_value_obj);
8deee039 1748
c2606e2f
PP
1749 switch (bt_ctf_value_get_type(
1750 bt_ctf_private_value_as_value(env_field_value_obj))) {
1751 case BT_CTF_VALUE_TYPE_INTEGER:
8deee039 1752 {
8deee039
PP
1753 int64_t int_value;
1754
c2606e2f
PP
1755 int_value = bt_ctf_value_integer_get(
1756 bt_ctf_private_value_as_value(
b5cdc106 1757 env_field_value_obj));
8deee039
PP
1758 g_string_append_printf(context->string,
1759 "\t%s = %" PRId64 ";\n", entry_name,
1760 int_value);
1761 break;
1762 }
c2606e2f 1763 case BT_CTF_VALUE_TYPE_STRING:
8deee039 1764 {
8deee039
PP
1765 const char *str_value;
1766 char *escaped_str = NULL;
1767
c2606e2f
PP
1768 str_value = bt_ctf_value_string_get(
1769 bt_ctf_private_value_as_value(
b5cdc106 1770 env_field_value_obj));
8deee039
PP
1771 escaped_str = g_strescape(str_value, NULL);
1772 if (!escaped_str) {
1773 BT_LOGE("Cannot escape string: string=\"%s\"",
1774 str_value);
5fe68922 1775 continue;
8deee039
PP
1776 }
1777
1778 g_string_append_printf(context->string,
1779 "\t%s = \"%s\";\n", entry_name, escaped_str);
1780 free(escaped_str);
1781 break;
1782 }
1783 default:
5fe68922 1784 continue;
8deee039 1785 }
8deee039
PP
1786 }
1787
1788 g_string_append(context->string, "};\n\n");
1789}
1790
1791char *bt_ctf_trace_get_metadata_string(struct bt_ctf_trace *trace)
1792{
1793 char *metadata = NULL;
1794 struct metadata_context *context = NULL;
1795 int err = 0;
1796 size_t i;
1797
1798 if (!trace) {
1799 BT_LOGW_STR("Invalid parameter: trace is NULL.");
1800 goto end;
1801 }
1802
1803 context = g_new0(struct metadata_context, 1);
1804 if (!context) {
1805 BT_LOGE_STR("Failed to allocate one metadata context.");
1806 goto end;
1807 }
1808
1809 context->field_name = g_string_sized_new(DEFAULT_IDENTIFIER_SIZE);
1810 context->string = g_string_sized_new(DEFAULT_METADATA_STRING_SIZE);
1811 g_string_append(context->string, "/* CTF 1.8 */\n\n");
1812 if (append_trace_metadata(trace, context)) {
1813 /* append_trace_metadata() logs errors */
1814 goto error;
1815 }
1816 append_env_metadata(trace, context);
1817 g_ptr_array_foreach(trace->common.clock_classes,
1818 (GFunc) bt_ctf_clock_class_serialize, context);
1819
1820 for (i = 0; i < trace->common.stream_classes->len; i++) {
086dc475 1821 /* bt_ctf_stream_class_serialize() logs details */
8deee039
PP
1822 err = bt_ctf_stream_class_serialize(
1823 trace->common.stream_classes->pdata[i], context);
1824 if (err) {
086dc475 1825 /* bt_ctf_stream_class_serialize() logs errors */
8deee039
PP
1826 goto error;
1827 }
1828 }
1829
1830 metadata = context->string->str;
1831
1832error:
1833 g_string_free(context->string, err ? TRUE : FALSE);
1834 g_string_free(context->field_name, TRUE);
1835 g_free(context);
1836
1837end:
1838 return metadata;
1839}
1840
1841enum bt_ctf_byte_order bt_ctf_trace_get_native_byte_order(
1842 struct bt_ctf_trace *trace)
1843{
086dc475 1844 return (int) bt_ctf_trace_common_get_native_byte_order(BT_CTF_TO_COMMON(trace));
8deee039
PP
1845}
1846
1847int bt_ctf_trace_set_native_byte_order(struct bt_ctf_trace *trace,
1848 enum bt_ctf_byte_order byte_order)
1849{
086dc475 1850 return bt_ctf_trace_common_set_native_byte_order(BT_CTF_TO_COMMON(trace),
8deee039
PP
1851 (int) byte_order, false);
1852}
1853
1854struct bt_ctf_field_type *bt_ctf_trace_get_packet_header_field_type(
1855 struct bt_ctf_trace *trace)
1856{
c2606e2f 1857 return bt_ctf_object_get_ref(bt_ctf_trace_common_borrow_packet_header_field_type(
086dc475 1858 BT_CTF_TO_COMMON(trace)));
8deee039
PP
1859}
1860
1861int bt_ctf_trace_set_packet_header_field_type(struct bt_ctf_trace *trace,
1862 struct bt_ctf_field_type *packet_header_type)
1863{
086dc475 1864 return bt_ctf_trace_common_set_packet_header_field_type(BT_CTF_TO_COMMON(trace),
8deee039
PP
1865 (void *) packet_header_type);
1866}
1867
1868const char *bt_ctf_trace_get_name(struct bt_ctf_trace *trace)
1869{
086dc475 1870 return bt_ctf_trace_common_get_name(BT_CTF_TO_COMMON(trace));
8deee039 1871}
This page took 0.185473 seconds and 4 git commands to generate.