2 * Copyright 2018 - Philippe Proulx <pproulx@efficios.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
15 #include <babeltrace2/babeltrace.h>
16 #include "common/macros.h"
17 #include "common/assert.h"
23 #include "ctf-meta-visitors.h"
26 int set_text_array_sequence_field_class(struct ctf_field_class
*fc
)
36 case CTF_FIELD_CLASS_TYPE_STRUCT
:
38 struct ctf_field_class_struct
*struct_fc
= (void *) fc
;
40 for (i
= 0; i
< struct_fc
->members
->len
; i
++) {
41 struct ctf_named_field_class
*named_fc
=
42 ctf_field_class_struct_borrow_member_by_index(
45 ret
= set_text_array_sequence_field_class(named_fc
->fc
);
53 case CTF_FIELD_CLASS_TYPE_VARIANT
:
55 struct ctf_field_class_variant
*var_fc
= (void *) fc
;
57 for (i
= 0; i
< var_fc
->options
->len
; i
++) {
58 struct ctf_named_field_class
*named_fc
=
59 ctf_field_class_variant_borrow_option_by_index(
62 ret
= set_text_array_sequence_field_class(named_fc
->fc
);
70 case CTF_FIELD_CLASS_TYPE_ARRAY
:
71 case CTF_FIELD_CLASS_TYPE_SEQUENCE
:
73 struct ctf_field_class_array_base
*array_fc
= (void *) fc
;
75 if (array_fc
->elem_fc
->type
== CTF_FIELD_CLASS_TYPE_INT
||
76 array_fc
->elem_fc
->type
== CTF_FIELD_CLASS_TYPE_ENUM
) {
77 struct ctf_field_class_int
*int_fc
=
78 (void *) array_fc
->elem_fc
;
80 if (int_fc
->base
.base
.alignment
== 8 &&
81 int_fc
->base
.size
== 8 &&
82 int_fc
->encoding
== CTF_ENCODING_UTF8
) {
83 array_fc
->is_text
= true;
86 * Force integer element to be unsigned;
87 * this makes the decoder enter a single
88 * path when reading a text
89 * array/sequence and we can safely
90 * decode bytes as characters anyway.
92 int_fc
->is_signed
= false;
96 ret
= set_text_array_sequence_field_class(array_fc
->elem_fc
);
112 int ctf_trace_class_update_text_array_sequence(struct ctf_trace_class
*ctf_tc
)
117 if (!ctf_tc
->is_translated
) {
118 ret
= set_text_array_sequence_field_class(
119 ctf_tc
->packet_header_fc
);
125 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
126 struct ctf_stream_class
*sc
= ctf_tc
->stream_classes
->pdata
[i
];
129 if (!sc
->is_translated
) {
130 ret
= set_text_array_sequence_field_class(
131 sc
->packet_context_fc
);
136 ret
= set_text_array_sequence_field_class(
137 sc
->event_header_fc
);
142 ret
= set_text_array_sequence_field_class(
143 sc
->event_common_context_fc
);
149 for (j
= 0; j
< sc
->event_classes
->len
; j
++) {
150 struct ctf_event_class
*ec
=
151 sc
->event_classes
->pdata
[j
];
153 if (ec
->is_translated
) {
157 ret
= set_text_array_sequence_field_class(
158 ec
->spec_context_fc
);
163 ret
= set_text_array_sequence_field_class(