1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Xiangxiu Yang, Mathieu Desnoyers
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;
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.
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,
28 #include "ltt-private.h"
31 static unsigned intSizes
[] = {
32 sizeof(int8_t), sizeof(int16_t), sizeof(int32_t), sizeof(int64_t),
35 typedef enum _intSizesNames
{ SIZE_INT8
, SIZE_INT16
, SIZE_INT32
,
36 SIZE_INT64
, SIZE_SHORT
, INT_SIZES_NUMBER
}
40 static unsigned floatSizes
[] = {
41 0, 0, sizeof(float), sizeof(double), 0, sizeof(float), sizeof(double) };
43 #define FLOAT_SIZES_NUMBER 7
46 /*****************************************************************************
48 * ltt_eventtype_name : get the name of the event type
52 * char * : the name of the event type
53 ****************************************************************************/
55 gchar
*ltt_eventtype_name(LttEventType
*et
)
60 /*****************************************************************************
62 * ltt_eventtype_description : get the description of the event type
66 * char * : the description of the event type
67 ****************************************************************************/
69 gchar
*ltt_eventtype_description(LttEventType
*et
)
71 return et
->description
;
74 /*****************************************************************************
76 * ltt_eventtype_facility : get the facility which contains the event type
80 * LttFacility * : the facility
81 ****************************************************************************/
83 LttFacility
*ltt_eventtype_facility(LttEventType
*et
)
88 /*****************************************************************************
90 * ltt_eventtype_relative_id : get the relative id of the event type
94 * unsigned : the relative id
95 ****************************************************************************/
97 unsigned ltt_eventtype_relative_id(LttEventType
*et
)
102 /*****************************************************************************
104 * ltt_eventtype_id : get the id of the event type
109 ****************************************************************************/
111 unsigned ltt_eventtype_id(LttEventType
*et
)
113 return et
->facility
->base_id
+ et
->index
;
116 /*****************************************************************************
118 * ltt_eventtype_type : get the type of the event type
122 * LttType * : the type of the event type
123 ****************************************************************************/
125 LttType
*ltt_eventtype_type(LttEventType
*et
)
127 if(unlikely(!et
->root_field
)) return NULL
;
128 else return et
->root_field
->field_type
;
131 /*****************************************************************************
133 * ltt_eventtype_field : get the root filed of the event type
137 * LttField * : the root filed of the event type
138 ****************************************************************************/
140 LttField
*ltt_eventtype_field(LttEventType
*et
)
142 return et
->root_field
;
145 /*****************************************************************************
147 * ltt_type_name : get the name of the type
151 * char * : the name of the type
152 ****************************************************************************/
154 gchar
*ltt_type_name(LttType
*t
)
156 return t
->element_name
;
159 /*****************************************************************************
161 * ltt_type_class : get the type class of the type
165 * LttTypeEnum : the type class of the type
166 ****************************************************************************/
168 LttTypeEnum
ltt_type_class(LttType
*t
)
170 return t
->type_class
;
173 /*****************************************************************************
175 * ltt_type_size : obtain the type size. The size is the number of bytes
176 * for primitive types (INT, UINT, FLOAT, ENUM), or the
177 * size for the unsigned integer length count for sequences
182 * unsigned : the type size
183 * returns 0 if erroneous, and show a critical warning message.
184 ****************************************************************************/
186 unsigned ltt_type_size(LttTrace
* trace
, LttType
*t
)
189 if(unlikely(t
->type_class
==LTT_STRUCT
|| t
->type_class
==LTT_ARRAY
||
190 t
->type_class
==LTT_STRING
|| t
->type_class
==LTT_UNION
)) {
193 if(t
->type_class
== LTT_FLOAT
){
194 size
= floatSizes
[t
->size
];
196 if(likely(t
->size
< INT_SIZES_NUMBER
))
197 size
= intSizes
[t
->size
];
199 LttArchSize archsize
= trace
->system_description
->size
;
200 if(archsize
== LTT_LP32
){
201 if(t
->size
== 5) size
= intSizes
[SIZE_INT16
];
202 else size
= intSizes
[SIZE_INT32
];
204 else if(archsize
== LTT_ILP32
|| archsize
== LTT_LP64
){
205 if(t
->size
== 5) size
= intSizes
[SIZE_INT32
];
207 if(archsize
== LTT_ILP32
) size
= intSizes
[SIZE_INT32
];
208 else size
= intSizes
[SIZE_INT64
];
211 else if(archsize
== LTT_ILP64
) size
= intSizes
[SIZE_INT64
];
219 /*****************************************************************************
221 * ltt_type_element_type : obtain the type of nested elements for arrays
226 * LttType : the type of nested element of array or sequence
227 ****************************************************************************/
229 LttType
*ltt_type_element_type(LttType
*t
)
231 LttType
*element_type
;
233 if(unlikely(t
->type_class
!= LTT_ARRAY
&& t
->type_class
!= LTT_SEQUENCE
))
236 element_type
= t
->element_type
[0];
241 /*****************************************************************************
243 * ltt_type_element_number : obtain the number of elements for arrays
247 * unsigned : the number of elements for arrays
248 ****************************************************************************/
250 unsigned ltt_type_element_number(LttType
*t
)
254 if(likely(t
->type_class
== LTT_ARRAY
))
255 ret
= t
->element_number
;
260 /*****************************************************************************
262 * ltt_type_member_number : obtain the number of data members for structure
266 * unsigned : the number of members for structure
267 ****************************************************************************/
269 unsigned ltt_type_member_number(LttType
*t
)
273 if(likely(t
->type_class
== LTT_STRUCT
|| t
->type_class
== LTT_UNION
))
274 ret
=t
->element_number
;
279 /*****************************************************************************
281 * ltt_type_member_type : obtain the type of a data member in a structure
285 * i : index of the member
287 * LttType * : the type of structure member
288 ****************************************************************************/
290 LttType
*ltt_type_member_type(LttType
*t
, unsigned i
, gchar
** name
)
292 LttType
*member_type
= NULL
;
294 if(unlikely( (t
->type_class
!= LTT_STRUCT
295 && t
->type_class
!= LTT_UNION
)
297 (i
>= t
->element_number
)
301 *name
= t
->element_type
[i
]->element_name
;
302 member_type
= t
->element_type
[i
];
308 /*****************************************************************************
310 * ltt_enum_string_get : for enumerations, obtain the symbolic string
311 * associated with a value (0 to n - 1 for an
312 * enumeration of n elements)
315 * i : index of the member
317 * char * : symbolic string associated with a value
318 ****************************************************************************/
320 char *ltt_enum_string_get(LttType
*t
, unsigned i
)
322 gchar
*string
= NULL
;
324 if(likely(t
->type_class
== LTT_ENUM
&& i
< t
->element_number
))
325 string
= t
->enum_strings
[i
];
330 /*****************************************************************************
332 * ltt_field_element : obtain the field of nested elements for arrays and
337 * LttField * : the field of the nested element
338 ****************************************************************************/
340 LttField
*ltt_field_element(LttField
*f
)
342 LttField
*nest
= NULL
;
344 if(likely(f
->field_type
->type_class
== LTT_ARRAY
||
345 f
->field_type
->type_class
== LTT_SEQUENCE
))
351 /*****************************************************************************
353 * ltt_field_member : obtain the field of data members for structure
356 * i : index of member field
358 * LttField * : the field of the nested element
359 ****************************************************************************/
361 LttField
*ltt_field_member(LttField
*f
, unsigned i
)
363 LttField
*field_member
;
365 if(unlikely( f
->field_type
->type_class
!= LTT_STRUCT
366 && f
->field_type
->type_class
!= LTT_UNION
)
367 || i
>= f
->field_type
->element_number
)
370 field_member
= f
->child
[i
];
375 /*****************************************************************************
377 * ltt_field_type : obtain the type of the field
381 * ltt_tyoe * : the type of field
382 ****************************************************************************/
384 LttType
*ltt_field_type(LttField
*f
)
386 if(unlikely(!f
))return NULL
;
387 return f
->field_type
;
390 int ltt_field_size(LttField
* f
)
392 if(unlikely(!f
))return 0;
393 return f
->field_size
;
This page took 0.03819 seconds and 4 git commands to generate.