+/* 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.
+ */
+
#include <stdio.h>
+#include <glib.h>
-#include <ltt/LTTTypes.h>
#include "parser.h"
+#include <ltt/ltt.h>
+#include "ltt-private.h"
#include <ltt/type.h>
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
* char * : the name of the event type
****************************************************************************/
-char *ltt_eventtype_name(LttEventType *et)
+gchar *ltt_eventtype_name(LttEventType *et)
{
return et->name;
}
* char * : the description of the event type
****************************************************************************/
-char *ltt_eventtype_description(LttEventType *et)
+gchar *ltt_eventtype_description(LttEventType *et)
{
return et->description;
}
*Input params
* et : an event type
*Return value
- * unsigned * : the relative id
+ * unsigned : the relative id
****************************************************************************/
-unsigned *ltt_eventtype_relative_id(LttEventType *et)
+unsigned ltt_eventtype_relative_id(LttEventType *et)
{
- return (unsigned*)&et->index;
+ return et->index;
}
/*****************************************************************************
*Input params
* et : an event type
*Return value
- * unsigned * : the id
+ * unsigned : the id
****************************************************************************/
-unsigned *ltt_eventtype_id(LttEventType *et)
+unsigned ltt_eventtype_id(LttEventType *et)
{
- unsigned *id = g_new(unsigned,1);
- *id = et->facility->base_id + et->index;
- return (unsigned*)id;
+ return et->facility->base_id + et->index;
}
/*****************************************************************************
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;
}
/*****************************************************************************
* char * : the name of the type
****************************************************************************/
-char *ltt_type_name(LttType *t)
+gchar *ltt_type_name(LttType *t)
{
return t->element_name;
}
* 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;
-
- if(t->type_class == LTT_FLOAT){
- return floatSizes[t->size];
- }else{
- if(t->size < sizeof(intSizes)/sizeof(unsigned))
- return intSizes[t->size];
- else{
- LttArchSize size = trace->system_description->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);
+ 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{
+ 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];
+ }
}
}
+
+ return size;
}
/*****************************************************************************
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;
}
/*****************************************************************************
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;
}
/*****************************************************************************
unsigned ltt_type_member_number(LttType *t)
{
- if(t->type_class != LTT_STRUCT && t->type_class != LTT_UNION)
- 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
* LttType * : the type of structure member
****************************************************************************/
-LttType *ltt_type_member_type(LttType *t, unsigned i)
+LttType *ltt_type_member_type(LttType *t, unsigned i, gchar ** name)
{
- if(t->type_class != LTT_STRUCT) return NULL;
- if(i >= t->element_number || i < 0 ) return NULL;
- return t->element_type[i];
+ 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;
}
/*****************************************************************************
****************************************************************************/
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;
- return t->enum_strings[i];
+{
+ gchar *string = NULL;
+
+ if(likely(t->type_class == LTT_ENUM && i < t->element_number))
+ string = t->enum_strings[i];
+
+ return string;
}
/*****************************************************************************
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
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];
+ 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;
}
/*****************************************************************************
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;
+}