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 PP |
7 | #include <stdint.h> |
8 | #include <string.h> | |
c802cacb | 9 | |
c802cacb | 10 | #include "common/assert.h" |
44c440bc | 11 | |
087cd0f5 | 12 | #include "ctf-meta-visitors.hpp" |
44c440bc | 13 | |
4164020e SM |
14 | static int update_field_class_stored_value_index(struct ctf_field_class *fc, |
15 | struct ctf_trace_class *tc, | |
16 | struct ctf_stream_class *sc, | |
17 | struct ctf_event_class *ec) | |
44c440bc | 18 | { |
4164020e SM |
19 | int ret = 0; |
20 | uint64_t i; | |
21 | struct ctf_field_path *field_path = NULL; | |
22 | struct ctf_field_class_int *tgt_fc = NULL; | |
23 | uint64_t *stored_value_index = NULL; | |
24 | ||
25 | if (!fc) { | |
26 | goto end; | |
27 | } | |
28 | ||
29 | switch (fc->type) { | |
30 | case CTF_FIELD_CLASS_TYPE_VARIANT: | |
31 | { | |
32 | ctf_field_class_variant *var_fc = ctf_field_class_as_variant(fc); | |
33 | ||
34 | field_path = &var_fc->tag_path; | |
35 | stored_value_index = &var_fc->stored_tag_index; | |
36 | tgt_fc = &var_fc->tag_fc->base; | |
37 | break; | |
38 | } | |
39 | case CTF_FIELD_CLASS_TYPE_SEQUENCE: | |
40 | { | |
41 | struct ctf_field_class_sequence *seq_fc = ctf_field_class_as_sequence(fc); | |
42 | ||
43 | field_path = &seq_fc->length_path; | |
44 | stored_value_index = &seq_fc->stored_length_index; | |
45 | tgt_fc = seq_fc->length_fc; | |
46 | break; | |
47 | } | |
48 | default: | |
49 | break; | |
50 | } | |
51 | ||
52 | if (field_path) { | |
53 | BT_ASSERT(tgt_fc); | |
54 | BT_ASSERT(tgt_fc->base.base.type == CTF_FIELD_CLASS_TYPE_INT || | |
55 | tgt_fc->base.base.type == CTF_FIELD_CLASS_TYPE_ENUM); | |
56 | if (tgt_fc->storing_index >= 0) { | |
57 | /* Already storing its value */ | |
58 | *stored_value_index = (uint64_t) tgt_fc->storing_index; | |
59 | } else { | |
60 | /* Not storing its value: allocate new index */ | |
61 | tgt_fc->storing_index = tc->stored_value_count; | |
62 | *stored_value_index = (uint64_t) tgt_fc->storing_index; | |
63 | tc->stored_value_count++; | |
64 | } | |
65 | } | |
66 | ||
67 | switch (fc->type) { | |
68 | case CTF_FIELD_CLASS_TYPE_STRUCT: | |
69 | { | |
70 | struct ctf_field_class_struct *struct_fc = ctf_field_class_as_struct(fc); | |
71 | ||
72 | for (i = 0; i < struct_fc->members->len; i++) { | |
73 | struct ctf_named_field_class *named_fc = | |
74 | ctf_field_class_struct_borrow_member_by_index(struct_fc, i); | |
75 | ||
76 | ret = update_field_class_stored_value_index(named_fc->fc, tc, sc, ec); | |
77 | if (ret) { | |
78 | goto end; | |
79 | } | |
80 | } | |
81 | ||
82 | break; | |
83 | } | |
84 | case CTF_FIELD_CLASS_TYPE_VARIANT: | |
85 | { | |
86 | struct ctf_field_class_variant *var_fc = ctf_field_class_as_variant(fc); | |
87 | ||
88 | for (i = 0; i < var_fc->options->len; i++) { | |
89 | struct ctf_named_field_class *named_fc = | |
90 | ctf_field_class_variant_borrow_option_by_index(var_fc, i); | |
91 | ||
92 | ret = update_field_class_stored_value_index(named_fc->fc, tc, sc, ec); | |
93 | if (ret) { | |
94 | goto end; | |
95 | } | |
96 | } | |
97 | ||
98 | break; | |
99 | } | |
100 | case CTF_FIELD_CLASS_TYPE_ARRAY: | |
101 | case CTF_FIELD_CLASS_TYPE_SEQUENCE: | |
102 | { | |
103 | struct ctf_field_class_array_base *array_fc = ctf_field_class_as_array_base(fc); | |
104 | ||
105 | ret = update_field_class_stored_value_index(array_fc->elem_fc, tc, sc, ec); | |
106 | if (ret) { | |
107 | goto end; | |
108 | } | |
109 | ||
110 | break; | |
111 | } | |
112 | default: | |
113 | break; | |
114 | } | |
44c440bc PP |
115 | |
116 | end: | |
4164020e | 117 | return ret; |
44c440bc PP |
118 | } |
119 | ||
44c440bc PP |
120 | int ctf_trace_class_update_value_storing_indexes(struct ctf_trace_class *ctf_tc) |
121 | { | |
4164020e SM |
122 | uint64_t i; |
123 | ||
124 | if (!ctf_tc->is_translated) { | |
125 | update_field_class_stored_value_index(ctf_tc->packet_header_fc, ctf_tc, NULL, NULL); | |
126 | } | |
127 | ||
128 | for (i = 0; i < ctf_tc->stream_classes->len; i++) { | |
129 | uint64_t j; | |
130 | ctf_stream_class *sc = (ctf_stream_class *) ctf_tc->stream_classes->pdata[i]; | |
131 | ||
132 | if (!sc->is_translated) { | |
133 | update_field_class_stored_value_index(sc->packet_context_fc, ctf_tc, sc, NULL); | |
134 | update_field_class_stored_value_index(sc->event_header_fc, ctf_tc, sc, NULL); | |
135 | update_field_class_stored_value_index(sc->event_common_context_fc, ctf_tc, sc, NULL); | |
136 | } | |
137 | ||
138 | for (j = 0; j < sc->event_classes->len; j++) { | |
139 | struct ctf_event_class *ec = (ctf_event_class *) sc->event_classes->pdata[j]; | |
140 | ||
141 | if (!ec->is_translated) { | |
142 | update_field_class_stored_value_index(ec->spec_context_fc, ctf_tc, sc, ec); | |
143 | update_field_class_stored_value_index(ec->payload_fc, ctf_tc, sc, ec); | |
144 | } | |
145 | } | |
146 | } | |
147 | ||
148 | return 0; | |
44c440bc | 149 | } |