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