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,
24 #include "ltt-private.h"
27 static unsigned intSizes
[] = {
28 sizeof(int8_t), sizeof(int16_t), sizeof(int32_t), sizeof(int64_t),
31 typedef enum _intSizesNames
{ SIZE_INT8
, SIZE_INT16
, SIZE_INT32
,
32 SIZE_INT64
, SIZE_SHORT
, INT_SIZES_NUMBER
}
36 static unsigned floatSizes
[] = {
37 0, 0, sizeof(float), sizeof(double), 0, sizeof(float), sizeof(double) };
39 #define FLOAT_SIZES_NUMBER 7
42 /*****************************************************************************
44 * ltt_eventtype_name : get the name of the event type
48 * char * : the name of the event type
49 ****************************************************************************/
51 gchar
*ltt_eventtype_name(LttEventType
*et
)
56 /*****************************************************************************
58 * ltt_eventtype_description : get the description of the event type
62 * char * : the description of the event type
63 ****************************************************************************/
65 gchar
*ltt_eventtype_description(LttEventType
*et
)
67 return et
->description
;
70 /*****************************************************************************
72 * ltt_eventtype_facility : get the facility which contains the event type
76 * LttFacility * : the facility
77 ****************************************************************************/
79 LttFacility
*ltt_eventtype_facility(LttEventType
*et
)
84 /*****************************************************************************
86 * ltt_eventtype_relative_id : get the relative id of the event type
90 * unsigned : the relative id
91 ****************************************************************************/
93 unsigned ltt_eventtype_relative_id(LttEventType
*et
)
98 /*****************************************************************************
100 * ltt_eventtype_id : get the id of the event type
105 ****************************************************************************/
107 unsigned ltt_eventtype_id(LttEventType
*et
)
109 return et
->facility
->base_id
+ et
->index
;
112 /*****************************************************************************
114 * ltt_eventtype_type : get the type of the event type
118 * LttType * : the type of the event type
119 ****************************************************************************/
121 LttType
*ltt_eventtype_type(LttEventType
*et
)
123 if(unlikely(!et
->root_field
)) return NULL
;
124 else return et
->root_field
->field_type
;
127 /*****************************************************************************
129 * ltt_eventtype_field : get the root filed of the event type
133 * LttField * : the root filed of the event type
134 ****************************************************************************/
136 LttField
*ltt_eventtype_field(LttEventType
*et
)
138 return et
->root_field
;
141 /*****************************************************************************
143 * ltt_type_name : get the name of the type
147 * char * : the name of the type
148 ****************************************************************************/
150 gchar
*ltt_type_name(LttType
*t
)
152 return t
->element_name
;
155 /*****************************************************************************
157 * ltt_type_class : get the type class of the type
161 * LttTypeEnum : the type class of the type
162 ****************************************************************************/
164 LttTypeEnum
ltt_type_class(LttType
*t
)
166 return t
->type_class
;
169 /*****************************************************************************
171 * ltt_type_size : obtain the type size. The size is the number of bytes
172 * for primitive types (INT, UINT, FLOAT, ENUM), or the
173 * size for the unsigned integer length count for sequences
178 * unsigned : the type size
179 * returns 0 if erroneous, and show a critical warning message.
180 ****************************************************************************/
182 unsigned ltt_type_size(LttTrace
* trace
, LttType
*t
)
185 if(unlikely(t
->type_class
==LTT_STRUCT
|| t
->type_class
==LTT_ARRAY
||
186 t
->type_class
==LTT_STRING
|| t
->type_class
==LTT_UNION
)) {
189 if(t
->type_class
== LTT_FLOAT
){
190 size
= floatSizes
[t
->size
];
192 if(likely(t
->size
< INT_SIZES_NUMBER
))
193 size
= intSizes
[t
->size
];
195 LttArchSize archsize
= trace
->system_description
->size
;
196 if(archsize
== LTT_LP32
){
197 if(t
->size
== 5) size
= intSizes
[SIZE_INT16
];
198 else size
= intSizes
[SIZE_INT32
];
200 else if(archsize
== LTT_ILP32
|| archsize
== LTT_LP64
){
201 if(t
->size
== 5) size
= intSizes
[SIZE_INT32
];
203 if(archsize
== LTT_ILP32
) size
= intSizes
[SIZE_INT32
];
204 else size
= intSizes
[SIZE_INT64
];
207 else if(archsize
== LTT_ILP64
) size
= intSizes
[SIZE_INT64
];
215 /*****************************************************************************
217 * ltt_type_element_type : obtain the type of nested elements for arrays
222 * LttType : the type of nested element of array or sequence
223 ****************************************************************************/
225 LttType
*ltt_type_element_type(LttType
*t
)
227 LttType
*element_type
;
229 if(unlikely(t
->type_class
!= LTT_ARRAY
&& t
->type_class
!= LTT_SEQUENCE
))
232 element_type
= t
->element_type
[0];
237 /*****************************************************************************
239 * ltt_type_element_number : obtain the number of elements for arrays
243 * unsigned : the number of elements for arrays
244 ****************************************************************************/
246 unsigned ltt_type_element_number(LttType
*t
)
250 if(likely(t
->type_class
== LTT_ARRAY
))
251 ret
= t
->element_number
;
256 /*****************************************************************************
258 * ltt_type_member_number : obtain the number of data members for structure
262 * unsigned : the number of members for structure
263 ****************************************************************************/
265 unsigned ltt_type_member_number(LttType
*t
)
269 if(likely(t
->type_class
== LTT_STRUCT
|| t
->type_class
== LTT_UNION
))
270 ret
=t
->element_number
;
275 /*****************************************************************************
277 * ltt_type_member_type : obtain the type of a data member in a structure
281 * i : index of the member
283 * LttType * : the type of structure member
284 ****************************************************************************/
286 LttType
*ltt_type_member_type(LttType
*t
, unsigned i
, gchar
** name
)
288 LttType
*member_type
= NULL
;
290 if(unlikely( (t
->type_class
!= LTT_STRUCT
291 && t
->type_class
!= LTT_UNION
)
293 (i
>= t
->element_number
)
297 *name
= t
->element_type
[i
]->element_name
;
298 member_type
= t
->element_type
[i
];
304 /*****************************************************************************
306 * ltt_enum_string_get : for enumerations, obtain the symbolic string
307 * associated with a value (0 to n - 1 for an
308 * enumeration of n elements)
311 * i : index of the member
313 * char * : symbolic string associated with a value
314 ****************************************************************************/
316 char *ltt_enum_string_get(LttType
*t
, unsigned i
)
318 gchar
*string
= NULL
;
320 if(likely(t
->type_class
== LTT_ENUM
&& i
< t
->element_number
))
321 string
= t
->enum_strings
[i
];
326 /*****************************************************************************
328 * ltt_field_element : obtain the field of nested elements for arrays and
333 * LttField * : the field of the nested element
334 ****************************************************************************/
336 LttField
*ltt_field_element(LttField
*f
)
338 LttField
*nest
= NULL
;
340 if(likely(f
->field_type
->type_class
== LTT_ARRAY
||
341 f
->field_type
->type_class
== LTT_SEQUENCE
))
347 /*****************************************************************************
349 * ltt_field_member : obtain the field of data members for structure
352 * i : index of member field
354 * LttField * : the field of the nested element
355 ****************************************************************************/
357 LttField
*ltt_field_member(LttField
*f
, unsigned i
)
359 LttField
*field_member
;
361 if(unlikely( f
->field_type
->type_class
!= LTT_STRUCT
362 && f
->field_type
->type_class
!= LTT_UNION
)
363 || i
>= f
->field_type
->element_number
)
366 field_member
= f
->child
[i
];
371 /*****************************************************************************
373 * ltt_field_type : obtain the type of the field
377 * ltt_tyoe * : the type of field
378 ****************************************************************************/
380 LttType
*ltt_field_type(LttField
*f
)
382 if(unlikely(!f
))return NULL
;
383 return f
->field_type
;
386 int ltt_field_size(LttField
* f
)
388 if(unlikely(!f
))return 0;
389 return f
->field_size
;
This page took 0.045871 seconds and 5 git commands to generate.