| 1 | /* This file is part of the Linux Trace Toolkit viewer |
| 2 | * Copyright (C) 2003-2004 Xiangxiu Yang |
| 3 | * |
| 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; |
| 7 | * |
| 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. |
| 12 | * |
| 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, |
| 16 | * MA 02111-1307, USA. |
| 17 | */ |
| 18 | |
| 19 | #include <stdio.h> |
| 20 | |
| 21 | #include "parser.h" |
| 22 | #include <ltt/ltt.h> |
| 23 | #include "ltt-private.h" |
| 24 | #include <ltt/type.h> |
| 25 | |
| 26 | static unsigned intSizes[] = { |
| 27 | sizeof(int8_t), sizeof(int16_t), sizeof(int32_t), sizeof(int64_t), |
| 28 | sizeof(short) }; |
| 29 | |
| 30 | static unsigned floatSizes[] = { |
| 31 | 0, 0, sizeof(float), sizeof(double), 0, sizeof(float), sizeof(double) }; |
| 32 | |
| 33 | |
| 34 | /***************************************************************************** |
| 35 | *Function name |
| 36 | * ltt_eventtype_name : get the name of the event type |
| 37 | *Input params |
| 38 | * et : an event type |
| 39 | *Return value |
| 40 | * char * : the name of the event type |
| 41 | ****************************************************************************/ |
| 42 | |
| 43 | char *ltt_eventtype_name(LttEventType *et) |
| 44 | { |
| 45 | return et->name; |
| 46 | } |
| 47 | |
| 48 | /***************************************************************************** |
| 49 | *Function name |
| 50 | * ltt_eventtype_description : get the description of the event type |
| 51 | *Input params |
| 52 | * et : an event type |
| 53 | *Return value |
| 54 | * char * : the description of the event type |
| 55 | ****************************************************************************/ |
| 56 | |
| 57 | char *ltt_eventtype_description(LttEventType *et) |
| 58 | { |
| 59 | return et->description; |
| 60 | } |
| 61 | |
| 62 | /***************************************************************************** |
| 63 | *Function name |
| 64 | * ltt_eventtype_facility : get the facility which contains the event type |
| 65 | *Input params |
| 66 | * et : an event type |
| 67 | *Return value |
| 68 | * LttFacility * : the facility |
| 69 | ****************************************************************************/ |
| 70 | |
| 71 | LttFacility *ltt_eventtype_facility(LttEventType *et) |
| 72 | { |
| 73 | return et->facility; |
| 74 | } |
| 75 | |
| 76 | /***************************************************************************** |
| 77 | *Function name |
| 78 | * ltt_eventtype_relative_id : get the relative id of the event type |
| 79 | *Input params |
| 80 | * et : an event type |
| 81 | *Return value |
| 82 | * unsigned : the relative id |
| 83 | ****************************************************************************/ |
| 84 | |
| 85 | unsigned ltt_eventtype_relative_id(LttEventType *et) |
| 86 | { |
| 87 | return et->index; |
| 88 | } |
| 89 | |
| 90 | /***************************************************************************** |
| 91 | *Function name |
| 92 | * ltt_eventtype_id : get the id of the event type |
| 93 | *Input params |
| 94 | * et : an event type |
| 95 | *Return value |
| 96 | * unsigned : the id |
| 97 | ****************************************************************************/ |
| 98 | |
| 99 | unsigned ltt_eventtype_id(LttEventType *et) |
| 100 | { |
| 101 | return et->facility->base_id + et->index; |
| 102 | } |
| 103 | |
| 104 | /***************************************************************************** |
| 105 | *Function name |
| 106 | * ltt_eventtype_type : get the type of the event type |
| 107 | *Input params |
| 108 | * et : an event type |
| 109 | *Return value |
| 110 | * LttType * : the type of the event type |
| 111 | ****************************************************************************/ |
| 112 | |
| 113 | LttType *ltt_eventtype_type(LttEventType *et) |
| 114 | { |
| 115 | if(!et->root_field) return NULL; |
| 116 | return et->root_field->field_type; |
| 117 | } |
| 118 | |
| 119 | /***************************************************************************** |
| 120 | *Function name |
| 121 | * ltt_eventtype_field : get the root filed of the event type |
| 122 | *Input params |
| 123 | * et : an event type |
| 124 | *Return value |
| 125 | * LttField * : the root filed of the event type |
| 126 | ****************************************************************************/ |
| 127 | |
| 128 | LttField *ltt_eventtype_field(LttEventType *et) |
| 129 | { |
| 130 | return et->root_field; |
| 131 | } |
| 132 | |
| 133 | /***************************************************************************** |
| 134 | *Function name |
| 135 | * ltt_type_name : get the name of the type |
| 136 | *Input params |
| 137 | * t : a type |
| 138 | *Return value |
| 139 | * char * : the name of the type |
| 140 | ****************************************************************************/ |
| 141 | |
| 142 | char *ltt_type_name(LttType *t) |
| 143 | { |
| 144 | return t->element_name; |
| 145 | } |
| 146 | |
| 147 | /***************************************************************************** |
| 148 | *Function name |
| 149 | * ltt_type_class : get the type class of the type |
| 150 | *Input params |
| 151 | * t : a type |
| 152 | *Return value |
| 153 | * LttTypeEnum : the type class of the type |
| 154 | ****************************************************************************/ |
| 155 | |
| 156 | LttTypeEnum ltt_type_class(LttType *t) |
| 157 | { |
| 158 | return t->type_class; |
| 159 | } |
| 160 | |
| 161 | /***************************************************************************** |
| 162 | *Function name |
| 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 |
| 166 | *Input params |
| 167 | * tf : trace file |
| 168 | * t : a type |
| 169 | *Return value |
| 170 | * unsigned : the type size |
| 171 | ****************************************************************************/ |
| 172 | |
| 173 | unsigned ltt_type_size(LttTrace * trace, LttType *t) |
| 174 | { |
| 175 | if(t->type_class==LTT_STRUCT || t->type_class==LTT_ARRAY || |
| 176 | t->type_class==LTT_STRING) return 0; |
| 177 | |
| 178 | if(t->type_class == LTT_FLOAT){ |
| 179 | return floatSizes[t->size]; |
| 180 | }else{ |
| 181 | if(t->size < sizeof(intSizes)/sizeof(unsigned)) |
| 182 | return intSizes[t->size]; |
| 183 | else{ |
| 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); |
| 188 | } |
| 189 | else if(size == LTT_ILP32 || size == LTT_LP64){ |
| 190 | if(t->size == 5)return sizeof(int32_t); |
| 191 | else{ |
| 192 | if(size == LTT_ILP32) return sizeof(int32_t); |
| 193 | else return sizeof(int64_t); |
| 194 | } |
| 195 | } |
| 196 | else if(size == LTT_ILP64)return sizeof(int64_t); |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | /***************************************************************************** |
| 202 | *Function name |
| 203 | * ltt_type_element_type : obtain the type of nested elements for arrays |
| 204 | * and sequences |
| 205 | *Input params |
| 206 | * t : a type |
| 207 | *Return value |
| 208 | * LttType : the type of nested element of array or sequence |
| 209 | ****************************************************************************/ |
| 210 | |
| 211 | LttType *ltt_type_element_type(LttType *t) |
| 212 | { |
| 213 | if(t->type_class != LTT_ARRAY && t->type_class != LTT_SEQUENCE) |
| 214 | return NULL; |
| 215 | return t->element_type[0]; |
| 216 | } |
| 217 | |
| 218 | /***************************************************************************** |
| 219 | *Function name |
| 220 | * ltt_type_element_number : obtain the number of elements for arrays |
| 221 | *Input params |
| 222 | * t : a type |
| 223 | *Return value |
| 224 | * unsigned : the number of elements for arrays |
| 225 | ****************************************************************************/ |
| 226 | |
| 227 | unsigned ltt_type_element_number(LttType *t) |
| 228 | { |
| 229 | if(t->type_class != LTT_ARRAY) |
| 230 | return 0; |
| 231 | return t->element_number; |
| 232 | } |
| 233 | |
| 234 | /***************************************************************************** |
| 235 | *Function name |
| 236 | * ltt_type_member_number : obtain the number of data members for structure |
| 237 | *Input params |
| 238 | * t : a type |
| 239 | *Return value |
| 240 | * unsigned : the number of members for structure |
| 241 | ****************************************************************************/ |
| 242 | |
| 243 | unsigned ltt_type_member_number(LttType *t) |
| 244 | { |
| 245 | if(t->type_class != LTT_STRUCT && t->type_class != LTT_UNION) |
| 246 | return 0; |
| 247 | return t->element_number; |
| 248 | } |
| 249 | |
| 250 | /***************************************************************************** |
| 251 | *Function name |
| 252 | * ltt_type_member_type : obtain the type of a data members in a structure |
| 253 | *Input params |
| 254 | * t : a type |
| 255 | * i : index of the member |
| 256 | *Return value |
| 257 | * LttType * : the type of structure member |
| 258 | ****************************************************************************/ |
| 259 | |
| 260 | LttType *ltt_type_member_type(LttType *t, unsigned i, char ** name) |
| 261 | { |
| 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]; |
| 266 | } |
| 267 | |
| 268 | /***************************************************************************** |
| 269 | *Function name |
| 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) |
| 273 | *Input params |
| 274 | * t : a type |
| 275 | * i : index of the member |
| 276 | *Return value |
| 277 | * char * : symbolic string associated with a value |
| 278 | ****************************************************************************/ |
| 279 | |
| 280 | char *ltt_enum_string_get(LttType *t, unsigned i) |
| 281 | { |
| 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]; |
| 285 | } |
| 286 | |
| 287 | /***************************************************************************** |
| 288 | *Function name |
| 289 | * ltt_field_element : obtain the field of nested elements for arrays and |
| 290 | * sequence |
| 291 | *Input params |
| 292 | * f : a field |
| 293 | *Return value |
| 294 | * LttField * : the field of the nested element |
| 295 | ****************************************************************************/ |
| 296 | |
| 297 | LttField *ltt_field_element(LttField *f) |
| 298 | { |
| 299 | if(f->field_type->type_class != LTT_ARRAY && |
| 300 | f->field_type->type_class != LTT_SEQUENCE) |
| 301 | return NULL; |
| 302 | |
| 303 | return f->child[0]; |
| 304 | } |
| 305 | |
| 306 | /***************************************************************************** |
| 307 | *Function name |
| 308 | * ltt_field_member : obtain the filed of data members for structure |
| 309 | *Input params |
| 310 | * f : a field |
| 311 | * i : index of member field |
| 312 | *Return value |
| 313 | * LttField * : the field of the nested element |
| 314 | ****************************************************************************/ |
| 315 | |
| 316 | LttField *ltt_field_member(LttField *f, unsigned i) |
| 317 | { |
| 318 | if(f->field_type->type_class != LTT_STRUCT) return NULL; |
| 319 | if(i < 0 || i >= f->field_type->element_number) return NULL; |
| 320 | return f->child[i]; |
| 321 | } |
| 322 | |
| 323 | /***************************************************************************** |
| 324 | *Function name |
| 325 | * ltt_field_type : obtain the type of the field |
| 326 | *Input params |
| 327 | * f : a field |
| 328 | *Return value |
| 329 | * ltt_tyoe * : the type of field |
| 330 | ****************************************************************************/ |
| 331 | |
| 332 | LttType *ltt_field_type(LttField *f) |
| 333 | { |
| 334 | if(!f)return NULL; |
| 335 | return f->field_type; |
| 336 | } |
| 337 | |
| 338 | int ltt_field_size(LttField * f) |
| 339 | { |
| 340 | if(!f)return 0; |
| 341 | return f->field_size; |
| 342 | } |