+/* 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 <stdio.h>
-#include <ltt/LTTTypes.h>
#include "parser.h"
+#include <ltt/ltt.h>
+#include "ltt-private.h"
#include <ltt/type.h>
static unsigned intSizes[] = {
LttType *ltt_eventtype_type(LttEventType *et)
{
+ if(!et->root_field) return NULL;
return et->root_field->field_type;
}
* 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];
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;
}
/*****************************************************************************
/*****************************************************************************
*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 *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];
}
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];
}
/*****************************************************************************
*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;
+ 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];
}
LttType *ltt_field_type(LttField *f)
{
+ if(!f)return NULL;
return f->field_type;
}
+int ltt_field_size(LttField * f)
+{
+ if(!f)return 0;
+ return f->field_size;
+}