449cb9d7 |
1 | /* This file is part of the Linux Trace Toolkit viewer |
2 | * Copyright (C) 2003-2004 Xiangxiu Yang |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License Version 2 as |
6 | * published by the Free Software Foundation; |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program; if not, write to the Free Software |
15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
16 | * MA 02111-1307, USA. |
17 | */ |
18 | |
6cd62ccf |
19 | #include <stdio.h> |
20 | |
6cd62ccf |
21 | #include "parser.h" |
a5dcde2f |
22 | #include <ltt/ltt.h> |
23 | #include "ltt-private.h" |
6cd62ccf |
24 | #include <ltt/type.h> |
25 | |
26 | static unsigned intSizes[] = { |
27 | sizeof(int8_t), sizeof(int16_t), sizeof(int32_t), sizeof(int64_t), |
28 | sizeof(short) }; |
29 | |
30 | static unsigned floatSizes[] = { |
31 | 0, 0, sizeof(float), sizeof(double), 0, sizeof(float), sizeof(double) }; |
32 | |
33 | |
34 | /***************************************************************************** |
35 | *Function name |
36 | * ltt_eventtype_name : get the name of the event type |
37 | *Input params |
38 | * et : an event type |
39 | *Return value |
40 | * char * : the name of the event type |
41 | ****************************************************************************/ |
42 | |
963b5f2d |
43 | char *ltt_eventtype_name(LttEventType *et) |
6cd62ccf |
44 | { |
45 | return et->name; |
46 | } |
47 | |
48 | /***************************************************************************** |
49 | *Function name |
50 | * ltt_eventtype_description : get the description of the event type |
51 | *Input params |
52 | * et : an event type |
53 | *Return value |
54 | * char * : the description of the event type |
55 | ****************************************************************************/ |
56 | |
963b5f2d |
57 | char *ltt_eventtype_description(LttEventType *et) |
6cd62ccf |
58 | { |
59 | return et->description; |
60 | } |
61 | |
963b5f2d |
62 | /***************************************************************************** |
63 | *Function name |
64 | * ltt_eventtype_facility : get the facility which contains the event type |
65 | *Input params |
66 | * et : an event type |
67 | *Return value |
68 | * LttFacility * : the facility |
69 | ****************************************************************************/ |
70 | |
71 | LttFacility *ltt_eventtype_facility(LttEventType *et) |
72 | { |
73 | return et->facility; |
74 | } |
75 | |
76 | /***************************************************************************** |
77 | *Function name |
78 | * ltt_eventtype_relative_id : get the relative id of the event type |
79 | *Input params |
80 | * et : an event type |
81 | *Return value |
33690006 |
82 | * unsigned : the relative id |
963b5f2d |
83 | ****************************************************************************/ |
84 | |
33690006 |
85 | unsigned ltt_eventtype_relative_id(LttEventType *et) |
963b5f2d |
86 | { |
33690006 |
87 | return et->index; |
963b5f2d |
88 | } |
89 | |
90 | /***************************************************************************** |
91 | *Function name |
92 | * ltt_eventtype_id : get the id of the event type |
93 | *Input params |
94 | * et : an event type |
95 | *Return value |
33690006 |
96 | * unsigned : the id |
963b5f2d |
97 | ****************************************************************************/ |
98 | |
33690006 |
99 | unsigned ltt_eventtype_id(LttEventType *et) |
963b5f2d |
100 | { |
33690006 |
101 | return et->facility->base_id + et->index; |
963b5f2d |
102 | } |
103 | |
6cd62ccf |
104 | /***************************************************************************** |
105 | *Function name |
106 | * ltt_eventtype_type : get the type of the event type |
107 | *Input params |
108 | * et : an event type |
109 | *Return value |
963b5f2d |
110 | * LttType * : the type of the event type |
6cd62ccf |
111 | ****************************************************************************/ |
112 | |
963b5f2d |
113 | LttType *ltt_eventtype_type(LttEventType *et) |
6cd62ccf |
114 | { |
a2331fa0 |
115 | if(!et->root_field) return NULL; |
6cd62ccf |
116 | return et->root_field->field_type; |
117 | } |
118 | |
963b5f2d |
119 | /***************************************************************************** |
120 | *Function name |
121 | * ltt_eventtype_field : get the root filed of the event type |
122 | *Input params |
123 | * et : an event type |
124 | *Return value |
125 | * LttField * : the root filed of the event type |
126 | ****************************************************************************/ |
127 | |
128 | LttField *ltt_eventtype_field(LttEventType *et) |
129 | { |
130 | return et->root_field; |
131 | } |
132 | |
6cd62ccf |
133 | /***************************************************************************** |
134 | *Function name |
135 | * ltt_type_name : get the name of the type |
136 | *Input params |
137 | * t : a type |
138 | *Return value |
139 | * char * : the name of the type |
140 | ****************************************************************************/ |
141 | |
963b5f2d |
142 | char *ltt_type_name(LttType *t) |
6cd62ccf |
143 | { |
144 | return t->element_name; |
145 | } |
146 | |
147 | /***************************************************************************** |
148 | *Function name |
149 | * ltt_type_class : get the type class of the type |
150 | *Input params |
151 | * t : a type |
152 | *Return value |
963b5f2d |
153 | * LttTypeEnum : the type class of the type |
6cd62ccf |
154 | ****************************************************************************/ |
155 | |
963b5f2d |
156 | LttTypeEnum ltt_type_class(LttType *t) |
6cd62ccf |
157 | { |
158 | return t->type_class; |
159 | } |
160 | |
161 | /***************************************************************************** |
162 | *Function name |
163 | * ltt_type_size : obtain the type size. The size is the number of bytes |
164 | * for primitive types (INT, UINT, FLOAT, ENUM), or the |
165 | * size for the unsigned integer length count for sequences |
166 | *Input params |
167 | * tf : trace file |
168 | * t : a type |
169 | *Return value |
170 | * unsigned : the type size |
8d1e6362 |
171 | * returns 0 if erroneous, and show a critical warning message. |
6cd62ccf |
172 | ****************************************************************************/ |
173 | |
963b5f2d |
174 | unsigned ltt_type_size(LttTrace * trace, LttType *t) |
6cd62ccf |
175 | { |
176 | if(t->type_class==LTT_STRUCT || t->type_class==LTT_ARRAY || |
59d7bdf3 |
177 | t->type_class==LTT_STRING || t->type_class==LTT_UNION) return 0; |
6cd62ccf |
178 | |
179 | if(t->type_class == LTT_FLOAT){ |
180 | return floatSizes[t->size]; |
181 | }else{ |
182 | if(t->size < sizeof(intSizes)/sizeof(unsigned)) |
183 | return intSizes[t->size]; |
184 | else{ |
963b5f2d |
185 | LttArchSize size = trace->system_description->size; |
62c72abf |
186 | if(size == LTT_LP32){ |
8d1e6362 |
187 | if(t->size == 5)return sizeof(int16_t); |
188 | else return sizeof(int32_t); |
62c72abf |
189 | } |
190 | else if(size == LTT_ILP32 || size == LTT_LP64){ |
8d1e6362 |
191 | if(t->size == 5)return sizeof(int32_t); |
192 | else{ |
193 | if(size == LTT_ILP32) return sizeof(int32_t); |
194 | else return sizeof(int64_t); |
195 | } |
62c72abf |
196 | } |
197 | else if(size == LTT_ILP64)return sizeof(int64_t); |
6cd62ccf |
198 | } |
199 | } |
8d1e6362 |
200 | |
201 | g_critical("ltt_type_size : Type size %u unknown", t->size); |
202 | return 0; |
6cd62ccf |
203 | } |
204 | |
205 | /***************************************************************************** |
206 | *Function name |
207 | * ltt_type_element_type : obtain the type of nested elements for arrays |
208 | * and sequences |
209 | *Input params |
210 | * t : a type |
211 | *Return value |
963b5f2d |
212 | * LttType : the type of nested element of array or sequence |
6cd62ccf |
213 | ****************************************************************************/ |
214 | |
963b5f2d |
215 | LttType *ltt_type_element_type(LttType *t) |
6cd62ccf |
216 | { |
c687f6c8 |
217 | if(t->type_class != LTT_ARRAY && t->type_class != LTT_SEQUENCE) |
6cd62ccf |
218 | return NULL; |
219 | return t->element_type[0]; |
220 | } |
221 | |
222 | /***************************************************************************** |
223 | *Function name |
224 | * ltt_type_element_number : obtain the number of elements for arrays |
225 | *Input params |
226 | * t : a type |
227 | *Return value |
228 | * unsigned : the number of elements for arrays |
229 | ****************************************************************************/ |
230 | |
963b5f2d |
231 | unsigned ltt_type_element_number(LttType *t) |
6cd62ccf |
232 | { |
233 | if(t->type_class != LTT_ARRAY) |
234 | return 0; |
235 | return t->element_number; |
236 | } |
237 | |
238 | /***************************************************************************** |
239 | *Function name |
240 | * ltt_type_member_number : obtain the number of data members for structure |
241 | *Input params |
242 | * t : a type |
243 | *Return value |
244 | * unsigned : the number of members for structure |
245 | ****************************************************************************/ |
246 | |
963b5f2d |
247 | unsigned ltt_type_member_number(LttType *t) |
6cd62ccf |
248 | { |
c687f6c8 |
249 | if(t->type_class != LTT_STRUCT && t->type_class != LTT_UNION) |
6cd62ccf |
250 | return 0; |
251 | return t->element_number; |
252 | } |
253 | |
254 | /***************************************************************************** |
255 | *Function name |
59d7bdf3 |
256 | * ltt_type_member_type : obtain the type of a data member in a structure |
257 | * or union. |
6cd62ccf |
258 | *Input params |
259 | * t : a type |
260 | * i : index of the member |
261 | *Return value |
963b5f2d |
262 | * LttType * : the type of structure member |
6cd62ccf |
263 | ****************************************************************************/ |
264 | |
02007847 |
265 | LttType *ltt_type_member_type(LttType *t, unsigned i, char ** name) |
6cd62ccf |
266 | { |
59d7bdf3 |
267 | if(t->type_class != LTT_STRUCT |
6220f7f1 |
268 | && t->type_class != LTT_UNION){*name = NULL; return NULL;} |
8d1e6362 |
269 | if(i >= t->element_number){*name = NULL; return NULL;} |
fe974fde |
270 | *name = t->element_type[i]->element_name; |
89d4760c |
271 | return t->element_type[i]; |
6cd62ccf |
272 | } |
273 | |
274 | /***************************************************************************** |
275 | *Function name |
276 | * ltt_enum_string_get : for enumerations, obtain the symbolic string |
277 | * associated with a value (0 to n - 1 for an |
278 | * enumeration of n elements) |
279 | *Input params |
280 | * t : a type |
281 | * i : index of the member |
282 | *Return value |
283 | * char * : symbolic string associated with a value |
284 | ****************************************************************************/ |
285 | |
963b5f2d |
286 | char *ltt_enum_string_get(LttType *t, unsigned i) |
6cd62ccf |
287 | { |
288 | if(t->type_class != LTT_ENUM) return NULL; |
8d1e6362 |
289 | if(i >= t->element_number) return NULL; |
89d4760c |
290 | return t->enum_strings[i]; |
6cd62ccf |
291 | } |
292 | |
293 | /***************************************************************************** |
294 | *Function name |
295 | * ltt_field_element : obtain the field of nested elements for arrays and |
296 | * sequence |
297 | *Input params |
298 | * f : a field |
299 | *Return value |
963b5f2d |
300 | * LttField * : the field of the nested element |
6cd62ccf |
301 | ****************************************************************************/ |
302 | |
963b5f2d |
303 | LttField *ltt_field_element(LttField *f) |
6cd62ccf |
304 | { |
c687f6c8 |
305 | if(f->field_type->type_class != LTT_ARRAY && |
6cd62ccf |
306 | f->field_type->type_class != LTT_SEQUENCE) |
307 | return NULL; |
308 | |
309 | return f->child[0]; |
310 | } |
311 | |
312 | /***************************************************************************** |
313 | *Function name |
59d7bdf3 |
314 | * ltt_field_member : obtain the field of data members for structure |
6cd62ccf |
315 | *Input params |
316 | * f : a field |
317 | * i : index of member field |
318 | *Return value |
963b5f2d |
319 | * LttField * : the field of the nested element |
6cd62ccf |
320 | ****************************************************************************/ |
321 | |
963b5f2d |
322 | LttField *ltt_field_member(LttField *f, unsigned i) |
6cd62ccf |
323 | { |
59d7bdf3 |
324 | if(f->field_type->type_class != LTT_STRUCT |
6220f7f1 |
325 | && f->field_type->type_class != LTT_UNION) return NULL; |
8d1e6362 |
326 | if(i >= f->field_type->element_number) return NULL; |
89d4760c |
327 | return f->child[i]; |
6cd62ccf |
328 | } |
329 | |
330 | /***************************************************************************** |
331 | *Function name |
332 | * ltt_field_type : obtain the type of the field |
333 | *Input params |
334 | * f : a field |
335 | *Return value |
336 | * ltt_tyoe * : the type of field |
337 | ****************************************************************************/ |
338 | |
963b5f2d |
339 | LttType *ltt_field_type(LttField *f) |
6cd62ccf |
340 | { |
a2331fa0 |
341 | if(!f)return NULL; |
6cd62ccf |
342 | return f->field_type; |
343 | } |
344 | |
a5dcde2f |
345 | int ltt_field_size(LttField * f) |
346 | { |
347 | if(!f)return 0; |
348 | return f->field_size; |
349 | } |