Commit | Line | Data |
---|---|---|
44c440bc | 1 | /* |
0235b0db | 2 | * SPDX-License-Identifier: MIT |
44c440bc | 3 | * |
0235b0db | 4 | * Copyright 2018 Philippe Proulx <pproulx@efficios.com> |
44c440bc PP |
5 | */ |
6 | ||
3fadfbc0 | 7 | #include <babeltrace2/babeltrace.h> |
91d81473 | 8 | #include "common/macros.h" |
578e048b | 9 | #include "common/assert.h" |
44c440bc PP |
10 | #include <glib.h> |
11 | #include <stdint.h> | |
12 | #include <string.h> | |
13 | #include <inttypes.h> | |
14 | ||
087cd0f5 | 15 | #include "ctf-meta-visitors.hpp" |
44c440bc PP |
16 | |
17 | static inline | |
5cd6d0e5 | 18 | int set_text_array_sequence_field_class(struct ctf_field_class *fc) |
44c440bc PP |
19 | { |
20 | int ret = 0; | |
21 | uint64_t i; | |
22 | ||
5cd6d0e5 | 23 | if (!fc) { |
44c440bc PP |
24 | goto end; |
25 | } | |
26 | ||
864cad70 PP |
27 | switch (fc->type) { |
28 | case CTF_FIELD_CLASS_TYPE_STRUCT: | |
44c440bc | 29 | { |
087cd0f5 | 30 | struct ctf_field_class_struct *struct_fc = ctf_field_class_as_struct(fc); |
44c440bc | 31 | |
5cd6d0e5 PP |
32 | for (i = 0; i < struct_fc->members->len; i++) { |
33 | struct ctf_named_field_class *named_fc = | |
34 | ctf_field_class_struct_borrow_member_by_index( | |
35 | struct_fc, i); | |
44c440bc | 36 | |
5cd6d0e5 | 37 | ret = set_text_array_sequence_field_class(named_fc->fc); |
44c440bc PP |
38 | if (ret) { |
39 | goto end; | |
40 | } | |
41 | } | |
42 | ||
43 | break; | |
44 | } | |
864cad70 | 45 | case CTF_FIELD_CLASS_TYPE_VARIANT: |
44c440bc | 46 | { |
087cd0f5 | 47 | struct ctf_field_class_variant *var_fc = ctf_field_class_as_variant(fc); |
44c440bc | 48 | |
5cd6d0e5 PP |
49 | for (i = 0; i < var_fc->options->len; i++) { |
50 | struct ctf_named_field_class *named_fc = | |
51 | ctf_field_class_variant_borrow_option_by_index( | |
52 | var_fc, i); | |
44c440bc | 53 | |
5cd6d0e5 | 54 | ret = set_text_array_sequence_field_class(named_fc->fc); |
44c440bc PP |
55 | if (ret) { |
56 | goto end; | |
57 | } | |
58 | } | |
59 | ||
60 | break; | |
61 | } | |
864cad70 PP |
62 | case CTF_FIELD_CLASS_TYPE_ARRAY: |
63 | case CTF_FIELD_CLASS_TYPE_SEQUENCE: | |
44c440bc | 64 | { |
087cd0f5 | 65 | struct ctf_field_class_array_base *array_fc = ctf_field_class_as_array_base(fc); |
44c440bc | 66 | |
864cad70 PP |
67 | if (array_fc->elem_fc->type == CTF_FIELD_CLASS_TYPE_INT || |
68 | array_fc->elem_fc->type == CTF_FIELD_CLASS_TYPE_ENUM) { | |
5cd6d0e5 | 69 | struct ctf_field_class_int *int_fc = |
087cd0f5 | 70 | ctf_field_class_as_int(array_fc->elem_fc); |
44c440bc | 71 | |
5cd6d0e5 PP |
72 | if (int_fc->base.base.alignment == 8 && |
73 | int_fc->base.size == 8 && | |
74 | int_fc->encoding == CTF_ENCODING_UTF8) { | |
75 | array_fc->is_text = true; | |
44c440bc PP |
76 | |
77 | /* | |
78 | * Force integer element to be unsigned; | |
79 | * this makes the decoder enter a single | |
80 | * path when reading a text | |
81 | * array/sequence and we can safely | |
82 | * decode bytes as characters anyway. | |
83 | */ | |
5cd6d0e5 | 84 | int_fc->is_signed = false; |
44c440bc PP |
85 | } |
86 | } | |
87 | ||
5cd6d0e5 | 88 | ret = set_text_array_sequence_field_class(array_fc->elem_fc); |
44c440bc PP |
89 | if (ret) { |
90 | goto end; | |
91 | } | |
92 | ||
93 | break; | |
94 | } | |
95 | default: | |
96 | break; | |
97 | } | |
98 | ||
99 | end: | |
100 | return ret; | |
101 | } | |
102 | ||
103 | BT_HIDDEN | |
104 | int ctf_trace_class_update_text_array_sequence(struct ctf_trace_class *ctf_tc) | |
105 | { | |
106 | int ret = 0; | |
107 | uint64_t i; | |
108 | ||
109 | if (!ctf_tc->is_translated) { | |
5cd6d0e5 PP |
110 | ret = set_text_array_sequence_field_class( |
111 | ctf_tc->packet_header_fc); | |
44c440bc PP |
112 | if (ret) { |
113 | goto end; | |
114 | } | |
115 | } | |
116 | ||
117 | for (i = 0; i < ctf_tc->stream_classes->len; i++) { | |
087cd0f5 | 118 | ctf_stream_class *sc = (ctf_stream_class *) ctf_tc->stream_classes->pdata[i]; |
44c440bc PP |
119 | uint64_t j; |
120 | ||
121 | if (!sc->is_translated) { | |
5cd6d0e5 PP |
122 | ret = set_text_array_sequence_field_class( |
123 | sc->packet_context_fc); | |
44c440bc PP |
124 | if (ret) { |
125 | goto end; | |
126 | } | |
127 | ||
5cd6d0e5 PP |
128 | ret = set_text_array_sequence_field_class( |
129 | sc->event_header_fc); | |
44c440bc PP |
130 | if (ret) { |
131 | goto end; | |
132 | } | |
133 | ||
5cd6d0e5 PP |
134 | ret = set_text_array_sequence_field_class( |
135 | sc->event_common_context_fc); | |
44c440bc PP |
136 | if (ret) { |
137 | goto end; | |
138 | } | |
139 | } | |
140 | ||
141 | for (j = 0; j < sc->event_classes->len; j++) { | |
142 | struct ctf_event_class *ec = | |
087cd0f5 | 143 | (ctf_event_class *) sc->event_classes->pdata[j]; |
44c440bc PP |
144 | |
145 | if (ec->is_translated) { | |
146 | continue; | |
147 | } | |
148 | ||
5cd6d0e5 PP |
149 | ret = set_text_array_sequence_field_class( |
150 | ec->spec_context_fc); | |
44c440bc PP |
151 | if (ret) { |
152 | goto end; | |
153 | } | |
154 | ||
5cd6d0e5 PP |
155 | ret = set_text_array_sequence_field_class( |
156 | ec->payload_fc); | |
44c440bc PP |
157 | if (ret) { |
158 | goto end; | |
159 | } | |
160 | } | |
161 | } | |
162 | ||
163 | end: | |
164 | return ret; | |
165 | } |