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");
739 /* print type alignment function.
741 * Copied from construct_types_and_fields in LTTV facility.c
743 * basename is the name which identifies the type (along with a prefix
746 int print_type_alignment_fct(type_descriptor_t
* td
, FILE *fd
,
748 char *nest_name
, char *field_name
)
750 char basename
[PATH_MAX
];
751 unsigned int basename_len
= 0;
753 strncpy(basename
, nest_name
, PATH_MAX
);
754 basename_len
= strlen(basename
);
756 /* For a named type, we use the type_name directly */
757 if(td
->type_name
!= NULL
) {
758 strncpy(basename
, td
->type_name
, PATH_MAX
);
759 basename_len
= strlen(basename
);
761 /* For a unnamed type, there must be a field name, except for
763 if((basename_len
!= 0)
764 && (basename
[basename_len
-1] != '_'
765 && (field_name
[0] != '\0'))) {
766 strncat(basename
, "_", PATH_MAX
- basename_len
);
767 basename_len
= strlen(basename
);
769 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
774 /* Function header */
775 fprintf(fd
, "static inline size_t lttng_get_alignment_sequence_%s(\n",
778 if(print_type(td
, fd
, 0, basename
, "")) return 1;
779 fprintf(fd
, " *obj)\n");
782 fprintf(fd
, "size_t align=0, localign;");
785 fprintf(fd
, "localign = ");
786 if(print_type_alignment(((field_t
*)td
->fields
.array
[0])->type
,
787 fd
, 0, basename
, "len", "obj->")) return 1;
790 fprintf(fd
, "align = max(align, localign);\n");
793 fprintf(fd
, "localign = ");
794 if(print_type_alignment(((field_t
*)td
->fields
.array
[1])->type
,
795 fd
, 0, basename
, "array[0]", "obj->")) return 1;
798 fprintf(fd
, "align = max(align, localign);\n");
801 fprintf(fd
, "return align;\n");
804 /* Function header */
805 fprintf(fd
, "static inline size_t lttng_get_alignment_struct_%s(\n",
808 if(print_type(td
, fd
, 0, basename
, "")) return 1;
809 fprintf(fd
, " *obj)\n");
812 fprintf(fd
, "size_t align=0, localign;");
814 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
815 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
816 type_descriptor_t
*type
= field
->type
;
818 fprintf(fd
, "localign = ");
819 if(print_type_alignment(type
, fd
, 0, basename
, field
->name
, "obj->"))
823 fprintf(fd
, "align = max(align, localign);\n");
827 fprintf(fd
, "return align;\n");
831 /* Function header */
832 fprintf(fd
, "static inline size_t lttng_get_alignment_union_%s(\n",
835 if(print_type(td
, fd
, 0, basename
, "")) return 1;
836 fprintf(fd
, " *obj)\n");
839 fprintf(fd
, "size_t align=0, localign;");
841 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
842 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
843 type_descriptor_t
*type
= field
->type
;
845 fprintf(fd
, "localign = ");
846 if(print_type_alignment(type
, fd
, 0, basename
, field
->name
, "obj->"))
850 fprintf(fd
, "align = max(align, localign);\n");
854 fprintf(fd
, "return align;\n");
858 /* Function header */
859 fprintf(fd
, "static inline size_t lttng_get_alignment_array_%s(\n",
862 if(print_type(td
, fd
, 0, basename
, "")) return 1;
863 fprintf(fd
, " obj)\n");
866 fprintf(fd
, "return \n");
867 if(print_type_alignment(((field_t
*)td
->fields
.array
[0])->type
,
868 fd
, 0, basename
, "", "obj[0]"))
873 dprintf("print_type_alignment_fct : type has no alignment function.\n");
879 /* Function footer */
886 /* print type write function.
888 * Copied from construct_types_and_fields in LTTV facility.c
890 * basename is the name which identifies the type (along with a prefix
893 int print_type_write_fct(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
894 char *nest_name
, char *field_name
)
896 char basename
[PATH_MAX
];
897 unsigned int basename_len
= 0;
899 strncpy(basename
, nest_name
, PATH_MAX
);
900 basename_len
= strlen(basename
);
902 /* For a named type, we use the type_name directly */
903 if(td
->type_name
!= NULL
) {
904 strncpy(basename
, td
->type_name
, PATH_MAX
);
905 basename_len
= strlen(basename
);
907 /* For a unnamed type, there must be a field name, except for
909 if((basename_len
!= 0)
910 && (basename
[basename_len
-1] != '_'
911 && (field_name
[0] != '\0'))) {
912 strncat(basename
, "_", PATH_MAX
- basename_len
);
913 basename_len
= strlen(basename
);
915 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
926 dprintf("print_type_write_fct : type has no write function.\n");
934 fprintf(fd
, "static inline void lttng_write_sequence_%s(\n",
938 fprintf(fd
, "static inline void lttng_write_struct_%s(\n", basename
);
941 fprintf(fd
, "static inline void lttng_write_union_%s(\n", basename
);
944 fprintf(fd
, "static inline void lttng_write_array_%s(\n", basename
);
947 fprintf(fd
, "static inline void lttng_write_string_%s(\n", basename
);
950 printf("print_type_write_fct : type has no write function.\n");
955 fprintf(fd
, "void *buffer,\n");
957 fprintf(fd
, "size_t *to_base,\n");
959 fprintf(fd
, "size_t *to,\n");
961 fprintf(fd
, "const void **from,\n");
963 fprintf(fd
, "size_t *len,\n");
965 if(print_type(td
, fd
, 0, basename
, "")) return 1;
969 fprintf(fd
, " *obj)\n");
972 fprintf(fd
, " *obj)\n");
975 fprintf(fd
, " *obj)\n");
978 fprintf(fd
, " obj)\n");
981 fprintf(fd
, " obj)\n");
984 printf("print_type_write_fct : type has no write function.\n");
990 fprintf(fd
, "size_t align, size;\n");
997 fprintf(fd
, "/* Flush pending memcpy */\n");
999 fprintf(fd
, "if(*len != 0) {\n");
1001 fprintf(fd
, "if(buffer != NULL)\n");
1003 fprintf(fd
, "memcpy(buffer+*to_base+*to, *from, *len);\n");
1007 fprintf(fd
, "*to += *len;\n");
1009 fprintf(fd
, "*len = 0;\n");
1017 printf("print_type_write_fct : type has no write function.\n");
1022 fprintf(fd
, "align = ");
1023 if(print_type_alignment(td
, fd
, 0, basename
, "", "obj")) return 1;
1027 fprintf(fd
, "if(*len == 0) {\n");
1029 fprintf(fd
, "*to += ltt_align(*to, align); /* align output */\n");
1031 fprintf(fd
, "} else {\n");
1033 fprintf(fd
, "*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */\n");
1038 /* First, check if the type has a fixed size. If it is the case, then the size
1039 * to write is know by the compiler : simply use a sizeof() */
1040 if(has_type_fixed_size(td
)) {
1042 fprintf(fd
, "/* Contains only fixed size fields : use compiler sizeof() */\n");
1045 fprintf(fd
, "size = sizeof(");
1046 if(print_type(td
, fd
, 0, basename
, field_name
)) return 1;
1047 fprintf(fd
, ");\n");
1049 fprintf(fd
, "*len += size;\n");
1051 /* The type contains nested variable size subtypes :
1052 * we must write field by field. */
1054 fprintf(fd
, "/* Contains variable sized fields : must explode the structure */\n");
1060 fprintf(fd
, "/* Copy members */\n");
1061 // print_tabs(1, fd);
1062 // fprintf(fd, "size = sizeof(\n");
1063 if(print_type_write(((field_t
*)td
->fields
.array
[0])->type
,
1064 fd
, 1, basename
, "len", "obj->", 1)) return 1;
1066 // fprintf(fd, ");\n");
1067 // print_tabs(1, fd);
1068 // fprintf(fd, "*to += ltt_align(*to, size);\n");
1070 fprintf(fd
, "if(buffer != NULL)\n");
1072 fprintf(fd
, "memcpy(buffer+*to_base+*to, &obj->len, size);\n");
1074 fprintf(fd
, "*to += size;\n");
1077 /* Write the child : varlen child or not ? */
1078 if(has_type_fixed_size(((field_t
*)td
->fields
.array
[1])->type
)) {
1079 /* Fixed size len child : use a multiplication of its size */
1080 // print_tabs(1, fd);
1081 // fprintf(fd, "size = sizeof(\n");
1082 if(print_type_write(((field_t
*)td
->fields
.array
[1])->type
,
1083 fd
, 1, basename
, "array[0]", "obj->", 1)) return 1;
1084 // fprintf(fd, ");\n");
1085 // print_tabs(1, fd);
1086 fprintf(fd
, "*to += ltt_align(*to, size);\n");
1088 fprintf(fd
, "size = obj->len * size;\n");
1090 fprintf(fd
, "if(buffer != NULL)\n");
1092 fprintf(fd
, "memcpy(buffer+*to_base+*to, obj->array, size);\n");
1094 fprintf(fd
, "*to += size;\n");
1098 fprintf(fd
, "/* Variable length child : iter. */\n");
1100 fprintf(fd
, "for(unsigned int i=0; i<obj->len; i++) {\n");
1101 if(print_type_write(((field_t
*)td
->fields
.array
[1])->type
,
1102 fd
, 2, basename
, "array[i]", "obj->", 1)) return 1;
1108 fprintf(fd
, "/* Realign the *to_base on arch size, set *to to 0 */\n");
1110 fprintf(fd
, "*to = ltt_align(*to, sizeof(void *));\n");
1112 fprintf(fd
, "*to_base = *to_base+*to;\n");
1114 fprintf(fd
, "*to = 0;\n");
1117 fprintf(fd
, "/* Put source *from just after the C sequence */\n");
1119 fprintf(fd
, "*from = obj+1;\n");
1123 fprintf(fd
, "size = strlen(obj) + 1; /* Include final NULL char. */\n");
1125 fprintf(fd
, "if(buffer != NULL)\n");
1127 fprintf(fd
, "memcpy(buffer+*to_base+*to, obj, size);\n");
1129 fprintf(fd
, "*to += size;\n");
1132 fprintf(fd
, "/* Realign the *to_base on arch size, set *to to 0 */\n");
1134 fprintf(fd
, "*to = ltt_align(*to, sizeof(void *));\n");
1136 fprintf(fd
, "*to_base = *to_base+*to;\n");
1138 fprintf(fd
, "*to = 0;\n");
1141 fprintf(fd
, "/* Put source *from just after the C string */\n");
1143 fprintf(fd
, "*from += size;\n");
1146 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
1147 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
1148 type_descriptor_t
*type
= field
->type
;
1149 if(print_type_write(type
,
1150 fd
, 1, basename
, field
->name
, "obj->", 1)) return 1;
1155 printf("ERROR : A union CANNOT contain a variable size child.\n");
1159 /* Write the child : varlen child or not ? */
1160 if(has_type_fixed_size(((field_t
*)td
->fields
.array
[0])->type
)) {
1161 /* Error : if an array has a variable size, then its child must also
1162 * have a variable size. */
1166 fprintf(fd
, "/* Variable length child : iter. */\n");
1168 fprintf(fd
, "for(unsigned int i=0; i<LTTNG_ARRAY_SIZE_%s; i++) {\n", basename
);
1169 if(print_type_write(((field_t
*)td
->fields
.array
[0])->type
,
1170 fd
, 2, basename
, "", "obj->array[i]", 1)) return 1;
1176 printf("print_type_write_fct : type has no write function.\n");
1184 /* Function footer */
1192 /* Print the logging function of an event. This is the core of genevent */
1193 int print_event_logging_function(char *basename
, facility_t
*fac
,
1194 event_t
*event
, FILE *fd
)
1196 fprintf(fd
, "static inline void trace_%s(\n", basename
);
1197 int has_argument
= 0;
1199 /* Does it support per trace tracing ? */
1200 if(event
->per_trace
) {
1202 fprintf(fd
, "struct ltt_trace_struct *dest_trace");
1206 /* Does it support per tracefile tracing ? */
1207 if(event
->per_tracefile
) {
1212 fprintf(fd
, "unsigned int tracefile_index");
1216 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
1217 /* For each field, print the function argument */
1218 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
1219 type_descriptor_t
*t
= f
->type
;
1224 if(print_arg(t
, fd
, 2, basename
, f
->name
)) return 1;
1229 fprintf(fd
, "void");
1233 "#if (!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_%s))\n",
1237 fprintf(fd
,"#else\n");
1239 /* Print the function variables */
1241 fprintf(fd
, "unsigned int index;\n");
1243 fprintf(fd
, "struct ltt_channel_struct *channel;\n");
1245 fprintf(fd
, "struct ltt_trace_struct *trace;\n");
1247 fprintf(fd
, "struct rchan_buf *relayfs_buf;\n");
1249 fprintf(fd
, "void *buffer = NULL;\n");
1251 fprintf(fd
, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
1253 fprintf(fd
, "size_t *to_base = &real_to_base;\n");
1255 fprintf(fd
, "size_t real_to = 0;\n");
1257 fprintf(fd
, "size_t *to = &real_to;\n");
1259 fprintf(fd
, "size_t real_len = 0;\n");
1261 fprintf(fd
, "size_t *len = &real_len;\n");
1263 fprintf(fd
, "size_t reserve_size;\n");
1265 fprintf(fd
, "size_t slot_size;\n");
1267 if(event
->fields
.position
> 0) {
1268 fprintf(fd
, "size_t size;\n");
1270 fprintf(fd
, "const void *real_from;\n");
1272 fprintf(fd
, "const void **from = &real_from;\n");
1275 fprintf(fd
, "cycles_t tsc;\n");
1277 fprintf(fd
, "size_t before_hdr_pad, after_hdr_pad, header_size;\n");
1281 fprintf(fd
, "if(ltt_traces.num_active_traces == 0) return;\n");
1284 /* Calculate event variable len + event data alignment offset.
1285 * Assume that the padding for alignment starts at a void*
1287 * This excludes the header size and alignment. */
1290 fprintf(fd
, "/* For each field, calculate the field size. */\n");
1292 fprintf(fd
, "/* size = *to_base + *to + *len */\n");
1294 fprintf(fd
, "/* Assume that the padding for alignment starts at a\n");
1296 fprintf(fd
, " * sizeof(void *) address. */\n");
1299 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1300 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1301 type_descriptor_t
*type
= field
->type
;
1304 switch(type
->type
) {
1310 fprintf(fd
, "*from = %s;\n", field
->name
);
1313 fprintf(fd
, "*from = &%s;\n", field
->name
);
1317 if(print_type_write(type
,
1318 fd
, 1, basename
, field
->name
, "", 0)) return 1;
1322 fprintf(fd
, "reserve_size = *to_base + *to + *len;\n");
1324 fprintf(fd
, "*to_base = *to = *len = 0;\n");
1327 /* Take locks : make sure the trace does not vanish while we write on
1328 * it. A simple preemption disabling is enough (using rcu traces). */
1330 fprintf(fd
, "preempt_disable();\n");
1332 fprintf(fd
, "ltt_nesting[smp_processor_id()]++;\n");
1334 /* Get facility index */
1336 if(event
->per_tracefile
) {
1338 fprintf(fd
, "index = tracefile_index;\n");
1342 "index = ltt_get_index_from_facility(ltt_facility_%s_%X,\n"\
1343 "\t\t\t\t\t\tevent_%s_%s);\n",
1344 fac
->name
, fac
->checksum
, fac
->name
, event
->name
);
1349 /* For each trace */
1351 fprintf(fd
, "list_for_each_entry_rcu(trace, <t_traces.head, list) {\n");
1353 fprintf(fd
, "if(!trace->active) continue;\n\n");
1355 if(event
->per_trace
) {
1357 fprintf(fd
, "if(dest_trace != trace) continue;\n\n");
1361 fprintf(fd
, "channel = ltt_get_channel_from_index(trace, index);\n");
1363 fprintf(fd
, "relayfs_buf = channel->rchan->buf[smp_processor_id()];\n");
1368 /* If error, increment event lost counter (done by ltt_reserve_slot) and
1371 fprintf(fd
, "slot_size = 0;\n");
1373 fprintf(fd
, "buffer = ltt_reserve_slot(trace, relayfs_buf,\n");
1375 fprintf(fd
, "reserve_size, &slot_size, &tsc,\n");
1377 fprintf(fd
, "&before_hdr_pad, &after_hdr_pad, &header_size);\n");
1378 /* If error, return */
1380 fprintf(fd
, "if(!buffer) return;\n\n");
1381 /* Write event header */
1383 fprintf(fd
, "ltt_write_event_header(trace, channel, buffer,\n");
1385 fprintf(fd
, "ltt_facility_%s_%X, event_%s_%s,\n", fac
->name
, fac
->checksum
,
1386 fac
->name
, event
->name
);
1388 fprintf(fd
, "reserve_size, before_hdr_pad, tsc);\n");
1390 fprintf(fd
, "*to_base += before_hdr_pad + after_hdr_pad + header_size;\n");
1392 /* write data : assume stack alignment is the same as struct alignment. */
1394 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1395 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1396 type_descriptor_t
*type
= field
->type
;
1400 switch(type
->type
) {
1406 fprintf(fd
, "*from = %s;\n", field
->name
);
1409 fprintf(fd
, "*from = &%s;\n", field
->name
);
1414 if(print_type_write(type
,
1415 fd
, 2, basename
, field
->name
, "", 0)) return 1;
1418 /* Don't forget to flush pending memcpy */
1420 fprintf(fd
, "/* Flush pending memcpy */\n");
1422 fprintf(fd
, "if(len != 0) {\n");
1424 fprintf(fd
, "memcpy(buffer+*to_base+*to, *from, *len);\n");
1426 fprintf(fd
, "*to += *len;\n");
1427 //print_tabs(3, fd);
1428 //fprintf(fd, "from += len;\n");
1430 fprintf(fd
, "*len = 0;\n");
1439 fprintf(fd
, "ltt_commit_slot(relayfs_buf, buffer, slot_size);\n\n");
1442 fprintf(fd
, "}\n\n");
1446 fprintf(fd
, "ltt_nesting[smp_processor_id()]--;\n");
1448 fprintf(fd
, "preempt_enable_no_resched();\n");
1451 fprintf(fd
, "#endif //(!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_%s))\n\n",
1457 /* ltt-facility-name.h : main logging header.
1460 void print_log_header_head(facility_t
*fac
, FILE *fd
)
1462 fprintf(fd
, "#ifndef _LTT_FACILITY_%s_H_\n", fac
->capname
);
1463 fprintf(fd
, "#define _LTT_FACILITY_%s_H_\n\n", fac
->capname
);
1464 fprintf(fd
, "#include <linux/types.h>\n");
1465 fprintf(fd
, "#include <linux/ltt/ltt-facility-id-%s.h>\n", fac
->name
);
1466 fprintf(fd
, "#include <linux/ltt-core.h>\n");
1472 int print_log_header_types(facility_t
*fac
, FILE *fd
)
1474 sequence_t
*types
= &fac
->named_types
.values
;
1475 fprintf(fd
, "/* Named types */\n");
1478 for(unsigned int i
= 0; i
< types
->position
; i
++) {
1479 /* For each named type, print the definition */
1480 if(print_type_declaration(types
->array
[i
], fd
,
1481 0, "", "")) return 1;
1482 /* Print also the align function */
1483 if(print_type_alignment_fct(types
->array
[i
], fd
,
1484 0, "", "")) return 1;
1485 /* Print also the write function */
1486 if(print_type_write_fct(types
->array
[i
], fd
,
1487 0, "", "")) return 1;
1492 int print_log_header_events(facility_t
*fac
, FILE *fd
)
1494 sequence_t
*events
= &fac
->events
;
1495 char basename
[PATH_MAX
];
1496 unsigned int facname_len
;
1498 strncpy(basename
, fac
->name
, PATH_MAX
);
1499 facname_len
= strlen(basename
);
1500 strncat(basename
, "_", PATH_MAX
-facname_len
);
1501 facname_len
= strlen(basename
);
1503 for(unsigned int i
= 0; i
< events
->position
; i
++) {
1504 event_t
*event
= (event_t
*)events
->array
[i
];
1505 strncpy(&basename
[facname_len
], event
->name
, PATH_MAX
-facname_len
);
1507 /* For each event, print structure, and then logging function */
1508 fprintf(fd
, "/* Event %s structures */\n",
1510 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
1511 /* For each unnamed type, print the definition */
1512 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
1513 type_descriptor_t
*t
= f
->type
;
1514 if(t
->type_name
== NULL
) {
1515 if((print_type_declaration(t
, fd
, 0, basename
, f
->name
))) return 1;
1516 /* Print also the align function */
1517 if((print_type_alignment_fct(t
, fd
, 0, basename
, f
->name
))) return 1;
1518 /* Print also the write function */
1519 if((print_type_write_fct(t
, fd
, 0, basename
, f
->name
))) return 1;
1525 fprintf(fd
, "/* Event %s logging function */\n",
1528 if(print_event_logging_function(basename
, fac
, event
, fd
)) return 1;
1537 void print_log_header_tail(facility_t
*fac
, FILE *fd
)
1539 fprintf(fd
, "#endif //_LTT_FACILITY_%s_H_\n",fac
->capname
);
1542 int print_log_header(facility_t
*fac
)
1544 char filename
[PATH_MAX
];
1545 unsigned int filename_size
= 0;
1547 dprintf("%s\n", fac
->name
);
1549 strcpy(filename
, "ltt-facility-");
1550 filename_size
= strlen(filename
);
1552 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1553 filename_size
= strlen(filename
);
1555 strncat(filename
, ".h", PATH_MAX
- filename_size
);
1556 filename_size
= strlen(filename
);
1559 fd
= fopen(filename
, "w");
1561 printf("Error opening file %s for writing : %s\n",
1562 filename
, strerror(errno
));
1566 /* Print file head */
1567 print_log_header_head(fac
, fd
);
1569 /* print named types in declaration order */
1570 if(print_log_header_types(fac
, fd
)) return 1;
1573 if(print_log_header_events(fac
, fd
)) return 1;
1575 /* Print file tail */
1576 print_log_header_tail(fac
, fd
);
1585 /* ltt-facility-id-name.h : facility id.
1587 int print_id_header(facility_t
*fac
)
1589 char filename
[PATH_MAX
];
1590 unsigned int filename_size
= 0;
1592 char basename
[PATH_MAX
];
1593 char basename_len
= 0;
1595 dprintf("%s\n", fac
->name
);
1597 strcpy(filename
, "ltt-facility-id-");
1598 filename_size
= strlen(filename
);
1600 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1601 filename_size
= strlen(filename
);
1603 strncat(filename
, ".h", PATH_MAX
- filename_size
);
1604 filename_size
= strlen(filename
);
1607 fd
= fopen(filename
, "w");
1609 printf("Error opening file %s for writing : %s\n",
1610 filename
, strerror(errno
));
1614 fprintf(fd
, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
1615 fprintf(fd
, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac
->capname
);
1616 fprintf(fd
, "#ifdef CONFIG_LTT\n");
1618 fprintf(fd
,"#include <linux/ltt-facilities.h>\n\n");
1620 fprintf(fd
,"/**** facility handle ****/\n\n");
1621 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s_%X;\n",
1622 fac
->name
, fac
->checksum
);
1623 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s;\n\n\n",fac
->name
);
1625 strncpy(basename
, fac
->name
, PATH_MAX
);
1626 basename_len
= strlen(basename
);
1627 strncat(basename
, "_", PATH_MAX
- basename_len
);
1630 fprintf(fd
,"/**** event index ****/\n\n");
1631 fprintf(fd
,"enum %s_event {\n",fac
->name
);
1633 for(unsigned int i
= 0; i
< fac
->events
.position
; i
++) {
1634 event_t
*event
= (event_t
*)fac
->events
.array
[i
];
1635 strncpy(basename
+basename_len
, event
->name
, PATH_MAX
-basename_len
);
1637 fprintf(fd
, "event_%s,\n", basename
);
1640 fprintf(fd
, "facility_%s_num_events\n", fac
->name
);
1641 fprintf(fd
, "};\n");
1645 fprintf(fd
, "#endif //CONFIG_LTT\n");
1646 fprintf(fd
, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
1655 /* ltt-facility-loader-name.h : facility specific loader info.
1657 int print_loader_header(facility_t
*fac
)
1659 char filename
[PATH_MAX
];
1660 unsigned int filename_size
= 0;
1662 dprintf("%s\n", fac
->name
);
1664 strcpy(filename
, "ltt-facility-loader-");
1665 filename_size
= strlen(filename
);
1667 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1668 filename_size
= strlen(filename
);
1670 strncat(filename
, ".h", PATH_MAX
- filename_size
);
1671 filename_size
= strlen(filename
);
1674 fd
= fopen(filename
, "w");
1676 printf("Error opening file %s for writing : %s\n",
1677 filename
, strerror(errno
));
1681 fprintf(fd
, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
1682 fprintf(fd
, "#define _LTT_FACILITY_LOADER_%s_H_\n\n", fac
->capname
);
1683 fprintf(fd
, "#ifdef CONFIG_LTT\n\n");
1684 fprintf(fd
,"#include <linux/ltt-facilities.h>\n");
1685 fprintf(fd
,"#include <linux/ltt/ltt-facility-id-%s.h>\n\n",
1687 fprintf(fd
,"ltt_facility_t\tltt_facility_%s;\n", fac
->name
);
1688 fprintf(fd
,"ltt_facility_t\tltt_facility_%s_%X;\n\n",
1689 fac
->name
, fac
->checksum
);
1691 fprintf(fd
,"#define LTT_FACILITY_SYMBOL\t\t\t\t\t\t\tltt_facility_%s\n",
1693 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM_SYMBOL\t\tltt_facility_%s_%X\n",
1694 fac
->name
, fac
->checksum
);
1695 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM\t\t\t\t\t\t0x%X\n", fac
->checksum
);
1696 fprintf(fd
,"#define LTT_FACILITY_NAME\t\t\t\t\t\t\t\t\"%s\"\n", fac
->name
);
1697 fprintf(fd
,"#define LTT_FACILITY_NUM_EVENTS\t\t\t\t\tfacility_%s_num_events\n\n",
1699 fprintf(fd
, "#endif //CONFIG_LTT\n\n");
1700 fprintf(fd
, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
1707 /* ltt-facility-loader-name.c : generic faciilty loader
1709 int print_loader_c(facility_t
*fac
)
1711 char filename
[PATH_MAX
];
1712 unsigned int filename_size
= 0;
1714 dprintf("%s\n", fac
->name
);
1716 strcpy(filename
, "ltt-facility-loader-");
1717 filename_size
= strlen(filename
);
1719 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1720 filename_size
= strlen(filename
);
1722 strncat(filename
, ".c", PATH_MAX
- filename_size
);
1723 filename_size
= strlen(filename
);
1726 fd
= fopen(filename
, "w");
1728 printf("Error opening file %s for writing : %s\n",
1729 filename
, strerror(errno
));
1733 fprintf(fd
, "/*\n");
1734 fprintf(fd
, " * ltt-facility-loader-%s.c\n", fac
->name
);
1735 fprintf(fd
, " *\n");
1736 fprintf(fd
, " * (C) Copyright 2005 - \n");
1737 fprintf(fd
, " * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)\n");
1738 fprintf(fd
, " *\n");
1739 fprintf(fd
, " * Contains the LTT facility loader.\n");
1740 fprintf(fd
, " *\n");
1741 fprintf(fd
, " */\n");
1744 fprintf(fd
, "#include <linux/ltt-facilities.h>\n");
1745 fprintf(fd
, "#include <linux/module.h>\n");
1746 fprintf(fd
, "#include <linux/init.h>\n");
1747 fprintf(fd
, "#include <linux/config.h>\n");
1748 fprintf(fd
, "#include \"ltt-facility-loader-%s.h\"\n", fac
->name
);
1751 fprintf(fd
, "#ifdef CONFIG_LTT\n");
1753 fprintf(fd
, "EXPORT_SYMBOL(LTT_FACILITY_SYMBOL);\n");
1754 fprintf(fd
, "EXPORT_SYMBOL(LTT_FACILITY_CHECKSUM_SYMBOL);\n");
1756 fprintf(fd
, "static const char ltt_facility_name[] = LTT_FACILITY_NAME;\n");
1758 fprintf(fd
, "#define SYMBOL_STRING(sym) #sym\n");
1760 fprintf(fd
, "static struct ltt_facility facility = {\n");
1761 fprintf(fd
, "\t.name = ltt_facility_name,\n");
1762 fprintf(fd
, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n");
1763 fprintf(fd
, "\t.checksum = LTT_FACILITY_CHECKSUM,\n");
1764 fprintf(fd
, "\t.symbol = SYMBOL_STRING(LTT_FACILITY_SYMBOL),\n");
1765 fprintf(fd
, "};\n");
1767 fprintf(fd
, "#ifndef MODULE\n");
1769 fprintf(fd
, "/* Built-in facility. */\n");
1771 fprintf(fd
, "static int __init facility_init(void)\n");
1773 fprintf(fd
, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init in kernel\\n\");\n", fac
->name
);
1775 fprintf(fd
, "\tLTT_FACILITY_SYMBOL = ltt_facility_builtin_register(&facility);\n");
1776 fprintf(fd
, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
1777 fprintf(fd
, "\t\n");
1778 fprintf(fd
, "\treturn LTT_FACILITY_SYMBOL;\n");
1780 fprintf(fd
, "__initcall(facility_init);\n");
1784 fprintf(fd
, "#else \n");
1786 fprintf(fd
, "/* Dynamic facility. */\n");
1788 fprintf(fd
, "static int __init facility_init(void)\n");
1790 fprintf(fd
, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init dynamic\\n\");\n", fac
->name
);
1792 fprintf(fd
, "\tLTT_FACILITY_SYMBOL = ltt_facility_dynamic_register(&facility);\n");
1793 fprintf(fd
, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
1795 fprintf(fd
, "\treturn LTT_FACILITY_SYMBOL;\n");
1798 fprintf(fd
, "static void __exit facility_exit(void)\n");
1800 fprintf(fd
, "\tint err;\n");
1802 fprintf(fd
, "\terr = ltt_facility_dynamic_unregister(LTT_FACILITY_SYMBOL);\n");
1803 fprintf(fd
, "\tif(err != 0)\n");
1804 fprintf(fd
, "\t\tprintk(KERN_ERR \"LTT : Error in unregistering facility.\\n\");\n");
1808 fprintf(fd
, "module_init(facility_init)\n");
1809 fprintf(fd
, "module_exit(facility_exit)\n");
1812 fprintf(fd
, "MODULE_LICENSE(\"GPL\");\n");
1813 fprintf(fd
, "MODULE_AUTHOR(\"Mathieu Desnoyers\");\n");
1814 fprintf(fd
, "MODULE_DESCRIPTION(\"Linux Trace Toolkit Facility\");\n");
1816 fprintf(fd
, "#endif //MODULE\n");
1818 fprintf(fd
, "#endif //CONFIG_LTT\n");
1828 /* code taken from ltt_facility_open in ltt/facility.c in lttv */
1830 /*****************************************************************************
1832 * ltt_facility_open : open facilities
1834 * pathname : the path name of the facility
1836 * Open the facility corresponding to the right checksum.
1838 *returns the facility on success, NULL on error.
1839 ****************************************************************************/
1840 facility_t
*ltt_facility_open(char * pathname
)
1845 facility_t
* fac
= NULL
;
1846 char buffer
[BUFFER_SIZE
];
1847 int generated
= FALSE
;
1849 in
.buffer
= &(buffer
[0]);
1851 in
.error
= error_callback
;
1855 in
.fp
= fopen(in
.name
, "r");
1862 token
= getToken(&in
);
1863 if(in
.type
== ENDFILE
) break;
1866 printf("More than one facility in the file. Only using the first one.\n");
1870 if(strcmp(token
, "<")) in
.error(&in
,"not a facility file");
1871 token
= getName(&in
);
1873 if(strcmp("facility",token
) == 0) {
1874 fac
= malloc(sizeof(facility_t
));
1876 fac
->description
= NULL
;
1877 sequence_init(&(fac
->events
));
1878 table_init(&(fac
->named_types
));
1879 sequence_init(&(fac
->unnamed_types
));
1881 parseFacility(&in
, fac
);
1883 //check if any namedType is not defined
1884 checkNamedTypesImplemented(&fac
->named_types
);
1886 generateChecksum(fac
->name
, &fac
->checksum
, &fac
->events
);
1891 printf("facility token was expected in file %s\n", in
.name
);
1902 printf("Cannot find facility %s\n", pathname
);
1909 /* Close the facility */
1910 void ltt_facility_close(facility_t
*fac
)
1914 free(fac
->description
);
1915 freeEvents(&fac
->events
);
1916 sequence_dispose(&fac
->events
);
1917 freeNamedType(&fac
->named_types
);
1918 table_dispose(&fac
->named_types
);
1919 freeTypes(&fac
->unnamed_types
);
1920 sequence_dispose(&fac
->unnamed_types
);
1926 void show_help(int argc
, char ** argv
)
1928 printf("Genevent help : \n");
1930 printf("Use %s name.xml\n", argv
[0]);
1931 printf("to create :\n");
1932 printf("ltt-facility-name.h\n");
1933 printf("ltt-facility-id-name.h\n");
1934 printf("ltt-facility-loader-name.h\n");
1935 printf("ltt-facility-loader-name.c\n");
1936 printf("In the current directory.\n");
1940 /* Parse program arguments */
1942 * 0 : continue program
1943 * -1 : stop program, return 0
1944 * > 0 : stop program, return value as exit.
1946 int check_args(int argc
, char **argv
)
1949 printf("Not enough arguments\n");
1950 show_help(argc
, argv
);
1954 if(strcmp(argv
[1], "-h") == 0) {
1955 show_help(argc
, argv
);
1962 int main(int argc
, char **argv
)
1967 err
= check_args(argc
, argv
);
1968 if(err
> 0) return err
;
1969 else if(err
< 0) return 0;
1971 /* open the facility */
1972 fac
= ltt_facility_open(argv
[1]);
1974 printf("Error opening file %s for reading : %s\n",
1975 argv
[1], strerror(errno
));
1979 /* generate the output C files */
1982 /* ltt-facility-name.h : main logging header.
1984 err
= print_log_header(fac
);
1987 /* ltt-facility-id-name.h : facility id.
1989 err
= print_id_header(fac
);
1992 /* ltt-facility-loader-name.h : facility specific loader info.
1994 err
= print_loader_header(fac
);
1997 /* ltt-facility-loader-name.c : generic faciilty loader
1999 err
= print_loader_c(fac
);
2002 /* close the facility */
2003 ltt_facility_close(fac
);
This page took 0.077721 seconds and 5 git commands to generate.