bbf90a5abb18017557745113f2899d8cf712afa2
1 /******************************************************************************
4 * Event generator. XML to logging C code converter.
9 * Will generate ltt-facility-name.h, ltt-facility-id-name.h
10 * ltt-facility-loader-name.c, ltt-facility-loader-name.h
11 * in the current directory.
15 * - C types : struct, union, enum, basic types.
16 * - Architectures : LP32, ILP32, ILP64, LLP64, LP64.
18 * Additionnal structures supported :
19 * - embedded variable size strings
20 * - embedded variable size arrays
21 * - embedded variable size sequences
25 * enums are limited to integer type, as this is what is used in C. Note,
26 * however, that ISO/IEC 9899:TC2 specify that the type of enum can be char,
27 * unsigned int or int. This is implementation defined (compiler). That's why we
28 * add a check for sizeof enum.
31 * Because of archtecture defined type sizes, we need to ask for ltt_align
32 * (which gives the alignment) by passing basic types, not their actual sizes.
33 * It's up to ltt_align to determine sizes of types.
36 * http://www.usenix.org/publications/login/standards/10.data.html
37 * (Andrew Josey <a.josey@opengroup.org>) :
39 * Data Type LP32 ILP32 ILP64 LLP64 LP64
41 * short 16 16 16 16 16
45 * long long (int64) 64
46 * pointer 32 32 64 64 64
48 * With these constraints :
49 * sizeof(char) <= sizeof(short) <= sizeof(int)
50 * <= sizeof(long) = sizeof(size_t)
52 * and therefore sizeof(long) <= sizeof(pointer) <= sizeof(size_t)
54 * Which means we only have to remember which is the biggest type in a structure
55 * to know the structure's alignment.
62 #include <sys/types.h>
77 /* Debugging printf */
79 #define dprintf(...) \
81 printf(__FILE__ ",%u,%s: ",\
91 void print_tabs(unsigned int tabs
, FILE *fd
)
93 for(unsigned int i
= 0; i
<tabs
;i
++)
99 * Copied from construct_types_and_fields in LTTV facility.c */
101 int print_type(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
102 char *nest_name
, char *field_name
)
104 char basename
[PATH_MAX
];
105 unsigned int basename_len
= 0;
107 strcpy(basename
, nest_name
);
108 basename_len
= strlen(basename
);
110 /* For a named type, we use the type_name directly */
111 if(td
->type_name
!= NULL
) {
112 strncpy(basename
, td
->type_name
, PATH_MAX
);
113 basename_len
= strlen(basename
);
115 /* For a unnamed type, there must be a field name */
116 if((basename_len
!= 0)
117 && (basename
[basename_len
-1] != '_')
118 && (field_name
[0] != '\0')) {
119 strncat(basename
, "_", PATH_MAX
- basename_len
);
120 basename_len
= strlen(basename
);
122 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
127 fprintf(fd
, "%s", intOutputTypes
[getSizeindex(td
->size
)]);
130 fprintf(fd
, "%s", uintOutputTypes
[getSizeindex(td
->size
)]);
133 fprintf(fd
, "signed char");
136 fprintf(fd
, "unsigned char");
139 fprintf(fd
, "short");
142 fprintf(fd
, "unsigned short");
148 fprintf(fd
, "unsigned int");
151 fprintf(fd
, "%s", floatOutputTypes
[getSizeindex(td
->size
)]);
154 fprintf(fd
, "const void *");
160 fprintf(fd
, "unsigned long");
163 fprintf(fd
, "size_t");
166 fprintf(fd
, "ssize_t");
169 fprintf(fd
, "off_t");
172 fprintf(fd
, "const char *");
175 fprintf(fd
, "enum lttng_%s", basename
);
178 fprintf(fd
, "lttng_array_%s", basename
);
181 fprintf(fd
, "lttng_sequence_%s", basename
);
184 fprintf(fd
, "struct lttng_%s", basename
);
187 fprintf(fd
, "union lttng_%s", basename
);
190 printf("print_type : unknown type\n");
197 /* Print logging function argument */
198 int print_arg(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
199 char *nest_name
, char *field_name
)
201 char basename
[PATH_MAX
];
202 unsigned int basename_len
= 0;
204 strcpy(basename
, nest_name
);
205 basename_len
= strlen(basename
);
207 /* For a named type, we use the type_name directly */
208 if(td
->type_name
!= NULL
) {
209 strncpy(basename
, td
->type_name
, PATH_MAX
);
210 basename_len
= strlen(basename
);
212 /* For a unnamed type, there must be a field name */
213 if((basename_len
!= 0)
214 && (basename
[basename_len
-1] != '_')
215 && (field_name
[0] != '\0')) {
216 strncat(basename
, "_", PATH_MAX
- basename_len
);
217 basename_len
= strlen(basename
);
219 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
222 print_tabs(tabs
, fd
);
226 fprintf(fd
, "%s", intOutputTypes
[getSizeindex(td
->size
)]);
227 fprintf(fd
, " %s", field_name
);
230 fprintf(fd
, "%s", uintOutputTypes
[getSizeindex(td
->size
)]);
231 fprintf(fd
, " %s", field_name
);
234 fprintf(fd
, "signed char");
235 fprintf(fd
, " %s", field_name
);
238 fprintf(fd
, "unsigned char");
239 fprintf(fd
, " %s", field_name
);
242 fprintf(fd
, "short");
243 fprintf(fd
, " %s", field_name
);
246 fprintf(fd
, "unsigned short");
247 fprintf(fd
, " %s", field_name
);
251 fprintf(fd
, " %s", field_name
);
254 fprintf(fd
, "unsigned int");
255 fprintf(fd
, " %s", field_name
);
258 fprintf(fd
, "%s", floatOutputTypes
[getSizeindex(td
->size
)]);
259 fprintf(fd
, " %s", field_name
);
262 fprintf(fd
, "const void *");
263 fprintf(fd
, " %s", field_name
);
267 fprintf(fd
, " %s", field_name
);
270 fprintf(fd
, "unsigned long");
271 fprintf(fd
, " %s", field_name
);
274 fprintf(fd
, "size_t");
275 fprintf(fd
, " %s", field_name
);
278 fprintf(fd
, "ssize_t");
279 fprintf(fd
, " %s", field_name
);
282 fprintf(fd
, "off_t");
283 fprintf(fd
, " %s", field_name
);
286 fprintf(fd
, "const char *");
287 fprintf(fd
, " %s", field_name
);
290 fprintf(fd
, "enum lttng_%s", basename
);
291 fprintf(fd
, " %s", field_name
);
294 fprintf(fd
, "lttng_array_%s", basename
);
295 fprintf(fd
, " %s", field_name
);
298 fprintf(fd
, "lttng_sequence_%s *", basename
);
299 fprintf(fd
, " %s", field_name
);
302 fprintf(fd
, "struct lttng_%s *", basename
);
303 fprintf(fd
, " %s", field_name
);
306 fprintf(fd
, "union lttng_%s *", basename
);
307 fprintf(fd
, " %s", field_name
);
310 printf("print_type : unknown type\n");
318 /* Does the type has a fixed size ? (as know from the compiler)
321 * 0 : variable length
323 int has_type_fixed_size(type_descriptor_t
*td
)
342 case UNION
: /* The union must have fixed size children. Must be checked by
352 int has_type_fixed
= 0;
353 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
354 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
355 type_descriptor_t
*type
= field
->type
;
357 has_type_fixed
= has_type_fixed_size(type
);
358 if(!has_type_fixed
) return 0;
364 assert(td
->size
>= 0);
365 return has_type_fixed_size(((field_t
*)td
->fields
.array
[0])->type
);
368 printf("There is a type defined to NONE : bad.\n");
372 return 0; //make gcc happy.
379 /* print type declaration.
381 * Copied from construct_types_and_fields in LTTV facility.c */
383 int print_type_declaration(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
384 char *nest_name
, char *field_name
)
386 char basename
[PATH_MAX
];
387 unsigned int basename_len
= 0;
389 strncpy(basename
, nest_name
, PATH_MAX
);
390 basename_len
= strlen(basename
);
392 /* For a named type, we use the type_name directly */
393 if(td
->type_name
!= NULL
) {
394 strncpy(basename
, td
->type_name
, PATH_MAX
);
395 basename_len
= strlen(basename
);
397 /* For a unnamed type, there must be a field name, except for
399 if((basename_len
!= 0)
400 && (basename
[basename_len
-1] != '_'
401 && (field_name
[0] != '\0'))) {
402 strncat(basename
, "_", PATH_MAX
- basename_len
);
403 basename_len
= strlen(basename
);
405 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
410 fprintf(fd
, "enum lttng_%s", basename
);
412 for(unsigned int i
=0;i
<td
->labels
.position
;i
++){
414 fprintf(fd
, "LTTNG_%s", ((char*)(td
->labels
.array
[i
])));
422 dprintf("%s\n", basename
);
423 assert(td
->size
>= 0);
424 if(((field_t
*)td
->fields
.array
[0])->type
->type_name
== NULL
) {
425 /* Not a named nested type : we must print its declaration first */
426 if(print_type_declaration(((field_t
*)td
->fields
.array
[0])->type
,
427 fd
, 0, basename
, "")) return 1;
429 fprintf(fd
, "#define LTTNG_ARRAY_SIZE_%s %zu\n", basename
,
431 fprintf(fd
, "typedef ");
432 if(print_type(((field_t
*)td
->fields
.array
[0])->type
,
433 fd
, tabs
, basename
, "")) return 1;
434 fprintf(fd
, " lttng_array_%s[LTTNG_ARRAY_SIZE_%s];\n", basename
,
439 /* We assume that the sequence length type does not need to be declared.
441 if(((field_t
*)td
->fields
.array
[1])->type
->type_name
== NULL
) {
442 /* Not a named nested type : we must print its declaration first */
443 if(print_type_declaration(((field_t
*)td
->fields
.array
[1])->type
,
444 fd
, 0, basename
, "")) return 1;
446 fprintf(fd
, "typedef struct lttng_sequence_%s lttng_sequence_%s;\n",
449 fprintf(fd
, "struct lttng_sequence_%s", basename
);
452 if(print_type(((field_t
*)td
->fields
.array
[0])->type
,
453 fd
, tabs
, basename
, "")) return 1;
454 fprintf(fd
, " len;\n");
456 fprintf(fd
, "const ");
457 if(print_type(((field_t
*)td
->fields
.array
[1])->type
,
458 fd
, tabs
, basename
, "")) return 1;
459 fprintf(fd
, " *array;\n");
460 fprintf(fd
, "};\n"); /* We do not LTT_ALIGN, because we never copy
461 it to the buffer directly. */
466 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
467 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
468 type_descriptor_t
*type
= field
->type
;
469 if(type
->type_name
== NULL
) {
470 /* Not a named nested type : we must print its declaration first */
471 if(print_type_declaration(type
,
472 fd
, 0, basename
, field
->name
)) return 1;
475 fprintf(fd
, "struct lttng_%s", basename
);
477 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
478 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
479 type_descriptor_t
*type
= field
->type
;
481 if(print_type(type
, fd
, tabs
, basename
, field
->name
)) return 1;
483 fprintf(fd
, "%s", field
->name
);
486 fprintf(fd
, "} LTT_ALIGN;\n");
490 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
491 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
492 type_descriptor_t
*type
= field
->type
;
493 if(type
->type_name
== NULL
) {
494 /* Not a named nested type : we must print its declaration first */
495 if(print_type_declaration(type
,
496 fd
, 0, basename
, field
->name
)) return 1;
499 fprintf(fd
, "union lttng_%s", basename
);
501 for(unsigned i
=0;i
<td
->fields
.position
;i
++){
502 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
503 type_descriptor_t
*type
= field
->type
;
505 if(print_type(type
, fd
, tabs
, basename
, field
->name
)) return 1;
507 fprintf(fd
, "%s", field
->name
);
510 fprintf(fd
, "} LTT_ALIGN;\n");
514 dprintf("print_type_declaration : unknown type or nothing to declare.\n");
522 /* print type alignment.
524 * Copied from construct_types_and_fields in LTTV facility.c
526 * basename is the name which identifies the type (along with a prefix
529 int print_type_alignment(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
530 char *nest_name
, char *field_name
, char *obj_prefix
)
532 char basename
[PATH_MAX
];
533 unsigned int basename_len
= 0;
535 strncpy(basename
, nest_name
, PATH_MAX
);
536 basename_len
= strlen(basename
);
538 /* For a named type, we use the type_name directly */
539 if(td
->type_name
!= NULL
) {
540 strncpy(basename
, td
->type_name
, PATH_MAX
);
541 basename_len
= strlen(basename
);
543 /* For a unnamed type, there must be a field name, except for
545 if((basename_len
!= 0)
546 && (basename
[basename_len
-1] != '_'
547 && field_name
!= NULL
548 && (field_name
[0] != '\0'))) {
549 strncat(basename
, "_", PATH_MAX
- basename_len
);
550 basename_len
= strlen(basename
);
552 if(field_name
!= NULL
)
553 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
556 if(field_name
[0] == '\0') {
557 /* We are in a write function : it's the obj that we must align. */
560 fprintf(fd
, "lttng_get_alignment_sequence_%s(%s)", basename
,
564 fprintf(fd
, "lttng_get_alignment_struct_%s(%s)", basename
,
568 fprintf(fd
, "lttng_get_alignment_union_%s(%s)", basename
,
572 fprintf(fd
, "lttng_get_alignment_array_%s(%s)", basename
,
575 fprintf(fd
, "sizeof(char)");
578 printf("error : type unexpected\n");
601 fprintf(fd
, "sizeof(");
602 if(print_type(td
, fd
, 0, basename
, "")) return 1;
606 fprintf(fd
, "sizeof(char)");
609 fprintf(fd
, "lttng_get_alignment_sequence_%s(&%s%s)", basename
,
610 obj_prefix
, field_name
);
613 fprintf(fd
, "lttng_get_alignment_struct_%s(&%s%s)", basename
,
614 obj_prefix
, field_name
);
617 fprintf(fd
, "lttng_get_alignment_union_%s(&%s%s)", basename
,
618 obj_prefix
, field_name
);
621 fprintf(fd
, "lttng_get_alignment_array_%s(%s%s)", basename
,
622 obj_prefix
, field_name
);
625 printf("error : type NONE unexpected\n");
636 * Copied from construct_types_and_fields in LTTV facility.c
638 * basename is the name which identifies the type (along with a prefix
641 int print_type_write(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
642 char *nest_name
, char *field_name
, char *obj_prefix
, int get_ptr
)
644 char basename
[PATH_MAX
];
645 unsigned int basename_len
= 0;
646 char get_ptr_char
[2] = "";
648 strncpy(basename
, nest_name
, PATH_MAX
);
649 basename_len
= strlen(basename
);
651 /* For a named type, we use the type_name directly */
652 if(td
->type_name
!= NULL
) {
653 strncpy(basename
, td
->type_name
, PATH_MAX
);
654 basename_len
= strlen(basename
);
656 /* For a unnamed type, there must be a field name, except for
658 if((basename_len
!= 0)
659 && (basename
[basename_len
-1] != '_'
660 && (field_name
[0] != '\0'))) {
661 strncat(basename
, "_", PATH_MAX
- basename_len
);
662 basename_len
= strlen(basename
);
664 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
668 strcpy(get_ptr_char
, "&");
688 print_tabs(tabs
, fd
);
689 fprintf(fd
, "size = ");
690 fprintf(fd
, "sizeof(");
691 if(print_type(td
, fd
, 0, basename
, "")) return 1;
693 print_tabs(tabs
, fd
);
694 fprintf(fd
, "size += ltt_align(*to+*len, size) + size;\n");
695 print_tabs(tabs
, fd
);
696 fprintf(fd
, "*len += size;");
699 print_tabs(tabs
, fd
);
701 "lttng_write_string_%s(buffer, to_base, to, from, len, %s%s);\n",
702 basename
, obj_prefix
, field_name
);
705 print_tabs(tabs
, fd
);
707 "lttng_write_sequence_%s(buffer, to_base, to, from, len, %s%s%s);",
708 basename
, get_ptr_char
, obj_prefix
, field_name
);
711 print_tabs(tabs
, fd
);
713 "lttng_write_struct_%s(buffer, to_base, to, from, len, %s%s%s);",
714 basename
, get_ptr_char
, obj_prefix
, field_name
);
717 print_tabs(tabs
, fd
);
719 "lttng_write_union_%s(buffer, to_base, to, from, len, %s%s%s);",
720 basename
, get_ptr_char
, obj_prefix
, field_name
);
723 print_tabs(tabs
, fd
);
725 "lttng_write_array_%s(buffer, to_base, to, from, len, %s%s);",
726 basename
, obj_prefix
, field_name
);
729 printf("Error : type NONE unexpected\n");
737 /* print need local vars ?.
739 * Copied from print_type_write
741 * Does the type_write call needs local size and from variables ?
742 * return value : 1 yes, 0 no.
745 int has_type_local(type_descriptor_t
* td
)
774 printf("Error : type NONE unexpected\n");
784 /* print type alignment function.
786 * Copied from construct_types_and_fields in LTTV facility.c
788 * basename is the name which identifies the type (along with a prefix
791 int print_type_alignment_fct(type_descriptor_t
* td
, FILE *fd
,
793 char *nest_name
, char *field_name
)
795 char basename
[PATH_MAX
];
796 unsigned int basename_len
= 0;
798 strncpy(basename
, nest_name
, PATH_MAX
);
799 basename_len
= strlen(basename
);
801 /* For a named type, we use the type_name directly */
802 if(td
->type_name
!= NULL
) {
803 strncpy(basename
, td
->type_name
, PATH_MAX
);
804 basename_len
= strlen(basename
);
806 /* For a unnamed type, there must be a field name, except for
808 if((basename_len
!= 0)
809 && (basename
[basename_len
-1] != '_'
810 && (field_name
[0] != '\0'))) {
811 strncat(basename
, "_", PATH_MAX
- basename_len
);
812 basename_len
= strlen(basename
);
814 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
819 /* Function header */
820 fprintf(fd
, "static inline size_t lttng_get_alignment_sequence_%s(\n",
823 if(print_type(td
, fd
, 0, basename
, "")) return 1;
824 fprintf(fd
, " *obj)\n");
827 fprintf(fd
, "size_t align=0, localign;");
830 fprintf(fd
, "localign = ");
831 if(print_type_alignment(((field_t
*)td
->fields
.array
[0])->type
,
832 fd
, 0, basename
, "len", "obj->")) return 1;
835 fprintf(fd
, "align = max(align, localign);\n");
838 fprintf(fd
, "localign = ");
839 if(print_type_alignment(((field_t
*)td
->fields
.array
[1])->type
,
840 fd
, 0, basename
, "array[0]", "obj->")) return 1;
843 fprintf(fd
, "align = max(align, localign);\n");
846 fprintf(fd
, "return align;\n");
849 /* Function header */
850 fprintf(fd
, "static inline size_t lttng_get_alignment_struct_%s(\n",
853 if(print_type(td
, fd
, 0, basename
, "")) return 1;
854 fprintf(fd
, " *obj)\n");
857 fprintf(fd
, "size_t align=0, localign;");
859 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
860 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
861 type_descriptor_t
*type
= field
->type
;
863 fprintf(fd
, "localign = ");
864 if(print_type_alignment(type
, fd
, 0, basename
, field
->name
, "obj->"))
868 fprintf(fd
, "align = max(align, localign);\n");
872 fprintf(fd
, "return align;\n");
876 /* Function header */
877 fprintf(fd
, "static inline size_t lttng_get_alignment_union_%s(\n",
880 if(print_type(td
, fd
, 0, basename
, "")) return 1;
881 fprintf(fd
, " *obj)\n");
884 fprintf(fd
, "size_t align=0, localign;");
886 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
887 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
888 type_descriptor_t
*type
= field
->type
;
890 fprintf(fd
, "localign = ");
891 if(print_type_alignment(type
, fd
, 0, basename
, field
->name
, "obj->"))
895 fprintf(fd
, "align = max(align, localign);\n");
899 fprintf(fd
, "return align;\n");
903 /* Function header */
904 fprintf(fd
, "static inline size_t lttng_get_alignment_array_%s(\n",
907 if(print_type(td
, fd
, 0, basename
, "")) return 1;
908 fprintf(fd
, " obj)\n");
911 fprintf(fd
, "return \n");
912 if(print_type_alignment(((field_t
*)td
->fields
.array
[0])->type
,
913 fd
, 0, basename
, "", "obj[0]"))
918 dprintf("print_type_alignment_fct : type has no alignment function.\n");
924 /* Function footer */
931 /* print type write function.
933 * Copied from construct_types_and_fields in LTTV facility.c
935 * basename is the name which identifies the type (along with a prefix
938 int print_type_write_fct(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
939 char *nest_name
, char *field_name
)
941 char basename
[PATH_MAX
];
942 unsigned int basename_len
= 0;
944 strncpy(basename
, nest_name
, PATH_MAX
);
945 basename_len
= strlen(basename
);
947 /* For a named type, we use the type_name directly */
948 if(td
->type_name
!= NULL
) {
949 strncpy(basename
, td
->type_name
, PATH_MAX
);
950 basename_len
= strlen(basename
);
952 /* For a unnamed type, there must be a field name, except for
954 if((basename_len
!= 0)
955 && (basename
[basename_len
-1] != '_'
956 && (field_name
[0] != '\0'))) {
957 strncat(basename
, "_", PATH_MAX
- basename_len
);
958 basename_len
= strlen(basename
);
960 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
971 dprintf("print_type_write_fct : type has no write function.\n");
979 fprintf(fd
, "static inline void lttng_write_sequence_%s(\n",
983 fprintf(fd
, "static inline void lttng_write_struct_%s(\n", basename
);
986 fprintf(fd
, "static inline void lttng_write_union_%s(\n", basename
);
989 fprintf(fd
, "static inline void lttng_write_array_%s(\n", basename
);
992 fprintf(fd
, "static inline void lttng_write_string_%s(\n", basename
);
995 printf("print_type_write_fct : type has no write function.\n");
1000 fprintf(fd
, "void *buffer,\n");
1002 fprintf(fd
, "size_t *to_base,\n");
1004 fprintf(fd
, "size_t *to,\n");
1006 fprintf(fd
, "const void **from,\n");
1008 fprintf(fd
, "size_t *len,\n");
1010 if(print_type(td
, fd
, 0, basename
, "")) return 1;
1014 fprintf(fd
, " *obj)\n");
1017 fprintf(fd
, " *obj)\n");
1020 fprintf(fd
, " *obj)\n");
1023 fprintf(fd
, " obj)\n");
1026 fprintf(fd
, " obj)\n");
1029 printf("print_type_write_fct : type has no write function.\n");
1035 fprintf(fd
, "size_t align, size;\n");
1042 fprintf(fd
, "/* Flush pending memcpy */\n");
1044 fprintf(fd
, "if(*len != 0) {\n");
1046 fprintf(fd
, "if(buffer != NULL)\n");
1048 fprintf(fd
, "memcpy(buffer+*to_base+*to, *from, *len);\n");
1052 fprintf(fd
, "*to += *len;\n");
1054 fprintf(fd
, "*len = 0;\n");
1062 printf("print_type_write_fct : type has no write function.\n");
1067 fprintf(fd
, "align = ");
1068 if(print_type_alignment(td
, fd
, 0, basename
, "", "obj")) return 1;
1072 fprintf(fd
, "if(*len == 0) {\n");
1074 fprintf(fd
, "*to += ltt_align(*to, align); /* align output */\n");
1076 fprintf(fd
, "} else {\n");
1078 fprintf(fd
, "*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */\n");
1083 /* First, check if the type has a fixed size. If it is the case, then the size
1084 * to write is know by the compiler : simply use a sizeof() */
1085 if(has_type_fixed_size(td
)) {
1087 fprintf(fd
, "/* Contains only fixed size fields : use compiler sizeof() */\n");
1090 fprintf(fd
, "size = sizeof(");
1091 if(print_type(td
, fd
, 0, basename
, field_name
)) return 1;
1092 fprintf(fd
, ");\n");
1094 fprintf(fd
, "*len += size;\n");
1096 /* The type contains nested variable size subtypes :
1097 * we must write field by field. */
1099 fprintf(fd
, "/* Contains variable sized fields : must explode the structure */\n");
1105 fprintf(fd
, "/* Copy members */\n");
1106 // print_tabs(1, fd);
1107 // fprintf(fd, "size = sizeof(\n");
1108 if(print_type_write(((field_t
*)td
->fields
.array
[0])->type
,
1109 fd
, 1, basename
, "len", "obj->", 1)) return 1;
1111 // fprintf(fd, ");\n");
1112 // print_tabs(1, fd);
1113 // fprintf(fd, "*to += ltt_align(*to, size);\n");
1115 fprintf(fd
, "if(buffer != NULL)\n");
1117 fprintf(fd
, "memcpy(buffer+*to_base+*to, &obj->len, size);\n");
1119 fprintf(fd
, "*to += size;\n");
1122 /* Write the child : varlen child or not ? */
1123 if(has_type_fixed_size(((field_t
*)td
->fields
.array
[1])->type
)) {
1124 /* Fixed size len child : use a multiplication of its size */
1125 // print_tabs(1, fd);
1126 // fprintf(fd, "size = sizeof(\n");
1127 if(print_type_write(((field_t
*)td
->fields
.array
[1])->type
,
1128 fd
, 1, basename
, "array[0]", "obj->", 1)) return 1;
1129 // fprintf(fd, ");\n");
1130 // print_tabs(1, fd);
1131 fprintf(fd
, "*to += ltt_align(*to, size);\n");
1133 fprintf(fd
, "size = obj->len * size;\n");
1135 fprintf(fd
, "if(buffer != NULL)\n");
1137 fprintf(fd
, "memcpy(buffer+*to_base+*to, obj->array, size);\n");
1139 fprintf(fd
, "*to += size;\n");
1143 fprintf(fd
, "/* Variable length child : iter. */\n");
1145 fprintf(fd
, "for(unsigned int i=0; i<obj->len; i++) {\n");
1146 if(print_type_write(((field_t
*)td
->fields
.array
[1])->type
,
1147 fd
, 2, basename
, "array[i]", "obj->", 1)) return 1;
1153 fprintf(fd
, "/* Realign the *to_base on arch size, set *to to 0 */\n");
1155 fprintf(fd
, "*to = ltt_align(*to, sizeof(void *));\n");
1157 fprintf(fd
, "*to_base = *to_base+*to;\n");
1159 fprintf(fd
, "*to = 0;\n");
1162 fprintf(fd
, "/* Put source *from just after the C sequence */\n");
1164 fprintf(fd
, "*from = obj+1;\n");
1168 fprintf(fd
, "size = strlen(obj) + 1; /* Include final NULL char. */\n");
1170 fprintf(fd
, "if(buffer != NULL)\n");
1172 fprintf(fd
, "memcpy(buffer+*to_base+*to, obj, size);\n");
1174 fprintf(fd
, "*to += size;\n");
1177 fprintf(fd
, "/* Realign the *to_base on arch size, set *to to 0 */\n");
1179 fprintf(fd
, "*to = ltt_align(*to, sizeof(void *));\n");
1181 fprintf(fd
, "*to_base = *to_base+*to;\n");
1183 fprintf(fd
, "*to = 0;\n");
1186 fprintf(fd
, "/* Put source *from just after the C string */\n");
1188 fprintf(fd
, "*from += size;\n");
1191 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
1192 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
1193 type_descriptor_t
*type
= field
->type
;
1194 if(print_type_write(type
,
1195 fd
, 1, basename
, field
->name
, "obj->", 1)) return 1;
1200 printf("ERROR : A union CANNOT contain a variable size child.\n");
1204 /* Write the child : varlen child or not ? */
1205 if(has_type_fixed_size(((field_t
*)td
->fields
.array
[0])->type
)) {
1206 /* Error : if an array has a variable size, then its child must also
1207 * have a variable size. */
1211 fprintf(fd
, "/* Variable length child : iter. */\n");
1213 fprintf(fd
, "for(unsigned int i=0; i<LTTNG_ARRAY_SIZE_%s; i++) {\n", basename
);
1214 if(print_type_write(((field_t
*)td
->fields
.array
[0])->type
,
1215 fd
, 2, basename
, "", "obj->array[i]", 1)) return 1;
1221 printf("print_type_write_fct : type has no write function.\n");
1229 /* Function footer */
1237 /* Print the logging function of an event. This is the core of genevent */
1238 int print_event_logging_function(char *basename
, facility_t
*fac
,
1239 event_t
*event
, FILE *fd
)
1241 fprintf(fd
, "static inline void trace_%s(\n", basename
);
1242 int has_argument
= 0;
1243 int has_type_fixed
= 0;
1245 /* Does it support per trace tracing ? */
1246 if(event
->per_trace
) {
1248 fprintf(fd
, "struct ltt_trace_struct *dest_trace");
1252 /* Does it support per tracefile tracing ? */
1253 if(event
->per_tracefile
) {
1258 fprintf(fd
, "unsigned int tracefile_index");
1262 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
1263 /* For each field, print the function argument */
1264 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
1265 type_descriptor_t
*t
= f
->type
;
1270 if(print_arg(t
, fd
, 2, basename
, f
->name
)) return 1;
1275 fprintf(fd
, "void");
1279 "#if (!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_%s))\n",
1283 fprintf(fd
,"#else\n");
1285 /* Print the function variables */
1287 fprintf(fd
, "unsigned int index;\n");
1289 fprintf(fd
, "struct ltt_channel_struct *channel;\n");
1291 fprintf(fd
, "struct ltt_trace_struct *trace;\n");
1293 fprintf(fd
, "struct rchan_buf *relayfs_buf;\n");
1295 fprintf(fd
, "void *buffer = NULL;\n");
1297 fprintf(fd
, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
1299 fprintf(fd
, "size_t *to_base = &real_to_base;\n");
1301 fprintf(fd
, "size_t real_to = 0;\n");
1303 fprintf(fd
, "size_t *to = &real_to;\n");
1305 fprintf(fd
, "size_t real_len = 0;\n");
1307 fprintf(fd
, "size_t *len = &real_len;\n");
1309 fprintf(fd
, "size_t reserve_size;\n");
1311 fprintf(fd
, "size_t slot_size;\n");
1314 if(event
->fields
.position
> 0) {
1315 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1316 /* Search for at least one child with fixed size. It means
1317 * we need local variables.*/
1318 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1319 type_descriptor_t
*type
= field
->type
;
1320 has_type_fixed
= has_type_local(type
);
1321 if(has_type_fixed
) break;
1324 if(has_type_fixed
) {
1325 fprintf(fd
, "size_t size;\n");
1329 fprintf(fd
, "const void *real_from;\n");
1331 fprintf(fd
, "const void **from = &real_from;\n");
1334 fprintf(fd
, "cycles_t tsc;\n");
1336 fprintf(fd
, "size_t before_hdr_pad, after_hdr_pad, header_size;\n");
1340 fprintf(fd
, "if(ltt_traces.num_active_traces == 0) return;\n");
1343 /* Calculate event variable len + event data alignment offset.
1344 * Assume that the padding for alignment starts at a void*
1346 * This excludes the header size and alignment. */
1349 fprintf(fd
, "/* For each field, calculate the field size. */\n");
1351 fprintf(fd
, "/* size = *to_base + *to + *len */\n");
1353 fprintf(fd
, "/* Assume that the padding for alignment starts at a\n");
1355 fprintf(fd
, " * sizeof(void *) address. */\n");
1358 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1359 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1360 type_descriptor_t
*type
= field
->type
;
1363 switch(type
->type
) {
1369 fprintf(fd
, "*from = %s;\n", field
->name
);
1372 fprintf(fd
, "*from = &%s;\n", field
->name
);
1376 if(print_type_write(type
,
1377 fd
, 1, basename
, field
->name
, "", 0)) return 1;
1381 fprintf(fd
, "reserve_size = *to_base + *to + *len;\n");
1383 fprintf(fd
, "*to_base = *to = *len = 0;\n");
1386 /* Take locks : make sure the trace does not vanish while we write on
1387 * it. A simple preemption disabling is enough (using rcu traces). */
1389 fprintf(fd
, "preempt_disable();\n");
1391 fprintf(fd
, "ltt_nesting[smp_processor_id()]++;\n");
1393 /* Get facility index */
1395 if(event
->per_tracefile
) {
1397 fprintf(fd
, "index = tracefile_index;\n");
1401 "index = ltt_get_index_from_facility(ltt_facility_%s_%X,\n"\
1402 "\t\t\t\t\t\tevent_%s_%s);\n",
1403 fac
->name
, fac
->checksum
, fac
->name
, event
->name
);
1408 /* For each trace */
1410 fprintf(fd
, "list_for_each_entry_rcu(trace, <t_traces.head, list) {\n");
1412 fprintf(fd
, "if(!trace->active) continue;\n\n");
1414 if(event
->per_trace
) {
1416 fprintf(fd
, "if(dest_trace != trace) continue;\n\n");
1420 fprintf(fd
, "channel = ltt_get_channel_from_index(trace, index);\n");
1422 fprintf(fd
, "relayfs_buf = channel->rchan->buf[smp_processor_id()];\n");
1427 /* If error, increment event lost counter (done by ltt_reserve_slot) and
1430 fprintf(fd
, "slot_size = 0;\n");
1432 fprintf(fd
, "buffer = ltt_reserve_slot(trace, relayfs_buf,\n");
1434 fprintf(fd
, "reserve_size, &slot_size, &tsc,\n");
1436 fprintf(fd
, "&before_hdr_pad, &after_hdr_pad, &header_size);\n");
1437 /* If error, return */
1439 fprintf(fd
, "if(!buffer) return;\n\n");
1440 /* Write event header */
1442 fprintf(fd
, "ltt_write_event_header(trace, channel, buffer,\n");
1444 fprintf(fd
, "ltt_facility_%s_%X, event_%s_%s,\n", fac
->name
, fac
->checksum
,
1445 fac
->name
, event
->name
);
1447 fprintf(fd
, "reserve_size, before_hdr_pad, tsc);\n");
1449 fprintf(fd
, "*to_base += before_hdr_pad + after_hdr_pad + header_size;\n");
1451 /* write data : assume stack alignment is the same as struct alignment. */
1453 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1454 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1455 type_descriptor_t
*type
= field
->type
;
1459 switch(type
->type
) {
1465 fprintf(fd
, "*from = %s;\n", field
->name
);
1468 fprintf(fd
, "*from = &%s;\n", field
->name
);
1473 if(print_type_write(type
,
1474 fd
, 2, basename
, field
->name
, "", 0)) return 1;
1477 /* Don't forget to flush pending memcpy */
1479 fprintf(fd
, "/* Flush pending memcpy */\n");
1481 fprintf(fd
, "if(len != 0) {\n");
1483 fprintf(fd
, "memcpy(buffer+*to_base+*to, *from, *len);\n");
1485 fprintf(fd
, "*to += *len;\n");
1486 //print_tabs(3, fd);
1487 //fprintf(fd, "from += len;\n");
1489 fprintf(fd
, "*len = 0;\n");
1498 fprintf(fd
, "ltt_commit_slot(relayfs_buf, buffer, slot_size);\n\n");
1501 fprintf(fd
, "}\n\n");
1505 fprintf(fd
, "ltt_nesting[smp_processor_id()]--;\n");
1507 fprintf(fd
, "preempt_enable_no_resched();\n");
1510 fprintf(fd
, "#endif //(!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_%s))\n\n",
1516 /* ltt-facility-name.h : main logging header.
1519 void print_log_header_head(facility_t
*fac
, FILE *fd
)
1521 fprintf(fd
, "#ifndef _LTT_FACILITY_%s_H_\n", fac
->capname
);
1522 fprintf(fd
, "#define _LTT_FACILITY_%s_H_\n\n", fac
->capname
);
1523 fprintf(fd
, "#include <linux/types.h>\n");
1524 fprintf(fd
, "#include <linux/ltt/ltt-facility-id-%s.h>\n", fac
->name
);
1525 fprintf(fd
, "#include <linux/ltt-core.h>\n");
1531 int print_log_header_types(facility_t
*fac
, FILE *fd
)
1533 sequence_t
*types
= &fac
->named_types
.values
;
1534 fprintf(fd
, "/* Named types */\n");
1537 for(unsigned int i
= 0; i
< types
->position
; i
++) {
1538 /* For each named type, print the definition */
1539 if(print_type_declaration(types
->array
[i
], fd
,
1540 0, "", "")) return 1;
1541 /* Print also the align function */
1542 if(print_type_alignment_fct(types
->array
[i
], fd
,
1543 0, "", "")) return 1;
1544 /* Print also the write function */
1545 if(print_type_write_fct(types
->array
[i
], fd
,
1546 0, "", "")) return 1;
1551 int print_log_header_events(facility_t
*fac
, FILE *fd
)
1553 sequence_t
*events
= &fac
->events
;
1554 char basename
[PATH_MAX
];
1555 unsigned int facname_len
;
1557 strncpy(basename
, fac
->name
, PATH_MAX
);
1558 facname_len
= strlen(basename
);
1559 strncat(basename
, "_", PATH_MAX
-facname_len
);
1560 facname_len
= strlen(basename
);
1562 for(unsigned int i
= 0; i
< events
->position
; i
++) {
1563 event_t
*event
= (event_t
*)events
->array
[i
];
1564 strncpy(&basename
[facname_len
], event
->name
, PATH_MAX
-facname_len
);
1566 /* For each event, print structure, and then logging function */
1567 fprintf(fd
, "/* Event %s structures */\n",
1569 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
1570 /* For each unnamed type, print the definition */
1571 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
1572 type_descriptor_t
*t
= f
->type
;
1573 if(t
->type_name
== NULL
) {
1574 if((print_type_declaration(t
, fd
, 0, basename
, f
->name
))) return 1;
1575 /* Print also the align function */
1576 if((print_type_alignment_fct(t
, fd
, 0, basename
, f
->name
))) return 1;
1577 /* Print also the write function */
1578 if((print_type_write_fct(t
, fd
, 0, basename
, f
->name
))) return 1;
1584 fprintf(fd
, "/* Event %s logging function */\n",
1587 if(print_event_logging_function(basename
, fac
, event
, fd
)) return 1;
1596 void print_log_header_tail(facility_t
*fac
, FILE *fd
)
1598 fprintf(fd
, "#endif //_LTT_FACILITY_%s_H_\n",fac
->capname
);
1601 int print_log_header(facility_t
*fac
)
1603 char filename
[PATH_MAX
];
1604 unsigned int filename_size
= 0;
1606 dprintf("%s\n", fac
->name
);
1608 strcpy(filename
, "ltt-facility-");
1609 filename_size
= strlen(filename
);
1611 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1612 filename_size
= strlen(filename
);
1614 strncat(filename
, ".h", PATH_MAX
- filename_size
);
1615 filename_size
= strlen(filename
);
1618 fd
= fopen(filename
, "w");
1620 printf("Error opening file %s for writing : %s\n",
1621 filename
, strerror(errno
));
1625 /* Print file head */
1626 print_log_header_head(fac
, fd
);
1628 /* print named types in declaration order */
1629 if(print_log_header_types(fac
, fd
)) return 1;
1632 if(print_log_header_events(fac
, fd
)) return 1;
1634 /* Print file tail */
1635 print_log_header_tail(fac
, fd
);
1644 /* ltt-facility-id-name.h : facility id.
1646 int print_id_header(facility_t
*fac
)
1648 char filename
[PATH_MAX
];
1649 unsigned int filename_size
= 0;
1651 char basename
[PATH_MAX
];
1652 char basename_len
= 0;
1654 dprintf("%s\n", fac
->name
);
1656 strcpy(filename
, "ltt-facility-id-");
1657 filename_size
= strlen(filename
);
1659 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1660 filename_size
= strlen(filename
);
1662 strncat(filename
, ".h", PATH_MAX
- filename_size
);
1663 filename_size
= strlen(filename
);
1666 fd
= fopen(filename
, "w");
1668 printf("Error opening file %s for writing : %s\n",
1669 filename
, strerror(errno
));
1673 fprintf(fd
, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
1674 fprintf(fd
, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac
->capname
);
1675 fprintf(fd
, "#ifdef CONFIG_LTT\n");
1677 fprintf(fd
,"#include <linux/ltt-facilities.h>\n\n");
1679 fprintf(fd
,"/**** facility handle ****/\n\n");
1680 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s_%X;\n",
1681 fac
->name
, fac
->checksum
);
1682 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s;\n\n\n",fac
->name
);
1684 strncpy(basename
, fac
->name
, PATH_MAX
);
1685 basename_len
= strlen(basename
);
1686 strncat(basename
, "_", PATH_MAX
- basename_len
);
1689 fprintf(fd
,"/**** event index ****/\n\n");
1690 fprintf(fd
,"enum %s_event {\n",fac
->name
);
1692 for(unsigned int i
= 0; i
< fac
->events
.position
; i
++) {
1693 event_t
*event
= (event_t
*)fac
->events
.array
[i
];
1694 strncpy(basename
+basename_len
, event
->name
, PATH_MAX
-basename_len
);
1696 fprintf(fd
, "event_%s,\n", basename
);
1699 fprintf(fd
, "facility_%s_num_events\n", fac
->name
);
1700 fprintf(fd
, "};\n");
1704 fprintf(fd
, "#endif //CONFIG_LTT\n");
1705 fprintf(fd
, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
1714 /* ltt-facility-loader-name.h : facility specific loader info.
1716 int print_loader_header(facility_t
*fac
)
1718 char filename
[PATH_MAX
];
1719 unsigned int filename_size
= 0;
1721 dprintf("%s\n", fac
->name
);
1723 strcpy(filename
, "ltt-facility-loader-");
1724 filename_size
= strlen(filename
);
1726 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1727 filename_size
= strlen(filename
);
1729 strncat(filename
, ".h", PATH_MAX
- filename_size
);
1730 filename_size
= strlen(filename
);
1733 fd
= fopen(filename
, "w");
1735 printf("Error opening file %s for writing : %s\n",
1736 filename
, strerror(errno
));
1740 fprintf(fd
, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
1741 fprintf(fd
, "#define _LTT_FACILITY_LOADER_%s_H_\n\n", fac
->capname
);
1742 fprintf(fd
, "#ifdef CONFIG_LTT\n\n");
1743 fprintf(fd
,"#include <linux/ltt-facilities.h>\n");
1744 fprintf(fd
,"#include <linux/ltt/ltt-facility-id-%s.h>\n\n",
1746 fprintf(fd
,"ltt_facility_t\tltt_facility_%s;\n", fac
->name
);
1747 fprintf(fd
,"ltt_facility_t\tltt_facility_%s_%X;\n\n",
1748 fac
->name
, fac
->checksum
);
1750 fprintf(fd
,"#define LTT_FACILITY_SYMBOL\t\t\t\t\t\t\tltt_facility_%s\n",
1752 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM_SYMBOL\t\tltt_facility_%s_%X\n",
1753 fac
->name
, fac
->checksum
);
1754 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM\t\t\t\t\t\t0x%X\n", fac
->checksum
);
1755 fprintf(fd
,"#define LTT_FACILITY_NAME\t\t\t\t\t\t\t\t\"%s\"\n", fac
->name
);
1756 fprintf(fd
,"#define LTT_FACILITY_NUM_EVENTS\t\t\t\t\tfacility_%s_num_events\n\n",
1758 fprintf(fd
, "#endif //CONFIG_LTT\n\n");
1759 fprintf(fd
, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
1766 /* ltt-facility-loader-name.c : generic faciilty loader
1768 int print_loader_c(facility_t
*fac
)
1770 char filename
[PATH_MAX
];
1771 unsigned int filename_size
= 0;
1773 dprintf("%s\n", fac
->name
);
1775 strcpy(filename
, "ltt-facility-loader-");
1776 filename_size
= strlen(filename
);
1778 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1779 filename_size
= strlen(filename
);
1781 strncat(filename
, ".c", PATH_MAX
- filename_size
);
1782 filename_size
= strlen(filename
);
1785 fd
= fopen(filename
, "w");
1787 printf("Error opening file %s for writing : %s\n",
1788 filename
, strerror(errno
));
1792 fprintf(fd
, "/*\n");
1793 fprintf(fd
, " * ltt-facility-loader-%s.c\n", fac
->name
);
1794 fprintf(fd
, " *\n");
1795 fprintf(fd
, " * (C) Copyright 2005 - \n");
1796 fprintf(fd
, " * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)\n");
1797 fprintf(fd
, " *\n");
1798 fprintf(fd
, " * Contains the LTT facility loader.\n");
1799 fprintf(fd
, " *\n");
1800 fprintf(fd
, " */\n");
1803 fprintf(fd
, "#include <linux/ltt-facilities.h>\n");
1804 fprintf(fd
, "#include <linux/module.h>\n");
1805 fprintf(fd
, "#include <linux/init.h>\n");
1806 fprintf(fd
, "#include <linux/config.h>\n");
1807 fprintf(fd
, "#include \"ltt-facility-loader-%s.h\"\n", fac
->name
);
1810 fprintf(fd
, "#ifdef CONFIG_LTT\n");
1812 fprintf(fd
, "EXPORT_SYMBOL(LTT_FACILITY_SYMBOL);\n");
1813 fprintf(fd
, "EXPORT_SYMBOL(LTT_FACILITY_CHECKSUM_SYMBOL);\n");
1815 fprintf(fd
, "static const char ltt_facility_name[] = LTT_FACILITY_NAME;\n");
1817 fprintf(fd
, "#define SYMBOL_STRING(sym) #sym\n");
1819 fprintf(fd
, "static struct ltt_facility facility = {\n");
1820 fprintf(fd
, "\t.name = ltt_facility_name,\n");
1821 fprintf(fd
, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n");
1822 fprintf(fd
, "\t.checksum = LTT_FACILITY_CHECKSUM,\n");
1823 fprintf(fd
, "\t.symbol = SYMBOL_STRING(LTT_FACILITY_SYMBOL),\n");
1824 fprintf(fd
, "};\n");
1826 fprintf(fd
, "#ifndef MODULE\n");
1828 fprintf(fd
, "/* Built-in facility. */\n");
1830 fprintf(fd
, "static int __init facility_init(void)\n");
1832 fprintf(fd
, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init in kernel\\n\");\n", fac
->name
);
1834 fprintf(fd
, "\tLTT_FACILITY_SYMBOL = ltt_facility_builtin_register(&facility);\n");
1835 fprintf(fd
, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
1836 fprintf(fd
, "\t\n");
1837 fprintf(fd
, "\treturn LTT_FACILITY_SYMBOL;\n");
1839 fprintf(fd
, "__initcall(facility_init);\n");
1843 fprintf(fd
, "#else \n");
1845 fprintf(fd
, "/* Dynamic facility. */\n");
1847 fprintf(fd
, "static int __init facility_init(void)\n");
1849 fprintf(fd
, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init dynamic\\n\");\n", fac
->name
);
1851 fprintf(fd
, "\tLTT_FACILITY_SYMBOL = ltt_facility_dynamic_register(&facility);\n");
1852 fprintf(fd
, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
1854 fprintf(fd
, "\treturn LTT_FACILITY_SYMBOL;\n");
1857 fprintf(fd
, "static void __exit facility_exit(void)\n");
1859 fprintf(fd
, "\tint err;\n");
1861 fprintf(fd
, "\terr = ltt_facility_dynamic_unregister(LTT_FACILITY_SYMBOL);\n");
1862 fprintf(fd
, "\tif(err != 0)\n");
1863 fprintf(fd
, "\t\tprintk(KERN_ERR \"LTT : Error in unregistering facility.\\n\");\n");
1867 fprintf(fd
, "module_init(facility_init)\n");
1868 fprintf(fd
, "module_exit(facility_exit)\n");
1871 fprintf(fd
, "MODULE_LICENSE(\"GPL\");\n");
1872 fprintf(fd
, "MODULE_AUTHOR(\"Mathieu Desnoyers\");\n");
1873 fprintf(fd
, "MODULE_DESCRIPTION(\"Linux Trace Toolkit Facility\");\n");
1875 fprintf(fd
, "#endif //MODULE\n");
1877 fprintf(fd
, "#endif //CONFIG_LTT\n");
1887 /* code taken from ltt_facility_open in ltt/facility.c in lttv */
1889 /*****************************************************************************
1891 * ltt_facility_open : open facilities
1893 * pathname : the path name of the facility
1895 * Open the facility corresponding to the right checksum.
1897 *returns the facility on success, NULL on error.
1898 ****************************************************************************/
1899 facility_t
*ltt_facility_open(char * pathname
)
1904 facility_t
* fac
= NULL
;
1905 char buffer
[BUFFER_SIZE
];
1906 int generated
= FALSE
;
1908 in
.buffer
= &(buffer
[0]);
1910 in
.error
= error_callback
;
1914 in
.fp
= fopen(in
.name
, "r");
1921 token
= getToken(&in
);
1922 if(in
.type
== ENDFILE
) break;
1925 printf("More than one facility in the file. Only using the first one.\n");
1929 if(strcmp(token
, "<")) in
.error(&in
,"not a facility file");
1930 token
= getName(&in
);
1932 if(strcmp("facility",token
) == 0) {
1933 fac
= malloc(sizeof(facility_t
));
1935 fac
->description
= NULL
;
1936 sequence_init(&(fac
->events
));
1937 table_init(&(fac
->named_types
));
1938 sequence_init(&(fac
->unnamed_types
));
1940 parseFacility(&in
, fac
);
1942 //check if any namedType is not defined
1943 checkNamedTypesImplemented(&fac
->named_types
);
1945 generateChecksum(fac
->name
, &fac
->checksum
, &fac
->events
);
1950 printf("facility token was expected in file %s\n", in
.name
);
1961 printf("Cannot find facility %s\n", pathname
);
1968 /* Close the facility */
1969 void ltt_facility_close(facility_t
*fac
)
1973 free(fac
->description
);
1974 freeEvents(&fac
->events
);
1975 sequence_dispose(&fac
->events
);
1976 freeNamedType(&fac
->named_types
);
1977 table_dispose(&fac
->named_types
);
1978 freeTypes(&fac
->unnamed_types
);
1979 sequence_dispose(&fac
->unnamed_types
);
1985 void show_help(int argc
, char ** argv
)
1987 printf("Genevent help : \n");
1989 printf("Use %s name.xml\n", argv
[0]);
1990 printf("to create :\n");
1991 printf("ltt-facility-name.h\n");
1992 printf("ltt-facility-id-name.h\n");
1993 printf("ltt-facility-loader-name.h\n");
1994 printf("ltt-facility-loader-name.c\n");
1995 printf("In the current directory.\n");
1999 /* Parse program arguments */
2001 * 0 : continue program
2002 * -1 : stop program, return 0
2003 * > 0 : stop program, return value as exit.
2005 int check_args(int argc
, char **argv
)
2008 printf("Not enough arguments\n");
2009 show_help(argc
, argv
);
2013 if(strcmp(argv
[1], "-h") == 0) {
2014 show_help(argc
, argv
);
2021 int main(int argc
, char **argv
)
2026 err
= check_args(argc
, argv
);
2027 if(err
> 0) return err
;
2028 else if(err
< 0) return 0;
2030 /* open the facility */
2031 fac
= ltt_facility_open(argv
[1]);
2033 printf("Error opening file %s for reading : %s\n",
2034 argv
[1], strerror(errno
));
2038 /* generate the output C files */
2041 /* ltt-facility-name.h : main logging header.
2043 err
= print_log_header(fac
);
2046 /* ltt-facility-id-name.h : facility id.
2048 err
= print_id_header(fac
);
2051 /* ltt-facility-loader-name.h : facility specific loader info.
2053 err
= print_loader_header(fac
);
2056 /* ltt-facility-loader-name.c : generic faciilty loader
2058 err
= print_loader_c(fac
);
2061 /* close the facility */
2062 ltt_facility_close(fac
);
This page took 0.071904 seconds and 4 git commands to generate.