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
, "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
, "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 if(print_type(((field_t
*)td
->fields
.array
[1])->type
,
457 fd
, tabs
, basename
, "")) return 1;
458 fprintf(fd
, " *array;\n");
459 fprintf(fd
, "};\n"); /* We do not LTT_ALIGN, because we never copy
460 it to the buffer directly. */
465 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
466 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
467 type_descriptor_t
*type
= field
->type
;
468 if(type
->type_name
== NULL
) {
469 /* Not a named nested type : we must print its declaration first */
470 if(print_type_declaration(type
,
471 fd
, 0, basename
, field
->name
)) return 1;
474 fprintf(fd
, "struct lttng_%s", basename
);
476 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
477 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
478 type_descriptor_t
*type
= field
->type
;
480 if(print_type(type
, fd
, tabs
, basename
, field
->name
)) return 1;
482 fprintf(fd
, "%s", field
->name
);
485 fprintf(fd
, "} LTT_ALIGN;\n");
489 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
490 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
491 type_descriptor_t
*type
= field
->type
;
492 if(type
->type_name
== NULL
) {
493 /* Not a named nested type : we must print its declaration first */
494 if(print_type_declaration(type
,
495 fd
, 0, basename
, field
->name
)) return 1;
498 fprintf(fd
, "union lttng_%s", basename
);
500 for(unsigned i
=0;i
<td
->fields
.position
;i
++){
501 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
502 type_descriptor_t
*type
= field
->type
;
504 if(print_type(type
, fd
, tabs
, basename
, field
->name
)) return 1;
506 fprintf(fd
, "%s", field
->name
);
509 fprintf(fd
, "} LTT_ALIGN;\n");
513 dprintf("print_type_declaration : unknown type or nothing to declare.\n");
521 /* print type alignment.
523 * Copied from construct_types_and_fields in LTTV facility.c
525 * basename is the name which identifies the type (along with a prefix
528 int print_type_alignment(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
529 char *nest_name
, char *field_name
, char *obj_prefix
)
531 char basename
[PATH_MAX
];
532 unsigned int basename_len
= 0;
534 strncpy(basename
, nest_name
, PATH_MAX
);
535 basename_len
= strlen(basename
);
537 /* For a named type, we use the type_name directly */
538 if(td
->type_name
!= NULL
) {
539 strncpy(basename
, td
->type_name
, PATH_MAX
);
540 basename_len
= strlen(basename
);
542 /* For a unnamed type, there must be a field name, except for
544 if((basename_len
!= 0)
545 && (basename
[basename_len
-1] != '_'
546 && field_name
!= NULL
547 && (field_name
[0] != '\0'))) {
548 strncat(basename
, "_", PATH_MAX
- basename_len
);
549 basename_len
= strlen(basename
);
551 if(field_name
!= NULL
)
552 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
555 if(field_name
[0] == '\0') {
556 /* We are in a write function : it's the obj that we must align. */
559 fprintf(fd
, "lttng_get_alignment_sequence_%s(%s)", basename
,
563 fprintf(fd
, "lttng_get_alignment_struct_%s(%s)", basename
,
567 fprintf(fd
, "lttng_get_alignment_union_%s(%s)", basename
,
571 fprintf(fd
, "lttng_get_alignment_array_%s(%s)", basename
,
575 printf("error : type unexpected\n");
598 fprintf(fd
, "sizeof(");
599 if(print_type(td
, fd
, 0, basename
, "")) return 1;
603 fprintf(fd
, "sizeof(char)");
606 fprintf(fd
, "lttng_get_alignment_sequence_%s(&%s%s)", basename
,
607 obj_prefix
, field_name
);
610 fprintf(fd
, "lttng_get_alignment_struct_%s(&%s%s)", basename
,
611 obj_prefix
, field_name
);
614 fprintf(fd
, "lttng_get_alignment_union_%s(&%s%s)", basename
,
615 obj_prefix
, field_name
);
618 fprintf(fd
, "lttng_get_alignment_array_%s(%s%s)", basename
,
619 obj_prefix
, field_name
);
622 printf("error : type NONE unexpected\n");
633 * Copied from construct_types_and_fields in LTTV facility.c
635 * basename is the name which identifies the type (along with a prefix
638 int print_type_write(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
639 char *nest_name
, char *field_name
, char *obj_prefix
)
641 char basename
[PATH_MAX
];
642 unsigned int basename_len
= 0;
644 strncpy(basename
, nest_name
, PATH_MAX
);
645 basename_len
= strlen(basename
);
647 /* For a named type, we use the type_name directly */
648 if(td
->type_name
!= NULL
) {
649 strncpy(basename
, td
->type_name
, PATH_MAX
);
650 basename_len
= strlen(basename
);
652 /* For a unnamed type, there must be a field name, except for
654 if((basename_len
!= 0)
655 && (basename
[basename_len
-1] != '_'
656 && (field_name
[0] != '\0'))) {
657 strncat(basename
, "_", PATH_MAX
- basename_len
);
658 basename_len
= strlen(basename
);
660 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
680 print_tabs(tabs
, fd
);
681 fprintf(fd
, "size = ");
682 fprintf(fd
, "sizeof(");
683 if(print_type(td
, fd
, 0, basename
, "")) return 1;
685 print_tabs(tabs
, fd
);
686 fprintf(fd
, "size += ltt_align(*to+*len, size) + size;\n");
687 print_tabs(tabs
, fd
);
688 fprintf(fd
, "*len += size;");
691 print_tabs(tabs
, fd
);
693 "lttng_write_string_%s(buffer, to_base, to, from, len, %s%s);\n",
694 basename
, obj_prefix
, field_name
);
697 print_tabs(tabs
, fd
);
699 "lttng_write_%s(buffer, to_base, to, from, len, &%s%s)",
700 basename
, obj_prefix
, field_name
);
703 print_tabs(tabs
, fd
);
705 "lttng_write_struct_%s(buffer, to_base, to, from, len, &%s%s)",
706 basename
, obj_prefix
, field_name
);
709 print_tabs(tabs
, fd
);
711 "lttng_write_union_%s(buffer, to_base, to, from, len, &%s%s)",
712 basename
, obj_prefix
, field_name
);
715 print_tabs(tabs
, fd
);
717 "lttng_write_array_%s(buffer, to_base, to, from, len, %s%s)",
718 basename
, obj_prefix
, field_name
);
721 printf("Error : type NONE unexpected\n");
731 /* print type alignment function.
733 * Copied from construct_types_and_fields in LTTV facility.c
735 * basename is the name which identifies the type (along with a prefix
738 int print_type_alignment_fct(type_descriptor_t
* td
, FILE *fd
,
740 char *nest_name
, char *field_name
)
742 char basename
[PATH_MAX
];
743 unsigned int basename_len
= 0;
745 strncpy(basename
, nest_name
, PATH_MAX
);
746 basename_len
= strlen(basename
);
748 /* For a named type, we use the type_name directly */
749 if(td
->type_name
!= NULL
) {
750 strncpy(basename
, td
->type_name
, PATH_MAX
);
751 basename_len
= strlen(basename
);
753 /* For a unnamed type, there must be a field name, except for
755 if((basename_len
!= 0)
756 && (basename
[basename_len
-1] != '_'
757 && (field_name
[0] != '\0'))) {
758 strncat(basename
, "_", PATH_MAX
- basename_len
);
759 basename_len
= strlen(basename
);
761 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
766 /* Function header */
767 fprintf(fd
, "static inline size_t lttng_get_alignment_sequence_%s(\n",
770 if(print_type(td
, fd
, 0, basename
, "")) return 1;
771 fprintf(fd
, " *obj)\n");
774 fprintf(fd
, "size_t align=0, localign;");
777 fprintf(fd
, "localign = ");
778 if(print_type_alignment(((field_t
*)td
->fields
.array
[0])->type
,
779 fd
, 0, basename
, "len", "obj->")) return 1;
782 fprintf(fd
, "align = max(align, localign);\n");
785 fprintf(fd
, "localign = ");
786 if(print_type_alignment(((field_t
*)td
->fields
.array
[1])->type
,
787 fd
, 0, basename
, "array[0]", "obj->")) return 1;
790 fprintf(fd
, "align = max(align, localign);\n");
793 fprintf(fd
, "return align;\n");
796 /* Function header */
797 fprintf(fd
, "static inline size_t lttng_get_alignment_struct_%s(\n",
800 if(print_type(td
, fd
, 0, basename
, "")) return 1;
801 fprintf(fd
, " *obj)\n");
804 fprintf(fd
, "size_t align=0, localign;");
806 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
807 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
808 type_descriptor_t
*type
= field
->type
;
810 fprintf(fd
, "localign = ");
811 if(print_type_alignment(type
, fd
, 0, basename
, field
->name
, "obj->"))
815 fprintf(fd
, "align = max(align, localign);\n");
819 fprintf(fd
, "return align;\n");
823 /* Function header */
824 fprintf(fd
, "static inline size_t lttng_get_alignment_union_%s(\n",
827 if(print_type(td
, fd
, 0, basename
, "")) return 1;
828 fprintf(fd
, " *obj)\n");
831 fprintf(fd
, "size_t align=0, localign;");
833 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
834 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
835 type_descriptor_t
*type
= field
->type
;
837 fprintf(fd
, "localign = ");
838 if(print_type_alignment(type
, fd
, 0, basename
, field
->name
, "obj->"))
842 fprintf(fd
, "align = max(align, localign);\n");
846 fprintf(fd
, "return align;\n");
850 /* Function header */
851 fprintf(fd
, "static inline size_t lttng_get_alignment_array_%s(\n",
854 if(print_type(td
, fd
, 0, basename
, "")) return 1;
855 fprintf(fd
, " obj)\n");
858 fprintf(fd
, "return \n");
859 if(print_type_alignment(((field_t
*)td
->fields
.array
[0])->type
,
860 fd
, 0, basename
, "", "obj[0]"))
865 dprintf("print_type_alignment_fct : type has no alignment function.\n");
871 /* Function footer */
878 /* print type write function.
880 * Copied from construct_types_and_fields in LTTV facility.c
882 * basename is the name which identifies the type (along with a prefix
885 int print_type_write_fct(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
886 char *nest_name
, char *field_name
)
888 char basename
[PATH_MAX
];
889 unsigned int basename_len
= 0;
891 strncpy(basename
, nest_name
, PATH_MAX
);
892 basename_len
= strlen(basename
);
894 /* For a named type, we use the type_name directly */
895 if(td
->type_name
!= NULL
) {
896 strncpy(basename
, td
->type_name
, PATH_MAX
);
897 basename_len
= strlen(basename
);
899 /* For a unnamed type, there must be a field name, except for
901 if((basename_len
!= 0)
902 && (basename
[basename_len
-1] != '_'
903 && (field_name
[0] != '\0'))) {
904 strncat(basename
, "_", PATH_MAX
- basename_len
);
905 basename_len
= strlen(basename
);
907 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
917 dprintf("print_type_write_fct : type has no write function.\n");
925 fprintf(fd
, "static inline void lttng_write_sequence_%s(\n",
929 fprintf(fd
, "static inline void lttng_write_struct_%s(\n", basename
);
932 fprintf(fd
, "static inline void lttng_write_union_%s(\n", basename
);
935 fprintf(fd
, "static inline void lttng_write_array_%s(\n", basename
);
938 printf("print_type_write_fct : type has no write function.\n");
943 fprintf(fd
, "void *buffer,\n");
945 fprintf(fd
, "size_t *to_base,\n");
947 fprintf(fd
, "size_t *to,\n");
949 fprintf(fd
, "void **from,\n");
951 fprintf(fd
, "size_t *len,\n");
953 if(print_type(td
, fd
, 0, basename
, "")) return 1;
957 fprintf(fd
, " *obj)\n");
960 fprintf(fd
, " *obj)\n");
963 fprintf(fd
, " *obj)\n");
966 fprintf(fd
, " obj)\n");
969 printf("print_type_write_fct : type has no write function.\n");
975 fprintf(fd
, "size_t align, size;\n");
982 fprintf(fd
, "/* Flush pending memcpy */\n");
984 fprintf(fd
, "if(*len != 0) {\n");
986 fprintf(fd
, "if(buffer != NULL)\n");
988 fprintf(fd
, "memcpy(buffer+*to_base+*to, *from, *len);\n");
992 fprintf(fd
, "*to += *len;\n");
994 fprintf(fd
, "*len = 0;\n");
1002 printf("print_type_write_fct : type has no write function.\n");
1007 fprintf(fd
, "align = ");
1008 if(print_type_alignment(td
, fd
, 0, basename
, "", "obj->")) return 1;
1012 fprintf(fd
, "if(*len == 0) {\n");
1014 fprintf(fd
, "*to += ltt_align(*to, align); /* align output */\n");
1016 fprintf(fd
, "} else {\n");
1018 fprintf(fd
, "*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */\n");
1023 /* First, check if the type has a fixed size. If it is the case, then the size
1024 * to write is know by the compiler : simply use a sizeof() */
1025 if(has_type_fixed_size(td
)) {
1027 fprintf(fd
, "/* Contains only fixed size fields : use compiler sizeof() */\n");
1030 fprintf(fd
, "size = sizeof(");
1031 if(print_type(td
, fd
, 0, basename
, field_name
)) return 1;
1032 fprintf(fd
, ");\n");
1034 fprintf(fd
, "*len += size;\n");
1036 /* The type contains nested variable size subtypes :
1037 * we must write field by field. */
1039 fprintf(fd
, "/* Contains variable sized fields : must explode the structure */\n");
1045 fprintf(fd
, "/* Copy members */\n");
1046 // print_tabs(1, fd);
1047 // fprintf(fd, "size = sizeof(\n");
1048 if(print_type_write(((field_t
*)td
->fields
.array
[0])->type
,
1049 fd
, 1, basename
, "len", "obj->")) return 1;
1051 // fprintf(fd, ");\n");
1052 // print_tabs(1, fd);
1053 // fprintf(fd, "*to += ltt_align(*to, size);\n");
1055 fprintf(fd
, "if(buffer != NULL)\n");
1057 fprintf(fd
, "memcpy(buffer+*to_base+*to, &obj->len, size);\n");
1059 fprintf(fd
, "*to += size;\n");
1062 /* Write the child : varlen child or not ? */
1063 if(has_type_fixed_size(((field_t
*)td
->fields
.array
[1])->type
)) {
1064 /* Fixed size len child : use a multiplication of its size */
1065 // print_tabs(1, fd);
1066 // fprintf(fd, "size = sizeof(\n");
1067 if(print_type_write(((field_t
*)td
->fields
.array
[1])->type
,
1068 fd
, 1, basename
, "array[0]", "obj->")) return 1;
1069 // fprintf(fd, ");\n");
1070 // print_tabs(1, fd);
1071 fprintf(fd
, "*to += ltt_align(*to, size);\n");
1073 fprintf(fd
, "size = obj->len * size;\n");
1075 fprintf(fd
, "if(buffer != NULL)\n");
1077 fprintf(fd
, "memcpy(buffer+*to_base+*to, obj->array, size);\n");
1079 fprintf(fd
, "*to += size;\n");
1083 fprintf(fd
, "/* Variable length child : iter. */\n");
1085 fprintf(fd
, "for(unsigned int i=0; i<obj->len; i++) {\n");
1086 if(print_type_write(((field_t
*)td
->fields
.array
[1])->type
,
1087 fd
, 2, basename
, "array[i]", "obj->")) return 1;
1093 fprintf(fd
, "/* Realign the *to_base on arch size, set *to to 0 */\n");
1095 fprintf(fd
, "*to = ltt_align(*to, sizeof(void *));\n");
1097 fprintf(fd
, "*to_base = *to_base+*to;\n");
1099 fprintf(fd
, "*to = 0;\n");
1101 fprintf(fd
, "/* Put source *from just after the C sequence */\n");
1103 fprintf(fd
, "*from = obj+1;\n");
1106 fprintf(fd
, "size = strlen(obj) + 1; /* Include final NULL char. */\n");
1108 fprintf(fd
, "if(buffer != NULL)\n");
1110 fprintf(fd
, "memcpy(buffer+*to_base+*to, obj, size);\n");
1112 fprintf(fd
, "*to += size;\n");
1115 fprintf(fd
, "/* Realign the *to_base on arch size, set *to to 0 */\n");
1117 fprintf(fd
, "*to = ltt_align(*to, sizeof(void *));\n");
1119 fprintf(fd
, "*to_base = *to_base+*to;\n");
1121 fprintf(fd
, "*to = 0;\n");
1123 fprintf(fd
, "/* Put source *from just after the C sequence */\n");
1125 fprintf(fd
, "*from = obj+1;\n");
1128 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
1129 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
1130 type_descriptor_t
*type
= field
->type
;
1131 if(print_type_write(type
,
1132 fd
, 1, basename
, field
->name
, "obj->")) return 1;
1137 printf("ERROR : A union CANNOT contain a variable size child.\n");
1141 /* Write the child : varlen child or not ? */
1142 if(has_type_fixed_size(((field_t
*)td
->fields
.array
[0])->type
)) {
1143 /* Error : if an array has a variable size, then its child must also
1144 * have a variable size. */
1148 fprintf(fd
, "/* Variable length child : iter. */\n");
1150 fprintf(fd
, "for(unsigned int i=0; i<LTTNG_ARRAY_SIZE_%s; i++) {\n", basename
);
1151 if(print_type_write(((field_t
*)td
->fields
.array
[0])->type
,
1152 fd
, 2, basename
, "", "obj->array[i]")) return 1;
1158 printf("print_type_write_fct : type has no write function.\n");
1166 /* Function footer */
1174 /* Print the logging function of an event. This is the core of genevent */
1175 int print_event_logging_function(char *basename
, facility_t
*fac
,
1176 event_t
*event
, FILE *fd
)
1178 fprintf(fd
, "static inline void trace_%s(\n", basename
);
1179 int has_argument
= 0;
1181 /* Does it support per trace tracing ? */
1182 if(event
->per_trace
) {
1184 fprintf(fd
, "struct ltt_trace_struct *dest_trace");
1188 /* Does it support per tracefile tracing ? */
1189 if(event
->per_tracefile
) {
1194 fprintf(fd
, "unsigned int tracefile_index");
1198 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
1199 /* For each field, print the function argument */
1200 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
1201 type_descriptor_t
*t
= f
->type
;
1206 if(print_arg(t
, fd
, 2, basename
, f
->name
)) return 1;
1211 fprintf(fd
, "void");
1215 "#if (!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_%s))\n",
1219 fprintf(fd
,"#else\n");
1221 /* Print the function variables */
1223 fprintf(fd
, "unsigned int index;\n");
1225 fprintf(fd
, "struct ltt_channel_struct *channel;\n");
1227 fprintf(fd
, "struct ltt_trace_struct *trace;\n");
1229 fprintf(fd
, "struct rchan_buf *relayfs_buf;\n");
1231 fprintf(fd
, "void *buffer = NULL;\n");
1233 fprintf(fd
, "size_t to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
1235 fprintf(fd
, "size_t to = 0;\n");
1237 fprintf(fd
, "void *from;");
1239 fprintf(fd
, "size_t len = 0;\n");
1241 fprintf(fd
, "size_t reserve_size;\n");
1243 fprintf(fd
, "size_t slot_size;\n");
1245 fprintf(fd
, "cycles_t tsc;\n");
1247 fprintf(fd
, "size_t before_hdr_pad, size_t after_hdr_pad;\n");
1251 fprintf(fd
, "if(ltt_traces.num_active_traces == 0) return;\n");
1254 /* Calculate event variable len + event data alignment offset.
1255 * Assume that the padding for alignment starts at a void*
1257 * This excludes the header size and alignment. */
1260 fprintf(fd
, "/* For each field, calculate the field size. */\n");
1262 fprintf(fd
, "/* size = to_base + to + len */\n");
1264 fprintf(fd
, "/* Assume that the padding for alignment starts at a\n");
1266 fprintf(fd
, " * sizeof(void *) address. */\n");
1269 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1270 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1271 type_descriptor_t
*type
= field
->type
;
1272 if(print_type_write(type
,
1273 fd
, 1, basename
, field
->name
, "")) return 1;
1277 fprintf(fd
, "reserve_size = to_base + to + len;\n");
1279 fprintf(fd
, "to_base = to = len = 0;\n");
1282 /* Take locks : make sure the trace does not vanish while we write on
1283 * it. A simple preemption disabling is enough (using rcu traces). */
1285 fprintf(fd
, "preempt_disable();\n");
1287 fprintf(fd
, "ltt_nesting[smp_processor_id()]++;\n");
1289 /* Get facility index */
1291 if(event
->per_tracefile
) {
1293 fprintf(fd
, "index = tracefile_index;\n");
1297 "index = ltt_get_index_from_facility(ltt_facility_%s_%X,\n"\
1298 "\t\t\t\t\t\tevent_%s);\n",
1299 fac
->name
, fac
->checksum
, event
->name
);
1304 /* For each trace */
1306 fprintf(fd
, "list_for_each_entry_rcu(trace, <t_traces.head, list) {\n");
1308 fprintf(fd
, "if(!trace->active) continue;\n\n");
1310 if(event
->per_trace
) {
1312 fprintf(fd
, "if(dest_trace != trace) continue;\n\n");
1316 fprintf(fd
, "channel = ltt_get_channel_from_index(trace, index);\n");
1318 fprintf(fd
, "relayfs_buf = channel->rchan->buf[channel->rchan->buf->cpu];\n");
1323 /* If error, increment event lost counter (done by ltt_reserve_slot) and
1326 fprintf(fd
, "slot_size = 0;\n");
1328 fprintf(fd
, "buffer = ltt_reserve_slot(trace, relayfs_buf,\n");
1330 fprintf(fd
, "reserve_size, &slot_size, &tsc,\n");
1332 fprintf(fd
, "&before_hdr_pad, &after_hdr_pad);\n");
1333 /* If error, return */
1335 fprintf(fd
, "if(!buffer) return;\n\n");
1337 /* write data : assume stack alignment is the same as struct alignment. */
1339 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1340 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1341 type_descriptor_t
*type
= field
->type
;
1345 switch(type
->type
) {
1351 fprintf(fd
, "from = %s;\n", field
->name
);
1354 fprintf(fd
, "from = &%s;\n", field
->name
);
1359 if(print_type_write(type
,
1360 fd
, 2, basename
, field
->name
, "")) return 1;
1363 /* Don't forget to flush pending memcpy */
1365 fprintf(fd
, "/* Flush pending memcpy */\n");
1367 fprintf(fd
, "if(len != 0) {\n");
1369 fprintf(fd
, "memcpy(buffer+to_base+to, from, len);\n");
1371 fprintf(fd
, "to += len;\n");
1372 //print_tabs(3, fd);
1373 //fprintf(fd, "from += len;\n");
1375 fprintf(fd
, "len = 0;\n");
1384 fprintf(fd
, "ltt_commit_slot(relayfs_buf, buffer, slot_size);\n\n");
1387 fprintf(fd
, "}\n\n");
1391 fprintf(fd
, "ltt_nesting[smp_processor_id()]--;\n");
1393 fprintf(fd
, "preempt_enable_no_resched();\n");
1396 fprintf(fd
, "#endif //(!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_%s))\n\n",
1402 /* ltt-facility-name.h : main logging header.
1405 void print_log_header_head(facility_t
*fac
, FILE *fd
)
1407 fprintf(fd
, "#ifndef _LTT_FACILITY_%s_H_\n", fac
->capname
);
1408 fprintf(fd
, "#define _LTT_FACILITY_%s_H_\n\n", fac
->capname
);
1409 fprintf(fd
, "#include <linux/types.h>\n");
1410 fprintf(fd
, "#include <linux/ltt/ltt-facility-id-%s.h>\n", fac
->name
);
1411 fprintf(fd
, "#include <linux/ltt-core.h>\n");
1417 int print_log_header_types(facility_t
*fac
, FILE *fd
)
1419 sequence_t
*types
= &fac
->named_types
.values
;
1420 fprintf(fd
, "/* Named types */\n");
1423 for(unsigned int i
= 0; i
< types
->position
; i
++) {
1424 /* For each named type, print the definition */
1425 if((print_type_declaration(types
->array
[i
], fd
,
1426 0, "", ""))) return 1;
1427 /* Print also the align function */
1428 if((print_type_alignment_fct(types
->array
[i
], fd
,
1429 0, "", ""))) return 1;
1430 /* Print also the write function */
1431 if((print_type_write_fct(types
->array
[i
], fd
,
1432 0, "", ""))) return 1;
1437 int print_log_header_events(facility_t
*fac
, FILE *fd
)
1439 sequence_t
*events
= &fac
->events
;
1440 char basename
[PATH_MAX
];
1441 unsigned int facname_len
;
1443 strncpy(basename
, fac
->name
, PATH_MAX
);
1444 facname_len
= strlen(basename
);
1445 strncat(basename
, "_", PATH_MAX
-facname_len
);
1446 facname_len
= strlen(basename
);
1448 for(unsigned int i
= 0; i
< events
->position
; i
++) {
1449 event_t
*event
= (event_t
*)events
->array
[i
];
1450 strncpy(&basename
[facname_len
], event
->name
, PATH_MAX
-facname_len
);
1452 /* For each event, print structure, and then logging function */
1453 fprintf(fd
, "/* Event %s structures */\n",
1455 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
1456 /* For each unnamed type, print the definition */
1457 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
1458 type_descriptor_t
*t
= f
->type
;
1459 if(t
->type_name
== NULL
) {
1460 if((print_type_declaration(t
, fd
, 0, basename
, f
->name
))) return 1;
1461 /* Print also the align function */
1462 if((print_type_alignment_fct(t
, fd
, 0, basename
, f
->name
))) return 1;
1463 /* Print also the write function */
1464 if((print_type_write_fct(t
, fd
, 0, basename
, f
->name
))) return 1;
1470 fprintf(fd
, "/* Event %s logging function */\n",
1473 if(print_event_logging_function(basename
, fac
, event
, fd
)) return 1;
1482 void print_log_header_tail(facility_t
*fac
, FILE *fd
)
1484 fprintf(fd
, "#endif //_LTT_FACILITY_%s_H_\n",fac
->capname
);
1487 int print_log_header(facility_t
*fac
)
1489 char filename
[PATH_MAX
];
1490 unsigned int filename_size
= 0;
1492 dprintf("%s\n", fac
->name
);
1494 strcpy(filename
, "ltt-facility-");
1495 filename_size
= strlen(filename
);
1497 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1498 filename_size
= strlen(filename
);
1500 strncat(filename
, ".h", PATH_MAX
- filename_size
);
1501 filename_size
= strlen(filename
);
1504 fd
= fopen(filename
, "w");
1506 printf("Error opening file %s for writing : %s\n",
1507 filename
, strerror(errno
));
1511 /* Print file head */
1512 print_log_header_head(fac
, fd
);
1514 /* print named types in declaration order */
1515 if(print_log_header_types(fac
, fd
)) return 1;
1518 if(print_log_header_events(fac
, fd
)) return 1;
1520 /* Print file tail */
1521 print_log_header_tail(fac
, fd
);
1530 /* ltt-facility-id-name.h : facility id.
1532 int print_id_header(facility_t
*fac
)
1534 char filename
[PATH_MAX
];
1535 unsigned int filename_size
= 0;
1537 char basename
[PATH_MAX
];
1538 char basename_len
= 0;
1540 dprintf("%s\n", fac
->name
);
1542 strcpy(filename
, "ltt-facility-id-");
1543 filename_size
= strlen(filename
);
1545 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1546 filename_size
= strlen(filename
);
1548 strncat(filename
, ".h", PATH_MAX
- filename_size
);
1549 filename_size
= strlen(filename
);
1552 fd
= fopen(filename
, "w");
1554 printf("Error opening file %s for writing : %s\n",
1555 filename
, strerror(errno
));
1559 fprintf(fd
, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
1560 fprintf(fd
, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac
->capname
);
1561 fprintf(fd
, "#ifdef CONFIG_LTT\n");
1563 fprintf(fd
,"#include <linux/ltt-facilities.h>\n\n");
1565 fprintf(fd
,"/**** facility handle ****/\n\n");
1566 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s_%X;\n",
1567 fac
->name
, fac
->checksum
);
1568 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s;\n\n\n",fac
->name
);
1570 strncpy(basename
, fac
->name
, PATH_MAX
);
1571 basename_len
= strlen(basename
);
1572 strncat(basename
, "_", PATH_MAX
- basename_len
);
1575 fprintf(fd
,"/**** event index ****/\n\n");
1576 fprintf(fd
,"enum %s_event {\n",fac
->name
);
1578 for(unsigned int i
= 0; i
< fac
->events
.position
; i
++) {
1579 event_t
*event
= (event_t
*)fac
->events
.array
[i
];
1580 strncpy(basename
+basename_len
, event
->name
, PATH_MAX
-basename_len
);
1582 fprintf(fd
, "event_%s,\n", basename
);
1585 fprintf(fd
, "facility_%s_num_events\n", fac
->name
);
1586 fprintf(fd
, "};\n");
1590 fprintf(fd
, "#endif //CONFIG_LTT\n");
1591 fprintf(fd
, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
1600 /* ltt-facility-loader-name.h : facility specific loader info.
1602 int print_loader_header(facility_t
*fac
)
1604 char filename
[PATH_MAX
];
1605 unsigned int filename_size
= 0;
1607 dprintf("%s\n", fac
->name
);
1609 strcpy(filename
, "ltt-facility-loader-");
1610 filename_size
= strlen(filename
);
1612 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1613 filename_size
= strlen(filename
);
1615 strncat(filename
, ".h", PATH_MAX
- filename_size
);
1616 filename_size
= strlen(filename
);
1619 fd
= fopen(filename
, "w");
1621 printf("Error opening file %s for writing : %s\n",
1622 filename
, strerror(errno
));
1626 fprintf(fd
, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
1627 fprintf(fd
, "#define _LTT_FACILITY_LOADER_%s_H_\n\n", fac
->capname
);
1628 fprintf(fd
, "#ifdef CONFIG_LTT\n\n");
1629 fprintf(fd
,"#include <linux/ltt-facilities.h>\n");
1630 fprintf(fd
,"#include <linux/ltt/ltt-facility-id-%s.h>\n\n",
1632 fprintf(fd
,"ltt_facility_t\tltt_facility_%s;\n", fac
->name
);
1633 fprintf(fd
,"ltt_facility_t\tltt_facility_%s_%X;\n\n",
1634 fac
->name
, fac
->checksum
);
1636 fprintf(fd
,"#define LTT_FACILITY_SYMBOL\t\t\t\t\t\t\tltt_facility_%s\n",
1638 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM_SYMBOL\t\tltt_facility_%s_%X\n",
1639 fac
->name
, fac
->checksum
);
1640 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM\t\t\t\t\t\t0x%X\n", fac
->checksum
);
1641 fprintf(fd
,"#define LTT_FACILITY_NAME\t\t\t\t\t\t\t\t\"%s\"\n", fac
->name
);
1642 fprintf(fd
,"#define LTT_FACILITY_NUM_EVENTS\t\t\t\t\tfacility_%s_num_events\n\n",
1644 fprintf(fd
, "#endif //CONFIG_LTT\n\n");
1645 fprintf(fd
, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
1652 /* ltt-facility-loader-name.c : generic faciilty loader
1654 int print_loader_c(facility_t
*fac
)
1656 char filename
[PATH_MAX
];
1657 unsigned int filename_size
= 0;
1659 dprintf("%s\n", fac
->name
);
1661 strcpy(filename
, "ltt-facility-loader-");
1662 filename_size
= strlen(filename
);
1664 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1665 filename_size
= strlen(filename
);
1667 strncat(filename
, ".c", PATH_MAX
- filename_size
);
1668 filename_size
= strlen(filename
);
1671 fd
= fopen(filename
, "w");
1673 printf("Error opening file %s for writing : %s\n",
1674 filename
, strerror(errno
));
1678 fprintf(fd
, "/*\n");
1679 fprintf(fd
, " * ltt-facility-loader-%s.c\n", fac
->name
);
1680 fprintf(fd
, " *\n");
1681 fprintf(fd
, " * (C) Copyright 2005 - \n");
1682 fprintf(fd
, " * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)\n");
1683 fprintf(fd
, " *\n");
1684 fprintf(fd
, " * Contains the LTT facility loader.\n");
1685 fprintf(fd
, " *\n");
1686 fprintf(fd
, " */\n");
1689 fprintf(fd
, "#include <linux/ltt-facilities.h>\n");
1690 fprintf(fd
, "#include <linux/module.h>\n");
1691 fprintf(fd
, "#include <linux/init.h>\n");
1692 fprintf(fd
, "#include <linux/config.h>\n");
1693 fprintf(fd
, "#include \"ltt-facility-loader-%s.h\"\n", fac
->name
);
1696 fprintf(fd
, "#ifdef CONFIG_LTT\n");
1698 fprintf(fd
, "EXPORT_SYMBOL(LTT_FACILITY_SYMBOL);\n");
1699 fprintf(fd
, "EXPORT_SYMBOL(LTT_FACILITY_CHECKSUM_SYMBOL);\n");
1701 fprintf(fd
, "static const char ltt_facility_name[] = LTT_FACILITY_NAME;\n");
1703 fprintf(fd
, "#define SYMBOL_STRING(sym) #sym\n");
1705 fprintf(fd
, "static struct ltt_facility facility = {\n");
1706 fprintf(fd
, "\t.name = ltt_facility_name,\n");
1707 fprintf(fd
, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n");
1708 fprintf(fd
, "\t.checksum = LTT_FACILITY_CHECKSUM,\n");
1709 fprintf(fd
, "\t.symbol = SYMBOL_STRING(LTT_FACILITY_SYMBOL),\n");
1710 fprintf(fd
, "};\n");
1712 fprintf(fd
, "#ifndef MODULE\n");
1714 fprintf(fd
, "/* Built-in facility. */\n");
1716 fprintf(fd
, "static int __init facility_init(void)\n");
1718 fprintf(fd
, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init in kernel\\n\");\n", fac
->name
);
1720 fprintf(fd
, "\tLTT_FACILITY_SYMBOL = ltt_facility_builtin_register(&facility);\n");
1721 fprintf(fd
, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
1722 fprintf(fd
, "\t\n");
1723 fprintf(fd
, "\treturn LTT_FACILITY_SYMBOL;\n");
1725 fprintf(fd
, "__initcall(facility_init);\n");
1729 fprintf(fd
, "#else \n");
1731 fprintf(fd
, "/* Dynamic facility. */\n");
1733 fprintf(fd
, "static int __init facility_init(void)\n");
1735 fprintf(fd
, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init dynamic\\n\");\n", fac
->name
);
1737 fprintf(fd
, "\tLTT_FACILITY_SYMBOL = ltt_facility_dynamic_register(&facility);\n");
1738 fprintf(fd
, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
1740 fprintf(fd
, "\treturn LTT_FACILITY_SYMBOL;\n");
1743 fprintf(fd
, "static void __exit facility_exit(void)\n");
1745 fprintf(fd
, "\tint err;\n");
1747 fprintf(fd
, "\terr = ltt_facility_dynamic_unregister(LTT_FACILITY_SYMBOL);\n");
1748 fprintf(fd
, "\tif(err != 0)\n");
1749 fprintf(fd
, "\t\tprintk(KERN_ERR \"LTT : Error in unregistering facility.\\n\");\n");
1753 fprintf(fd
, "module_init(facility_init)\n");
1754 fprintf(fd
, "module_exit(facility_exit)\n");
1757 fprintf(fd
, "MODULE_LICENSE(\"GPL\");\n");
1758 fprintf(fd
, "MODULE_AUTHOR(\"Mathieu Desnoyers\");\n");
1759 fprintf(fd
, "MODULE_DESCRIPTION(\"Linux Trace Toolkit Facility\");\n");
1761 fprintf(fd
, "#endif //MODULE\n");
1763 fprintf(fd
, "#endif //CONFIG_LTT\n");
1773 /* code taken from ltt_facility_open in ltt/facility.c in lttv */
1775 /*****************************************************************************
1777 * ltt_facility_open : open facilities
1779 * pathname : the path name of the facility
1781 * Open the facility corresponding to the right checksum.
1783 *returns the facility on success, NULL on error.
1784 ****************************************************************************/
1785 facility_t
*ltt_facility_open(char * pathname
)
1790 facility_t
* fac
= NULL
;
1791 char buffer
[BUFFER_SIZE
];
1792 int generated
= FALSE
;
1794 in
.buffer
= &(buffer
[0]);
1796 in
.error
= error_callback
;
1800 in
.fp
= fopen(in
.name
, "r");
1807 token
= getToken(&in
);
1808 if(in
.type
== ENDFILE
) break;
1811 printf("More than one facility in the file. Only using the first one.\n");
1815 if(strcmp(token
, "<")) in
.error(&in
,"not a facility file");
1816 token
= getName(&in
);
1818 if(strcmp("facility",token
) == 0) {
1819 fac
= malloc(sizeof(facility_t
));
1821 fac
->description
= NULL
;
1822 sequence_init(&(fac
->events
));
1823 table_init(&(fac
->named_types
));
1824 sequence_init(&(fac
->unnamed_types
));
1826 parseFacility(&in
, fac
);
1828 //check if any namedType is not defined
1829 checkNamedTypesImplemented(&fac
->named_types
);
1831 generateChecksum(fac
->name
, &fac
->checksum
, &fac
->events
);
1836 printf("facility token was expected in file %s\n", in
.name
);
1847 printf("Cannot find facility %s\n", pathname
);
1854 /* Close the facility */
1855 void ltt_facility_close(facility_t
*fac
)
1859 free(fac
->description
);
1860 freeEvents(&fac
->events
);
1861 sequence_dispose(&fac
->events
);
1862 freeNamedType(&fac
->named_types
);
1863 table_dispose(&fac
->named_types
);
1864 freeTypes(&fac
->unnamed_types
);
1865 sequence_dispose(&fac
->unnamed_types
);
1871 void show_help(int argc
, char ** argv
)
1873 printf("Genevent help : \n");
1875 printf("Use %s name.xml\n", argv
[0]);
1876 printf("to create :\n");
1877 printf("ltt-facility-name.h\n");
1878 printf("ltt-facility-id-name.h\n");
1879 printf("ltt-facility-loader-name.h\n");
1880 printf("ltt-facility-loader-name.c\n");
1881 printf("In the current directory.\n");
1885 /* Parse program arguments */
1887 * 0 : continue program
1888 * -1 : stop program, return 0
1889 * > 0 : stop program, return value as exit.
1891 int check_args(int argc
, char **argv
)
1894 printf("Not enough arguments\n");
1895 show_help(argc
, argv
);
1899 if(strcmp(argv
[1], "-h") == 0) {
1900 show_help(argc
, argv
);
1907 int main(int argc
, char **argv
)
1912 err
= check_args(argc
, argv
);
1913 if(err
> 0) return err
;
1914 else if(err
< 0) return 0;
1916 /* open the facility */
1917 fac
= ltt_facility_open(argv
[1]);
1919 printf("Error opening file %s for reading : %s\n",
1920 argv
[1], strerror(errno
));
1924 /* generate the output C files */
1927 /* ltt-facility-name.h : main logging header.
1929 err
= print_log_header(fac
);
1932 /* ltt-facility-id-name.h : facility id.
1934 err
= print_id_header(fac
);
1937 /* ltt-facility-loader-name.h : facility specific loader info.
1939 err
= print_loader_header(fac
);
1942 /* ltt-facility-loader-name.c : generic faciilty loader
1944 err
= print_loader_c(fac
);
1947 /* close the facility */
1948 ltt_facility_close(fac
);
This page took 0.092779 seconds and 5 git commands to generate.