Commit | Line | Data |
---|---|---|
7b33a0e0 PP |
1 | /* |
2 | * Copyright 2018 - Philippe Proulx <pproulx@efficios.com> | |
3 | * | |
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: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included in | |
12 | * all copies or substantial portions of the Software. | |
13 | */ | |
14 | ||
15 | #define BT_LOG_TAG "PLUGIN-CTF-METADATA-META-UPDATE-TEXT-ARRAY-SEQ" | |
16 | #include "logging.h" | |
17 | ||
71c5da58 MJ |
18 | #include <babeltrace2/babeltrace.h> |
19 | #include <babeltrace2/babeltrace-internal.h> | |
20 | #include <babeltrace2/assert-internal.h> | |
7b33a0e0 PP |
21 | #include <glib.h> |
22 | #include <stdint.h> | |
23 | #include <string.h> | |
24 | #include <inttypes.h> | |
25 | ||
26 | #include "ctf-meta-visitors.h" | |
27 | ||
28 | static inline | |
939190b3 | 29 | int set_text_array_sequence_field_class(struct ctf_field_class *fc) |
7b33a0e0 PP |
30 | { |
31 | int ret = 0; | |
32 | uint64_t i; | |
33 | ||
939190b3 | 34 | if (!fc) { |
7b33a0e0 PP |
35 | goto end; |
36 | } | |
37 | ||
af0c18e3 PP |
38 | switch (fc->type) { |
39 | case CTF_FIELD_CLASS_TYPE_STRUCT: | |
7b33a0e0 | 40 | { |
939190b3 | 41 | struct ctf_field_class_struct *struct_fc = (void *) fc; |
7b33a0e0 | 42 | |
939190b3 PP |
43 | for (i = 0; i < struct_fc->members->len; i++) { |
44 | struct ctf_named_field_class *named_fc = | |
45 | ctf_field_class_struct_borrow_member_by_index( | |
46 | struct_fc, i); | |
7b33a0e0 | 47 | |
939190b3 | 48 | ret = set_text_array_sequence_field_class(named_fc->fc); |
7b33a0e0 PP |
49 | if (ret) { |
50 | goto end; | |
51 | } | |
52 | } | |
53 | ||
54 | break; | |
55 | } | |
af0c18e3 | 56 | case CTF_FIELD_CLASS_TYPE_VARIANT: |
7b33a0e0 | 57 | { |
939190b3 | 58 | struct ctf_field_class_variant *var_fc = (void *) fc; |
7b33a0e0 | 59 | |
939190b3 PP |
60 | for (i = 0; i < var_fc->options->len; i++) { |
61 | struct ctf_named_field_class *named_fc = | |
62 | ctf_field_class_variant_borrow_option_by_index( | |
63 | var_fc, i); | |
7b33a0e0 | 64 | |
939190b3 | 65 | ret = set_text_array_sequence_field_class(named_fc->fc); |
7b33a0e0 PP |
66 | if (ret) { |
67 | goto end; | |
68 | } | |
69 | } | |
70 | ||
71 | break; | |
72 | } | |
af0c18e3 PP |
73 | case CTF_FIELD_CLASS_TYPE_ARRAY: |
74 | case CTF_FIELD_CLASS_TYPE_SEQUENCE: | |
7b33a0e0 | 75 | { |
939190b3 | 76 | struct ctf_field_class_array_base *array_fc = (void *) fc; |
7b33a0e0 | 77 | |
af0c18e3 PP |
78 | if (array_fc->elem_fc->type == CTF_FIELD_CLASS_TYPE_INT || |
79 | array_fc->elem_fc->type == CTF_FIELD_CLASS_TYPE_ENUM) { | |
939190b3 PP |
80 | struct ctf_field_class_int *int_fc = |
81 | (void *) array_fc->elem_fc; | |
7b33a0e0 | 82 | |
939190b3 PP |
83 | if (int_fc->base.base.alignment == 8 && |
84 | int_fc->base.size == 8 && | |
85 | int_fc->encoding == CTF_ENCODING_UTF8) { | |
86 | array_fc->is_text = true; | |
7b33a0e0 PP |
87 | |
88 | /* | |
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. | |
94 | */ | |
939190b3 | 95 | int_fc->is_signed = false; |
7b33a0e0 PP |
96 | } |
97 | } | |
98 | ||
939190b3 | 99 | ret = set_text_array_sequence_field_class(array_fc->elem_fc); |
7b33a0e0 PP |
100 | if (ret) { |
101 | goto end; | |
102 | } | |
103 | ||
104 | break; | |
105 | } | |
106 | default: | |
107 | break; | |
108 | } | |
109 | ||
110 | end: | |
111 | return ret; | |
112 | } | |
113 | ||
114 | BT_HIDDEN | |
115 | int ctf_trace_class_update_text_array_sequence(struct ctf_trace_class *ctf_tc) | |
116 | { | |
117 | int ret = 0; | |
118 | uint64_t i; | |
119 | ||
120 | if (!ctf_tc->is_translated) { | |
939190b3 PP |
121 | ret = set_text_array_sequence_field_class( |
122 | ctf_tc->packet_header_fc); | |
7b33a0e0 PP |
123 | if (ret) { |
124 | goto end; | |
125 | } | |
126 | } | |
127 | ||
128 | for (i = 0; i < ctf_tc->stream_classes->len; i++) { | |
129 | struct ctf_stream_class *sc = ctf_tc->stream_classes->pdata[i]; | |
130 | uint64_t j; | |
131 | ||
132 | if (!sc->is_translated) { | |
939190b3 PP |
133 | ret = set_text_array_sequence_field_class( |
134 | sc->packet_context_fc); | |
7b33a0e0 PP |
135 | if (ret) { |
136 | goto end; | |
137 | } | |
138 | ||
939190b3 PP |
139 | ret = set_text_array_sequence_field_class( |
140 | sc->event_header_fc); | |
7b33a0e0 PP |
141 | if (ret) { |
142 | goto end; | |
143 | } | |
144 | ||
939190b3 PP |
145 | ret = set_text_array_sequence_field_class( |
146 | sc->event_common_context_fc); | |
7b33a0e0 PP |
147 | if (ret) { |
148 | goto end; | |
149 | } | |
150 | } | |
151 | ||
152 | for (j = 0; j < sc->event_classes->len; j++) { | |
153 | struct ctf_event_class *ec = | |
154 | sc->event_classes->pdata[j]; | |
155 | ||
156 | if (ec->is_translated) { | |
157 | continue; | |
158 | } | |
159 | ||
939190b3 PP |
160 | ret = set_text_array_sequence_field_class( |
161 | ec->spec_context_fc); | |
7b33a0e0 PP |
162 | if (ret) { |
163 | goto end; | |
164 | } | |
165 | ||
939190b3 PP |
166 | ret = set_text_array_sequence_field_class( |
167 | ec->payload_fc); | |
7b33a0e0 PP |
168 | if (ret) { |
169 | goto end; | |
170 | } | |
171 | } | |
172 | } | |
173 | ||
174 | end: | |
175 | return ret; | |
176 | } |