From: compudj Date: Sun, 8 Aug 2004 20:53:33 +0000 (+0000) Subject: ltt library extra careful warnings check X-Git-Tag: v0.12.20~2809 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=8d1e6362a5e8b3086942948c0d5c79c0433dadcd;p=lttv.git ltt library extra careful warnings check git-svn-id: http://ltt.polymtl.ca/svn@680 04897980-b3bd-0310-b5e0-8ef037075253 --- diff --git a/ltt/branches/poly/ltt/convert/convert.c b/ltt/branches/poly/ltt/convert/convert.c index 427a10d2..760eba6d 100644 --- a/ltt/branches/poly/ltt/convert/convert.c +++ b/ltt/branches/poly/ltt/convert/convert.c @@ -35,11 +35,12 @@ int readFile(int fd, void * buf, size_t size, char * mesg) { ssize_t nbBytes = read(fd, buf, size); - if(nbBytes < 0) { - perror("Error in readFile : "); - exit(1); - } else if((size_t)nbBytes != size) { - printf("%s\n",mesg); + if((size_t)nbBytes != size) { + if(nbBytes < 0) { + perror("Error in readFile : "); + } else { + printf("%s\n",mesg); + } exit(1); } return 0; diff --git a/ltt/branches/poly/ltt/event.c b/ltt/branches/poly/ltt/event.c index 3bc93857..e4cdfc77 100644 --- a/ltt/branches/poly/ltt/event.c +++ b/ltt/branches/poly/ltt/event.c @@ -17,6 +17,9 @@ */ #include +#include +#include + #include #include @@ -460,7 +463,8 @@ void ltt_event_field_element_select(LttEvent *e, LttField *f, unsigned i) { unsigned element_number; LttField *fld; - int k, size; + unsigned int k; + int size; void *evD; if(f->field_type->type_class != LTT_ARRAY && @@ -468,7 +472,9 @@ void ltt_event_field_element_select(LttEvent *e, LttField *f, unsigned i) return ; element_number = ltt_event_field_element_number(e,f); - if((element_number-1) < i || i < 0) return; + /* Sanity check for i : 1..n only, and must be lower or equal element_number + */ + if(element_number < i || i == 0) return; fld = f->child[0]; @@ -477,7 +483,6 @@ void ltt_event_field_element_select(LttEvent *e, LttField *f, unsigned i) for(k=0;koffset_root+size,size, fld, evD+size); } - f->current_element = i - 1; } @@ -516,6 +521,8 @@ unsigned ltt_event_get_unsigned(LttEvent *e, LttField *f) else return (unsigned int) (revFlag ? GUINT64_FROM_LE(x): x); } + g_critical("ltt_event_get_unsigned : field size %i unknown", f->field_size); + return 0; } int ltt_event_get_int(LttEvent *e, LttField *f) @@ -547,6 +554,8 @@ int ltt_event_get_int(LttEvent *e, LttField *f) else return (int) (revFlag ? GINT64_FROM_LE(x): x); } + g_critical("ltt_event_get_int : field size %i unknown", f->field_size); + return 0; } unsigned long ltt_event_get_long_unsigned(LttEvent *e, LttField *f) @@ -579,6 +588,8 @@ unsigned long ltt_event_get_long_unsigned(LttEvent *e, LttField *f) else return (unsigned long) (revFlag ? GUINT64_FROM_LE(x): x); } + g_critical("ltt_event_get_long_unsigned : field size %i unknown", f->field_size); + return 0; } long int ltt_event_get_long_int(LttEvent *e, LttField *f) @@ -610,6 +621,8 @@ long int ltt_event_get_long_int(LttEvent *e, LttField *f) else return (long) (revFlag ? GINT64_FROM_LE(x): x); } + g_critical("ltt_event_get_long_int : field size %i unknown", f->field_size); + return 0; } float ltt_event_get_float(LttEvent *e, LttField *f) diff --git a/ltt/branches/poly/ltt/facility.c b/ltt/branches/poly/ltt/facility.c index a14a6e09..2964021d 100644 --- a/ltt/branches/poly/ltt/facility.c +++ b/ltt/branches/poly/ltt/facility.c @@ -34,7 +34,7 @@ void constructTypeAndFields(LttFacility * fac,type_descriptor * td, LttField * fld); /* generate the facility according to the events belongin to it */ -void generateFacility(LttFacility * f, facility * fac, +void generateFacility(LttFacility * f, facility_t * fac, LttChecksum checksum); /* functions to release the memory occupied by a facility */ @@ -58,7 +58,7 @@ void ltt_facility_open(LttTrace * t, char * pathname) char *token; parse_file in; char buffer[BUFFER_SIZE]; - facility * fac; + facility_t * fac; LttFacility * f; LttChecksum checksum; @@ -78,7 +78,7 @@ void ltt_facility_open(LttTrace * t, char * pathname) token = getName(&in); if(strcmp("facility",token) == 0) { - fac = g_new(facility, 1); + fac = g_new(facility_t, 1); fac->name = NULL; fac->description = NULL; sequence_init(&(fac->events)); @@ -124,7 +124,7 @@ void ltt_facility_open(LttTrace * t, char * pathname) * checksum : checksum of the facility ****************************************************************************/ -void generateFacility(LttFacility *f, facility *fac,LttChecksum checksum) +void generateFacility(LttFacility *f, facility_t *fac,LttChecksum checksum) { char * facilityName = fac->name; sequence * events = &fac->events; @@ -148,17 +148,17 @@ void generateFacility(LttFacility *f, facility *fac,LttChecksum checksum) evType = g_new(LttEventType,1); f->events[i] = evType; - evType->name = g_strdup(((event*)(events->array[i]))->name); - evType->description=g_strdup(((event*)(events->array[i]))->description); + evType->name = g_strdup(((event_t*)(events->array[i]))->name); + evType->description=g_strdup(((event_t*)(events->array[i]))->description); field = g_new(LttField, 1); evType->root_field = field; evType->facility = f; evType->index = i; - if(((event*)(events->array[i]))->type != NULL){ + if(((event_t*)(events->array[i]))->type != NULL){ field->field_pos = 0; - type = lookup_named_type(f,((event*)(events->array[i]))->type); + type = lookup_named_type(f,((event_t*)(events->array[i]))->type); field->field_type = type; field->offset_root = 0; field->fixed_root = 1; @@ -172,7 +172,7 @@ void generateFacility(LttFacility *f, facility *fac,LttChecksum checksum) field->current_element = 0; //construct field tree and type graph - constructTypeAndFields(f,((event*)(events->array[i]))->type,field); + constructTypeAndFields(f,((event_t*)(events->array[i]))->type,field); }else{ evType->root_field = NULL; g_free(field); @@ -242,7 +242,7 @@ void constructTypeAndFields(LttFacility * fac,type_descriptor * td, fld->child = g_new(LttField*, td->fields.position); for(i=0;ifields.position;i++){ - tmpTd = ((field*)(td->fields.array[i]))->type; + tmpTd = ((type_fields*)(td->fields.array[i]))->type; if(flag) fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd); @@ -253,7 +253,7 @@ void constructTypeAndFields(LttFacility * fac,type_descriptor * td, if(flag){ fld->child[i]->field_type->element_name - = g_strdup(((field*)(td->fields.array[i]))->name); + = g_strdup(((type_fields*)(td->fields.array[i]))->name); } fld->child[i]->offset_root = -1; @@ -286,7 +286,7 @@ void constructTypeAndFields(LttFacility * fac,type_descriptor * td, LttType * lookup_named_type(LttFacility *fac, type_descriptor * td) { LttType * lttType = NULL; - int i; + unsigned int i; char * name; if(td->type_name){ for(i=0;inamed_types_number; i++){ @@ -348,7 +348,7 @@ int ltt_facility_close(LttFacility *f) void freeFacility(LttFacility * fac) { - int i; + unsigned int i; g_free(fac->name); //free facility name //free event types @@ -385,7 +385,6 @@ void freeEventtype(LttEventType * evType) void freeLttNamedType(LttType * type) { - int i; g_free(type->type_name); type->type_name = NULL; freeLttType(&type); @@ -393,7 +392,7 @@ void freeLttNamedType(LttType * type) void freeLttType(LttType ** type) { - int i; + unsigned int i; if(*type == NULL) return; if((*type)->type_name){ return; //this is a named type @@ -493,7 +492,7 @@ unsigned ltt_facility_base_id(LttFacility *f) unsigned ltt_facility_eventtype_number(LttFacility *f) { - return (unsigned)(f->event_number); + return (f->event_number); } /***************************************************************************** @@ -525,7 +524,7 @@ LttEventType *ltt_facility_eventtype_get(LttFacility *f, unsigned i) LttEventType *ltt_facility_eventtype_get_by_name(LttFacility *f, char *name) { - int i; + unsigned int i; LttEventType * ev; for(i=0;ievent_number;i++){ ev = f->events[i]; diff --git a/ltt/branches/poly/ltt/facility.h b/ltt/branches/poly/ltt/facility.h index 8fda81e9..1608e818 100644 --- a/ltt/branches/poly/ltt/facility.h +++ b/ltt/branches/poly/ltt/facility.h @@ -45,5 +45,7 @@ LttEventType *ltt_facility_eventtype_get(LttFacility *f, unsigned i); LttEventType *ltt_facility_eventtype_get_by_name(LttFacility *f, char *name); +int ltt_facility_close(LttFacility *f); + #endif // FACILITY_H diff --git a/ltt/branches/poly/ltt/ltt-private.h b/ltt/branches/poly/ltt/ltt-private.h index 6e9e3e48..ae7cc7e8 100644 --- a/ltt/branches/poly/ltt/ltt-private.h +++ b/ltt/branches/poly/ltt/ltt-private.h @@ -65,7 +65,7 @@ struct _LttType{ char * type_name; //type name if it is a named type char * element_name; //elements name of the struct char * fmt; - int size; + unsigned int size; LttTypeEnum type_class; //which type char ** enum_strings; //for enum labels struct _LttType ** element_type; //for array, sequence and struct @@ -79,8 +79,8 @@ struct _LttEventType{ int index; //id of the event type within the facility LttFacility * facility; //the facility that contains the event type LttField * root_field; //root field - int latest_block; //the latest block using the event type - int latest_event; //the latest event using the event type + unsigned int latest_block; //the latest block using the event type + unsigned int latest_event; //the latest event using the event type }; struct _LttEvent{ @@ -90,8 +90,8 @@ struct _LttEvent{ LttCycleCount event_cycle_count; LttTracefile * tracefile; void * data; //event data - int which_block; //the current block of the event - int which_event; //the position of the event + unsigned int which_block; //the current block of the event + unsigned int which_event; //the position of the event /* This is a workaround for fast position seek */ void * last_event_pos; @@ -137,12 +137,12 @@ struct _LttField{ struct _LttFacility{ char * name; //facility name - int event_number; //number of events in the facility + unsigned int event_number; //number of events in the facility LttChecksum checksum; //checksum of the facility guint32 base_id; //base id of the facility LttEventType ** events; //array of event types LttType ** named_types; - int named_types_number; + unsigned int named_types_number; }; struct _LttTracefile{ @@ -151,9 +151,9 @@ struct _LttTracefile{ int fd; //file descriptor off_t file_size; //file size unsigned block_size; //block_size - int block_number; //number of blocks in the file - int which_block; //which block the current block is - int which_event; //which event of the current block + unsigned int block_number; //number of blocks in the file + unsigned int which_block; //which block the current block is + unsigned int which_event; //which event of the current block //is currently processed LttTime current_event_time; //time of the current event BlockStart * a_block_start; //block start of the block @@ -168,7 +168,7 @@ struct _LttTracefile{ LttTime prev_block_end_time; //the end time of previous block LttTime prev_event_time; //the time of the previous event LttCycleCount pre_cycle_count; //previous cycle count of the event - int count; //the number of overflow of cycle count + unsigned int count; //the number of overflow of cycle count }; struct _LttTrace{ diff --git a/ltt/branches/poly/ltt/parser.c b/ltt/branches/poly/ltt/parser.c index b6561ca5..e4917ce5 100644 --- a/ltt/branches/poly/ltt/parser.c +++ b/ltt/branches/poly/ltt/parser.c @@ -36,6 +36,7 @@ This program is distributed in the hope that it will be useful, #include #include #include +#include #include @@ -175,7 +176,7 @@ char * getFormatAttribute(parse_file *in) int getSizeAttribute(parse_file *in) { - char * token; + /* skip name and equal */ getName(in); getEqual(in); @@ -184,7 +185,7 @@ int getSizeAttribute(parse_file *in) int getValueAttribute(parse_file *in) { - char * token; + /* skip name and equal */ getName(in); getEqual(in); @@ -255,10 +256,10 @@ char * getDescription(parse_file *in) * fac : facility filled with event list ****************************************************************************/ -void parseFacility(parse_file *in, facility * fac) +void parseFacility(parse_file *in, facility_t * fac) { char * token; - event *ev; + event_t *ev; fac->name = allocAndCopy(getNameAttribute(in)); getRAnglebracket(in); @@ -273,7 +274,7 @@ void parseFacility(parse_file *in, facility * fac) in->error(in,"the definition of the facility is not finished"); if(strcmp("event",token) == 0){ - ev = (event*) memAlloc(sizeof(event)); + ev = (event_t*) memAlloc(sizeof(event_t)); sequence_push(&(fac->events),ev); parseEvent(in,ev, &(fac->unnamed_types), &(fac->named_types)); }else if(strcmp("type",token) == 0){ @@ -300,11 +301,10 @@ void parseFacility(parse_file *in, facility * fac) * ev : new event (parameters are passed to it) ****************************************************************************/ -void parseEvent(parse_file *in, event * ev, sequence * unnamed_types, +void parseEvent(parse_file *in, event_t * ev, sequence * unnamed_types, table * named_types) { char *token; - type_descriptor *t; // ev->name = allocAndCopy(getNameAttribute(in)); @@ -350,9 +350,9 @@ void parseFields(parse_file *in, type_descriptor *t, sequence * unnamed_types, table * named_types) { char * token; - field *f; + type_fields *f; - f = (field *)memAlloc(sizeof(field)); + f = (type_fields *)memAlloc(sizeof(type_fields)); sequence_push(&(t->fields),f); // @@ -864,21 +864,6 @@ void skipEOL(parse_file * in) if(car == EOF)ungetc(car, in->fp); } -int isalpha(char c) -{ - int i,j; - if(c == '_')return 1; - i = c - 'a'; - j = c - 'A'; - if((i>=0 && i<26) || (j>=0 && j<26)) return 1; - return 0; -} - -int isalnum(char c) -{ - return (isalpha(c) || isdigit(c)); -} - /***************************************************************************** *Function name * checkNamedTypesImplemented : check if all named types have definition @@ -913,12 +898,12 @@ void generateChecksum( char* facName, unsigned long * checksum, sequence * event { unsigned long crc ; int pos; - event * ev; + event_t * ev; char str[256]; crc = crc32(facName); for(pos = 0; pos < events->position; pos++){ - ev = (event *)(events->array[pos]); + ev = (event_t *)(events->array[pos]); crc = partial_crc32(ev->name,crc); if(!ev->type) continue; //event without type if(ev->type->type != STRUCT){ @@ -945,7 +930,7 @@ unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type) unsigned long crc = aCrc; char * str = NULL, buf[16]; int flag = 0, pos; - field * fld; + type_fields * fld; switch(type->type){ case INT: @@ -966,12 +951,12 @@ unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type) flag = 1; break; case ARRAY: - sprintf(buf,"%d\0",type->size); + sprintf(buf,"%d",type->size); str = appendString("array ",buf); flag = 1; break; case SEQUENCE: - sprintf(buf,"%d\0",type->size); + sprintf(buf,"%d",type->size); str = appendString("sequence ",buf); flag = 1; break; @@ -997,7 +982,7 @@ unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type) crc = getTypeChecksum(crc,type->nested_type); }else if(type->type == STRUCT || type->type == UNION){ for(pos =0; pos < type->fields.position; pos++){ - fld = (field *) type->fields.array[pos]; + fld = (type_fields *) type->fields.array[pos]; crc = partial_crc32(fld->name,crc); crc = getTypeChecksum(crc, fld->type); } @@ -1014,7 +999,7 @@ unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type) void freeType(type_descriptor * tp) { int pos2; - field *f; + type_fields *f; if(tp->fmt != NULL) free(tp->fmt); if(tp->type == ENUM) { @@ -1025,7 +1010,7 @@ void freeType(type_descriptor * tp) } if(tp->type == STRUCT) { for(pos2 = 0; pos2 < tp->fields.position; pos2++) { - f = (field *) tp->fields.array[pos2]; + f = (type_fields *) tp->fields.array[pos2]; free(f->name); free(f->description); free(f); @@ -1049,9 +1034,8 @@ void freeNamedType(table * t) void freeTypes(sequence *t) { - int pos, pos2; + int pos; type_descriptor *tp; - field *f; for(pos = 0 ; pos < t->position; pos++) { tp = (type_descriptor *)t->array[pos]; @@ -1063,10 +1047,10 @@ void freeTypes(sequence *t) void freeEvents(sequence *t) { int pos; - event *ev; + event_t *ev; for(pos = 0 ; pos < t->position; pos++) { - ev = (event *) t->array[pos]; + ev = (event_t *) t->array[pos]; free(ev->name); free(ev->description); free(ev); diff --git a/ltt/branches/poly/ltt/parser.h b/ltt/branches/poly/ltt/parser.h index 484b2371..c82493de 100644 --- a/ltt/branches/poly/ltt/parser.h +++ b/ltt/branches/poly/ltt/parser.h @@ -89,8 +89,6 @@ char seekNextChar(parse_file *in); void skipComment(parse_file * in); void skipEOL(parse_file * in); -int isalpha(char car); -int isalnum(char car); /* Some constants */ @@ -128,34 +126,34 @@ typedef struct _type_descriptor { /* Fields within types */ -typedef struct _field{ +typedef struct _type_fields{ char *name; char *description; type_descriptor *type; -} field; +} type_fields; /* Events definitions */ -typedef struct _event { +typedef struct _event_t { char *name; char *description; type_descriptor *type; -} event; +} event_t; -typedef struct _facility { +typedef struct _facility_t { char * name; char * description; sequence events; sequence unnamed_types; table named_types; -} facility; +} facility_t; int getSize(parse_file *in); unsigned long getTypeChecksum(unsigned long aCrc, type_descriptor * type); -void parseFacility(parse_file *in, facility * fac); -void parseEvent(parse_file *in, event *ev, sequence * unnamed_types, table * named_types); +void parseFacility(parse_file *in, facility_t * fac); +void parseEvent(parse_file *in, event_t *ev, sequence * unnamed_types, table * named_types); void parseTypeDefinition(parse_file *in, sequence * unnamed_types, table * named_types); type_descriptor *parseType(parse_file *in, type_descriptor *t, sequence * unnamed_types, table * named_types); void parseFields(parse_file *in, type_descriptor *t, sequence * unnamed_types, table * named_types); diff --git a/ltt/branches/poly/ltt/time.h b/ltt/branches/poly/ltt/time.h index d9049530..a151505c 100644 --- a/ltt/branches/poly/ltt/time.h +++ b/ltt/branches/poly/ltt/time.h @@ -64,43 +64,6 @@ static inline LttTime ltt_time_add(LttTime t1, LttTime t2) } -static inline LttTime ltt_time_mul(LttTime t1, float f) -{ - LttTime res; - float d; - double sec; - - if(f == 0.0){ - res.tv_sec = 0; - res.tv_nsec = 0; - }else{ - d = 1.0/f; - sec = t1.tv_sec / (double)d; - res.tv_sec = sec; - res.tv_nsec = t1.tv_nsec / (double)d + (sec - res.tv_sec) * - NANOSECONDS_PER_SECOND; - res.tv_sec += res.tv_nsec / NANOSECONDS_PER_SECOND; - res.tv_nsec %= NANOSECONDS_PER_SECOND; - } - return res; -} - - -static inline LttTime ltt_time_div(LttTime t1, float f) -{ - double sec; - LttTime res; - - sec = t1.tv_sec / (double)f; - res.tv_sec = sec; - res.tv_nsec = t1.tv_nsec / (double)f + (sec - res.tv_sec) * - NANOSECONDS_PER_SECOND; - res.tv_sec += res.tv_nsec / NANOSECONDS_PER_SECOND; - res.tv_nsec %= NANOSECONDS_PER_SECOND; - return res; -} - - static inline int ltt_time_compare(LttTime t1, LttTime t2) { if(t1.tv_sec > t2.tv_sec) return 1; @@ -150,4 +113,70 @@ static inline LttTime ltt_time_from_double(double t1) return res; } +/* Use ltt_time_to_double and ltt_time_from_double to check for lack + * of precision. + */ +static inline LttTime ltt_time_mul(LttTime t1, double d) +{ + LttTime res; + + double time_double = ltt_time_to_double(t1); + + time_double = time_double * d; + + res = ltt_time_from_double(time_double); + + return res; + +#if 0 + /* What is that ? (Mathieu) */ + if(f == 0.0){ + res.tv_sec = 0; + res.tv_nsec = 0; + }else{ + double d; + d = 1.0/f; + sec = t1.tv_sec / (double)d; + res.tv_sec = sec; + res.tv_nsec = t1.tv_nsec / (double)d + (sec - res.tv_sec) * + NANOSECONDS_PER_SECOND; + res.tv_sec += res.tv_nsec / NANOSECONDS_PER_SECOND; + res.tv_nsec %= NANOSECONDS_PER_SECOND; + } + return res; +#endif //0 +} + + +/* Use ltt_time_to_double and ltt_time_from_double to check for lack + * of precision. + */ +static inline LttTime ltt_time_div(LttTime t1, double d) +{ + LttTime res; + + double time_double = ltt_time_to_double(t1); + + time_double = time_double / d; + + res = ltt_time_from_double(time_double); + + return res; + + +#if 0 + double sec; + LttTime res; + + sec = t1.tv_sec / (double)f; + res.tv_sec = sec; + res.tv_nsec = t1.tv_nsec / (double)f + (sec - res.tv_sec) * + NANOSECONDS_PER_SECOND; + res.tv_sec += res.tv_nsec / NANOSECONDS_PER_SECOND; + res.tv_nsec %= NANOSECONDS_PER_SECOND; + return res; +#endif //0 +} + + #endif // LTT_TIME_H diff --git a/ltt/branches/poly/ltt/trace.h b/ltt/branches/poly/ltt/trace.h index 03f47694..448ea797 100644 --- a/ltt/branches/poly/ltt/trace.h +++ b/ltt/branches/poly/ltt/trace.h @@ -85,13 +85,15 @@ unsigned ltt_trace_control_tracefile_number(LttTrace *t); unsigned ltt_trace_per_cpu_tracefile_number(LttTrace *t); -/* It is possible to search for the tracefiles by name or by CPU position. - The index within the tracefiles of the same type is returned if found - and a negative value otherwise. */ +/* It is possible to search for the tracefiles by name or by CPU tracefile + * name. + * The index within the tracefiles of the same type is returned if found + * and a negative value otherwise. + */ -int ltt_trace_control_tracefile_find(LttTrace *t, char *name); +int ltt_trace_control_tracefile_find(LttTrace *t, const gchar *name); -int ltt_trace_per_cpu_tracefile_find(LttTrace *t, unsigned i); +int ltt_trace_per_cpu_tracefile_find(LttTrace *t, const gchar *name); /* Get a specific tracefile */ diff --git a/ltt/branches/poly/ltt/tracefile.c b/ltt/branches/poly/ltt/tracefile.c index 980512b6..a1decdde 100644 --- a/ltt/branches/poly/ltt/tracefile.c +++ b/ltt/branches/poly/ltt/tracefile.c @@ -18,10 +18,12 @@ #include #include +#include +#include #include #include -#include -#include +#include +#include // For realpath #include @@ -34,8 +36,10 @@ #include #include #include +#include #define DIR_NAME_SIZE 256 +#define UNUSED __attribute__((__unused__)) /* set the offset of the fields belonging to the event, need the information of the archecture */ @@ -61,7 +65,7 @@ int skipEvent(LttTracefile * t); /* Functions to parse system.xml file (using glib xml parser) */ -static void parser_start_element (GMarkupParseContext *context, +static void parser_start_element (GMarkupParseContext UNUSED *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, @@ -125,18 +129,11 @@ static void parser_start_element (GMarkupParseContext *context, } } -static void parser_end_element (GMarkupParseContext *context, - const gchar *element_name, - gpointer user_data, - GError **error) -{ -} - -static void parser_characters (GMarkupParseContext *context, +static void parser_characters (GMarkupParseContext UNUSED *context, const gchar *text, - gsize text_len, + gsize UNUSED text_len, gpointer user_data, - GError **error) + GError UNUSED **error) { LttSystemDescription* des = (LttSystemDescription* )user_data; des->description = g_strdup(text); @@ -157,7 +154,6 @@ LttTracefile* ltt_tracefile_open(LttTrace * t, char * fileName) { LttTracefile * tf; struct stat lTDFStat; /* Trace data file status */ - BlockStart a_block_start; tf = g_new(LttTracefile, 1); @@ -182,7 +178,7 @@ LttTracefile* ltt_tracefile_open(LttTrace * t, char * fileName) } // Is the file large enough to contain a trace - if(lTDFStat.st_size < sizeof(BlockStart) + EVENT_HEADER_SIZE){ + if(lTDFStat.st_size < (off_t)(sizeof(BlockStart) + EVENT_HEADER_SIZE)){ g_print("The input data file %s does not contain a trace\n", fileName); g_free(tf->name); close(tf->fd); @@ -224,10 +220,9 @@ gint ltt_tracefile_open_control(LttTrace *t, char * control_name) LttTracefile * tf; LttEvent ev; LttFacility * f; - guint16 evId; void * pos; FacilityLoad fLoad; - int i; + unsigned int i; tf = ltt_tracefile_open(t,control_name); if(!tf) { @@ -256,8 +251,8 @@ gint ltt_tracefile_open_control(LttTrace *t, char * control_name) } } if(i==t->facility_number) { - g_warning("Facility: %s, checksum: %d is not found\n", - fLoad.name,fLoad.checksum); + g_warning("Facility: %s, checksum: %u is not found", + fLoad.name,(unsigned int)fLoad.checksum); return -1; } }else if(ev.event_id == TRACE_BLOCK_START){ @@ -265,7 +260,7 @@ gint ltt_tracefile_open_control(LttTrace *t, char * control_name) }else if(ev.event_id == TRACE_BLOCK_END){ break; }else { - g_warning("Not valid facilities trace file\n"); + g_warning("Not valid facilities trace file"); return -1; } } @@ -296,14 +291,13 @@ gint getSystemInfo(LttSystemDescription* des, char * pathname) { FILE * fp; char buf[DIR_NAME_SIZE]; - char description[4*DIR_NAME_SIZE]; GMarkupParseContext * context; GError * error = NULL; GMarkupParser markup_parser = { parser_start_element, - parser_end_element, + NULL, parser_characters, NULL, /* passthrough */ NULL /* error */ @@ -342,7 +336,7 @@ gint getFacilityInfo(LttTrace *t, char* eventdefs) DIR * dir; struct dirent *entry; char * ptr; - int i,j; + unsigned int i,j; LttFacility * f; LttEventType * et; char name[DIR_NAME_SIZE]; @@ -430,29 +424,31 @@ gint getCpuFileInfo(LttTrace *t, char* cpu) * *When a trace is closed, all the associated facilities, types and fields *are released as well. + */ + + +/**************************************************************************** + * get_absolute_pathname * + * return the unique pathname in the system + * * MD : Fixed this function so it uses realpath, dealing well with * forgotten cases (.. were not used correctly before). * ****************************************************************************/ - void get_absolute_pathname(const char *pathname, char * abs_pathname) { - char * ptr, *ptr1; - size_t size = DIR_NAME_SIZE; abs_pathname[0] = '\0'; if ( realpath (pathname, abs_pathname) != NULL) return; else { - // FIXME : Path is wrong, is it ok to return the pathname unmodified ? + /* error, return the original path unmodified */ strcpy(abs_pathname, pathname); return; } - return; - } LttTrace *ltt_trace_open(const char *pathname) @@ -570,7 +566,7 @@ LttTrace *ltt_trace_copy(LttTrace *self) void ltt_trace_close(LttTrace *t) { - int i; + unsigned int i; LttTracefile * tf; LttFacility * f; @@ -653,7 +649,7 @@ LttFacility *ltt_trace_facility_get(LttTrace *t, unsigned i) unsigned ltt_trace_facility_find(LttTrace *t, char *name, unsigned *position) { - int i, count=0; + unsigned int i, count=0; LttFacility * f; for(i=0;ifacility_number;i++){ f = (LttFacility*)g_ptr_array_index(t->facilities, i); @@ -673,7 +669,7 @@ unsigned ltt_trace_facility_find(LttTrace *t, char *name, unsigned *position) unsigned ltt_trace_eventtype_number(LttTrace *t) { - int i; + unsigned int i; unsigned count = 0; LttFacility * f; for(i=0;ifacility_number;i++){ @@ -686,7 +682,7 @@ unsigned ltt_trace_eventtype_number(LttTrace *t) LttFacility * ltt_trace_facility_by_id(LttTrace * trace, unsigned id) { LttFacility * facility; - int i; + unsigned int i; for(i=0;ifacility_number;i++){ facility = (LttFacility*) g_ptr_array_index(trace->facilities,i); if(id >= facility->base_id && @@ -727,10 +723,10 @@ unsigned ltt_trace_per_cpu_tracefile_number(LttTrace *t) *and a negative value otherwise. ****************************************************************************/ -int ltt_trace_control_tracefile_find(LttTrace *t, char *name) +int ltt_trace_control_tracefile_find(LttTrace *t, const gchar *name) { LttTracefile * tracefile; - int i; + unsigned int i; for(i=0;icontrol_tracefile_number;i++){ tracefile = (LttTracefile*)g_ptr_array_index(t->control_tracefiles, i); if(strcmp(tracefile->name, name)==0)break; @@ -739,17 +735,19 @@ int ltt_trace_control_tracefile_find(LttTrace *t, char *name) return i; } -int ltt_trace_per_cpu_tracefile_find(LttTrace *t, unsigned i) +/* not really useful. We just have to know that cpu tracefiles + * comes before control tracefiles. + */ +int ltt_trace_per_cpu_tracefile_find(LttTrace *t, const gchar *name) { LttTracefile * tracefile; - int j, name; - for(j=0;jper_cpu_tracefile_number;j++){ - tracefile = (LttTracefile*)g_ptr_array_index(t->per_cpu_tracefiles, j); - name = atoi(tracefile->name); - if(name == (int)i)break; + unsigned int i; + for(i=0;iper_cpu_tracefile_number;i++){ + tracefile = (LttTracefile*)g_ptr_array_index(t->per_cpu_tracefiles, i); + if(strcmp(tracefile->name, name)==0)break; } - if(j == t->per_cpu_tracefile_number) return -1; - return j; + if(i == t->per_cpu_tracefile_number) return -1; + return i; } /***************************************************************************** @@ -773,7 +771,7 @@ LttTracefile *ltt_trace_per_cpu_tracefile_get(LttTrace *t, unsigned i) void ltt_trace_time_span_get(LttTrace *t, LttTime *start, LttTime *end) { LttTime startSmall, startTmp, endBig, endTmp; - int i, j=0; + unsigned int i, j=0; LttTracefile * tf; for(i=0;icontrol_tracefile_number;i++){ @@ -923,7 +921,7 @@ void ltt_tracefile_seek_time(LttTracefile *t, LttTime time) lttTime = getEventTime(t); err = ltt_time_compare(lttTime, time); if(err > 0){ - if(t->which_event==2 || (&t->prev_event_time,&time)<0){ + if(t->which_event==2 || ltt_time_compare(t->prev_event_time,time)<0){ return; }else{ updateTracefile(t); @@ -1095,10 +1093,14 @@ LttEvent *ltt_tracefile_read(LttTracefile *t, LttEvent *event) int readFile(int fd, void * buf, size_t size, char * mesg) { - ssize_t nbBytes; - nbBytes = read(fd, buf, size); - if(nbBytes != size){ - printf("%s\n",mesg); + ssize_t nbBytes = read(fd, buf, size); + + if((size_t)nbBytes != size) { + if(nbBytes < 0) { + perror("Error in readFile : "); + } else { + g_warning("%s",mesg); + } return EIO; } return 0; @@ -1186,7 +1188,7 @@ void updateTracefile(LttTracefile * tf) int skipEvent(LttTracefile * t) { - int evId, err; + int evId; void * evData; LttEventType * evT; LttField * rootFld; diff --git a/ltt/branches/poly/ltt/type.c b/ltt/branches/poly/ltt/type.c index 725b4e34..9600023c 100644 --- a/ltt/branches/poly/ltt/type.c +++ b/ltt/branches/poly/ltt/type.c @@ -168,6 +168,7 @@ LttTypeEnum ltt_type_class(LttType *t) * 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) @@ -183,19 +184,22 @@ unsigned ltt_type_size(LttTrace * trace, LttType *t) 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; } /***************************************************************************** @@ -259,8 +263,8 @@ unsigned ltt_type_member_number(LttType *t) 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){*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]; } @@ -280,7 +284,7 @@ LttType *ltt_type_member_type(LttType *t, unsigned i, char ** name) 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]; } @@ -316,7 +320,7 @@ LttField *ltt_field_element(LttField *f) 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(i >= f->field_type->element_number) return NULL; return f->child[i]; }