+ int err;
+ LttFacility *fac;
+ GArray *fac_ids;
+ guint i;
+ LttEventType *et;
+
+ while(1) {
+ err = ltt_tracefile_read_seek(tf);
+ if(err == EPERM) goto seek_error;
+ else if(err == ERANGE) break; /* End of tracefile */
+
+ err = ltt_tracefile_read_update_event(tf);
+ if(err) goto update_error;
+
+ /* We are on a facility load/or facility unload/ or heartbeat event */
+ /* The rules are :
+ * * facility 0 is hardcoded : this is the core facility. It will be shown
+ * in the facility array though, and is shown as "loaded builtin" in the
+ * trace.
+ * It contains event :
+ * 0 : facility load
+ * 1 : facility unload
+ * 2 : state dump facility load
+ * 3 : heartbeat
+ */
+ if(tf->event.facility_id != LTT_FACILITY_CORE) {
+ /* Should only contain core facility */
+ g_warning("Error in processing facility file %s, "
+ "should not contain facility id %u.", g_quark_to_string(tf->name),
+ tf->event.facility_id);
+ err = EPERM;
+ goto fac_id_error;
+ } else {
+
+ struct LttFacilityLoad *fac_load_data;
+ struct LttStateDumpFacilityLoad *fac_state_dump_load_data;
+ char *fac_name;
+
+ // FIXME align
+ switch((enum ltt_core_events)tf->event.event_id) {
+ case LTT_EVENT_FACILITY_LOAD:
+ fac_name = (char*)(tf->event.data);
+ g_debug("Doing LTT_EVENT_FACILITY_LOAD of facility %s",
+ fac_name);
+ fac_load_data =
+ (struct LttFacilityLoad *)
+ (tf->event.data + strlen(fac_name) + 1);
+ fac = &g_array_index (tf->trace->facilities_by_num, LttFacility,
+ ltt_get_uint32(LTT_GET_BO(tf), &fac_load_data->id));
+ g_assert(fac->exists == 0);
+ fac->name = g_quark_from_string(fac_name);
+ fac->checksum = ltt_get_uint32(LTT_GET_BO(tf),
+ &fac_load_data->checksum);
+ fac->id = ltt_get_uint32(LTT_GET_BO(tf), &fac_load_data->id);
+ fac->pointer_size = ltt_get_uint32(LTT_GET_BO(tf),
+ &fac_load_data->pointer_size);
+ fac->long_size = ltt_get_uint32(LTT_GET_BO(tf),
+ &fac_load_data->long_size);
+ fac->size_t_size = ltt_get_uint32(LTT_GET_BO(tf),
+ &fac_load_data->size_t_size);
+ fac->alignment = ltt_get_uint32(LTT_GET_BO(tf),
+ &fac_load_data->alignment);
+
+ if(ltt_get_facility_description(fac, tf->trace, tf))
+ continue; /* error opening description */
+
+ fac->trace = tf->trace;
+
+ /* Preset the field offsets */
+ for(i=0; i<fac->events->len; i++){
+ et = &g_array_index(fac->events, LttEventType, i);
+ set_fields_offsets(tf, et);
+ }
+
+ fac->exists = 1;
+
+ fac_ids = g_datalist_id_get_data(&tf->trace->facilities_by_name,
+ fac->name);
+ if(fac_ids == NULL) {
+ fac_ids = g_array_sized_new (FALSE, TRUE, sizeof(guint), 1);
+ g_datalist_id_set_data_full(&tf->trace->facilities_by_name,
+ fac->name,
+ fac_ids, ltt_fac_ids_destroy);
+ }
+ g_array_append_val(fac_ids, fac->id);
+
+ break;
+ case LTT_EVENT_FACILITY_UNLOAD:
+ g_debug("Doing LTT_EVENT_FACILITY_UNLOAD");
+ /* We don't care about unload : facilities ID are valid for the whole
+ * trace. They simply won't be used after the unload. */
+ break;
+ case LTT_EVENT_STATE_DUMP_FACILITY_LOAD:
+ fac_name = (char*)(tf->event.data);
+ g_debug("Doing LTT_EVENT_STATE_DUMP_FACILITY_LOAD of facility %s",
+ fac_name);
+ fac_state_dump_load_data =
+ (struct LttStateDumpFacilityLoad *)
+ (tf->event.data + strlen(fac_name) + 1);
+ fac = &g_array_index (tf->trace->facilities_by_num, LttFacility,
+ ltt_get_uint32(LTT_GET_BO(tf), &fac_state_dump_load_data->id));
+ g_assert(fac->exists == 0);
+ fac->name = g_quark_from_string(fac_name);
+ fac->checksum = ltt_get_uint32(LTT_GET_BO(tf),
+ &fac_state_dump_load_data->checksum);
+ fac->id = fac_state_dump_load_data->id;
+ fac->pointer_size = ltt_get_uint32(LTT_GET_BO(tf),
+ &fac_state_dump_load_data->pointer_size);
+ fac->long_size = ltt_get_uint32(LTT_GET_BO(tf),
+ &fac_state_dump_load_data->long_size);
+ fac->size_t_size = ltt_get_uint32(LTT_GET_BO(tf),
+ &fac_state_dump_load_data->size_t_size);
+ fac->alignment = ltt_get_uint32(LTT_GET_BO(tf),
+ &fac_state_dump_load_data->alignment);
+ if(ltt_get_facility_description(fac, tf->trace, tf))
+ continue; /* error opening description */
+
+ fac->trace = tf->trace;
+
+ /* Preset the field offsets */
+ for(i=0; i<fac->events->len; i++){
+ et = &g_array_index(fac->events, LttEventType, i);
+ set_fields_offsets(tf, et);
+ }
+
+ fac->exists = 1;
+
+ fac_ids = g_datalist_id_get_data(&tf->trace->facilities_by_name,
+ fac->name);
+ if(fac_ids == NULL) {
+ fac_ids = g_array_sized_new (FALSE, TRUE, sizeof(guint), 1);
+ g_datalist_id_set_data_full(&tf->trace->facilities_by_name,
+ fac->name,
+ fac_ids, ltt_fac_ids_destroy);
+ }
+ g_array_append_val(fac_ids, fac->id);
+
+ break;
+ case LTT_EVENT_HEARTBEAT:
+ break;
+ default:
+ g_warning("Error in processing facility file %s, "
+ "unknown event id %hhu in core facility.",
+ g_quark_to_string(tf->name),
+ tf->event.event_id);
+ err = EPERM;
+ goto event_id_error;
+ }
+ }
+ }
+ return 0;
+
+ /* Error handling */
+event_id_error:
+fac_id_error:
+update_error:
+seek_error:
+ g_warning("An error occured in facility tracefile parsing");
+ return err;