X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Fltt%2Ftype.c;h=e153d5403c322595ef83ad17d34aee61e2d216c5;hb=3aee1200b100fe8063661fd2d8eaa5fbbfc1977f;hp=981507726abcd6b9107aa8ddc9776a0885c6f4ed;hpb=6cd62ccfe338056a2a7571addbb63e0e16354e86;p=lttv.git diff --git a/ltt/branches/poly/ltt/type.c b/ltt/branches/poly/ltt/type.c index 98150772..e153d540 100644 --- a/ltt/branches/poly/ltt/type.c +++ b/ltt/branches/poly/ltt/type.c @@ -1,16 +1,47 @@ +/* This file is part of the Linux Trace Toolkit viewer + * Copyright (C) 2003-2004 Xiangxiu Yang, Mathieu Desnoyers + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License Version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + #include +#include -#include "LTTTypes.h" #include "parser.h" +#include +#include "ltt-private.h" #include static unsigned intSizes[] = { sizeof(int8_t), sizeof(int16_t), sizeof(int32_t), sizeof(int64_t), sizeof(short) }; +typedef enum _intSizesNames { SIZE_INT8, SIZE_INT16, SIZE_INT32, + SIZE_INT64, SIZE_SHORT, INT_SIZES_NUMBER } + intSizesNames; + + static unsigned floatSizes[] = { 0, 0, sizeof(float), sizeof(double), 0, sizeof(float), sizeof(double) }; +#define FLOAT_SIZES_NUMBER 7 + /***************************************************************************** *Function name @@ -18,10 +49,10 @@ static unsigned floatSizes[] = { *Input params * et : an event type *Return value - * char * : the name of the event type + * GQuark : the name of the event type ****************************************************************************/ -char *ltt_eventtype_name(ltt_eventtype *et) +GQuark ltt_eventtype_name(LttEventType *et) { return et->name; } @@ -35,23 +66,66 @@ char *ltt_eventtype_name(ltt_eventtype *et) * char * : the description of the event type ****************************************************************************/ -char *ltt_eventtype_description(ltt_eventtype *et) +gchar *ltt_eventtype_description(LttEventType *et) { return et->description; } +/***************************************************************************** + *Function name + * ltt_eventtype_facility : get the facility which contains the event type + *Input params + * et : an event type + *Return value + * LttFacility * : the facility + ****************************************************************************/ + +LttFacility *ltt_eventtype_facility(LttEventType *et) +{ + return et->facility; +} + +/***************************************************************************** + *Function name + * ltt_eventtype_id : get the id of the event type + *Input params + * et : an event type + *Return value + * unsigned : the id + ****************************************************************************/ + +guint8 ltt_eventtype_id(LttEventType *et) +{ + return et->index; +} + /***************************************************************************** *Function name * ltt_eventtype_type : get the type of the event type *Input params * et : an event type *Return value - * ltt_type * : the type of the event type + * LttType * : the type of the event type ****************************************************************************/ -ltt_type *ltt_eventtype_type(ltt_eventtype *et) +LttType *ltt_eventtype_type(LttEventType *et) { - return et->root_field->field_type; + if(unlikely(!et->root_field)) return NULL; + else return et->root_field->field_type; +} + +/***************************************************************************** + *Function name + * ltt_eventtype_field : get the root filed of the event type + *Input params + * et : an event type + *Return value + * LttField * : the root filed of the event type + ****************************************************************************/ + +LttField *ltt_eventtype_field(LttEventType *et) +{ + return et->root_field; } /***************************************************************************** @@ -63,7 +137,7 @@ ltt_type *ltt_eventtype_type(ltt_eventtype *et) * char * : the name of the type ****************************************************************************/ -char *ltt_type_name(ltt_type *t) +GQuark ltt_type_name(LttType *t) { return t->element_name; } @@ -74,10 +148,10 @@ char *ltt_type_name(ltt_type *t) *Input params * t : a type *Return value - * ltt_type_enum : the type class of the type + * LttTypeEnum : the type class of the type ****************************************************************************/ -ltt_type_enum ltt_type_class(ltt_type *t) +LttTypeEnum ltt_type_class(LttType *t) { return t->type_class; } @@ -85,35 +159,58 @@ ltt_type_enum ltt_type_class(ltt_type *t) /***************************************************************************** *Function name * ltt_type_size : obtain the type size. The size is the number of bytes - * for primitive types (INT, UINT, FLOAT, ENUM), or the - * size for the unsigned integer length count for sequences + * for primitive types (INT, UINT, FLOAT, ENUM) + * or the size for the unsigned integer length count for + * sequences *Input params * tf : trace file * t : a type *Return value - * unsigned : the type size + * : the type size + * returns 0 if erroneous, and show a critical warning message. ****************************************************************************/ -unsigned ltt_type_size(ltt_tracefile * tf, ltt_type *t) +size_t ltt_type_size(LttTrace * trace, LttType *t) { - if(t->type_class==LTT_STRUCT || t->type_class==LTT_ARRAY || - t->type_class==LTT_STRING) return 0; - - if(t->type_class == LTT_FLOAT){ - return floatSizes[t->size]; - }else{ - if(t->size < sizeof(intSizes)/sizeof(unsigned)) - return intSizes[t->size]; - else{ - ltt_arch_size size = tf->trace_header->arch_size; - if(size == LTT_LP32) - return sizeof(int16_t); - else if(size == LTT_ILP32 || size == LTT_LP64) - return sizeof(int32_t); - else if(size == LTT_ILP64) - return sizeof(int64_t); - } + size_t size; + + switch(t->type_class) { + + case LTT_INT: + case LTT_UINT: + case LTT_SEQUENCE: + case LTT_ENUM: + if(likely(t->size < INT_SIZES_NUMBER)) + size = intSizes[t->size]; + else + goto error; + break; + case LTT_FLOAT: + if(likely(t->size < FLOAT_SIZES_NUMBER)) + size = floatSizes[t->size]; + else + goto error; + break; + case LTT_POINTER: + case LTT_LONG: + case LTT_ULONG: + case LTT_SIZE_T: + case LTT_SSIZE_T: + case LTT_OFF_T: + case LTT_STRING: + case LTT_ARRAY: + case LTT_STRUCT: + case LTT_UNION: + goto error; + break; } + + return size; + + +error: + g_warning("no size known for the type"); + return 0; } /***************************************************************************** @@ -123,14 +220,19 @@ unsigned ltt_type_size(ltt_tracefile * tf, ltt_type *t) *Input params * t : a type *Return value - * ltt_type : the type of nested element of array or sequence + * LttType : the type of nested element of array or sequence ****************************************************************************/ -ltt_type *ltt_type_element_type(ltt_type *t) +LttType *ltt_type_element_type(LttType *t) { - if(t->type_class != LTT_ARRAY || t->type_class != LTT_SEQUENCE) - return NULL; - return t->element_type[0]; + LttType *element_type; + + if(unlikely(t->type_class != LTT_ARRAY && t->type_class != LTT_SEQUENCE)) + element_type = NULL; + else + element_type = t->element_type[0]; + + return element_type; } /***************************************************************************** @@ -142,11 +244,14 @@ ltt_type *ltt_type_element_type(ltt_type *t) * unsigned : the number of elements for arrays ****************************************************************************/ -unsigned ltt_type_element_number(ltt_type *t) +unsigned ltt_type_element_number(LttType *t) { - if(t->type_class != LTT_ARRAY) - return 0; - return t->element_number; + unsigned ret = 0; + + if(likely(t->type_class == LTT_ARRAY)) + ret = t->element_number; + + return ret; } /***************************************************************************** @@ -158,28 +263,43 @@ unsigned ltt_type_element_number(ltt_type *t) * unsigned : the number of members for structure ****************************************************************************/ -unsigned ltt_type_member_number(ltt_type *t) +unsigned ltt_type_member_number(LttType *t) { - if(t->type_class != LTT_STRUCT) - return 0; - return t->element_number; + unsigned ret = 0; + + if(likely(t->type_class == LTT_STRUCT || t->type_class == LTT_UNION)) + ret =t->element_number; + + return ret; } /***************************************************************************** *Function name - * ltt_type_member_type : obtain the type of a data members in a structure + * ltt_type_member_type : obtain the type of a data member in a structure + * or union. *Input params * t : a type * i : index of the member *Return value - * ltt_type * : the type of structure member + * LttType * : the type of structure member ****************************************************************************/ -ltt_type *ltt_type_member_type(ltt_type *t, unsigned i) +LttType *ltt_type_member_type(LttType *t, unsigned i, GQuark *name) { - if(t->type_class != LTT_STRUCT) return NULL; - if(i > t->element_number || i == 0 ) return NULL; - return t->element_type[i-1]; + LttType *member_type = NULL; + + if(unlikely( (t->type_class != LTT_STRUCT + && t->type_class != LTT_UNION) + || + (i >= t->element_number) + )) { + *name = 0; + } else { + *name = t->element_type[i]->element_name; + member_type = t->element_type[i]; + } + + return member_type; } /***************************************************************************** @@ -194,11 +314,12 @@ ltt_type *ltt_type_member_type(ltt_type *t, unsigned i) * char * : symbolic string associated with a value ****************************************************************************/ -char *ltt_enum_string_get(ltt_type *t, unsigned i) -{ - if(t->type_class != LTT_ENUM) return NULL; - if(i > t->element_number || i == 0 ) return NULL; - return t->enum_strings[i-1]; +GQuark ltt_enum_string_get(LttType *t, unsigned i) +{ + if(likely(t->type_class == LTT_ENUM && i < t->element_number)) + return t->enum_strings[i]; + else + return 0; } /***************************************************************************** @@ -208,33 +329,42 @@ char *ltt_enum_string_get(ltt_type *t, unsigned i) *Input params * f : a field *Return value - * ltt_field * : the field of the nested element + * LttField * : the field of the nested element ****************************************************************************/ -ltt_field *ltt_field_element(ltt_field *f) +LttField *ltt_field_element(LttField *f) { - if(f->field_type->type_class != LTT_ARRAY || - f->field_type->type_class != LTT_SEQUENCE) - return NULL; + LttField *nest = NULL; + + if(likely(f->field_type->type_class == LTT_ARRAY || + f->field_type->type_class == LTT_SEQUENCE)) + nest = f->child[0]; - return f->child[0]; + return nest; } /***************************************************************************** *Function name - * ltt_field_member : obtain the filed of data members for structure + * ltt_field_member : obtain the field of data members for structure *Input params * f : a field * i : index of member field *Return value - * ltt_field * : the field of the nested element + * LttField * : the field of the nested element ****************************************************************************/ -ltt_field *ltt_field_member(ltt_field *f, unsigned i) +LttField *ltt_field_member(LttField *f, unsigned i) { - if(f->field_type->type_class != LTT_STRUCT) return NULL; - if(i==0 || i>f->field_type->element_number) return NULL; - return f->child[i-1]; + LttField *field_member; + + if(unlikely( f->field_type->type_class != LTT_STRUCT + && f->field_type->type_class != LTT_UNION) + || i >= f->field_type->element_number ) + field_member = NULL; + else + field_member = f->child[i]; + + return field_member; } /***************************************************************************** @@ -246,8 +376,14 @@ ltt_field *ltt_field_member(ltt_field *f, unsigned i) * ltt_tyoe * : the type of field ****************************************************************************/ -ltt_type *ltt_field_type(ltt_field *f) +LttType *ltt_field_type(LttField *f) { + if(unlikely(!f))return NULL; return f->field_type; } +int ltt_field_size(LttField * f) +{ + if(unlikely(!f))return 0; + return f->field_size; +}