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 * returns 0 if erroneous, and show a critical warning message.
172 ****************************************************************************/
174 unsigned ltt_type_size(LttTrace
* trace
, LttType
*t
)
176 if(t
->type_class
==LTT_STRUCT
|| t
->type_class
==LTT_ARRAY
||
177 t
->type_class
==LTT_STRING
|| t
->type_class
==LTT_UNION
) return 0;
179 if(t
->type_class
== LTT_FLOAT
){
180 return floatSizes
[t
->size
];
182 if(t
->size
< sizeof(intSizes
)/sizeof(unsigned))
183 return intSizes
[t
->size
];
185 LttArchSize size
= trace
->system_description
->size
;
186 if(size
== LTT_LP32
){
187 if(t
->size
== 5)return sizeof(int16_t);
188 else return sizeof(int32_t);
190 else if(size
== LTT_ILP32
|| size
== LTT_LP64
){
191 if(t
->size
== 5)return sizeof(int32_t);
193 if(size
== LTT_ILP32
) return sizeof(int32_t);
194 else return sizeof(int64_t);
197 else if(size
== LTT_ILP64
)return sizeof(int64_t);
201 g_critical("ltt_type_size : Type size %u unknown", t
->size
);
205 /*****************************************************************************
207 * ltt_type_element_type : obtain the type of nested elements for arrays
212 * LttType : the type of nested element of array or sequence
213 ****************************************************************************/
215 LttType
*ltt_type_element_type(LttType
*t
)
217 if(t
->type_class
!= LTT_ARRAY
&& t
->type_class
!= LTT_SEQUENCE
)
219 return t
->element_type
[0];
222 /*****************************************************************************
224 * ltt_type_element_number : obtain the number of elements for arrays
228 * unsigned : the number of elements for arrays
229 ****************************************************************************/
231 unsigned ltt_type_element_number(LttType
*t
)
233 if(t
->type_class
!= LTT_ARRAY
)
235 return t
->element_number
;
238 /*****************************************************************************
240 * ltt_type_member_number : obtain the number of data members for structure
244 * unsigned : the number of members for structure
245 ****************************************************************************/
247 unsigned ltt_type_member_number(LttType
*t
)
249 if(t
->type_class
!= LTT_STRUCT
&& t
->type_class
!= LTT_UNION
)
251 return t
->element_number
;
254 /*****************************************************************************
256 * ltt_type_member_type : obtain the type of a data member in a structure
260 * i : index of the member
262 * LttType * : the type of structure member
263 ****************************************************************************/
265 LttType
*ltt_type_member_type(LttType
*t
, unsigned i
, char ** name
)
267 if(t
->type_class
!= LTT_STRUCT
268 && t
->type_class
!= LTT_UNION
){*name
= NULL
; return NULL
;}
269 if(i
>= t
->element_number
){*name
= NULL
; return NULL
;}
270 *name
= t
->element_type
[i
]->element_name
;
271 return t
->element_type
[i
];
274 /*****************************************************************************
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)
281 * i : index of the member
283 * char * : symbolic string associated with a value
284 ****************************************************************************/
286 char *ltt_enum_string_get(LttType
*t
, unsigned i
)
288 if(t
->type_class
!= LTT_ENUM
) return NULL
;
289 if(i
>= t
->element_number
) return NULL
;
290 return t
->enum_strings
[i
];
293 /*****************************************************************************
295 * ltt_field_element : obtain the field of nested elements for arrays and
300 * LttField * : the field of the nested element
301 ****************************************************************************/
303 LttField
*ltt_field_element(LttField
*f
)
305 if(f
->field_type
->type_class
!= LTT_ARRAY
&&
306 f
->field_type
->type_class
!= LTT_SEQUENCE
)
312 /*****************************************************************************
314 * ltt_field_member : obtain the field of data members for structure
317 * i : index of member field
319 * LttField * : the field of the nested element
320 ****************************************************************************/
322 LttField
*ltt_field_member(LttField
*f
, unsigned i
)
324 if(f
->field_type
->type_class
!= LTT_STRUCT
325 && f
->field_type
->type_class
!= LTT_UNION
) return NULL
;
326 if(i
>= f
->field_type
->element_number
) return NULL
;
330 /*****************************************************************************
332 * ltt_field_type : obtain the type of the field
336 * ltt_tyoe * : the type of field
337 ****************************************************************************/
339 LttType
*ltt_field_type(LttField
*f
)
342 return f
->field_type
;
345 int ltt_field_size(LttField
* f
)
348 return f
->field_size
;
This page took 0.041146 seconds and 5 git commands to generate.