X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=genevent%2Fgenevent.c;h=5adf87885fe9af8237f7c14e3bafc6ee5248754d;hb=8c6ca411f1f7dc33394552044fcfc0bed6e961b4;hp=e6c5bb8934f744f0b4c2655e097e316206a89ac2;hpb=31cbc5d38faf2afcf879ec0636e580192f0b817c;p=lttv.git diff --git a/genevent/genevent.c b/genevent/genevent.c index e6c5bb89..5adf8788 100644 --- a/genevent/genevent.c +++ b/genevent/genevent.c @@ -45,7 +45,6 @@ This program is distributed in the hope that it will be useful, #include "parser.h" #include "genevent.h" - /* Named types may be referenced from anywhere */ facility * fac; @@ -124,8 +123,8 @@ int main(int argc, char** argv) * name : name of event definition file ****************************************************************************/ void generateFile(char *name){ - char *cName, *hName, *tmp; - FILE * cFp, *hFp; + char *loadName, *hName, *tmp, *tmp2; + FILE * lFp, *hFp; int nbEvent; unsigned long checksum=0; @@ -141,12 +140,18 @@ void generateFile(char *name){ }else{ tmp = name; } - - cName = appendString(tmp,".c"); - hName = appendString(tmp,".h"); - cFp = fopen(cName,"w"); - if(!cFp){ - printf("Cannot open the file : %s\n",cName); + + loadName = appendString("ltt-facility-loader-", tmp); + tmp2 = appendString(loadName,".h"); + free(loadName); + loadName = tmp2; + hName = appendString("ltt-facility-", tmp); + tmp2 = appendString(hName,".h"); + free(hName); + hName = tmp2; + lFp = fopen(loadName,"w"); + if(!lFp){ + printf("Cannot open the file : %s\n",loadName); exit(1); } @@ -156,7 +161,7 @@ void generateFile(char *name){ exit(1); } - free(cName); + free(loadName); free(hName); generateChecksum(fac->name, &checksum, &(fac->events)); @@ -169,11 +174,11 @@ void generateFile(char *name){ generateStructFunc(hFp, fac->name,checksum); fprintf(hFp, "#endif //_LTT_FACILITY_%s_H_\n",fac->capname); - /* generate .c file, calls to register the facility at init time */ - generateCfile(cFp,fac->name,nbEvent,checksum); + /* generate .h file, calls to register the facility at init time */ + generateLoaderfile(lFp,fac->name,nbEvent,checksum,fac->capname); fclose(hFp); - fclose(cFp); + fclose(lFp); } @@ -222,6 +227,7 @@ void generateEnumEvent(FILE *fp, char *facName, int * nbEvent, unsigned long che * hasStrSeq : string or sequence present? * structCount : struct postfix ****************************************************************************/ + static void printStruct(FILE * fp, int len, void ** array, char * name, char * facName, int * whichTypeFirst, int * hasStrSeq, int * structCount) @@ -235,34 +241,32 @@ printStruct(FILE * fp, int len, void ** array, char * name, char * facName, fld = (field *)array[pos]; td = fld->type; if( td->type != STRING && td->type != SEQUENCE && - td->type != ARRAY) { + td->type != ARRAY) { if (*whichTypeFirst == 0) { *whichTypeFirst = 1; //struct first } if (flag == 0) { flag = 1; - fprintf(fp,"struct %s_%s", - name, facName); - if (structCount) { - fprintf(fp, "_%d {\n", - ++*structCount); - } else { - fprintf(fp, " {\n"); - } + fprintf(fp,"struct %s_%s",name, facName); + if (structCount) { + fprintf(fp, "_%d {\n",++*structCount); + } else { + fprintf(fp, " {\n"); + } } - fprintf(fp, "\t%s %s; /* %s */\n", - getTypeStr(td),fld->name,fld->description ); + fprintf(fp, "\t%s %s; /* %s */\n", + getTypeStr(td),fld->name,fld->description ); } else { - if (*whichTypeFirst == 0) { + if (*whichTypeFirst == 0) { //string or sequence or array first - *whichTypeFirst = 2; - } - (*hasStrSeq)++; - if(flag) { - fprintf(fp,"} __attribute__ ((packed));\n\n"); - } - flag = 0; + *whichTypeFirst = 2; + } + (*hasStrSeq)++; + if(flag) { + fprintf(fp,"} __attribute__ ((packed));\n\n"); + } + flag = 0; } } @@ -309,9 +313,13 @@ void generateEnumDefinition(FILE * fp, type_descriptor * type){ fprintf(fp,"enum {\n"); for(pos = 0; pos < type->labels.position; pos++){ fprintf(fp,"\t%s", type->labels.array[pos]); - if (pos != type->labels.position - 1) fprintf(fp,",\n"); + if (pos != type->labels.position - 1) fprintf(fp,","); + if(type->labels_description.array[pos] != NULL) + fprintf(fp,"\t/* %s */\n",type->labels_description.array[pos]); + else + fprintf(fp,"\n"); } - fprintf(fp,"\n};\n\n\n"); + fprintf(fp,"};\n\n\n"); } /***************************************************************************** @@ -565,30 +573,27 @@ char * getTypeStr(type_descriptor * td){ /***************************************************************************** *Function name - * generateCfile : generate a .c file + * generateLoaderfile: generate a facility loaded .h file *Input Params * fp : file to be written to * facName : name of facility * nbEvent : number of events in the facility * checksum : checksum for the facility ****************************************************************************/ -void generateCfile(FILE * fp, char * facName, int nbEvent, unsigned long checksum){ - //will be removed later - fprintf(fp,"typedef unsigned int trace_facility_t;\n\n"); - - fprintf(fp,"static unsigned long checksum = %lu;\n\n",checksum); - fprintf(fp,"/* facility handle */\n"); - fprintf(fp,"trace_facility_t facility_%s;\n\n",facName); - - fprintf(fp,"static void __init facility_%s_init(){\n",facName); - fprintf(fp,"\tfacility_%s = trace_register_facility_by_checksum(\"%s\", checksum,%d);\n",facName,facName,nbEvent); - fprintf(fp,"}\n\n"); - - fprintf(fp,"static void __exit facility_%s_exit(){\n",facName); - fprintf(fp,"}\n\n"); - - fprintf(fp,"module_init(facility_%s_init);\n",facName); - fprintf(fp,"module_exit(facility_%s_exit);\n",facName); +void generateLoaderfile(FILE * fp, char * facName, int nbEvent, unsigned long checksum, char *capname){ + fprintf(fp, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n",capname); + fprintf(fp, "#define _LTT_FACILITY_LOADER_%s_H_\n\n",capname); + fprintf(fp,"#include \n", facName, checksum); + fprintf(fp,"#include \n\n", facName, checksum); + fprintf(fp,"ltt_facility_t\tltt_facility_%s_%X;\n\n", facName, checksum); + + fprintf(fp,"EXPORT_SYMBOL(ltt_facility_%s_%X);\n\n",facName, checksum); + fprintf(fp,"#define LTT_FACILITY_SYMBOL\t\t\t\tltt_facility_%s_%X\n", + facName, checksum); + fprintf(fp,"#define LTT_FACILITY_CHECKSUM\t\t\t0x%X\n", checksum); + fprintf(fp,"#define LTT_FACILITY_NAME\t\t\t\t\t\"%s\"\n", facName); + fprintf(fp,"#define LTT_FACILITY_NUM_EVENTS\t\t%d\n\n", nbEvent); + fprintf(fp, "#endif //_LTT_FACILITY_LOADER_%s_H_\n",capname); }