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 #define BT_LOG_TAG "PLUGIN-CTF-METADATA-META-UPDATE-TEXT-ARRAY-SEQ"
18 #include <babeltrace/babeltrace.h>
19 #include <babeltrace/babeltrace-internal.h>
20 #include <babeltrace/assert-internal.h>
26 #include "ctf-meta-visitors.h"
29 int set_text_array_sequence_field_type(struct ctf_field_type
*ft
)
39 case CTF_FIELD_TYPE_ID_STRUCT
:
41 struct ctf_field_type_struct
*struct_ft
= (void *) ft
;
43 for (i
= 0; i
< struct_ft
->members
->len
; i
++) {
44 struct ctf_named_field_type
*named_ft
=
45 ctf_field_type_struct_borrow_member_by_index(
48 ret
= set_text_array_sequence_field_type(named_ft
->ft
);
56 case CTF_FIELD_TYPE_ID_VARIANT
:
58 struct ctf_field_type_variant
*var_ft
= (void *) ft
;
60 for (i
= 0; i
< var_ft
->options
->len
; i
++) {
61 struct ctf_named_field_type
*named_ft
=
62 ctf_field_type_variant_borrow_option_by_index(
65 ret
= set_text_array_sequence_field_type(named_ft
->ft
);
73 case CTF_FIELD_TYPE_ID_ARRAY
:
74 case CTF_FIELD_TYPE_ID_SEQUENCE
:
76 struct ctf_field_type_array_base
*array_ft
= (void *) ft
;
78 if (array_ft
->elem_ft
->id
== CTF_FIELD_TYPE_ID_INT
||
79 array_ft
->elem_ft
->id
== CTF_FIELD_TYPE_ID_ENUM
) {
80 struct ctf_field_type_int
*int_ft
=
81 (void *) array_ft
->elem_ft
;
83 if (int_ft
->base
.base
.alignment
== 8 &&
84 int_ft
->base
.size
== 8 &&
85 int_ft
->encoding
== CTF_ENCODING_UTF8
) {
86 array_ft
->is_text
= true;
89 * Force integer element to be unsigned;
90 * this makes the decoder enter a single
91 * path when reading a text
92 * array/sequence and we can safely
93 * decode bytes as characters anyway.
95 int_ft
->is_signed
= false;
99 ret
= set_text_array_sequence_field_type(array_ft
->elem_ft
);
115 int ctf_trace_class_update_text_array_sequence(struct ctf_trace_class
*ctf_tc
)
120 if (!ctf_tc
->is_translated
) {
121 ret
= set_text_array_sequence_field_type(
122 ctf_tc
->packet_header_ft
);
128 for (i
= 0; i
< ctf_tc
->stream_classes
->len
; i
++) {
129 struct ctf_stream_class
*sc
= ctf_tc
->stream_classes
->pdata
[i
];
132 if (!sc
->is_translated
) {
133 ret
= set_text_array_sequence_field_type(
134 sc
->packet_context_ft
);
139 ret
= set_text_array_sequence_field_type(
140 sc
->event_header_ft
);
145 ret
= set_text_array_sequence_field_type(
146 sc
->event_common_context_ft
);
152 for (j
= 0; j
< sc
->event_classes
->len
; j
++) {
153 struct ctf_event_class
*ec
=
154 sc
->event_classes
->pdata
[j
];
156 if (ec
->is_translated
) {
160 ret
= set_text_array_sequence_field_type(
161 ec
->spec_context_ft
);
166 ret
= set_text_array_sequence_field_type(