X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Fltt%2Fparser.c;h=7ac11e7ec8492fb683169fd5004c4cbd0fb2df18;hb=d27446d1c753dc4d628c3072f11e6b7581ccfcd8;hp=785cb652aaf2a47e7771024817649956274c6f28;hpb=0dee0e75e8a541ad435e9af431c426c53f155d71;p=lttv.git diff --git a/ltt/branches/poly/ltt/parser.c b/ltt/branches/poly/ltt/parser.c index 785cb652..7ac11e7e 100644 --- a/ltt/branches/poly/ltt/parser.c +++ b/ltt/branches/poly/ltt/parser.c @@ -1,11 +1,14 @@ + + + /* parser.c: Generate helper declarations and functions to trace events from an event description file. - Copyright (C) 2005, Mathieu Desnoyers + Copyright (C) 2005, Mathieu Desnoyers Copyright (C) 2002, Xianxiu Yang - Copyright (C) 2002, Michel Dagenais + Copyright (C) 2002, Michel Dagenais This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. @@ -20,9 +23,9 @@ parser.c: Generate helper declarations and functions to trace events Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* This program reads the ".xml" event definitions input files +/* This program reads the ".xml" event definitions input files and constructs structure for each event. - + The program uses a very simple tokenizer, called from a hand written recursive descent parser to fill a data structure describing the events. The result is a sequence of events definitions which refer to type @@ -30,14 +33,14 @@ parser.c: Generate helper declarations and functions to trace events A table of named types is maintained to allow refering to types by name when the same type is used at several places. Finally a sequence of - all types is maintained to facilitate the freeing of all type + all types is maintained to facilitate the freeing of all type information when the processing of an ".xml" file is finished. */ -#include +#include #include #include #include -#include +#include #include #include @@ -60,16 +63,16 @@ char *floatOutputTypes[] = { void strupper(char *string) { char *ptr = string; - + while(*ptr != '\0') { *ptr = toupper(*ptr); - ptr++; + ptr++; } } int getSizeindex(unsigned int value) -{ +{ switch(value) { case 1: return 0; @@ -88,20 +91,39 @@ int getSizeindex(unsigned int value) /***************************************************************************** *Function name * getSize : translate from string to integer - *Input params + *Input params * in : input file handle - *Return values - * size + *Return values + * size *****************************************************************************/ unsigned long long int getSize(parse_file_t *in) { - char *token; + char *token, *token2; + unsigned long long int ret; token = getToken(in); + + + if(in->type == QUOTEDSTRING) { + in->type = NUMBER; + token2 = token; + do { + if (!isdigit(*token2)) { + in->type = QUOTEDSTRING; + break; + } + } while (*(++token2) != '\0'); + } + if(in->type == NUMBER) { - return strtoull(token, NULL, 0); + ret = strtoull(token, NULL, 0); + } else { + goto error; } + + return ret; +error: in->error(in,"incorrect size specification"); return -1; } @@ -111,7 +133,7 @@ unsigned long long int getSize(parse_file_t *in) * error_callback : print out error info *Input params * in : input file handle - * msg : message to be printed + * msg : message to be printed ****************************************************************************/ void error_callback(parse_file_t *in, char *msg) @@ -126,11 +148,11 @@ void error_callback(parse_file_t *in, char *msg) /***************************************************************************** *Function name - * memAlloc : allocate memory - *Input params - * size : required memory size - *return value - * void * : pointer to allocate memory or NULL + * memAlloc : allocate memory + *Input params + * size : required memory size + *return value + * void * : pointer to allocate memory or NULL ****************************************************************************/ void * memAlloc(int size) @@ -139,18 +161,18 @@ void * memAlloc(int size) if(size == 0) return NULL; addr = malloc(size); if(!addr){ - printf("Failed to allocate memory"); + printf("Failed to allocate memory"); exit(1); } - return addr; + return addr; } /***************************************************************************** *Function name - * allocAndCopy : allocate memory and initialize it - *Input params - * str : string to be put in memory - *return value + * allocAndCopy : allocate memory and initialize it + *Input params + * str : string to be put in memory + *return value * char * : pointer to allocate memory or NULL ****************************************************************************/ @@ -176,24 +198,27 @@ char *allocAndCopy(char *str) **************************************************************************/ void getTypeAttributes(parse_file_t *in, type_descriptor_t *t, - sequence_t * unnamed_types, table_t * named_types) + sequence_t * unnamed_types, table_t * named_types) { char * token; + int car; t->fmt = NULL; t->size = 0; t->custom_write = 0; - + t->network = 0; + while(1) { - token = getToken(in); + token = getToken(in); if(strcmp("/",token) == 0 || strcmp(">",token) == 0){ ungetToken(in); break; } - + if(!strcmp("format",token)) { getEqual(in); t->fmt = allocAndCopy(getQuotedString(in)); + // printf("%s - ",t->fmt); //} else if(!strcmp("name",token)) { // getEqual(in); // car = seekNextChar(in); @@ -205,6 +230,24 @@ void getTypeAttributes(parse_file_t *in, type_descriptor_t *t, t->size = getSize(in); } else if(!strcmp("custom_write", token)) { t->custom_write = 1; + } else if(!strcmp("byte_order",token)) { + getEqual(in); + car = seekNextChar(in); + if(car == EOF) in->error(in,"byte order was expected (network?)"); + else if(car == '\"') token = getQuotedString(in); + else token = getName(in); + if(!strcmp("network", token)) { + t->network = 1; + } + } else if(!strcmp("write",token)) { + getEqual(in); + car = seekNextChar(in); + if(car == EOF) in->error(in,"write type was expected (custom?)"); + else if(car == '\"') token = getQuotedString(in); + else token = getName(in); + if(!strcmp("custom", token)) { + t->custom_write = 1; + } } } } @@ -224,14 +267,19 @@ void getTypeAttributes(parse_file_t *in, type_descriptor_t *t, void getEventAttributes(parse_file_t *in, event_t *ev) { char * token; - char car; - + int car; + ev->name = NULL; ev->per_trace = 0; ev->per_tracefile = 0; + ev->param_buffer = 0; + ev->no_instrument_function = 0; + ev->high_priority = 0; + ev->force = 0; + ev->compact_data = 0; while(1) { - token = getToken(in); + token = getToken(in); if(strcmp("/",token) == 0 || strcmp(">",token) == 0){ ungetToken(in); break; @@ -243,12 +291,36 @@ void getEventAttributes(parse_file_t *in, event_t *ev) if(car == EOF) in->error(in,"name was expected"); else if(car == '\"') ev->name = allocAndCopy(getQuotedString(in)); else ev->name = allocAndCopy(getName(in)); - } else if(!strcmp("per_trace", token)) { - ev->per_trace = 1; - } else if(!strcmp("per_tracefile", token)) { - ev->per_tracefile = 1; + } else if(!strcmp("scope", token)) { + getEqual(in); + car = seekNextChar(in); + if(car == EOF) in->error(in,"scope was expected"); + else if(car == '\"') token = getQuotedString(in); + else token = getName(in); + if(!strcmp(token, "trace")) ev->per_trace = 1; + else if(!strcmp(token, "tracefile")) ev->per_tracefile = 1; + } else if(!strcmp("param", token)) { + getEqual(in); + car = seekNextChar(in); + if(car == EOF) in->error(in,"parameter type was expected"); + else if(car == '\"') token = getQuotedString(in); + else token = getName(in); + if(!strcmp(token, "buffer")) ev->param_buffer = 1; + } else if(!strcmp("attribute", token)) { + getEqual(in); + car = seekNextChar(in); + if(car == EOF) in->error(in,"attribute was expected"); + else if(car == '\"') token = getQuotedString(in); + else token = getName(in); + if(!strcmp(token, "no_instrument_function")) + ev->no_instrument_function = 1; + else if(!strcmp(token, "high_priority")) + ev->high_priority = 1; + else if(!strcmp(token, "force")) + ev->force = 1; + else if(!strcmp(token, "compact_data")) + ev->compact_data = 1; } - } } @@ -267,13 +339,15 @@ void getEventAttributes(parse_file_t *in, event_t *ev) void getFacilityAttributes(parse_file_t *in, facility_t *fac) { char * token; - char car; - + int car; + fac->name = NULL; fac->arch = NULL; + fac->align = 1; + fac->user = 0; while(1) { - token = getToken(in); + token = getToken(in); if(strcmp("/",token) == 0 || strcmp(">",token) == 0){ ungetToken(in); break; @@ -285,12 +359,18 @@ void getFacilityAttributes(parse_file_t *in, facility_t *fac) if(car == EOF) in->error(in,"name was expected"); else if(car == '\"') fac->name = allocAndCopy(getQuotedString(in)); else fac->name = allocAndCopy(getName(in)); + if(!strncmp(fac->name, "user_", sizeof("user_")-1)) + fac->user = 1; } else if(!strcmp("arch", token)) { getEqual(in); car = seekNextChar(in); - if(car == '\"') fac->name = allocAndCopy(getQuotedString(in)); - else fac->arch = allocAndCopy(getName(in)); - } + if(car == '\"') fac->arch = allocAndCopy(getQuotedString(in)); + else fac->arch = allocAndCopy(getName(in)); + } else if(!strcmp("align", token)) { + getEqual(in); + fac->align = getSize(in); + } + } } @@ -309,12 +389,12 @@ void getFacilityAttributes(parse_file_t *in, facility_t *fac) void getFieldAttributes(parse_file_t *in, field_t *f) { char * token; - char car; + int car; f->name = NULL; while(1) { - token = getToken(in); + token = getToken(in); if(strcmp("/",token) == 0 || strcmp(">",token) == 0){ ungetToken(in); break; @@ -334,10 +414,10 @@ char *getNameAttribute(parse_file_t *in) { char * token; char *name = NULL; - char car; - + int car; + while(1) { - token = getToken(in); + token = getToken(in); if(!strcmp("name",token)) { getEqual(in); car = seekNextChar(in); @@ -356,28 +436,37 @@ char *getNameAttribute(parse_file_t *in) -//for