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 | 16 | |
4164020e | 17 | static inline int set_text_array_sequence_field_class(struct ctf_field_class *fc) |
44c440bc | 18 | { |
4164020e SM |
19 | int ret = 0; |
20 | uint64_t i; | |
21 | ||
22 | if (!fc) { | |
23 | goto end; | |
24 | } | |
25 | ||
26 | switch (fc->type) { | |
27 | case CTF_FIELD_CLASS_TYPE_STRUCT: | |
28 | { | |
29 | struct ctf_field_class_struct *struct_fc = ctf_field_class_as_struct(fc); | |
30 | ||
31 | for (i = 0; i < struct_fc->members->len; i++) { | |
32 | struct ctf_named_field_class *named_fc = | |
33 | ctf_field_class_struct_borrow_member_by_index(struct_fc, i); | |
34 | ||
35 | ret = set_text_array_sequence_field_class(named_fc->fc); | |
36 | if (ret) { | |
37 | goto end; | |
38 | } | |
39 | } | |
40 | ||
41 | break; | |
42 | } | |
43 | case CTF_FIELD_CLASS_TYPE_VARIANT: | |
44 | { | |
45 | struct ctf_field_class_variant *var_fc = ctf_field_class_as_variant(fc); | |
46 | ||
47 | for (i = 0; i < var_fc->options->len; i++) { | |
48 | struct ctf_named_field_class *named_fc = | |
49 | ctf_field_class_variant_borrow_option_by_index(var_fc, i); | |
50 | ||
51 | ret = set_text_array_sequence_field_class(named_fc->fc); | |
52 | if (ret) { | |
53 | goto end; | |
54 | } | |
55 | } | |
56 | ||
57 | break; | |
58 | } | |
59 | case CTF_FIELD_CLASS_TYPE_ARRAY: | |
60 | case CTF_FIELD_CLASS_TYPE_SEQUENCE: | |
61 | { | |
62 | struct ctf_field_class_array_base *array_fc = ctf_field_class_as_array_base(fc); | |
63 | ||
64 | if (array_fc->elem_fc->type == CTF_FIELD_CLASS_TYPE_INT || | |
65 | array_fc->elem_fc->type == CTF_FIELD_CLASS_TYPE_ENUM) { | |
66 | struct ctf_field_class_int *int_fc = ctf_field_class_as_int(array_fc->elem_fc); | |
67 | ||
68 | if (int_fc->base.base.alignment == 8 && int_fc->base.size == 8 && | |
69 | int_fc->encoding == CTF_ENCODING_UTF8) { | |
70 | array_fc->is_text = true; | |
71 | ||
72 | /* | |
73 | * Force integer element to be unsigned; | |
74 | * this makes the decoder enter a single | |
75 | * path when reading a text | |
76 | * array/sequence and we can safely | |
77 | * decode bytes as characters anyway. | |
78 | */ | |
79 | int_fc->is_signed = false; | |
80 | } | |
81 | } | |
82 | ||
83 | ret = set_text_array_sequence_field_class(array_fc->elem_fc); | |
84 | if (ret) { | |
85 | goto end; | |
86 | } | |
87 | ||
88 | break; | |
89 | } | |
90 | default: | |
91 | break; | |
92 | } | |
44c440bc PP |
93 | |
94 | end: | |
4164020e | 95 | return ret; |
44c440bc PP |
96 | } |
97 | ||
44c440bc PP |
98 | int ctf_trace_class_update_text_array_sequence(struct ctf_trace_class *ctf_tc) |
99 | { | |
4164020e SM |
100 | int ret = 0; |
101 | uint64_t i; | |
102 | ||
103 | if (!ctf_tc->is_translated) { | |
104 | ret = set_text_array_sequence_field_class(ctf_tc->packet_header_fc); | |
105 | if (ret) { | |
106 | goto end; | |
107 | } | |
108 | } | |
109 | ||
110 | for (i = 0; i < ctf_tc->stream_classes->len; i++) { | |
111 | ctf_stream_class *sc = (ctf_stream_class *) ctf_tc->stream_classes->pdata[i]; | |
112 | uint64_t j; | |
113 | ||
114 | if (!sc->is_translated) { | |
115 | ret = set_text_array_sequence_field_class(sc->packet_context_fc); | |
116 | if (ret) { | |
117 | goto end; | |
118 | } | |
119 | ||
120 | ret = set_text_array_sequence_field_class(sc->event_header_fc); | |
121 | if (ret) { | |
122 | goto end; | |
123 | } | |
124 | ||
125 | ret = set_text_array_sequence_field_class(sc->event_common_context_fc); | |
126 | if (ret) { | |
127 | goto end; | |
128 | } | |
129 | } | |
130 | ||
131 | for (j = 0; j < sc->event_classes->len; j++) { | |
132 | struct ctf_event_class *ec = (ctf_event_class *) sc->event_classes->pdata[j]; | |
133 | ||
134 | if (ec->is_translated) { | |
135 | continue; | |
136 | } | |
137 | ||
138 | ret = set_text_array_sequence_field_class(ec->spec_context_fc); | |
139 | if (ret) { | |
140 | goto end; | |
141 | } | |
142 | ||
143 | ret = set_text_array_sequence_field_class(ec->payload_fc); | |
144 | if (ret) { | |
145 | goto end; | |
146 | } | |
147 | } | |
148 | } | |
44c440bc PP |
149 | |
150 | end: | |
4164020e | 151 | return ret; |
44c440bc | 152 | } |