1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Xiangxiu Yang
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,
23 #include "ltt-private.h"
26 static unsigned intSizes
[] = {
27 sizeof(int8_t), sizeof(int16_t), sizeof(int32_t), sizeof(int64_t),
30 static unsigned floatSizes
[] = {
31 0, 0, sizeof(float), sizeof(double), 0, sizeof(float), sizeof(double) };
34 /*****************************************************************************
36 * ltt_eventtype_name : get the name of the event type
40 * char * : the name of the event type
41 ****************************************************************************/
43 char *ltt_eventtype_name(LttEventType
*et
)
48 /*****************************************************************************
50 * ltt_eventtype_description : get the description of the event type
54 * char * : the description of the event type
55 ****************************************************************************/
57 char *ltt_eventtype_description(LttEventType
*et
)
59 return et
->description
;
62 /*****************************************************************************
64 * ltt_eventtype_facility : get the facility which contains the event type
68 * LttFacility * : the facility
69 ****************************************************************************/
71 LttFacility
*ltt_eventtype_facility(LttEventType
*et
)
76 /*****************************************************************************
78 * ltt_eventtype_relative_id : get the relative id of the event type
82 * unsigned : the relative id
83 ****************************************************************************/
85 unsigned ltt_eventtype_relative_id(LttEventType
*et
)
90 /*****************************************************************************
92 * ltt_eventtype_id : get the id of the event type
97 ****************************************************************************/
99 unsigned ltt_eventtype_id(LttEventType
*et
)
101 return et
->facility
->base_id
+ et
->index
;
104 /*****************************************************************************
106 * ltt_eventtype_type : get the type of the event type
110 * LttType * : the type of the event type
111 ****************************************************************************/
113 LttType
*ltt_eventtype_type(LttEventType
*et
)
115 if(!et
->root_field
) return NULL
;
116 return et
->root_field
->field_type
;
119 /*****************************************************************************
121 * ltt_eventtype_field : get the root filed of the event type
125 * LttField * : the root filed of the event type
126 ****************************************************************************/
128 LttField
*ltt_eventtype_field(LttEventType
*et
)
130 return et
->root_field
;
133 /*****************************************************************************
135 * ltt_type_name : get the name of the type
139 * char * : the name of the type
140 ****************************************************************************/
142 char *ltt_type_name(LttType
*t
)
144 return t
->element_name
;
147 /*****************************************************************************
149 * ltt_type_class : get the type class of the type
153 * LttTypeEnum : the type class of the type
154 ****************************************************************************/
156 LttTypeEnum
ltt_type_class(LttType
*t
)
158 return t
->type_class
;
161 /*****************************************************************************
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
170 * unsigned : the type size
171 ****************************************************************************/
173 unsigned ltt_type_size(LttTrace
* trace
, LttType
*t
)
175 if(t
->type_class
==LTT_STRUCT
|| t
->type_class
==LTT_ARRAY
||
176 t
->type_class
==LTT_STRING
) return 0;
178 if(t
->type_class
== LTT_FLOAT
){
179 return floatSizes
[t
->size
];
181 if(t
->size
< sizeof(intSizes
)/sizeof(unsigned))
182 return intSizes
[t
->size
];
184 LttArchSize size
= trace
->system_description
->size
;
185 if(size
== LTT_LP32
){
186 if(t
->size
== 5)return sizeof(int16_t);
187 else return sizeof(int32_t);
189 else if(size
== LTT_ILP32
|| size
== LTT_LP64
){
190 if(t
->size
== 5)return sizeof(int32_t);
192 if(size
== LTT_ILP32
) return sizeof(int32_t);
193 else return sizeof(int64_t);
196 else if(size
== LTT_ILP64
)return sizeof(int64_t);
201 /*****************************************************************************
203 * ltt_type_element_type : obtain the type of nested elements for arrays
208 * LttType : the type of nested element of array or sequence
209 ****************************************************************************/
211 LttType
*ltt_type_element_type(LttType
*t
)
213 if(t
->type_class
!= LTT_ARRAY
&& t
->type_class
!= LTT_SEQUENCE
)
215 return t
->element_type
[0];
218 /*****************************************************************************
220 * ltt_type_element_number : obtain the number of elements for arrays
224 * unsigned : the number of elements for arrays
225 ****************************************************************************/
227 unsigned ltt_type_element_number(LttType
*t
)
229 if(t
->type_class
!= LTT_ARRAY
)
231 return t
->element_number
;
234 /*****************************************************************************
236 * ltt_type_member_number : obtain the number of data members for structure
240 * unsigned : the number of members for structure
241 ****************************************************************************/
243 unsigned ltt_type_member_number(LttType
*t
)
245 if(t
->type_class
!= LTT_STRUCT
&& t
->type_class
!= LTT_UNION
)
247 return t
->element_number
;
250 /*****************************************************************************
252 * ltt_type_member_type : obtain the type of a data members in a structure
255 * i : index of the member
257 * LttType * : the type of structure member
258 ****************************************************************************/
260 LttType
*ltt_type_member_type(LttType
*t
, unsigned i
, char ** name
)
262 if(t
->type_class
!= LTT_STRUCT
){*name
== NULL
; return NULL
;}
263 if(i
>= t
->element_number
|| i
< 0 ){*name
= NULL
; return NULL
;}
264 *name
= t
->element_type
[i
]->element_name
;
265 return t
->element_type
[i
];
268 /*****************************************************************************
270 * ltt_enum_string_get : for enumerations, obtain the symbolic string
271 * associated with a value (0 to n - 1 for an
272 * enumeration of n elements)
275 * i : index of the member
277 * char * : symbolic string associated with a value
278 ****************************************************************************/
280 char *ltt_enum_string_get(LttType
*t
, unsigned i
)
282 if(t
->type_class
!= LTT_ENUM
) return NULL
;
283 if(i
>= t
->element_number
|| i
< 0 ) return NULL
;
284 return t
->enum_strings
[i
];
287 /*****************************************************************************
289 * ltt_field_element : obtain the field of nested elements for arrays and
294 * LttField * : the field of the nested element
295 ****************************************************************************/
297 LttField
*ltt_field_element(LttField
*f
)
299 if(f
->field_type
->type_class
!= LTT_ARRAY
&&
300 f
->field_type
->type_class
!= LTT_SEQUENCE
)
306 /*****************************************************************************
308 * ltt_field_member : obtain the filed of data members for structure
311 * i : index of member field
313 * LttField * : the field of the nested element
314 ****************************************************************************/
316 LttField
*ltt_field_member(LttField
*f
, unsigned i
)
318 if(f
->field_type
->type_class
!= LTT_STRUCT
) return NULL
;
319 if(i
< 0 || i
>= f
->field_type
->element_number
) return NULL
;
323 /*****************************************************************************
325 * ltt_field_type : obtain the type of the field
329 * ltt_tyoe * : the type of field
330 ****************************************************************************/
332 LttType
*ltt_field_type(LttField
*f
)
335 return f
->field_type
;
338 int ltt_field_size(LttField
* f
)
341 return f
->field_size
;
This page took 0.042985 seconds and 5 git commands to generate.