X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Fltt%2Ftype.c;h=df1b8ea805d52c4edc90e064d52b9d2f1455c93c;hb=3c165eaf5aa1e60ce88c036cfb692ce3e1d81585;hp=34eeb4e01ac356eb78acf891e927a9d57bee1487;hpb=45e14832eebe9f25938b2c668d8ef1acd56a2436;p=lttv.git diff --git a/ltt/branches/poly/ltt/type.c b/ltt/branches/poly/ltt/type.c index 34eeb4e0..df1b8ea8 100644 --- a/ltt/branches/poly/ltt/type.c +++ b/ltt/branches/poly/ltt/type.c @@ -1,21 +1,26 @@ /* This file is part of the Linux Trace Toolkit viewer - * Copyright (C) 2003-2004 Xiangxiu Yang, Mathieu Desnoyers + * Copyright (C) 2003-2004 Xiangxiu Yang + * 2005 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 library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License Version 2.1 as published by the Free Software Foundation. * - * This program is distributed in the hope that it will be useful, + * This library 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. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser 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. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; 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 @@ -28,13 +33,19 @@ static unsigned intSizes[] = { sizeof(int8_t), sizeof(int16_t), sizeof(int32_t), sizeof(int64_t), sizeof(short) }; +static unsigned floatSizes[] = { + 0, 0, sizeof(float), sizeof(double), 0, sizeof(float), sizeof(double) }; + + typedef enum _intSizesNames { SIZE_INT8, SIZE_INT16, SIZE_INT32, SIZE_INT64, SIZE_SHORT, INT_SIZES_NUMBER } intSizesNames; +static char * typeNames[] = { + "int_fixed", "uint_fixed", "pointer", "char", "uchar", "short", "ushort", + "int", "uint", "long", "ulong", "size_t", "ssize_t", "off_t", "float", + "string", "enum", "array", "sequence", "struct", "union", "none" }; -static unsigned floatSizes[] = { - 0, 0, sizeof(float), sizeof(double), 0, sizeof(float), sizeof(double) }; #define FLOAT_SIZES_NUMBER 7 @@ -45,10 +56,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 ****************************************************************************/ -gchar *ltt_eventtype_name(LttEventType *et) +GQuark ltt_eventtype_name(LttEventType *et) { return et->name; } @@ -67,34 +78,6 @@ 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_relative_id : get the relative id of the event type - *Input params - * et : an event type - *Return value - * unsigned : the relative id - ****************************************************************************/ - -unsigned ltt_eventtype_relative_id(LttEventType *et) -{ - return et->index; -} - /***************************************************************************** *Function name * ltt_eventtype_id : get the id of the event type @@ -104,52 +87,37 @@ unsigned ltt_eventtype_relative_id(LttEventType *et) * unsigned : the id ****************************************************************************/ -unsigned ltt_eventtype_id(LttEventType *et) +guint8 ltt_eventtype_id(LttEventType *et) { - return et->facility->base_id + et->index; -} - -/***************************************************************************** - *Function name - * ltt_eventtype_type : get the type of the event type - *Input params - * et : an event type - *Return value - * LttType * : the type of the event type - ****************************************************************************/ - -LttType *ltt_eventtype_type(LttEventType *et) -{ - if(unlikely(!et->root_field)) return NULL; - else return et->root_field->field_type; + return et->index; } /***************************************************************************** *Function name - * ltt_eventtype_field : get the root filed of the event type + * ltt_type_name : get the name of the type *Input params - * et : an event type + * t : a type *Return value - * LttField * : the root filed of the event type + * GQuark : the name of the type ****************************************************************************/ -LttField *ltt_eventtype_field(LttEventType *et) +GQuark ltt_type_name(LttType *t) { - return et->root_field; + return g_quark_from_static_string(typeNames[t->type_class]); } /***************************************************************************** *Function name - * ltt_type_name : get the name of the type + * ltt_field_name : get the name of the field *Input params - * t : a type + * f : a field *Return value * char * : the name of the type ****************************************************************************/ -gchar *ltt_type_name(LttType *t) +GQuark ltt_field_name(LttField *f) { - return t->element_name; + return f->name; } /***************************************************************************** @@ -169,47 +137,64 @@ LttTypeEnum ltt_type_class(LttType *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(LttTrace * trace, LttType *t) +guint ltt_type_size(LttTrace * trace, LttType *t) { - unsigned size; - if(unlikely(t->type_class==LTT_STRUCT || t->type_class==LTT_ARRAY || - t->type_class==LTT_STRING || t->type_class==LTT_UNION)) { - size = 0; - } else { - if(t->type_class == LTT_FLOAT){ - size = floatSizes[t->size]; - }else{ + guint size; + + switch(t->type_class) { + case LTT_INT_FIXED: + case LTT_UINT_FIXED: + case LTT_CHAR: + case LTT_UCHAR: + case LTT_SHORT: + case LTT_USHORT: + case LTT_INT: + case LTT_UINT: + case LTT_ENUM: if(likely(t->size < INT_SIZES_NUMBER)) size = intSizes[t->size]; - else{ - LttArchSize archsize = trace->system_description->size; - if(archsize == LTT_LP32){ - if(t->size == 5) size = intSizes[SIZE_INT16]; - else size = intSizes[SIZE_INT32]; - } - else if(archsize == LTT_ILP32 || archsize == LTT_LP64){ - if(t->size == 5) size = intSizes[SIZE_INT32]; - else{ - if(archsize == LTT_ILP32) size = intSizes[SIZE_INT32]; - else size = intSizes[SIZE_INT64]; - } - } - else if(archsize == LTT_ILP64) size = intSizes[SIZE_INT64]; - } - } + 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_SEQUENCE: + case LTT_OFF_T: + case LTT_STRING: + case LTT_ARRAY: + case LTT_STRUCT: + case LTT_UNION: + case LTT_NONE: + goto error; + break; } return size; + + +error: + g_warning("no size known for the type"); + return 0; } /***************************************************************************** @@ -225,30 +210,36 @@ unsigned ltt_type_size(LttTrace * trace, LttType *t) LttType *ltt_type_element_type(LttType *t) { LttType *element_type; + LttField *field; if(unlikely(t->type_class != LTT_ARRAY && t->type_class != LTT_SEQUENCE)) element_type = NULL; - else - element_type = t->element_type[0]; + else { + if(t->type_class == LTT_ARRAY) + field = &g_array_index(t->fields, LttField, 0); + else + field = &g_array_index(t->fields, LttField, 1); + element_type = ltt_field_type(field); + } return element_type; } /***************************************************************************** *Function name - * ltt_type_element_number : obtain the number of elements for arrays + * ltt_type_element_number : obtain the number of elements for enums *Input params - * t : a type + * t : a type *Return value * unsigned : the number of elements for arrays ****************************************************************************/ - unsigned ltt_type_element_number(LttType *t) { unsigned ret = 0; - if(likely(t->type_class == LTT_ARRAY)) - ret = t->element_number; + if(likely(t->type_class == LTT_ENUM)) + // Permits non full enums ret = g_hash_table_size(t->enum_map); + ret = (unsigned)(t->highest_value - t->lowest_value); return ret; } @@ -267,39 +258,11 @@ unsigned ltt_type_member_number(LttType *t) unsigned ret = 0; if(likely(t->type_class == LTT_STRUCT || t->type_class == LTT_UNION)) - ret =t->element_number; + ret = t->fields->len; return ret; } -/***************************************************************************** - *Function name - * 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 - * LttType * : the type of structure member - ****************************************************************************/ - -LttType *ltt_type_member_type(LttType *t, unsigned i, gchar ** name) -{ - LttType *member_type = NULL; - - if(unlikely( (t->type_class != LTT_STRUCT - && t->type_class != LTT_UNION) - || - (i >= t->element_number) - )) { - *name = NULL; - } else { - *name = t->element_type[i]->element_name; - member_type = t->element_type[i]; - } - - return member_type; -} /***************************************************************************** *Function name @@ -313,16 +276,14 @@ LttType *ltt_type_member_type(LttType *t, unsigned i, gchar ** name) * char * : symbolic string associated with a value ****************************************************************************/ -char *ltt_enum_string_get(LttType *t, unsigned i) +GQuark ltt_enum_string_get(LttType *t, gulong i) { - gchar *string = NULL; - - if(likely(t->type_class == LTT_ENUM && i < t->element_number)) - string = t->enum_strings[i]; - - return string; + if(likely(t->type_class == LTT_ENUM)) + return (GQuark)g_hash_table_lookup(t->enum_map, (gpointer)i); + else + return 0; } - +#if 0 /***************************************************************************** *Function name * ltt_field_element : obtain the field of nested elements for arrays and @@ -343,6 +304,30 @@ LttField *ltt_field_element(LttField *f) return nest; } +#endif//0 + +/***************************************************************************** + *Function name + * ltt_field_member_by_name : obtain the field of data members for structure + *Input params + * f : a field + * name : name of the field + *Return value + * LttField * : the field of the nested element + ****************************************************************************/ + +LttField *ltt_field_member_by_name(LttField *f, GQuark name) +{ + LttField *field_member; + + g_assert(f->field_type.type_class == LTT_STRUCT || + f->field_type.type_class == LTT_UNION); + + field_member = g_datalist_id_get_data(&f->field_type.fields_by_name, name); + + return field_member; +} + /***************************************************************************** *Function name @@ -354,16 +339,15 @@ LttField *ltt_field_element(LttField *f) * LttField * : the field of the nested element ****************************************************************************/ -LttField *ltt_field_member(LttField *f, unsigned i) +LttField *ltt_field_member(LttField *f, guint i) { 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]; + g_assert(f->field_type.type_class == LTT_STRUCT || + f->field_type.type_class == LTT_UNION); + g_assert(i < f->field_type.fields->len); + + field_member = &g_array_index(f->field_type.fields, LttField, i); return field_member; } @@ -380,7 +364,7 @@ LttField *ltt_field_member(LttField *f, unsigned i) LttType *ltt_field_type(LttField *f) { if(unlikely(!f))return NULL; - return f->field_type; + return &f->field_type; } int ltt_field_size(LttField * f) @@ -388,3 +372,60 @@ int ltt_field_size(LttField * f) if(unlikely(!f))return 0; return f->field_size; } + + +/***************************************************************************** + *Function name + * ltt_eventtype_num_fields : get the number of fields of the event + *Input params + * e : an instance of an event type + *Return value + * guint : number of fields + ****************************************************************************/ + +guint ltt_eventtype_num_fields(LttEventType *event_type) +{ + if(unlikely(!event_type)) return 0; + + return event_type->fields->len; + +} +/***************************************************************************** + *Function name + * ltt_eventtype_field : get the i th field of the event + *Input params + * e : an instance of an event type + * i : field index + *Return value + * LttField * : The requested field, or NULL + ****************************************************************************/ + +LttField *ltt_eventtype_field(LttEventType *event_type, guint i) +{ + if(unlikely(!event_type)) return NULL; + + if(i >= event_type->fields->len) return NULL; + + return &g_array_index(event_type->fields, LttField, i); + +} + +/***************************************************************************** + *Function name + * ltt_eventtype_field_by_name : get a field of the event + *Input params + * e : an instance of an event type + * name : field name + *Return value + * LttField * : The requested field, or NULL + ****************************************************************************/ + +LttField *ltt_eventtype_field_by_name(LttEventType *event_type, GQuark name) +{ + if(unlikely(!event_type)) return NULL; + + return (LttField*)g_datalist_id_get_data(&event_type->fields_by_name, name); + +} + +