X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Fltt%2Ftype.c;h=a28e8fe3e33cd510cbe5df7701d77c6b54e871b2;hb=49f3c39e02a4f8a60a3656c2cbdeec23ef8f58ca;hp=a2c73f229c428f9c42822a6a9aa8892c7606d72c;hpb=a2331fa0f3390c29cee40007f69f14fa1d216707;p=lttv.git diff --git a/ltt/branches/poly/ltt/type.c b/ltt/branches/poly/ltt/type.c index a2c73f22..a28e8fe3 100644 --- a/ltt/branches/poly/ltt/type.c +++ b/ltt/branches/poly/ltt/type.c @@ -1,7 +1,26 @@ +/* This file is part of the Linux Trace Toolkit viewer + * Copyright (C) 2003-2004 Xiangxiu Yang + * + * 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. + */ + #include -#include #include "parser.h" +#include +#include "ltt-private.h" #include static unsigned intSizes[] = { @@ -149,12 +168,13 @@ LttTypeEnum ltt_type_class(LttType *t) * t : a type *Return value * unsigned : the type size + * returns 0 if erroneous, and show a critical warning message. ****************************************************************************/ unsigned 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; + t->type_class==LTT_STRING || t->type_class==LTT_UNION) return 0; if(t->type_class == LTT_FLOAT){ return floatSizes[t->size]; @@ -164,19 +184,22 @@ unsigned ltt_type_size(LttTrace * trace, LttType *t) else{ LttArchSize size = trace->system_description->size; if(size == LTT_LP32){ - if(t->size == 5)return sizeof(int16_t); - else return sizeof(int32_t); + if(t->size == 5)return sizeof(int16_t); + else return sizeof(int32_t); } else if(size == LTT_ILP32 || size == LTT_LP64){ - if(t->size == 5)return sizeof(int32_t); - else{ - if(size == LTT_ILP32) return sizeof(int32_t); - else return sizeof(int64_t); - } + if(t->size == 5)return sizeof(int32_t); + else{ + if(size == LTT_ILP32) return sizeof(int32_t); + else return sizeof(int64_t); + } } else if(size == LTT_ILP64)return sizeof(int64_t); } } + + g_critical("ltt_type_size : Type size %u unknown", t->size); + return 0; } /***************************************************************************** @@ -230,7 +253,8 @@ unsigned ltt_type_member_number(LttType *t) /***************************************************************************** *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 @@ -240,8 +264,9 @@ unsigned ltt_type_member_number(LttType *t) LttType *ltt_type_member_type(LttType *t, unsigned i, char ** name) { - if(t->type_class != LTT_STRUCT){*name == NULL; return NULL;} - if(i >= t->element_number || i < 0 ){*name = NULL; return NULL;} + if(t->type_class != LTT_STRUCT + && t->type_class != LTT_UNION){*name = NULL; return NULL;} + if(i >= t->element_number){*name = NULL; return NULL;} *name = t->element_type[i]->element_name; return t->element_type[i]; } @@ -261,7 +286,7 @@ LttType *ltt_type_member_type(LttType *t, unsigned i, char ** name) char *ltt_enum_string_get(LttType *t, unsigned i) { if(t->type_class != LTT_ENUM) return NULL; - if(i >= t->element_number || i < 0 ) return NULL; + if(i >= t->element_number) return NULL; return t->enum_strings[i]; } @@ -286,7 +311,7 @@ LttField *ltt_field_element(LttField *f) /***************************************************************************** *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 @@ -296,8 +321,9 @@ LttField *ltt_field_element(LttField *f) 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; + if(f->field_type->type_class != LTT_STRUCT + && f->field_type->type_class != LTT_UNION) return NULL; + if(i >= f->field_type->element_number) return NULL; return f->child[i]; } @@ -316,3 +342,8 @@ LttType *ltt_field_type(LttField *f) return f->field_type; } +int ltt_field_size(LttField * f) +{ + if(!f)return 0; + return f->field_size; +}