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
) 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 members in a structure
259 * i : index of the member
261 * LttType * : the type of structure member
262 ****************************************************************************/
264 LttType
*ltt_type_member_type(LttType
*t
, unsigned i
, char ** name
)
266 if(t
->type_class
!= LTT_STRUCT
){*name
= NULL
; return NULL
;}
267 if(i
>= t
->element_number
){*name
= NULL
; return NULL
;}
268 *name
= t
->element_type
[i
]->element_name
;
269 return t
->element_type
[i
];
272 /*****************************************************************************
274 * ltt_enum_string_get : for enumerations, obtain the symbolic string
275 * associated with a value (0 to n - 1 for an
276 * enumeration of n elements)
279 * i : index of the member
281 * char * : symbolic string associated with a value
282 ****************************************************************************/
284 char *ltt_enum_string_get(LttType
*t
, unsigned i
)
286 if(t
->type_class
!= LTT_ENUM
) return NULL
;
287 if(i
>= t
->element_number
) return NULL
;
288 return t
->enum_strings
[i
];
291 /*****************************************************************************
293 * ltt_field_element : obtain the field of nested elements for arrays and
298 * LttField * : the field of the nested element
299 ****************************************************************************/
301 LttField
*ltt_field_element(LttField
*f
)
303 if(f
->field_type
->type_class
!= LTT_ARRAY
&&
304 f
->field_type
->type_class
!= LTT_SEQUENCE
)
310 /*****************************************************************************
312 * ltt_field_member : obtain the filed of data members for structure
315 * i : index of member field
317 * LttField * : the field of the nested element
318 ****************************************************************************/
320 LttField
*ltt_field_member(LttField
*f
, unsigned i
)
322 if(f
->field_type
->type_class
!= LTT_STRUCT
) return NULL
;
323 if(i
>= f
->field_type
->element_number
) return NULL
;
327 /*****************************************************************************
329 * ltt_field_type : obtain the type of the field
333 * ltt_tyoe * : the type of field
334 ****************************************************************************/
336 LttType
*ltt_field_type(LttField
*f
)
339 return f
->field_type
;
342 int ltt_field_size(LttField
* f
)
345 return f
->field_size
;
This page took 0.037811 seconds and 4 git commands to generate.