a489165e91db5dbacd24e1911ad8cc8c1e9cc5b8
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 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
,
574 fprintf(fd
, "sizeof(char)");
577 printf("error : type unexpected\n");
600 fprintf(fd
, "sizeof(");
601 if(print_type(td
, fd
, 0, basename
, "")) return 1;
605 fprintf(fd
, "sizeof(char)");
608 fprintf(fd
, "lttng_get_alignment_sequence_%s(&%s%s)", basename
,
609 obj_prefix
, field_name
);
612 fprintf(fd
, "lttng_get_alignment_struct_%s(&%s%s)", basename
,
613 obj_prefix
, field_name
);
616 fprintf(fd
, "lttng_get_alignment_union_%s(&%s%s)", basename
,
617 obj_prefix
, field_name
);
620 fprintf(fd
, "lttng_get_alignment_array_%s(%s%s)", basename
,
621 obj_prefix
, field_name
);
624 printf("error : type NONE unexpected\n");
635 * Copied from construct_types_and_fields in LTTV facility.c
637 * basename is the name which identifies the type (along with a prefix
640 int print_type_write(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
641 char *nest_name
, char *field_name
, char *obj_prefix
)
643 char basename
[PATH_MAX
];
644 unsigned int basename_len
= 0;
646 strncpy(basename
, nest_name
, PATH_MAX
);
647 basename_len
= strlen(basename
);
649 /* For a named type, we use the type_name directly */
650 if(td
->type_name
!= NULL
) {
651 strncpy(basename
, td
->type_name
, PATH_MAX
);
652 basename_len
= strlen(basename
);
654 /* For a unnamed type, there must be a field name, except for
656 if((basename_len
!= 0)
657 && (basename
[basename_len
-1] != '_'
658 && (field_name
[0] != '\0'))) {
659 strncat(basename
, "_", PATH_MAX
- basename_len
);
660 basename_len
= strlen(basename
);
662 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
682 print_tabs(tabs
, fd
);
683 fprintf(fd
, "size = ");
684 fprintf(fd
, "sizeof(");
685 if(print_type(td
, fd
, 0, basename
, "")) return 1;
687 print_tabs(tabs
, fd
);
688 fprintf(fd
, "size += ltt_align(*to+*len, size) + size;\n");
689 print_tabs(tabs
, fd
);
690 fprintf(fd
, "*len += size;");
693 print_tabs(tabs
, fd
);
695 "lttng_write_string_%s(buffer, to_base, to, from, len, %s%s);\n",
696 basename
, obj_prefix
, field_name
);
699 print_tabs(tabs
, fd
);
701 "lttng_write_sequence_%s(buffer, to_base, to, from, len, &%s%s);",
702 basename
, obj_prefix
, field_name
);
705 print_tabs(tabs
, fd
);
707 "lttng_write_struct_%s(buffer, to_base, to, from, len, &%s%s);",
708 basename
, obj_prefix
, field_name
);
711 print_tabs(tabs
, fd
);
713 "lttng_write_union_%s(buffer, to_base, to, from, len, &%s%s);",
714 basename
, obj_prefix
, field_name
);
717 print_tabs(tabs
, fd
);
719 "lttng_write_array_%s(buffer, to_base, to, from, len, %s%s);",
720 basename
, obj_prefix
, field_name
);
723 printf("Error : type NONE unexpected\n");
733 /* print type alignment function.
735 * Copied from construct_types_and_fields in LTTV facility.c
737 * basename is the name which identifies the type (along with a prefix
740 int print_type_alignment_fct(type_descriptor_t
* td
, FILE *fd
,
742 char *nest_name
, char *field_name
)
744 char basename
[PATH_MAX
];
745 unsigned int basename_len
= 0;
747 strncpy(basename
, nest_name
, PATH_MAX
);
748 basename_len
= strlen(basename
);
750 /* For a named type, we use the type_name directly */
751 if(td
->type_name
!= NULL
) {
752 strncpy(basename
, td
->type_name
, PATH_MAX
);
753 basename_len
= strlen(basename
);
755 /* For a unnamed type, there must be a field name, except for
757 if((basename_len
!= 0)
758 && (basename
[basename_len
-1] != '_'
759 && (field_name
[0] != '\0'))) {
760 strncat(basename
, "_", PATH_MAX
- basename_len
);
761 basename_len
= strlen(basename
);
763 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
768 /* Function header */
769 fprintf(fd
, "static inline size_t lttng_get_alignment_sequence_%s(\n",
772 if(print_type(td
, fd
, 0, basename
, "")) return 1;
773 fprintf(fd
, " *obj)\n");
776 fprintf(fd
, "size_t align=0, localign;");
779 fprintf(fd
, "localign = ");
780 if(print_type_alignment(((field_t
*)td
->fields
.array
[0])->type
,
781 fd
, 0, basename
, "len", "obj->")) return 1;
784 fprintf(fd
, "align = max(align, localign);\n");
787 fprintf(fd
, "localign = ");
788 if(print_type_alignment(((field_t
*)td
->fields
.array
[1])->type
,
789 fd
, 0, basename
, "array[0]", "obj->")) return 1;
792 fprintf(fd
, "align = max(align, localign);\n");
795 fprintf(fd
, "return align;\n");
798 /* Function header */
799 fprintf(fd
, "static inline size_t lttng_get_alignment_struct_%s(\n",
802 if(print_type(td
, fd
, 0, basename
, "")) return 1;
803 fprintf(fd
, " *obj)\n");
806 fprintf(fd
, "size_t align=0, localign;");
808 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
809 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
810 type_descriptor_t
*type
= field
->type
;
812 fprintf(fd
, "localign = ");
813 if(print_type_alignment(type
, fd
, 0, basename
, field
->name
, "obj->"))
817 fprintf(fd
, "align = max(align, localign);\n");
821 fprintf(fd
, "return align;\n");
825 /* Function header */
826 fprintf(fd
, "static inline size_t lttng_get_alignment_union_%s(\n",
829 if(print_type(td
, fd
, 0, basename
, "")) return 1;
830 fprintf(fd
, " *obj)\n");
833 fprintf(fd
, "size_t align=0, localign;");
835 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
836 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
837 type_descriptor_t
*type
= field
->type
;
839 fprintf(fd
, "localign = ");
840 if(print_type_alignment(type
, fd
, 0, basename
, field
->name
, "obj->"))
844 fprintf(fd
, "align = max(align, localign);\n");
848 fprintf(fd
, "return align;\n");
852 /* Function header */
853 fprintf(fd
, "static inline size_t lttng_get_alignment_array_%s(\n",
856 if(print_type(td
, fd
, 0, basename
, "")) return 1;
857 fprintf(fd
, " obj)\n");
860 fprintf(fd
, "return \n");
861 if(print_type_alignment(((field_t
*)td
->fields
.array
[0])->type
,
862 fd
, 0, basename
, "", "obj[0]"))
867 dprintf("print_type_alignment_fct : type has no alignment function.\n");
873 /* Function footer */
880 /* print type write function.
882 * Copied from construct_types_and_fields in LTTV facility.c
884 * basename is the name which identifies the type (along with a prefix
887 int print_type_write_fct(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
888 char *nest_name
, char *field_name
)
890 char basename
[PATH_MAX
];
891 unsigned int basename_len
= 0;
893 strncpy(basename
, nest_name
, PATH_MAX
);
894 basename_len
= strlen(basename
);
896 /* For a named type, we use the type_name directly */
897 if(td
->type_name
!= NULL
) {
898 strncpy(basename
, td
->type_name
, PATH_MAX
);
899 basename_len
= strlen(basename
);
901 /* For a unnamed type, there must be a field name, except for
903 if((basename_len
!= 0)
904 && (basename
[basename_len
-1] != '_'
905 && (field_name
[0] != '\0'))) {
906 strncat(basename
, "_", PATH_MAX
- basename_len
);
907 basename_len
= strlen(basename
);
909 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
920 dprintf("print_type_write_fct : type has no write function.\n");
928 fprintf(fd
, "static inline void lttng_write_sequence_%s(\n",
932 fprintf(fd
, "static inline void lttng_write_struct_%s(\n", basename
);
935 fprintf(fd
, "static inline void lttng_write_union_%s(\n", basename
);
938 fprintf(fd
, "static inline void lttng_write_array_%s(\n", basename
);
941 fprintf(fd
, "static inline void lttng_write_string_%s(\n", basename
);
944 printf("print_type_write_fct : type has no write function.\n");
949 fprintf(fd
, "void *buffer,\n");
951 fprintf(fd
, "size_t *to_base,\n");
953 fprintf(fd
, "size_t *to,\n");
955 fprintf(fd
, "void **from,\n");
957 fprintf(fd
, "size_t *len,\n");
959 if(print_type(td
, fd
, 0, basename
, "")) return 1;
963 fprintf(fd
, " *obj)\n");
966 fprintf(fd
, " *obj)\n");
969 fprintf(fd
, " *obj)\n");
972 fprintf(fd
, " obj)\n");
975 fprintf(fd
, " obj)\n");
978 printf("print_type_write_fct : type has no write function.\n");
984 fprintf(fd
, "size_t align, size;\n");
991 fprintf(fd
, "/* Flush pending memcpy */\n");
993 fprintf(fd
, "if(*len != 0) {\n");
995 fprintf(fd
, "if(buffer != NULL)\n");
997 fprintf(fd
, "memcpy(buffer+*to_base+*to, *from, *len);\n");
1001 fprintf(fd
, "*to += *len;\n");
1003 fprintf(fd
, "*len = 0;\n");
1011 printf("print_type_write_fct : type has no write function.\n");
1016 fprintf(fd
, "align = ");
1017 if(print_type_alignment(td
, fd
, 0, basename
, "", "obj")) return 1;
1021 fprintf(fd
, "if(*len == 0) {\n");
1023 fprintf(fd
, "*to += ltt_align(*to, align); /* align output */\n");
1025 fprintf(fd
, "} else {\n");
1027 fprintf(fd
, "*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */\n");
1032 /* First, check if the type has a fixed size. If it is the case, then the size
1033 * to write is know by the compiler : simply use a sizeof() */
1034 if(has_type_fixed_size(td
)) {
1036 fprintf(fd
, "/* Contains only fixed size fields : use compiler sizeof() */\n");
1039 fprintf(fd
, "size = sizeof(");
1040 if(print_type(td
, fd
, 0, basename
, field_name
)) return 1;
1041 fprintf(fd
, ");\n");
1043 fprintf(fd
, "*len += size;\n");
1045 /* The type contains nested variable size subtypes :
1046 * we must write field by field. */
1048 fprintf(fd
, "/* Contains variable sized fields : must explode the structure */\n");
1054 fprintf(fd
, "/* Copy members */\n");
1055 // print_tabs(1, fd);
1056 // fprintf(fd, "size = sizeof(\n");
1057 if(print_type_write(((field_t
*)td
->fields
.array
[0])->type
,
1058 fd
, 1, basename
, "len", "obj->")) return 1;
1060 // fprintf(fd, ");\n");
1061 // print_tabs(1, fd);
1062 // fprintf(fd, "*to += ltt_align(*to, size);\n");
1064 fprintf(fd
, "if(buffer != NULL)\n");
1066 fprintf(fd
, "memcpy(buffer+*to_base+*to, &obj->len, size);\n");
1068 fprintf(fd
, "*to += size;\n");
1071 /* Write the child : varlen child or not ? */
1072 if(has_type_fixed_size(((field_t
*)td
->fields
.array
[1])->type
)) {
1073 /* Fixed size len child : use a multiplication of its size */
1074 // print_tabs(1, fd);
1075 // fprintf(fd, "size = sizeof(\n");
1076 if(print_type_write(((field_t
*)td
->fields
.array
[1])->type
,
1077 fd
, 1, basename
, "array[0]", "obj->")) return 1;
1078 // fprintf(fd, ");\n");
1079 // print_tabs(1, fd);
1080 fprintf(fd
, "*to += ltt_align(*to, size);\n");
1082 fprintf(fd
, "size = obj->len * size;\n");
1084 fprintf(fd
, "if(buffer != NULL)\n");
1086 fprintf(fd
, "memcpy(buffer+*to_base+*to, obj->array, size);\n");
1088 fprintf(fd
, "*to += size;\n");
1092 fprintf(fd
, "/* Variable length child : iter. */\n");
1094 fprintf(fd
, "for(unsigned int i=0; i<obj->len; i++) {\n");
1095 if(print_type_write(((field_t
*)td
->fields
.array
[1])->type
,
1096 fd
, 2, basename
, "array[i]", "obj->")) return 1;
1102 fprintf(fd
, "/* Realign the *to_base on arch size, set *to to 0 */\n");
1104 fprintf(fd
, "*to = ltt_align(*to, sizeof(void *));\n");
1106 fprintf(fd
, "*to_base = *to_base+*to;\n");
1108 fprintf(fd
, "*to = 0;\n");
1111 fprintf(fd
, "/* Put source *from just after the C sequence */\n");
1113 fprintf(fd
, "*from = obj+1;\n");
1117 fprintf(fd
, "size = strlen(obj) + 1; /* Include final NULL char. */\n");
1119 fprintf(fd
, "if(buffer != NULL)\n");
1121 fprintf(fd
, "memcpy(buffer+*to_base+*to, obj, size);\n");
1123 fprintf(fd
, "*to += size;\n");
1126 fprintf(fd
, "/* Realign the *to_base on arch size, set *to to 0 */\n");
1128 fprintf(fd
, "*to = ltt_align(*to, sizeof(void *));\n");
1130 fprintf(fd
, "*to_base = *to_base+*to;\n");
1132 fprintf(fd
, "*to = 0;\n");
1135 fprintf(fd
, "/* Put source *from just after the C string */\n");
1137 fprintf(fd
, "*from += size;\n");
1140 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
1141 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
1142 type_descriptor_t
*type
= field
->type
;
1143 if(print_type_write(type
,
1144 fd
, 1, basename
, field
->name
, "obj->")) return 1;
1149 printf("ERROR : A union CANNOT contain a variable size child.\n");
1153 /* Write the child : varlen child or not ? */
1154 if(has_type_fixed_size(((field_t
*)td
->fields
.array
[0])->type
)) {
1155 /* Error : if an array has a variable size, then its child must also
1156 * have a variable size. */
1160 fprintf(fd
, "/* Variable length child : iter. */\n");
1162 fprintf(fd
, "for(unsigned int i=0; i<LTTNG_ARRAY_SIZE_%s; i++) {\n", basename
);
1163 if(print_type_write(((field_t
*)td
->fields
.array
[0])->type
,
1164 fd
, 2, basename
, "", "obj->array[i]")) return 1;
1170 printf("print_type_write_fct : type has no write function.\n");
1178 /* Function footer */
1186 /* Print the logging function of an event. This is the core of genevent */
1187 int print_event_logging_function(char *basename
, facility_t
*fac
,
1188 event_t
*event
, FILE *fd
)
1190 fprintf(fd
, "static inline void trace_%s(\n", basename
);
1191 int has_argument
= 0;
1193 /* Does it support per trace tracing ? */
1194 if(event
->per_trace
) {
1196 fprintf(fd
, "struct ltt_trace_struct *dest_trace");
1200 /* Does it support per tracefile tracing ? */
1201 if(event
->per_tracefile
) {
1206 fprintf(fd
, "unsigned int tracefile_index");
1210 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
1211 /* For each field, print the function argument */
1212 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
1213 type_descriptor_t
*t
= f
->type
;
1218 if(print_arg(t
, fd
, 2, basename
, f
->name
)) return 1;
1223 fprintf(fd
, "void");
1227 "#if (!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_%s))\n",
1231 fprintf(fd
,"#else\n");
1233 /* Print the function variables */
1235 fprintf(fd
, "unsigned int index;\n");
1237 fprintf(fd
, "struct ltt_channel_struct *channel;\n");
1239 fprintf(fd
, "struct ltt_trace_struct *trace;\n");
1241 fprintf(fd
, "struct rchan_buf *relayfs_buf;\n");
1243 fprintf(fd
, "void *buffer = NULL;\n");
1245 fprintf(fd
, "size_t to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
1247 fprintf(fd
, "size_t to = 0;\n");
1249 fprintf(fd
, "void *from;");
1251 fprintf(fd
, "size_t len = 0;\n");
1253 fprintf(fd
, "size_t reserve_size;\n");
1255 fprintf(fd
, "size_t slot_size;\n");
1257 fprintf(fd
, "cycles_t tsc;\n");
1259 fprintf(fd
, "size_t before_hdr_pad, size_t after_hdr_pad;\n");
1263 fprintf(fd
, "if(ltt_traces.num_active_traces == 0) return;\n");
1266 /* Calculate event variable len + event data alignment offset.
1267 * Assume that the padding for alignment starts at a void*
1269 * This excludes the header size and alignment. */
1272 fprintf(fd
, "/* For each field, calculate the field size. */\n");
1274 fprintf(fd
, "/* size = to_base + to + len */\n");
1276 fprintf(fd
, "/* Assume that the padding for alignment starts at a\n");
1278 fprintf(fd
, " * sizeof(void *) address. */\n");
1281 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1282 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1283 type_descriptor_t
*type
= field
->type
;
1284 if(print_type_write(type
,
1285 fd
, 1, basename
, field
->name
, "")) return 1;
1289 fprintf(fd
, "reserve_size = to_base + to + len;\n");
1291 fprintf(fd
, "to_base = to = len = 0;\n");
1294 /* Take locks : make sure the trace does not vanish while we write on
1295 * it. A simple preemption disabling is enough (using rcu traces). */
1297 fprintf(fd
, "preempt_disable();\n");
1299 fprintf(fd
, "ltt_nesting[smp_processor_id()]++;\n");
1301 /* Get facility index */
1303 if(event
->per_tracefile
) {
1305 fprintf(fd
, "index = tracefile_index;\n");
1309 "index = ltt_get_index_from_facility(ltt_facility_%s_%X,\n"\
1310 "\t\t\t\t\t\tevent_%s);\n",
1311 fac
->name
, fac
->checksum
, event
->name
);
1316 /* For each trace */
1318 fprintf(fd
, "list_for_each_entry_rcu(trace, <t_traces.head, list) {\n");
1320 fprintf(fd
, "if(!trace->active) continue;\n\n");
1322 if(event
->per_trace
) {
1324 fprintf(fd
, "if(dest_trace != trace) continue;\n\n");
1328 fprintf(fd
, "channel = ltt_get_channel_from_index(trace, index);\n");
1330 fprintf(fd
, "relayfs_buf = channel->rchan->buf[channel->rchan->buf->cpu];\n");
1335 /* If error, increment event lost counter (done by ltt_reserve_slot) and
1338 fprintf(fd
, "slot_size = 0;\n");
1340 fprintf(fd
, "buffer = ltt_reserve_slot(trace, relayfs_buf,\n");
1342 fprintf(fd
, "reserve_size, &slot_size, &tsc,\n");
1344 fprintf(fd
, "&before_hdr_pad, &after_hdr_pad);\n");
1345 /* If error, return */
1347 fprintf(fd
, "if(!buffer) return;\n\n");
1349 /* write data : assume stack alignment is the same as struct alignment. */
1351 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1352 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1353 type_descriptor_t
*type
= field
->type
;
1357 switch(type
->type
) {
1363 fprintf(fd
, "from = %s;\n", field
->name
);
1366 fprintf(fd
, "from = &%s;\n", field
->name
);
1371 if(print_type_write(type
,
1372 fd
, 2, basename
, field
->name
, "")) return 1;
1375 /* Don't forget to flush pending memcpy */
1377 fprintf(fd
, "/* Flush pending memcpy */\n");
1379 fprintf(fd
, "if(len != 0) {\n");
1381 fprintf(fd
, "memcpy(buffer+to_base+to, from, len);\n");
1383 fprintf(fd
, "to += len;\n");
1384 //print_tabs(3, fd);
1385 //fprintf(fd, "from += len;\n");
1387 fprintf(fd
, "len = 0;\n");
1396 fprintf(fd
, "ltt_commit_slot(relayfs_buf, buffer, slot_size);\n\n");
1399 fprintf(fd
, "}\n\n");
1403 fprintf(fd
, "ltt_nesting[smp_processor_id()]--;\n");
1405 fprintf(fd
, "preempt_enable_no_resched();\n");
1408 fprintf(fd
, "#endif //(!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_%s))\n\n",
1414 /* ltt-facility-name.h : main logging header.
1417 void print_log_header_head(facility_t
*fac
, FILE *fd
)
1419 fprintf(fd
, "#ifndef _LTT_FACILITY_%s_H_\n", fac
->capname
);
1420 fprintf(fd
, "#define _LTT_FACILITY_%s_H_\n\n", fac
->capname
);
1421 fprintf(fd
, "#include <linux/types.h>\n");
1422 fprintf(fd
, "#include <linux/ltt/ltt-facility-id-%s.h>\n", fac
->name
);
1423 fprintf(fd
, "#include <linux/ltt-core.h>\n");
1429 int print_log_header_types(facility_t
*fac
, FILE *fd
)
1431 sequence_t
*types
= &fac
->named_types
.values
;
1432 fprintf(fd
, "/* Named types */\n");
1435 for(unsigned int i
= 0; i
< types
->position
; i
++) {
1436 /* For each named type, print the definition */
1437 if((print_type_declaration(types
->array
[i
], fd
,
1438 0, "", ""))) return 1;
1439 /* Print also the align function */
1440 if((print_type_alignment_fct(types
->array
[i
], fd
,
1441 0, "", ""))) return 1;
1442 /* Print also the write function */
1443 if((print_type_write_fct(types
->array
[i
], fd
,
1444 0, "", ""))) return 1;
1449 int print_log_header_events(facility_t
*fac
, FILE *fd
)
1451 sequence_t
*events
= &fac
->events
;
1452 char basename
[PATH_MAX
];
1453 unsigned int facname_len
;
1455 strncpy(basename
, fac
->name
, PATH_MAX
);
1456 facname_len
= strlen(basename
);
1457 strncat(basename
, "_", PATH_MAX
-facname_len
);
1458 facname_len
= strlen(basename
);
1460 for(unsigned int i
= 0; i
< events
->position
; i
++) {
1461 event_t
*event
= (event_t
*)events
->array
[i
];
1462 strncpy(&basename
[facname_len
], event
->name
, PATH_MAX
-facname_len
);
1464 /* For each event, print structure, and then logging function */
1465 fprintf(fd
, "/* Event %s structures */\n",
1467 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
1468 /* For each unnamed type, print the definition */
1469 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
1470 type_descriptor_t
*t
= f
->type
;
1471 if(t
->type_name
== NULL
) {
1472 if((print_type_declaration(t
, fd
, 0, basename
, f
->name
))) return 1;
1473 /* Print also the align function */
1474 if((print_type_alignment_fct(t
, fd
, 0, basename
, f
->name
))) return 1;
1475 /* Print also the write function */
1476 if((print_type_write_fct(t
, fd
, 0, basename
, f
->name
))) return 1;
1482 fprintf(fd
, "/* Event %s logging function */\n",
1485 if(print_event_logging_function(basename
, fac
, event
, fd
)) return 1;
1494 void print_log_header_tail(facility_t
*fac
, FILE *fd
)
1496 fprintf(fd
, "#endif //_LTT_FACILITY_%s_H_\n",fac
->capname
);
1499 int print_log_header(facility_t
*fac
)
1501 char filename
[PATH_MAX
];
1502 unsigned int filename_size
= 0;
1504 dprintf("%s\n", fac
->name
);
1506 strcpy(filename
, "ltt-facility-");
1507 filename_size
= strlen(filename
);
1509 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1510 filename_size
= strlen(filename
);
1512 strncat(filename
, ".h", PATH_MAX
- filename_size
);
1513 filename_size
= strlen(filename
);
1516 fd
= fopen(filename
, "w");
1518 printf("Error opening file %s for writing : %s\n",
1519 filename
, strerror(errno
));
1523 /* Print file head */
1524 print_log_header_head(fac
, fd
);
1526 /* print named types in declaration order */
1527 if(print_log_header_types(fac
, fd
)) return 1;
1530 if(print_log_header_events(fac
, fd
)) return 1;
1532 /* Print file tail */
1533 print_log_header_tail(fac
, fd
);
1542 /* ltt-facility-id-name.h : facility id.
1544 int print_id_header(facility_t
*fac
)
1546 char filename
[PATH_MAX
];
1547 unsigned int filename_size
= 0;
1549 char basename
[PATH_MAX
];
1550 char basename_len
= 0;
1552 dprintf("%s\n", fac
->name
);
1554 strcpy(filename
, "ltt-facility-id-");
1555 filename_size
= strlen(filename
);
1557 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1558 filename_size
= strlen(filename
);
1560 strncat(filename
, ".h", PATH_MAX
- filename_size
);
1561 filename_size
= strlen(filename
);
1564 fd
= fopen(filename
, "w");
1566 printf("Error opening file %s for writing : %s\n",
1567 filename
, strerror(errno
));
1571 fprintf(fd
, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
1572 fprintf(fd
, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac
->capname
);
1573 fprintf(fd
, "#ifdef CONFIG_LTT\n");
1575 fprintf(fd
,"#include <linux/ltt-facilities.h>\n\n");
1577 fprintf(fd
,"/**** facility handle ****/\n\n");
1578 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s_%X;\n",
1579 fac
->name
, fac
->checksum
);
1580 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s;\n\n\n",fac
->name
);
1582 strncpy(basename
, fac
->name
, PATH_MAX
);
1583 basename_len
= strlen(basename
);
1584 strncat(basename
, "_", PATH_MAX
- basename_len
);
1587 fprintf(fd
,"/**** event index ****/\n\n");
1588 fprintf(fd
,"enum %s_event {\n",fac
->name
);
1590 for(unsigned int i
= 0; i
< fac
->events
.position
; i
++) {
1591 event_t
*event
= (event_t
*)fac
->events
.array
[i
];
1592 strncpy(basename
+basename_len
, event
->name
, PATH_MAX
-basename_len
);
1594 fprintf(fd
, "event_%s,\n", basename
);
1597 fprintf(fd
, "facility_%s_num_events\n", fac
->name
);
1598 fprintf(fd
, "};\n");
1602 fprintf(fd
, "#endif //CONFIG_LTT\n");
1603 fprintf(fd
, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
1612 /* ltt-facility-loader-name.h : facility specific loader info.
1614 int print_loader_header(facility_t
*fac
)
1616 char filename
[PATH_MAX
];
1617 unsigned int filename_size
= 0;
1619 dprintf("%s\n", fac
->name
);
1621 strcpy(filename
, "ltt-facility-loader-");
1622 filename_size
= strlen(filename
);
1624 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1625 filename_size
= strlen(filename
);
1627 strncat(filename
, ".h", PATH_MAX
- filename_size
);
1628 filename_size
= strlen(filename
);
1631 fd
= fopen(filename
, "w");
1633 printf("Error opening file %s for writing : %s\n",
1634 filename
, strerror(errno
));
1638 fprintf(fd
, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
1639 fprintf(fd
, "#define _LTT_FACILITY_LOADER_%s_H_\n\n", fac
->capname
);
1640 fprintf(fd
, "#ifdef CONFIG_LTT\n\n");
1641 fprintf(fd
,"#include <linux/ltt-facilities.h>\n");
1642 fprintf(fd
,"#include <linux/ltt/ltt-facility-id-%s.h>\n\n",
1644 fprintf(fd
,"ltt_facility_t\tltt_facility_%s;\n", fac
->name
);
1645 fprintf(fd
,"ltt_facility_t\tltt_facility_%s_%X;\n\n",
1646 fac
->name
, fac
->checksum
);
1648 fprintf(fd
,"#define LTT_FACILITY_SYMBOL\t\t\t\t\t\t\tltt_facility_%s\n",
1650 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM_SYMBOL\t\tltt_facility_%s_%X\n",
1651 fac
->name
, fac
->checksum
);
1652 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM\t\t\t\t\t\t0x%X\n", fac
->checksum
);
1653 fprintf(fd
,"#define LTT_FACILITY_NAME\t\t\t\t\t\t\t\t\"%s\"\n", fac
->name
);
1654 fprintf(fd
,"#define LTT_FACILITY_NUM_EVENTS\t\t\t\t\tfacility_%s_num_events\n\n",
1656 fprintf(fd
, "#endif //CONFIG_LTT\n\n");
1657 fprintf(fd
, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
1664 /* ltt-facility-loader-name.c : generic faciilty loader
1666 int print_loader_c(facility_t
*fac
)
1668 char filename
[PATH_MAX
];
1669 unsigned int filename_size
= 0;
1671 dprintf("%s\n", fac
->name
);
1673 strcpy(filename
, "ltt-facility-loader-");
1674 filename_size
= strlen(filename
);
1676 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1677 filename_size
= strlen(filename
);
1679 strncat(filename
, ".c", PATH_MAX
- filename_size
);
1680 filename_size
= strlen(filename
);
1683 fd
= fopen(filename
, "w");
1685 printf("Error opening file %s for writing : %s\n",
1686 filename
, strerror(errno
));
1690 fprintf(fd
, "/*\n");
1691 fprintf(fd
, " * ltt-facility-loader-%s.c\n", fac
->name
);
1692 fprintf(fd
, " *\n");
1693 fprintf(fd
, " * (C) Copyright 2005 - \n");
1694 fprintf(fd
, " * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)\n");
1695 fprintf(fd
, " *\n");
1696 fprintf(fd
, " * Contains the LTT facility loader.\n");
1697 fprintf(fd
, " *\n");
1698 fprintf(fd
, " */\n");
1701 fprintf(fd
, "#include <linux/ltt-facilities.h>\n");
1702 fprintf(fd
, "#include <linux/module.h>\n");
1703 fprintf(fd
, "#include <linux/init.h>\n");
1704 fprintf(fd
, "#include <linux/config.h>\n");
1705 fprintf(fd
, "#include \"ltt-facility-loader-%s.h\"\n", fac
->name
);
1708 fprintf(fd
, "#ifdef CONFIG_LTT\n");
1710 fprintf(fd
, "EXPORT_SYMBOL(LTT_FACILITY_SYMBOL);\n");
1711 fprintf(fd
, "EXPORT_SYMBOL(LTT_FACILITY_CHECKSUM_SYMBOL);\n");
1713 fprintf(fd
, "static const char ltt_facility_name[] = LTT_FACILITY_NAME;\n");
1715 fprintf(fd
, "#define SYMBOL_STRING(sym) #sym\n");
1717 fprintf(fd
, "static struct ltt_facility facility = {\n");
1718 fprintf(fd
, "\t.name = ltt_facility_name,\n");
1719 fprintf(fd
, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n");
1720 fprintf(fd
, "\t.checksum = LTT_FACILITY_CHECKSUM,\n");
1721 fprintf(fd
, "\t.symbol = SYMBOL_STRING(LTT_FACILITY_SYMBOL),\n");
1722 fprintf(fd
, "};\n");
1724 fprintf(fd
, "#ifndef MODULE\n");
1726 fprintf(fd
, "/* Built-in facility. */\n");
1728 fprintf(fd
, "static int __init facility_init(void)\n");
1730 fprintf(fd
, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init in kernel\\n\");\n", fac
->name
);
1732 fprintf(fd
, "\tLTT_FACILITY_SYMBOL = ltt_facility_builtin_register(&facility);\n");
1733 fprintf(fd
, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
1734 fprintf(fd
, "\t\n");
1735 fprintf(fd
, "\treturn LTT_FACILITY_SYMBOL;\n");
1737 fprintf(fd
, "__initcall(facility_init);\n");
1741 fprintf(fd
, "#else \n");
1743 fprintf(fd
, "/* Dynamic facility. */\n");
1745 fprintf(fd
, "static int __init facility_init(void)\n");
1747 fprintf(fd
, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init dynamic\\n\");\n", fac
->name
);
1749 fprintf(fd
, "\tLTT_FACILITY_SYMBOL = ltt_facility_dynamic_register(&facility);\n");
1750 fprintf(fd
, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
1752 fprintf(fd
, "\treturn LTT_FACILITY_SYMBOL;\n");
1755 fprintf(fd
, "static void __exit facility_exit(void)\n");
1757 fprintf(fd
, "\tint err;\n");
1759 fprintf(fd
, "\terr = ltt_facility_dynamic_unregister(LTT_FACILITY_SYMBOL);\n");
1760 fprintf(fd
, "\tif(err != 0)\n");
1761 fprintf(fd
, "\t\tprintk(KERN_ERR \"LTT : Error in unregistering facility.\\n\");\n");
1765 fprintf(fd
, "module_init(facility_init)\n");
1766 fprintf(fd
, "module_exit(facility_exit)\n");
1769 fprintf(fd
, "MODULE_LICENSE(\"GPL\");\n");
1770 fprintf(fd
, "MODULE_AUTHOR(\"Mathieu Desnoyers\");\n");
1771 fprintf(fd
, "MODULE_DESCRIPTION(\"Linux Trace Toolkit Facility\");\n");
1773 fprintf(fd
, "#endif //MODULE\n");
1775 fprintf(fd
, "#endif //CONFIG_LTT\n");
1785 /* code taken from ltt_facility_open in ltt/facility.c in lttv */
1787 /*****************************************************************************
1789 * ltt_facility_open : open facilities
1791 * pathname : the path name of the facility
1793 * Open the facility corresponding to the right checksum.
1795 *returns the facility on success, NULL on error.
1796 ****************************************************************************/
1797 facility_t
*ltt_facility_open(char * pathname
)
1802 facility_t
* fac
= NULL
;
1803 char buffer
[BUFFER_SIZE
];
1804 int generated
= FALSE
;
1806 in
.buffer
= &(buffer
[0]);
1808 in
.error
= error_callback
;
1812 in
.fp
= fopen(in
.name
, "r");
1819 token
= getToken(&in
);
1820 if(in
.type
== ENDFILE
) break;
1823 printf("More than one facility in the file. Only using the first one.\n");
1827 if(strcmp(token
, "<")) in
.error(&in
,"not a facility file");
1828 token
= getName(&in
);
1830 if(strcmp("facility",token
) == 0) {
1831 fac
= malloc(sizeof(facility_t
));
1833 fac
->description
= NULL
;
1834 sequence_init(&(fac
->events
));
1835 table_init(&(fac
->named_types
));
1836 sequence_init(&(fac
->unnamed_types
));
1838 parseFacility(&in
, fac
);
1840 //check if any namedType is not defined
1841 checkNamedTypesImplemented(&fac
->named_types
);
1843 generateChecksum(fac
->name
, &fac
->checksum
, &fac
->events
);
1848 printf("facility token was expected in file %s\n", in
.name
);
1859 printf("Cannot find facility %s\n", pathname
);
1866 /* Close the facility */
1867 void ltt_facility_close(facility_t
*fac
)
1871 free(fac
->description
);
1872 freeEvents(&fac
->events
);
1873 sequence_dispose(&fac
->events
);
1874 freeNamedType(&fac
->named_types
);
1875 table_dispose(&fac
->named_types
);
1876 freeTypes(&fac
->unnamed_types
);
1877 sequence_dispose(&fac
->unnamed_types
);
1883 void show_help(int argc
, char ** argv
)
1885 printf("Genevent help : \n");
1887 printf("Use %s name.xml\n", argv
[0]);
1888 printf("to create :\n");
1889 printf("ltt-facility-name.h\n");
1890 printf("ltt-facility-id-name.h\n");
1891 printf("ltt-facility-loader-name.h\n");
1892 printf("ltt-facility-loader-name.c\n");
1893 printf("In the current directory.\n");
1897 /* Parse program arguments */
1899 * 0 : continue program
1900 * -1 : stop program, return 0
1901 * > 0 : stop program, return value as exit.
1903 int check_args(int argc
, char **argv
)
1906 printf("Not enough arguments\n");
1907 show_help(argc
, argv
);
1911 if(strcmp(argv
[1], "-h") == 0) {
1912 show_help(argc
, argv
);
1919 int main(int argc
, char **argv
)
1924 err
= check_args(argc
, argv
);
1925 if(err
> 0) return err
;
1926 else if(err
< 0) return 0;
1928 /* open the facility */
1929 fac
= ltt_facility_open(argv
[1]);
1931 printf("Error opening file %s for reading : %s\n",
1932 argv
[1], strerror(errno
));
1936 /* generate the output C files */
1939 /* ltt-facility-name.h : main logging header.
1941 err
= print_log_header(fac
);
1944 /* ltt-facility-id-name.h : facility id.
1946 err
= print_id_header(fac
);
1949 /* ltt-facility-loader-name.h : facility specific loader info.
1951 err
= print_loader_header(fac
);
1954 /* ltt-facility-loader-name.c : generic faciilty loader
1956 err
= print_loader_c(fac
);
1959 /* close the facility */
1960 ltt_facility_close(fac
);
This page took 0.126547 seconds and 4 git commands to generate.