fix sparse enums
[lttv.git] / ltt / branches / poly / ltt / facility.c
index 252c6759c49ac65bd9f9eda3718a1a23b828fa9a..380689b4628e773ea4195c8d2fe122e811702cb8 100644 (file)
@@ -2,19 +2,19 @@
  * 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
@@ -48,7 +48,7 @@ LttType * lookup_named_type(LttFacility *fac, type_descriptor_t * td);
 
 /* construct directed acyclic graph for types, and tree for fields */
 void construct_fields(LttFacility *fac,
-                                                                                       LttField *field,
+                      LttField *field,
                       field_t *fld);
 
 /* generate the facility according to the events belongin to it */
@@ -102,6 +102,24 @@ int ltt_facility_open(LttFacility *f, LttTrace * t, gchar * pathname)
   while(1){
     token = getToken(&in);
     if(in.type == ENDFILE) break;
+   
+    if(g_ascii_strcasecmp(token, "<")) in.error(&in,"not a facility file");
+    token = getName(&in);
+    if(g_ascii_strcasecmp(token, "?")) in.error(&in,"not a facility file");
+    token = getName(&in);
+    if(g_ascii_strcasecmp(token, "xml")) in.error(&in,"not a facility file");
+    token = getName(&in);
+    if(g_ascii_strcasecmp(token, "version")) in.error(&in,"not a facility file");
+    token = getName(&in);
+    if(g_ascii_strcasecmp(token, "=")) in.error(&in,"not a facility file");
+    token = getQuotedString(&in);
+    if(g_ascii_strcasecmp(token, "1.0")) in.error(&in,"not a facility file");
+    token = getName(&in);
+    if(g_ascii_strcasecmp(token, "?")) in.error(&in,"not a facility file");
+    token = getToken(&in);
+    if(g_ascii_strcasecmp(token, ">")) in.error(&in,"not a facility file");
+
+    token = getToken(&in);
     
     if(g_ascii_strcasecmp(token, "<")) in.error(&in,"not a facility file");
     token = getName(&in);
@@ -120,11 +138,13 @@ int ltt_facility_open(LttFacility *f, LttTrace * t, gchar * pathname)
       checkNamedTypesImplemented(&fac->named_types);
     
       generateChecksum(fac->name, &checksum, &fac->events);
-  
-      if(checksum == f->checksum) {
+      // FIXME if(checksum == f->checksum) {
         generateFacility(f, fac, checksum);
         generated = TRUE;
-      }
+      //}
+      if (checksum != f->checksum)
+       g_warning("Facility checksum mismatch for facility %s : kernel 0x%X vs "
+               "XML 0x%X\n", fac->name, f->checksum, checksum);
 
       g_free(fac->name);
       free(fac->capname);
@@ -177,7 +197,7 @@ void generateFacility(LttFacility *f, facility_t *fac, guint32 checksum)
   table_t *named_types = &fac->named_types;
   
   g_assert(f->name == g_quark_from_string(facilityName));
-  g_assert(f->checksum == checksum);
+  //g_assert(f->checksum == checksum);
 
   //f->event_number = events->position;
   
@@ -217,7 +237,7 @@ void generateFacility(LttFacility *f, facility_t *fac, guint32 checksum)
   /* The second day, he created the event fields and types */
   //for each event, construct field and type acyclic graph
   for(i=0;i<events->position;i++){
-               event_t *parser_event = (event_t*)events->array[i];
+    event_t *parser_event = (event_t*)events->array[i];
     LttEventType *event_type = &g_array_index(f->events, LttEventType, i);
 
     event_type->name = 
@@ -232,6 +252,8 @@ void generateFacility(LttFacility *f, facility_t *fac, guint32 checksum)
     event_type->index = i;
     event_type->facility = f;
 
+    event_type->has_compact_data = parser_event->compact_data;
+
     event_type->fields = g_array_sized_new(FALSE, TRUE,
         sizeof(LttField), parser_event->fields.position);
     event_type->fields = 
@@ -274,14 +296,18 @@ void generateFacility(LttFacility *f, facility_t *fac, guint32 checksum)
 
 
 void construct_fields(LttFacility *fac,
-                                                                                       LttField *field,
+                      LttField *field,
                       field_t *fld)
 {
   guint len;
   type_descriptor_t *td;
   LttType *type;
 
-  field->name = g_quark_from_string(fld->name);
+  if(fld->name)
+    field->name = g_quark_from_string(fld->name);
+  else
+    fld->name = 0;
+
   if(fld->description) {
     len = strlen(fld->description);
     field->description = g_new(gchar, len+1);
@@ -294,7 +320,8 @@ void construct_fields(LttFacility *fac,
   type->enum_map = NULL;
   type->fields = NULL;
   type->fields_by_name = NULL;
+  type->network = td->network;
+
   switch(td->type) {
     case INT_FIXED:
       type->type_class = LTT_INT_FIXED;
@@ -315,6 +342,7 @@ void construct_fields(LttFacility *fac,
     case UCHAR:
       type->type_class = LTT_UCHAR;
       type->size = td->size;
+      g_assert(type->size != 0);
       break;
     case SHORT:
       type->type_class = LTT_SHORT;
@@ -331,6 +359,7 @@ void construct_fields(LttFacility *fac,
     case UINT:
       type->type_class = LTT_UINT;
       type->size = fac->int_size;
+      g_assert(type->size != 0);
       break;
     case LONG:
       type->type_class = LTT_LONG;
@@ -365,13 +394,18 @@ void construct_fields(LttFacility *fac,
       type->size = fac->int_size;
       {
         guint i;
-        type->enum_map = g_hash_table_new(g_int_hash, g_int_equal);
+        type->enum_map = g_hash_table_new(g_direct_hash, g_direct_equal);
+       type->lowest_value = G_MAXINT32;
+       type->highest_value = G_MININT32;
         for(i=0; i<td->labels.position; i++) {
           GQuark value = g_quark_from_string((char*)td->labels.array[i]);
           gint key = *(int*)td->labels_values.array[i];
           g_hash_table_insert(type->enum_map, (gpointer)key, (gpointer)value);
+         type->highest_value = max(key, type->highest_value);
+         type->lowest_value = min(key, type->lowest_value);
         }
       }
+      g_assert(type->size != 0);
       break;
     case ARRAY:
       type->type_class = LTT_ARRAY;
@@ -538,14 +572,14 @@ void construct_types_and_fields(LttFacility * fac, type_descriptor_t * td,
     for(i=0;i<td->fields.position;i++){
       tmpTd = ((field_t*)(td->fields.array[i]))->type;
 
-       fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd);
+      fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd);
       fld->child[i] = g_new(LttField,1); 
 
  //     fld->child[i]->field_pos = i;
       fld->child[i]->field_type = fld->field_type->element_type[i]; 
 
       fld->child[i]->field_type->element_name 
-                 = g_quark_from_string(((field_t*)(td->fields.array[i]))->name);
+            = g_quark_from_string(((field_t*)(td->fields.array[i]))->name);
 
       fld->child[i]->offset_root = 0;
       fld->child[i]->fixed_root = FIELD_UNKNOWN;
@@ -624,15 +658,15 @@ void construct_types_and_fields(LttFacility * fac, type_descriptor * td,
       tmpTd = ((type_fields*)(td->fields.array[i]))->type;
 
       if(flag)
-       fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd);
+  fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd);
       fld->child[i] = g_new(LttField,1); 
 
       fld->child[i]->field_pos = i;
       fld->child[i]->field_type = fld->field_type->element_type[i]; 
 
       if(flag){
-       fld->child[i]->field_type->element_name 
-                 = g_quark_from_string(((type_fields*)(td->fields.array[i]))->name);
+        fld->child[i]->field_type->element_name 
+            = g_quark_from_string(((type_fields*)(td->fields.array[i]))->name);
       }
 
       fld->child[i]->offset_root = -1;
This page took 0.026431 seconds and 4 git commands to generate.