b79e4a39253f7a331cfe5f9ebea7661f4c041fea
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
)
644 char basename
[PATH_MAX
];
645 unsigned int basename_len
= 0;
647 strncpy(basename
, nest_name
, PATH_MAX
);
648 basename_len
= strlen(basename
);
650 /* For a named type, we use the type_name directly */
651 if(td
->type_name
!= NULL
) {
652 strncpy(basename
, td
->type_name
, PATH_MAX
);
653 basename_len
= strlen(basename
);
655 /* For a unnamed type, there must be a field name, except for
657 if((basename_len
!= 0)
658 && (basename
[basename_len
-1] != '_'
659 && (field_name
[0] != '\0'))) {
660 strncat(basename
, "_", PATH_MAX
- basename_len
);
661 basename_len
= strlen(basename
);
663 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
683 print_tabs(tabs
, fd
);
684 fprintf(fd
, "size = ");
685 fprintf(fd
, "sizeof(");
686 if(print_type(td
, fd
, 0, basename
, "")) return 1;
688 print_tabs(tabs
, fd
);
689 fprintf(fd
, "size += ltt_align(*to+*len, size) + size;\n");
690 print_tabs(tabs
, fd
);
691 fprintf(fd
, "*len += size;");
694 print_tabs(tabs
, fd
);
696 "lttng_write_string_%s(buffer, to_base, to, from, len, %s%s);\n",
697 basename
, obj_prefix
, field_name
);
700 print_tabs(tabs
, fd
);
702 "lttng_write_sequence_%s(buffer, to_base, to, from, len, &%s%s);",
703 basename
, obj_prefix
, field_name
);
706 print_tabs(tabs
, fd
);
708 "lttng_write_struct_%s(buffer, to_base, to, from, len, &%s%s);",
709 basename
, obj_prefix
, field_name
);
712 print_tabs(tabs
, fd
);
714 "lttng_write_union_%s(buffer, to_base, to, from, len, &%s%s);",
715 basename
, obj_prefix
, field_name
);
718 print_tabs(tabs
, fd
);
720 "lttng_write_array_%s(buffer, to_base, to, from, len, %s%s);",
721 basename
, obj_prefix
, field_name
);
724 printf("Error : type NONE unexpected\n");
734 /* print type alignment function.
736 * Copied from construct_types_and_fields in LTTV facility.c
738 * basename is the name which identifies the type (along with a prefix
741 int print_type_alignment_fct(type_descriptor_t
* td
, FILE *fd
,
743 char *nest_name
, char *field_name
)
745 char basename
[PATH_MAX
];
746 unsigned int basename_len
= 0;
748 strncpy(basename
, nest_name
, PATH_MAX
);
749 basename_len
= strlen(basename
);
751 /* For a named type, we use the type_name directly */
752 if(td
->type_name
!= NULL
) {
753 strncpy(basename
, td
->type_name
, PATH_MAX
);
754 basename_len
= strlen(basename
);
756 /* For a unnamed type, there must be a field name, except for
758 if((basename_len
!= 0)
759 && (basename
[basename_len
-1] != '_'
760 && (field_name
[0] != '\0'))) {
761 strncat(basename
, "_", PATH_MAX
- basename_len
);
762 basename_len
= strlen(basename
);
764 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
769 /* Function header */
770 fprintf(fd
, "static inline size_t lttng_get_alignment_sequence_%s(\n",
773 if(print_type(td
, fd
, 0, basename
, "")) return 1;
774 fprintf(fd
, " *obj)\n");
777 fprintf(fd
, "size_t align=0, localign;");
780 fprintf(fd
, "localign = ");
781 if(print_type_alignment(((field_t
*)td
->fields
.array
[0])->type
,
782 fd
, 0, basename
, "len", "obj->")) return 1;
785 fprintf(fd
, "align = max(align, localign);\n");
788 fprintf(fd
, "localign = ");
789 if(print_type_alignment(((field_t
*)td
->fields
.array
[1])->type
,
790 fd
, 0, basename
, "array[0]", "obj->")) return 1;
793 fprintf(fd
, "align = max(align, localign);\n");
796 fprintf(fd
, "return align;\n");
799 /* Function header */
800 fprintf(fd
, "static inline size_t lttng_get_alignment_struct_%s(\n",
803 if(print_type(td
, fd
, 0, basename
, "")) return 1;
804 fprintf(fd
, " *obj)\n");
807 fprintf(fd
, "size_t align=0, localign;");
809 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
810 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
811 type_descriptor_t
*type
= field
->type
;
813 fprintf(fd
, "localign = ");
814 if(print_type_alignment(type
, fd
, 0, basename
, field
->name
, "obj->"))
818 fprintf(fd
, "align = max(align, localign);\n");
822 fprintf(fd
, "return align;\n");
826 /* Function header */
827 fprintf(fd
, "static inline size_t lttng_get_alignment_union_%s(\n",
830 if(print_type(td
, fd
, 0, basename
, "")) return 1;
831 fprintf(fd
, " *obj)\n");
834 fprintf(fd
, "size_t align=0, localign;");
836 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
837 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
838 type_descriptor_t
*type
= field
->type
;
840 fprintf(fd
, "localign = ");
841 if(print_type_alignment(type
, fd
, 0, basename
, field
->name
, "obj->"))
845 fprintf(fd
, "align = max(align, localign);\n");
849 fprintf(fd
, "return align;\n");
853 /* Function header */
854 fprintf(fd
, "static inline size_t lttng_get_alignment_array_%s(\n",
857 if(print_type(td
, fd
, 0, basename
, "")) return 1;
858 fprintf(fd
, " obj)\n");
861 fprintf(fd
, "return \n");
862 if(print_type_alignment(((field_t
*)td
->fields
.array
[0])->type
,
863 fd
, 0, basename
, "", "obj[0]"))
868 dprintf("print_type_alignment_fct : type has no alignment function.\n");
874 /* Function footer */
881 /* print type write function.
883 * Copied from construct_types_and_fields in LTTV facility.c
885 * basename is the name which identifies the type (along with a prefix
888 int print_type_write_fct(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
889 char *nest_name
, char *field_name
)
891 char basename
[PATH_MAX
];
892 unsigned int basename_len
= 0;
894 strncpy(basename
, nest_name
, PATH_MAX
);
895 basename_len
= strlen(basename
);
897 /* For a named type, we use the type_name directly */
898 if(td
->type_name
!= NULL
) {
899 strncpy(basename
, td
->type_name
, PATH_MAX
);
900 basename_len
= strlen(basename
);
902 /* For a unnamed type, there must be a field name, except for
904 if((basename_len
!= 0)
905 && (basename
[basename_len
-1] != '_'
906 && (field_name
[0] != '\0'))) {
907 strncat(basename
, "_", PATH_MAX
- basename_len
);
908 basename_len
= strlen(basename
);
910 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
921 dprintf("print_type_write_fct : type has no write function.\n");
929 fprintf(fd
, "static inline void lttng_write_sequence_%s(\n",
933 fprintf(fd
, "static inline void lttng_write_struct_%s(\n", basename
);
936 fprintf(fd
, "static inline void lttng_write_union_%s(\n", basename
);
939 fprintf(fd
, "static inline void lttng_write_array_%s(\n", basename
);
942 fprintf(fd
, "static inline void lttng_write_string_%s(\n", basename
);
945 printf("print_type_write_fct : type has no write function.\n");
950 fprintf(fd
, "void *buffer,\n");
952 fprintf(fd
, "size_t *to_base,\n");
954 fprintf(fd
, "size_t *to,\n");
956 fprintf(fd
, "void **from,\n");
958 fprintf(fd
, "size_t *len,\n");
960 if(print_type(td
, fd
, 0, basename
, "")) return 1;
964 fprintf(fd
, " *obj)\n");
967 fprintf(fd
, " *obj)\n");
970 fprintf(fd
, " *obj)\n");
973 fprintf(fd
, " obj)\n");
976 fprintf(fd
, " obj)\n");
979 printf("print_type_write_fct : type has no write function.\n");
985 fprintf(fd
, "size_t align, size;\n");
992 fprintf(fd
, "/* Flush pending memcpy */\n");
994 fprintf(fd
, "if(*len != 0) {\n");
996 fprintf(fd
, "if(buffer != NULL)\n");
998 fprintf(fd
, "memcpy(buffer+*to_base+*to, *from, *len);\n");
1002 fprintf(fd
, "*to += *len;\n");
1004 fprintf(fd
, "*len = 0;\n");
1012 printf("print_type_write_fct : type has no write function.\n");
1017 fprintf(fd
, "align = ");
1018 if(print_type_alignment(td
, fd
, 0, basename
, "", "obj")) return 1;
1022 fprintf(fd
, "if(*len == 0) {\n");
1024 fprintf(fd
, "*to += ltt_align(*to, align); /* align output */\n");
1026 fprintf(fd
, "} else {\n");
1028 fprintf(fd
, "*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */\n");
1033 /* First, check if the type has a fixed size. If it is the case, then the size
1034 * to write is know by the compiler : simply use a sizeof() */
1035 if(has_type_fixed_size(td
)) {
1037 fprintf(fd
, "/* Contains only fixed size fields : use compiler sizeof() */\n");
1040 fprintf(fd
, "size = sizeof(");
1041 if(print_type(td
, fd
, 0, basename
, field_name
)) return 1;
1042 fprintf(fd
, ");\n");
1044 fprintf(fd
, "*len += size;\n");
1046 /* The type contains nested variable size subtypes :
1047 * we must write field by field. */
1049 fprintf(fd
, "/* Contains variable sized fields : must explode the structure */\n");
1055 fprintf(fd
, "/* Copy members */\n");
1056 // print_tabs(1, fd);
1057 // fprintf(fd, "size = sizeof(\n");
1058 if(print_type_write(((field_t
*)td
->fields
.array
[0])->type
,
1059 fd
, 1, basename
, "len", "obj->")) return 1;
1061 // fprintf(fd, ");\n");
1062 // print_tabs(1, fd);
1063 // fprintf(fd, "*to += ltt_align(*to, size);\n");
1065 fprintf(fd
, "if(buffer != NULL)\n");
1067 fprintf(fd
, "memcpy(buffer+*to_base+*to, &obj->len, size);\n");
1069 fprintf(fd
, "*to += size;\n");
1072 /* Write the child : varlen child or not ? */
1073 if(has_type_fixed_size(((field_t
*)td
->fields
.array
[1])->type
)) {
1074 /* Fixed size len child : use a multiplication of its size */
1075 // print_tabs(1, fd);
1076 // fprintf(fd, "size = sizeof(\n");
1077 if(print_type_write(((field_t
*)td
->fields
.array
[1])->type
,
1078 fd
, 1, basename
, "array[0]", "obj->")) return 1;
1079 // fprintf(fd, ");\n");
1080 // print_tabs(1, fd);
1081 fprintf(fd
, "*to += ltt_align(*to, size);\n");
1083 fprintf(fd
, "size = obj->len * size;\n");
1085 fprintf(fd
, "if(buffer != NULL)\n");
1087 fprintf(fd
, "memcpy(buffer+*to_base+*to, obj->array, size);\n");
1089 fprintf(fd
, "*to += size;\n");
1093 fprintf(fd
, "/* Variable length child : iter. */\n");
1095 fprintf(fd
, "for(unsigned int i=0; i<obj->len; i++) {\n");
1096 if(print_type_write(((field_t
*)td
->fields
.array
[1])->type
,
1097 fd
, 2, basename
, "array[i]", "obj->")) return 1;
1103 fprintf(fd
, "/* Realign the *to_base on arch size, set *to to 0 */\n");
1105 fprintf(fd
, "*to = ltt_align(*to, sizeof(void *));\n");
1107 fprintf(fd
, "*to_base = *to_base+*to;\n");
1109 fprintf(fd
, "*to = 0;\n");
1112 fprintf(fd
, "/* Put source *from just after the C sequence */\n");
1114 fprintf(fd
, "*from = obj+1;\n");
1118 fprintf(fd
, "size = strlen(obj) + 1; /* Include final NULL char. */\n");
1120 fprintf(fd
, "if(buffer != NULL)\n");
1122 fprintf(fd
, "memcpy(buffer+*to_base+*to, obj, size);\n");
1124 fprintf(fd
, "*to += size;\n");
1127 fprintf(fd
, "/* Realign the *to_base on arch size, set *to to 0 */\n");
1129 fprintf(fd
, "*to = ltt_align(*to, sizeof(void *));\n");
1131 fprintf(fd
, "*to_base = *to_base+*to;\n");
1133 fprintf(fd
, "*to = 0;\n");
1136 fprintf(fd
, "/* Put source *from just after the C string */\n");
1138 fprintf(fd
, "*from += size;\n");
1141 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
1142 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
1143 type_descriptor_t
*type
= field
->type
;
1144 if(print_type_write(type
,
1145 fd
, 1, basename
, field
->name
, "obj->")) return 1;
1150 printf("ERROR : A union CANNOT contain a variable size child.\n");
1154 /* Write the child : varlen child or not ? */
1155 if(has_type_fixed_size(((field_t
*)td
->fields
.array
[0])->type
)) {
1156 /* Error : if an array has a variable size, then its child must also
1157 * have a variable size. */
1161 fprintf(fd
, "/* Variable length child : iter. */\n");
1163 fprintf(fd
, "for(unsigned int i=0; i<LTTNG_ARRAY_SIZE_%s; i++) {\n", basename
);
1164 if(print_type_write(((field_t
*)td
->fields
.array
[0])->type
,
1165 fd
, 2, basename
, "", "obj->array[i]")) return 1;
1171 printf("print_type_write_fct : type has no write function.\n");
1179 /* Function footer */
1187 /* Print the logging function of an event. This is the core of genevent */
1188 int print_event_logging_function(char *basename
, facility_t
*fac
,
1189 event_t
*event
, FILE *fd
)
1191 fprintf(fd
, "static inline void trace_%s(\n", basename
);
1192 int has_argument
= 0;
1194 /* Does it support per trace tracing ? */
1195 if(event
->per_trace
) {
1197 fprintf(fd
, "struct ltt_trace_struct *dest_trace");
1201 /* Does it support per tracefile tracing ? */
1202 if(event
->per_tracefile
) {
1207 fprintf(fd
, "unsigned int tracefile_index");
1211 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
1212 /* For each field, print the function argument */
1213 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
1214 type_descriptor_t
*t
= f
->type
;
1219 if(print_arg(t
, fd
, 2, basename
, f
->name
)) return 1;
1224 fprintf(fd
, "void");
1228 "#if (!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_%s))\n",
1232 fprintf(fd
,"#else\n");
1234 /* Print the function variables */
1236 fprintf(fd
, "unsigned int index;\n");
1238 fprintf(fd
, "struct ltt_channel_struct *channel;\n");
1240 fprintf(fd
, "struct ltt_trace_struct *trace;\n");
1242 fprintf(fd
, "struct rchan_buf *relayfs_buf;\n");
1244 fprintf(fd
, "void *buffer = NULL;\n");
1246 fprintf(fd
, "size_t to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
1248 fprintf(fd
, "size_t to = 0;\n");
1250 fprintf(fd
, "void *from;");
1252 fprintf(fd
, "size_t len = 0;\n");
1254 fprintf(fd
, "size_t reserve_size;\n");
1256 fprintf(fd
, "size_t slot_size;\n");
1258 fprintf(fd
, "cycles_t tsc;\n");
1260 fprintf(fd
, "size_t before_hdr_pad, size_t after_hdr_pad;\n");
1264 fprintf(fd
, "if(ltt_traces.num_active_traces == 0) return;\n");
1267 /* Calculate event variable len + event data alignment offset.
1268 * Assume that the padding for alignment starts at a void*
1270 * This excludes the header size and alignment. */
1273 fprintf(fd
, "/* For each field, calculate the field size. */\n");
1275 fprintf(fd
, "/* size = to_base + to + len */\n");
1277 fprintf(fd
, "/* Assume that the padding for alignment starts at a\n");
1279 fprintf(fd
, " * sizeof(void *) address. */\n");
1282 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1283 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1284 type_descriptor_t
*type
= field
->type
;
1285 if(print_type_write(type
,
1286 fd
, 1, basename
, field
->name
, "")) return 1;
1290 fprintf(fd
, "reserve_size = to_base + to + len;\n");
1292 fprintf(fd
, "to_base = to = len = 0;\n");
1295 /* Take locks : make sure the trace does not vanish while we write on
1296 * it. A simple preemption disabling is enough (using rcu traces). */
1298 fprintf(fd
, "preempt_disable();\n");
1300 fprintf(fd
, "ltt_nesting[smp_processor_id()]++;\n");
1302 /* Get facility index */
1304 if(event
->per_tracefile
) {
1306 fprintf(fd
, "index = tracefile_index;\n");
1310 "index = ltt_get_index_from_facility(ltt_facility_%s_%X,\n"\
1311 "\t\t\t\t\t\tevent_%s);\n",
1312 fac
->name
, fac
->checksum
, event
->name
);
1317 /* For each trace */
1319 fprintf(fd
, "list_for_each_entry_rcu(trace, <t_traces.head, list) {\n");
1321 fprintf(fd
, "if(!trace->active) continue;\n\n");
1323 if(event
->per_trace
) {
1325 fprintf(fd
, "if(dest_trace != trace) continue;\n\n");
1329 fprintf(fd
, "channel = ltt_get_channel_from_index(trace, index);\n");
1331 fprintf(fd
, "relayfs_buf = channel->rchan->buf[channel->rchan->buf->cpu];\n");
1336 /* If error, increment event lost counter (done by ltt_reserve_slot) and
1339 fprintf(fd
, "slot_size = 0;\n");
1341 fprintf(fd
, "buffer = ltt_reserve_slot(trace, relayfs_buf,\n");
1343 fprintf(fd
, "reserve_size, &slot_size, &tsc,\n");
1345 fprintf(fd
, "&before_hdr_pad, &after_hdr_pad);\n");
1346 /* If error, return */
1348 fprintf(fd
, "if(!buffer) return;\n\n");
1350 /* write data : assume stack alignment is the same as struct alignment. */
1352 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1353 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1354 type_descriptor_t
*type
= field
->type
;
1358 switch(type
->type
) {
1364 fprintf(fd
, "from = %s;\n", field
->name
);
1367 fprintf(fd
, "from = &%s;\n", field
->name
);
1372 if(print_type_write(type
,
1373 fd
, 2, basename
, field
->name
, "")) return 1;
1376 /* Don't forget to flush pending memcpy */
1378 fprintf(fd
, "/* Flush pending memcpy */\n");
1380 fprintf(fd
, "if(len != 0) {\n");
1382 fprintf(fd
, "memcpy(buffer+to_base+to, from, len);\n");
1384 fprintf(fd
, "to += len;\n");
1385 //print_tabs(3, fd);
1386 //fprintf(fd, "from += len;\n");
1388 fprintf(fd
, "len = 0;\n");
1397 fprintf(fd
, "ltt_commit_slot(relayfs_buf, buffer, slot_size);\n\n");
1400 fprintf(fd
, "}\n\n");
1404 fprintf(fd
, "ltt_nesting[smp_processor_id()]--;\n");
1406 fprintf(fd
, "preempt_enable_no_resched();\n");
1409 fprintf(fd
, "#endif //(!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_%s))\n\n",
1415 /* ltt-facility-name.h : main logging header.
1418 void print_log_header_head(facility_t
*fac
, FILE *fd
)
1420 fprintf(fd
, "#ifndef _LTT_FACILITY_%s_H_\n", fac
->capname
);
1421 fprintf(fd
, "#define _LTT_FACILITY_%s_H_\n\n", fac
->capname
);
1422 fprintf(fd
, "#include <linux/types.h>\n");
1423 fprintf(fd
, "#include <linux/ltt/ltt-facility-id-%s.h>\n", fac
->name
);
1424 fprintf(fd
, "#include <linux/ltt-core.h>\n");
1430 int print_log_header_types(facility_t
*fac
, FILE *fd
)
1432 sequence_t
*types
= &fac
->named_types
.values
;
1433 fprintf(fd
, "/* Named types */\n");
1436 for(unsigned int i
= 0; i
< types
->position
; i
++) {
1437 /* For each named type, print the definition */
1438 if((print_type_declaration(types
->array
[i
], fd
,
1439 0, "", ""))) return 1;
1440 /* Print also the align function */
1441 if((print_type_alignment_fct(types
->array
[i
], fd
,
1442 0, "", ""))) return 1;
1443 /* Print also the write function */
1444 if((print_type_write_fct(types
->array
[i
], fd
,
1445 0, "", ""))) return 1;
1450 int print_log_header_events(facility_t
*fac
, FILE *fd
)
1452 sequence_t
*events
= &fac
->events
;
1453 char basename
[PATH_MAX
];
1454 unsigned int facname_len
;
1456 strncpy(basename
, fac
->name
, PATH_MAX
);
1457 facname_len
= strlen(basename
);
1458 strncat(basename
, "_", PATH_MAX
-facname_len
);
1459 facname_len
= strlen(basename
);
1461 for(unsigned int i
= 0; i
< events
->position
; i
++) {
1462 event_t
*event
= (event_t
*)events
->array
[i
];
1463 strncpy(&basename
[facname_len
], event
->name
, PATH_MAX
-facname_len
);
1465 /* For each event, print structure, and then logging function */
1466 fprintf(fd
, "/* Event %s structures */\n",
1468 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
1469 /* For each unnamed type, print the definition */
1470 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
1471 type_descriptor_t
*t
= f
->type
;
1472 if(t
->type_name
== NULL
) {
1473 if((print_type_declaration(t
, fd
, 0, basename
, f
->name
))) return 1;
1474 /* Print also the align function */
1475 if((print_type_alignment_fct(t
, fd
, 0, basename
, f
->name
))) return 1;
1476 /* Print also the write function */
1477 if((print_type_write_fct(t
, fd
, 0, basename
, f
->name
))) return 1;
1483 fprintf(fd
, "/* Event %s logging function */\n",
1486 if(print_event_logging_function(basename
, fac
, event
, fd
)) return 1;
1495 void print_log_header_tail(facility_t
*fac
, FILE *fd
)
1497 fprintf(fd
, "#endif //_LTT_FACILITY_%s_H_\n",fac
->capname
);
1500 int print_log_header(facility_t
*fac
)
1502 char filename
[PATH_MAX
];
1503 unsigned int filename_size
= 0;
1505 dprintf("%s\n", fac
->name
);
1507 strcpy(filename
, "ltt-facility-");
1508 filename_size
= strlen(filename
);
1510 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1511 filename_size
= strlen(filename
);
1513 strncat(filename
, ".h", PATH_MAX
- filename_size
);
1514 filename_size
= strlen(filename
);
1517 fd
= fopen(filename
, "w");
1519 printf("Error opening file %s for writing : %s\n",
1520 filename
, strerror(errno
));
1524 /* Print file head */
1525 print_log_header_head(fac
, fd
);
1527 /* print named types in declaration order */
1528 if(print_log_header_types(fac
, fd
)) return 1;
1531 if(print_log_header_events(fac
, fd
)) return 1;
1533 /* Print file tail */
1534 print_log_header_tail(fac
, fd
);
1543 /* ltt-facility-id-name.h : facility id.
1545 int print_id_header(facility_t
*fac
)
1547 char filename
[PATH_MAX
];
1548 unsigned int filename_size
= 0;
1550 char basename
[PATH_MAX
];
1551 char basename_len
= 0;
1553 dprintf("%s\n", fac
->name
);
1555 strcpy(filename
, "ltt-facility-id-");
1556 filename_size
= strlen(filename
);
1558 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1559 filename_size
= strlen(filename
);
1561 strncat(filename
, ".h", PATH_MAX
- filename_size
);
1562 filename_size
= strlen(filename
);
1565 fd
= fopen(filename
, "w");
1567 printf("Error opening file %s for writing : %s\n",
1568 filename
, strerror(errno
));
1572 fprintf(fd
, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
1573 fprintf(fd
, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac
->capname
);
1574 fprintf(fd
, "#ifdef CONFIG_LTT\n");
1576 fprintf(fd
,"#include <linux/ltt-facilities.h>\n\n");
1578 fprintf(fd
,"/**** facility handle ****/\n\n");
1579 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s_%X;\n",
1580 fac
->name
, fac
->checksum
);
1581 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s;\n\n\n",fac
->name
);
1583 strncpy(basename
, fac
->name
, PATH_MAX
);
1584 basename_len
= strlen(basename
);
1585 strncat(basename
, "_", PATH_MAX
- basename_len
);
1588 fprintf(fd
,"/**** event index ****/\n\n");
1589 fprintf(fd
,"enum %s_event {\n",fac
->name
);
1591 for(unsigned int i
= 0; i
< fac
->events
.position
; i
++) {
1592 event_t
*event
= (event_t
*)fac
->events
.array
[i
];
1593 strncpy(basename
+basename_len
, event
->name
, PATH_MAX
-basename_len
);
1595 fprintf(fd
, "event_%s,\n", basename
);
1598 fprintf(fd
, "facility_%s_num_events\n", fac
->name
);
1599 fprintf(fd
, "};\n");
1603 fprintf(fd
, "#endif //CONFIG_LTT\n");
1604 fprintf(fd
, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
1613 /* ltt-facility-loader-name.h : facility specific loader info.
1615 int print_loader_header(facility_t
*fac
)
1617 char filename
[PATH_MAX
];
1618 unsigned int filename_size
= 0;
1620 dprintf("%s\n", fac
->name
);
1622 strcpy(filename
, "ltt-facility-loader-");
1623 filename_size
= strlen(filename
);
1625 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1626 filename_size
= strlen(filename
);
1628 strncat(filename
, ".h", PATH_MAX
- filename_size
);
1629 filename_size
= strlen(filename
);
1632 fd
= fopen(filename
, "w");
1634 printf("Error opening file %s for writing : %s\n",
1635 filename
, strerror(errno
));
1639 fprintf(fd
, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
1640 fprintf(fd
, "#define _LTT_FACILITY_LOADER_%s_H_\n\n", fac
->capname
);
1641 fprintf(fd
, "#ifdef CONFIG_LTT\n\n");
1642 fprintf(fd
,"#include <linux/ltt-facilities.h>\n");
1643 fprintf(fd
,"#include <linux/ltt/ltt-facility-id-%s.h>\n\n",
1645 fprintf(fd
,"ltt_facility_t\tltt_facility_%s;\n", fac
->name
);
1646 fprintf(fd
,"ltt_facility_t\tltt_facility_%s_%X;\n\n",
1647 fac
->name
, fac
->checksum
);
1649 fprintf(fd
,"#define LTT_FACILITY_SYMBOL\t\t\t\t\t\t\tltt_facility_%s\n",
1651 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM_SYMBOL\t\tltt_facility_%s_%X\n",
1652 fac
->name
, fac
->checksum
);
1653 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM\t\t\t\t\t\t0x%X\n", fac
->checksum
);
1654 fprintf(fd
,"#define LTT_FACILITY_NAME\t\t\t\t\t\t\t\t\"%s\"\n", fac
->name
);
1655 fprintf(fd
,"#define LTT_FACILITY_NUM_EVENTS\t\t\t\t\tfacility_%s_num_events\n\n",
1657 fprintf(fd
, "#endif //CONFIG_LTT\n\n");
1658 fprintf(fd
, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
1665 /* ltt-facility-loader-name.c : generic faciilty loader
1667 int print_loader_c(facility_t
*fac
)
1669 char filename
[PATH_MAX
];
1670 unsigned int filename_size
= 0;
1672 dprintf("%s\n", fac
->name
);
1674 strcpy(filename
, "ltt-facility-loader-");
1675 filename_size
= strlen(filename
);
1677 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1678 filename_size
= strlen(filename
);
1680 strncat(filename
, ".c", PATH_MAX
- filename_size
);
1681 filename_size
= strlen(filename
);
1684 fd
= fopen(filename
, "w");
1686 printf("Error opening file %s for writing : %s\n",
1687 filename
, strerror(errno
));
1691 fprintf(fd
, "/*\n");
1692 fprintf(fd
, " * ltt-facility-loader-%s.c\n", fac
->name
);
1693 fprintf(fd
, " *\n");
1694 fprintf(fd
, " * (C) Copyright 2005 - \n");
1695 fprintf(fd
, " * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)\n");
1696 fprintf(fd
, " *\n");
1697 fprintf(fd
, " * Contains the LTT facility loader.\n");
1698 fprintf(fd
, " *\n");
1699 fprintf(fd
, " */\n");
1702 fprintf(fd
, "#include <linux/ltt-facilities.h>\n");
1703 fprintf(fd
, "#include <linux/module.h>\n");
1704 fprintf(fd
, "#include <linux/init.h>\n");
1705 fprintf(fd
, "#include <linux/config.h>\n");
1706 fprintf(fd
, "#include \"ltt-facility-loader-%s.h\"\n", fac
->name
);
1709 fprintf(fd
, "#ifdef CONFIG_LTT\n");
1711 fprintf(fd
, "EXPORT_SYMBOL(LTT_FACILITY_SYMBOL);\n");
1712 fprintf(fd
, "EXPORT_SYMBOL(LTT_FACILITY_CHECKSUM_SYMBOL);\n");
1714 fprintf(fd
, "static const char ltt_facility_name[] = LTT_FACILITY_NAME;\n");
1716 fprintf(fd
, "#define SYMBOL_STRING(sym) #sym\n");
1718 fprintf(fd
, "static struct ltt_facility facility = {\n");
1719 fprintf(fd
, "\t.name = ltt_facility_name,\n");
1720 fprintf(fd
, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n");
1721 fprintf(fd
, "\t.checksum = LTT_FACILITY_CHECKSUM,\n");
1722 fprintf(fd
, "\t.symbol = SYMBOL_STRING(LTT_FACILITY_SYMBOL),\n");
1723 fprintf(fd
, "};\n");
1725 fprintf(fd
, "#ifndef MODULE\n");
1727 fprintf(fd
, "/* Built-in facility. */\n");
1729 fprintf(fd
, "static int __init facility_init(void)\n");
1731 fprintf(fd
, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init in kernel\\n\");\n", fac
->name
);
1733 fprintf(fd
, "\tLTT_FACILITY_SYMBOL = ltt_facility_builtin_register(&facility);\n");
1734 fprintf(fd
, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
1735 fprintf(fd
, "\t\n");
1736 fprintf(fd
, "\treturn LTT_FACILITY_SYMBOL;\n");
1738 fprintf(fd
, "__initcall(facility_init);\n");
1742 fprintf(fd
, "#else \n");
1744 fprintf(fd
, "/* Dynamic facility. */\n");
1746 fprintf(fd
, "static int __init facility_init(void)\n");
1748 fprintf(fd
, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init dynamic\\n\");\n", fac
->name
);
1750 fprintf(fd
, "\tLTT_FACILITY_SYMBOL = ltt_facility_dynamic_register(&facility);\n");
1751 fprintf(fd
, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
1753 fprintf(fd
, "\treturn LTT_FACILITY_SYMBOL;\n");
1756 fprintf(fd
, "static void __exit facility_exit(void)\n");
1758 fprintf(fd
, "\tint err;\n");
1760 fprintf(fd
, "\terr = ltt_facility_dynamic_unregister(LTT_FACILITY_SYMBOL);\n");
1761 fprintf(fd
, "\tif(err != 0)\n");
1762 fprintf(fd
, "\t\tprintk(KERN_ERR \"LTT : Error in unregistering facility.\\n\");\n");
1766 fprintf(fd
, "module_init(facility_init)\n");
1767 fprintf(fd
, "module_exit(facility_exit)\n");
1770 fprintf(fd
, "MODULE_LICENSE(\"GPL\");\n");
1771 fprintf(fd
, "MODULE_AUTHOR(\"Mathieu Desnoyers\");\n");
1772 fprintf(fd
, "MODULE_DESCRIPTION(\"Linux Trace Toolkit Facility\");\n");
1774 fprintf(fd
, "#endif //MODULE\n");
1776 fprintf(fd
, "#endif //CONFIG_LTT\n");
1786 /* code taken from ltt_facility_open in ltt/facility.c in lttv */
1788 /*****************************************************************************
1790 * ltt_facility_open : open facilities
1792 * pathname : the path name of the facility
1794 * Open the facility corresponding to the right checksum.
1796 *returns the facility on success, NULL on error.
1797 ****************************************************************************/
1798 facility_t
*ltt_facility_open(char * pathname
)
1803 facility_t
* fac
= NULL
;
1804 char buffer
[BUFFER_SIZE
];
1805 int generated
= FALSE
;
1807 in
.buffer
= &(buffer
[0]);
1809 in
.error
= error_callback
;
1813 in
.fp
= fopen(in
.name
, "r");
1820 token
= getToken(&in
);
1821 if(in
.type
== ENDFILE
) break;
1824 printf("More than one facility in the file. Only using the first one.\n");
1828 if(strcmp(token
, "<")) in
.error(&in
,"not a facility file");
1829 token
= getName(&in
);
1831 if(strcmp("facility",token
) == 0) {
1832 fac
= malloc(sizeof(facility_t
));
1834 fac
->description
= NULL
;
1835 sequence_init(&(fac
->events
));
1836 table_init(&(fac
->named_types
));
1837 sequence_init(&(fac
->unnamed_types
));
1839 parseFacility(&in
, fac
);
1841 //check if any namedType is not defined
1842 checkNamedTypesImplemented(&fac
->named_types
);
1844 generateChecksum(fac
->name
, &fac
->checksum
, &fac
->events
);
1849 printf("facility token was expected in file %s\n", in
.name
);
1860 printf("Cannot find facility %s\n", pathname
);
1867 /* Close the facility */
1868 void ltt_facility_close(facility_t
*fac
)
1872 free(fac
->description
);
1873 freeEvents(&fac
->events
);
1874 sequence_dispose(&fac
->events
);
1875 freeNamedType(&fac
->named_types
);
1876 table_dispose(&fac
->named_types
);
1877 freeTypes(&fac
->unnamed_types
);
1878 sequence_dispose(&fac
->unnamed_types
);
1884 void show_help(int argc
, char ** argv
)
1886 printf("Genevent help : \n");
1888 printf("Use %s name.xml\n", argv
[0]);
1889 printf("to create :\n");
1890 printf("ltt-facility-name.h\n");
1891 printf("ltt-facility-id-name.h\n");
1892 printf("ltt-facility-loader-name.h\n");
1893 printf("ltt-facility-loader-name.c\n");
1894 printf("In the current directory.\n");
1898 /* Parse program arguments */
1900 * 0 : continue program
1901 * -1 : stop program, return 0
1902 * > 0 : stop program, return value as exit.
1904 int check_args(int argc
, char **argv
)
1907 printf("Not enough arguments\n");
1908 show_help(argc
, argv
);
1912 if(strcmp(argv
[1], "-h") == 0) {
1913 show_help(argc
, argv
);
1920 int main(int argc
, char **argv
)
1925 err
= check_args(argc
, argv
);
1926 if(err
> 0) return err
;
1927 else if(err
< 0) return 0;
1929 /* open the facility */
1930 fac
= ltt_facility_open(argv
[1]);
1932 printf("Error opening file %s for reading : %s\n",
1933 argv
[1], strerror(errno
));
1937 /* generate the output C files */
1940 /* ltt-facility-name.h : main logging header.
1942 err
= print_log_header(fac
);
1945 /* ltt-facility-id-name.h : facility id.
1947 err
= print_id_header(fac
);
1950 /* ltt-facility-loader-name.h : facility specific loader info.
1952 err
= print_loader_header(fac
);
1955 /* ltt-facility-loader-name.c : generic faciilty loader
1957 err
= print_loader_c(fac
);
1960 /* close the facility */
1961 ltt_facility_close(fac
);
This page took 0.072071 seconds and 4 git commands to generate.