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
)
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(obj)", basename
);
562 fprintf(fd
, "lttng_get_alignment_struct_%s(obj)", basename
);
565 fprintf(fd
, "lttng_get_alignment_union_%s(obj)", basename
);
568 fprintf(fd
, "lttng_get_alignment_array_%s(obj)", basename
);
571 printf("error : type unexpected\n");
594 fprintf(fd
, "sizeof(");
595 if(print_type(td
, fd
, 0, basename
, "")) return 1;
599 fprintf(fd
, "sizeof(char)");
602 fprintf(fd
, "lttng_get_alignment_sequence_%s(&obj->%s)", basename
,
606 fprintf(fd
, "lttng_get_alignment_struct_%s(&obj->%s)", basename
,
610 fprintf(fd
, "lttng_get_alignment_union_%s(&obj->%s)", basename
,
614 fprintf(fd
, "lttng_get_alignment_array_%s(obj->%s)", basename
,
618 printf("error : type NONE unexpected\n");
629 * Copied from construct_types_and_fields in LTTV facility.c
631 * basename is the name which identifies the type (along with a prefix
634 int print_type_write(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
635 char *nest_name
, char *field_name
)
637 char basename
[PATH_MAX
];
638 unsigned int basename_len
= 0;
640 strncpy(basename
, nest_name
, PATH_MAX
);
641 basename_len
= strlen(basename
);
643 /* For a named type, we use the type_name directly */
644 if(td
->type_name
!= NULL
) {
645 strncpy(basename
, td
->type_name
, PATH_MAX
);
646 basename_len
= strlen(basename
);
648 /* For a unnamed type, there must be a field name, except for
650 if((basename_len
!= 0)
651 && (basename
[basename_len
-1] != '_'
652 && (field_name
[0] != '\0'))) {
653 strncat(basename
, "_", PATH_MAX
- basename_len
);
654 basename_len
= strlen(basename
);
656 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
676 print_tabs(tabs
, fd
);
677 fprintf(fd
, "size = ");
678 fprintf(fd
, "sizeof(");
679 if(print_type(td
, fd
, 0, basename
, "")) return 1;
681 print_tabs(tabs
, fd
);
682 fprintf(fd
, "size += ltt_align(*to+*len, size) + size;\n");
683 print_tabs(tabs
, fd
);
684 fprintf(fd
, "*len += size;");
687 print_tabs(tabs
, fd
);
688 fprintf(fd
, "lttng_write_string_%s(buffer, to_base, to, from, len, obj->%s);\n", basename
, field_name
);
691 print_tabs(tabs
, fd
);
692 fprintf(fd
, "lttng_write_%s(buffer, to_base, to, from, len, &obj->%s)", basename
,
696 print_tabs(tabs
, fd
);
697 fprintf(fd
, "lttng_write_struct_%s(buffer, to_base, to, from, len, &obj->%s)", basename
,
701 print_tabs(tabs
, fd
);
702 fprintf(fd
, "lttng_write_union_%s(buffer, to_base, to, from, len, &obj->%s)", basename
,
706 print_tabs(tabs
, fd
);
707 fprintf(fd
, "lttng_write_array_%s(buffer, to_base, to, from, len, obj->%s)", basename
,
711 printf("Error : type NONE unexpected\n");
721 /* print type alignment function.
723 * Copied from construct_types_and_fields in LTTV facility.c
725 * basename is the name which identifies the type (along with a prefix
728 int print_type_alignment_fct(type_descriptor_t
* td
, FILE *fd
,
730 char *nest_name
, char *field_name
)
732 char basename
[PATH_MAX
];
733 unsigned int basename_len
= 0;
735 strncpy(basename
, nest_name
, PATH_MAX
);
736 basename_len
= strlen(basename
);
738 /* For a named type, we use the type_name directly */
739 if(td
->type_name
!= NULL
) {
740 strncpy(basename
, td
->type_name
, PATH_MAX
);
741 basename_len
= strlen(basename
);
743 /* For a unnamed type, there must be a field name, except for
745 if((basename_len
!= 0)
746 && (basename
[basename_len
-1] != '_'
747 && (field_name
[0] != '\0'))) {
748 strncat(basename
, "_", PATH_MAX
- basename_len
);
749 basename_len
= strlen(basename
);
751 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
756 /* Function header */
757 fprintf(fd
, "static inline size_t lttng_get_alignment_sequence_%s(\n",
760 if(print_type(td
, fd
, 0, basename
, "")) return 1;
761 fprintf(fd
, " *obj)\n");
764 fprintf(fd
, "size_t align=0, localign;");
767 fprintf(fd
, "localign = ");
768 if(print_type_alignment(((field_t
*)td
->fields
.array
[0])->type
,
769 fd
, 0, basename
, ((field_t
*)td
->fields
.array
[0])->name
)) return 1;
772 fprintf(fd
, "align = max(align, localign);\n");
775 fprintf(fd
, "localign = ");
776 if(print_type_alignment(((field_t
*)td
->fields
.array
[1])->type
,
777 fd
, 0, basename
, ((field_t
*)td
->fields
.array
[1])->name
)) return 1;
780 fprintf(fd
, "align = max(align, localign);\n");
783 fprintf(fd
, "return align;\n");
786 /* Function header */
787 fprintf(fd
, "static inline size_t lttng_get_alignment_struct_%s(\n",
790 if(print_type(td
, fd
, 0, basename
, "")) return 1;
791 fprintf(fd
, " *obj)\n");
794 fprintf(fd
, "size_t align=0, localign;");
796 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
797 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
798 type_descriptor_t
*type
= field
->type
;
800 fprintf(fd
, "localign = ");
801 if(print_type_alignment(type
, fd
, 0, basename
, field
->name
)) return 1;
804 fprintf(fd
, "align = max(align, localign);\n");
808 fprintf(fd
, "return align;\n");
812 /* Function header */
813 fprintf(fd
, "static inline size_t lttng_get_alignment_union_%s(\n",
816 if(print_type(td
, fd
, 0, basename
, "")) return 1;
817 fprintf(fd
, " *obj)\n");
820 fprintf(fd
, "size_t align=0, localign;");
822 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
823 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
824 type_descriptor_t
*type
= field
->type
;
826 fprintf(fd
, "localign = ");
827 if(print_type_alignment(type
, fd
, 0, basename
, field
->name
)) return 1;
830 fprintf(fd
, "align = max(align, localign);\n");
834 fprintf(fd
, "return align;\n");
838 /* Function header */
839 fprintf(fd
, "static inline size_t lttng_get_alignment_array_%s(\n",
842 if(print_type(td
, fd
, 0, basename
, "")) return 1;
843 fprintf(fd
, " obj)\n");
846 fprintf(fd
, "return \n");
847 if(print_type_alignment(((field_t
*)td
->fields
.array
[0])->type
,
848 fd
, 0, basename
, ((field_t
*)td
->fields
.array
[0])->name
)) return 1;
852 dprintf("print_type_alignment_fct : type has no alignment function.\n");
858 /* Function footer */
865 /* print type write function.
867 * Copied from construct_types_and_fields in LTTV facility.c
869 * basename is the name which identifies the type (along with a prefix
872 int print_type_write_fct(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
873 char *nest_name
, char *field_name
)
875 char basename
[PATH_MAX
];
876 unsigned int basename_len
= 0;
878 strncpy(basename
, nest_name
, PATH_MAX
);
879 basename_len
= strlen(basename
);
881 /* For a named type, we use the type_name directly */
882 if(td
->type_name
!= NULL
) {
883 strncpy(basename
, td
->type_name
, PATH_MAX
);
884 basename_len
= strlen(basename
);
886 /* For a unnamed type, there must be a field name, except for
888 if((basename_len
!= 0)
889 && (basename
[basename_len
-1] != '_'
890 && (field_name
[0] != '\0'))) {
891 strncat(basename
, "_", PATH_MAX
- basename_len
);
892 basename_len
= strlen(basename
);
894 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
904 dprintf("print_type_write_fct : type has no write function.\n");
912 fprintf(fd
, "static inline void lttng_write_sequence_%s(\n",
916 fprintf(fd
, "static inline void lttng_write_struct_%s(\n", basename
);
919 fprintf(fd
, "static inline void lttng_write_union_%s(\n", basename
);
922 fprintf(fd
, "static inline void lttng_write_array_%s(\n", basename
);
925 printf("print_type_write_fct : type has no write function.\n");
930 fprintf(fd
, "void *buffer,\n");
932 fprintf(fd
, "size_t *to_base,\n");
934 fprintf(fd
, "size_t *to,\n");
936 fprintf(fd
, "void **from,\n");
938 fprintf(fd
, "size_t *len,\n");
940 if(print_type(td
, fd
, 0, basename
, "")) return 1;
944 fprintf(fd
, " *obj)\n");
947 fprintf(fd
, " *obj)\n");
950 fprintf(fd
, " *obj)\n");
953 fprintf(fd
, " obj)\n");
956 printf("print_type_write_fct : type has no write function.\n");
962 fprintf(fd
, "size_t align, size;\n");
969 fprintf(fd
, "/* Flush pending memcpy */\n");
971 fprintf(fd
, "if(*len != 0) {\n");
973 fprintf(fd
, "if(buffer != NULL)\n");
975 fprintf(fd
, "memcpy(buffer+*to_base+*to, *from, *len);\n");
979 fprintf(fd
, "*to += *len;\n");
981 fprintf(fd
, "*len = 0;\n");
989 printf("print_type_write_fct : type has no write function.\n");
994 fprintf(fd
, "align = ");
995 if(print_type_alignment(td
, fd
, 0, basename
, field_name
)) return 1;
999 fprintf(fd
, "if(*len == 0) {\n");
1001 fprintf(fd
, "*to += ltt_align(*to, align); /* align output */\n");
1003 fprintf(fd
, "} else {\n");
1005 fprintf(fd
, "*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */\n");
1010 /* First, check if the type has a fixed size. If it is the case, then the size
1011 * to write is know by the compiler : simply use a sizeof() */
1012 if(has_type_fixed_size(td
)) {
1014 fprintf(fd
, "/* Contains only fixed size fields : use compiler sizeof() */\n");
1017 fprintf(fd
, "size = sizeof(");
1018 if(print_type(td
, fd
, 0, basename
, field_name
)) return 1;
1019 fprintf(fd
, ");\n");
1021 fprintf(fd
, "*len += size;\n");
1023 /* The type contains nested variable size subtypes :
1024 * we must write field by field. */
1026 fprintf(fd
, "/* Contains variable sized fields : must explode the structure */\n");
1032 fprintf(fd
, "/* Copy members */\n");
1034 fprintf(fd
, "size = sizeof(\n");
1035 if(print_type_write(((field_t
*)td
->fields
.array
[0])->type
,
1036 fd
, 1, basename
, ((field_t
*)td
->fields
.array
[0])->name
)) return 1;
1037 fprintf(fd
, ");\n");
1039 fprintf(fd
, "*to += ltt_align(*to, size);\n");
1041 fprintf(fd
, "if(buffer != NULL)\n");
1043 fprintf(fd
, "memcpy(buffer+*to_base+*to, &obj->len, size);\n");
1045 fprintf(fd
, "*to += size;\n");
1048 /* Write the child : varlen child or not ? */
1049 if(has_type_fixed_size(((field_t
*)td
->fields
.array
[1])->type
)) {
1050 /* Fixed size len child : use a multiplication of its size */
1052 fprintf(fd
, "size = sizeof(\n");
1053 if(print_type_write(((field_t
*)td
->fields
.array
[1])->type
,
1054 fd
, 1, basename
, ((field_t
*)td
->fields
.array
[1])->name
)) return 1;
1055 fprintf(fd
, ");\n");
1057 fprintf(fd
, "*to += ltt_align(*to, size);\n");
1059 fprintf(fd
, "size = obj->len * size;\n");
1061 fprintf(fd
, "if(buffer != NULL)\n");
1063 fprintf(fd
, "memcpy(buffer+*to_base+*to, obj->array, size);\n");
1065 fprintf(fd
, "*to += size;\n");
1069 fprintf(fd
, "/* Variable length child : iter. */\n");
1071 fprintf(fd
, "for(unsigned int i=0; i<obj->len; i++) {\n");
1072 if(print_type_write(((field_t
*)td
->fields
.array
[1])->type
,
1073 fd
, 2, basename
, ((field_t
*)td
->fields
.array
[1])->name
)) return 1;
1079 fprintf(fd
, "/* Realign the *to_base on arch size, set *to to 0 */\n");
1081 fprintf(fd
, "*to = ltt_align(*to, sizeof(void *));\n");
1083 fprintf(fd
, "*to_base = *to_base+*to;\n");
1085 fprintf(fd
, "*to = 0;\n");
1087 fprintf(fd
, "/* Put source *from just after the C sequence */\n");
1089 fprintf(fd
, "*from = obj+1;\n");
1092 fprintf(fd
, "size = strlen(obj) + 1; /* Include '\0' */\n");
1094 fprintf(fd
, "if(buffer != NULL)\n");
1096 fprintf(fd
, "memcpy(buffer+*to_base+*to, obj, size);\n");
1098 fprintf(fd
, "*to += size;\n");
1101 fprintf(fd
, "/* Realign the *to_base on arch size, set *to to 0 */\n");
1103 fprintf(fd
, "*to = ltt_align(*to, sizeof(void *));\n");
1105 fprintf(fd
, "*to_base = *to_base+*to;\n");
1107 fprintf(fd
, "*to = 0;\n");
1109 fprintf(fd
, "/* Put source *from just after the C sequence */\n");
1111 fprintf(fd
, "*from = obj+1;\n");
1114 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
1115 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
1116 type_descriptor_t
*type
= field
->type
;
1117 if(print_type_write(type
,
1118 fd
, 1, basename
, field
->name
)) return 1;
1123 printf("ERROR : A union CANNOT contain a variable size child.\n");
1127 /* Write the child : varlen child or not ? */
1128 if(has_type_fixed_size(((field_t
*)td
->fields
.array
[0])->type
)) {
1129 /* Error : if an array has a variable size, then its child must also
1130 * have a variable size. */
1134 fprintf(fd
, "/* Variable length child : iter. */\n");
1136 fprintf(fd
, "for(unsigned int i=0; i<LTTNG_ARRAY_SIZE_%s; i++) {\n", basename
);
1137 if(print_type_write(((field_t
*)td
->fields
.array
[1])->type
,
1138 fd
, 2, basename
, ((field_t
*)td
->fields
.array
[1])->name
)) return 1;
1144 printf("print_type_write_fct : type has no write function.\n");
1152 /* Function footer */
1160 /* Print the logging function of an event. This is the core of genevent */
1161 int print_event_logging_function(char *basename
, facility_t
*fac
,
1162 event_t
*event
, FILE *fd
)
1164 fprintf(fd
, "static inline void trace_%s(\n", basename
);
1165 int has_argument
= 0;
1167 /* Does it support per trace tracing ? */
1168 if(event
->per_trace
) {
1170 fprintf(fd
, "struct ltt_trace_struct *dest_trace");
1174 /* Does it support per tracefile tracing ? */
1175 if(event
->per_tracefile
) {
1180 fprintf(fd
, "unsigned int tracefile_index");
1184 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
1185 /* For each field, print the function argument */
1186 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
1187 type_descriptor_t
*t
= f
->type
;
1192 if(print_arg(t
, fd
, 2, basename
, f
->name
)) return 1;
1197 fprintf(fd
, "void");
1201 "#if (!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_%s))\n",
1205 fprintf(fd
,"#else\n");
1207 /* Print the function variables */
1209 fprintf(fd
, "unsigned int index;\n");
1211 fprintf(fd
, "struct ltt_channel_struct *channel;\n");
1213 fprintf(fd
, "struct ltt_trace_struct *trace;\n");
1215 fprintf(fd
, "struct rchan_buf *relayfs_buf;\n");
1217 fprintf(fd
, "void *buffer = NULL;\n");
1219 fprintf(fd
, "size_t to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
1221 fprintf(fd
, "size_t to = 0;\n");
1223 fprintf(fd
, "void *from;");
1225 fprintf(fd
, "size_t len = 0;\n");
1227 fprintf(fd
, "size_t reserve_size;\n");
1229 fprintf(fd
, "size_t slot_size;\n");
1231 fprintf(fd
, "cycles_t tsc;\n");
1233 fprintf(fd
, "size_t before_hdr_pad, size_t after_hdr_pad;\n");
1237 fprintf(fd
, "if(ltt_traces.num_active_traces == 0) return;\n");
1240 /* Calculate event variable len + event data alignment offset.
1241 * Assume that the padding for alignment starts at a void*
1243 * This excludes the header size and alignment. */
1246 fprintf(fd
, "/* For each field, calculate the field size. */\n");
1248 fprintf(fd
, "/* size = to_base + to + len */\n");
1250 fprintf(fd
, "/* Assume that the padding for alignment starts at a\n");
1252 fprintf(fd
, " * sizeof(void *) address. */\n");
1255 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1256 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1257 type_descriptor_t
*type
= field
->type
;
1258 if(print_type_write(type
,
1259 fd
, 1, basename
, field
->name
)) return 1;
1263 fprintf(fd
, "reserve_size = to_base + to + len;\n");
1265 fprintf(fd
, "to_base = to = len = 0;\n");
1268 /* Take locks : make sure the trace does not vanish while we write on
1269 * it. A simple preemption disabling is enough (using rcu traces). */
1271 fprintf(fd
, "preempt_disable();\n");
1273 fprintf(fd
, "ltt_nesting[smp_processor_id()]++;\n");
1275 /* Get facility index */
1277 if(event
->per_tracefile
) {
1279 fprintf(fd
, "index = tracefile_index;\n");
1283 "index = ltt_get_index_from_facility(ltt_facility_%s_%X,\n"\
1284 "\t\t\t\t\t\tevent_%s);\n",
1285 fac
->name
, fac
->checksum
, event
->name
);
1290 /* For each trace */
1292 fprintf(fd
, "list_for_each_entry_rcu(trace, <t_traces.head, list) {\n");
1294 fprintf(fd
, "if(!trace->active) continue;\n\n");
1296 if(event
->per_trace
) {
1298 fprintf(fd
, "if(dest_trace != trace) continue;\n\n");
1302 fprintf(fd
, "channel = ltt_get_channel_from_index(trace, index);\n");
1304 fprintf(fd
, "relayfs_buf = channel->rchan->buf[channel->rchan->buf->cpu];\n");
1309 /* If error, increment event lost counter (done by ltt_reserve_slot) and
1312 fprintf(fd
, "slot_size = 0;\n");
1314 fprintf(fd
, "buffer = ltt_reserve_slot(trace, relayfs_buf,\n");
1316 fprintf(fd
, "reserve_size, &slot_size, &tsc,\n");
1318 fprintf(fd
, "&before_hdr_pad, &after_hdr_pad);\n");
1319 /* If error, return */
1321 fprintf(fd
, "if(!buffer) return;\n\n");
1323 /* write data : assume stack alignment is the same as struct alignment. */
1325 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1326 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1327 type_descriptor_t
*type
= field
->type
;
1331 switch(type
->type
) {
1337 fprintf(fd
, "from = %s;\n", field
->name
);
1340 fprintf(fd
, "from = &%s;\n", field
->name
);
1345 if(print_type_write(type
,
1346 fd
, 2, basename
, field
->name
)) return 1;
1349 /* Don't forget to flush pending memcpy */
1351 fprintf(fd
, "/* Flush pending memcpy */\n");
1353 fprintf(fd
, "if(len != 0) {\n");
1355 fprintf(fd
, "memcpy(buffer+to_base+to, from, len);\n");
1357 fprintf(fd
, "to += len;\n");
1358 //print_tabs(3, fd);
1359 //fprintf(fd, "from += len;\n");
1361 fprintf(fd
, "len = 0;\n");
1370 fprintf(fd
, "ltt_commit_slot(relayfs_buf, buffer, slot_size);\n\n");
1373 fprintf(fd
, "}\n\n");
1377 fprintf(fd
, "ltt_nesting[smp_processor_id()]--;\n");
1379 fprintf(fd
, "preempt_enable_no_resched();\n");
1382 fprintf(fd
, "#endif //(!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_%s))\n\n",
1388 /* ltt-facility-name.h : main logging header.
1391 void print_log_header_head(facility_t
*fac
, FILE *fd
)
1393 fprintf(fd
, "#ifndef _LTT_FACILITY_%s_H_\n", fac
->capname
);
1394 fprintf(fd
, "#define _LTT_FACILITY_%s_H_\n\n", fac
->capname
);
1395 fprintf(fd
, "#include <linux/types.h>\n");
1396 fprintf(fd
, "#include <linux/ltt/ltt-facility-id-%s.h>\n", fac
->name
);
1397 fprintf(fd
, "#include <linux/ltt-core.h>\n");
1403 int print_log_header_types(facility_t
*fac
, FILE *fd
)
1405 sequence_t
*types
= &fac
->named_types
.values
;
1406 fprintf(fd
, "/* Named types */\n");
1409 for(unsigned int i
= 0; i
< types
->position
; i
++) {
1410 /* For each named type, print the definition */
1411 if((print_type_declaration(types
->array
[i
], fd
,
1412 0, "", ""))) return 1;
1413 /* Print also the align function */
1414 if((print_type_alignment_fct(types
->array
[i
], fd
,
1415 0, "", ""))) return 1;
1416 /* Print also the write function */
1417 if((print_type_write_fct(types
->array
[i
], fd
,
1418 0, "", ""))) return 1;
1423 int print_log_header_events(facility_t
*fac
, FILE *fd
)
1425 sequence_t
*events
= &fac
->events
;
1426 char basename
[PATH_MAX
];
1427 unsigned int facname_len
;
1429 strncpy(basename
, fac
->name
, PATH_MAX
);
1430 facname_len
= strlen(basename
);
1431 strncat(basename
, "_", PATH_MAX
-facname_len
);
1432 facname_len
= strlen(basename
);
1434 for(unsigned int i
= 0; i
< events
->position
; i
++) {
1435 event_t
*event
= (event_t
*)events
->array
[i
];
1436 strncpy(&basename
[facname_len
], event
->name
, PATH_MAX
-facname_len
);
1438 /* For each event, print structure, and then logging function */
1439 fprintf(fd
, "/* Event %s structures */\n",
1441 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
1442 /* For each unnamed type, print the definition */
1443 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
1444 type_descriptor_t
*t
= f
->type
;
1445 if(t
->type_name
== NULL
) {
1446 if((print_type_declaration(t
, fd
, 0, basename
, f
->name
))) return 1;
1447 /* Print also the align function */
1448 if((print_type_alignment_fct(t
, fd
, 0, basename
, f
->name
))) return 1;
1449 /* Print also the write function */
1450 if((print_type_write_fct(t
, fd
, 0, basename
, f
->name
))) return 1;
1456 fprintf(fd
, "/* Event %s logging function */\n",
1459 if(print_event_logging_function(basename
, fac
, event
, fd
)) return 1;
1468 void print_log_header_tail(facility_t
*fac
, FILE *fd
)
1470 fprintf(fd
, "#endif //_LTT_FACILITY_%s_H_\n",fac
->capname
);
1473 int print_log_header(facility_t
*fac
)
1475 char filename
[PATH_MAX
];
1476 unsigned int filename_size
= 0;
1478 dprintf("%s\n", fac
->name
);
1480 strcpy(filename
, "ltt-facility-");
1481 filename_size
= strlen(filename
);
1483 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1484 filename_size
= strlen(filename
);
1486 strncat(filename
, ".h", PATH_MAX
- filename_size
);
1487 filename_size
= strlen(filename
);
1490 fd
= fopen(filename
, "w");
1492 printf("Error opening file %s for writing : %s\n",
1493 filename
, strerror(errno
));
1497 /* Print file head */
1498 print_log_header_head(fac
, fd
);
1500 /* print named types in declaration order */
1501 if(print_log_header_types(fac
, fd
)) return 1;
1504 if(print_log_header_events(fac
, fd
)) return 1;
1506 /* Print file tail */
1507 print_log_header_tail(fac
, fd
);
1516 /* ltt-facility-id-name.h : facility id.
1518 int print_id_header(facility_t
*fac
)
1520 char filename
[PATH_MAX
];
1521 unsigned int filename_size
= 0;
1523 char basename
[PATH_MAX
];
1524 char basename_len
= 0;
1526 dprintf("%s\n", fac
->name
);
1528 strcpy(filename
, "ltt-facility-id-");
1529 filename_size
= strlen(filename
);
1531 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1532 filename_size
= strlen(filename
);
1534 strncat(filename
, ".h", PATH_MAX
- filename_size
);
1535 filename_size
= strlen(filename
);
1538 fd
= fopen(filename
, "w");
1540 printf("Error opening file %s for writing : %s\n",
1541 filename
, strerror(errno
));
1545 fprintf(fd
, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
1546 fprintf(fd
, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac
->capname
);
1547 fprintf(fd
, "#ifdef CONFIG_LTT\n");
1549 fprintf(fd
,"#include <linux/ltt-facilities.h>\n\n");
1551 fprintf(fd
,"/**** facility handle ****/\n\n");
1552 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s_%X;\n",
1553 fac
->name
, fac
->checksum
);
1554 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s;\n\n\n",fac
->name
);
1556 strncpy(basename
, fac
->name
, PATH_MAX
);
1557 basename_len
= strlen(basename
);
1558 strncat(basename
, "_", PATH_MAX
- basename_len
);
1561 fprintf(fd
,"/**** event index ****/\n\n");
1562 fprintf(fd
,"enum %s_event {\n",fac
->name
);
1564 for(unsigned int i
= 0; i
< fac
->events
.position
; i
++) {
1565 event_t
*event
= (event_t
*)fac
->events
.array
[i
];
1566 strncpy(basename
+basename_len
, event
->name
, PATH_MAX
-basename_len
);
1568 fprintf(fd
, "event_%s,\n", basename
);
1571 fprintf(fd
, "facility_%s_num_events\n", fac
->name
);
1572 fprintf(fd
, "};\n");
1576 fprintf(fd
, "#endif //CONFIG_LTT\n");
1577 fprintf(fd
, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
1586 /* ltt-facility-loader-name.h : facility specific loader info.
1588 int print_loader_header(facility_t
*fac
)
1590 char filename
[PATH_MAX
];
1591 unsigned int filename_size
= 0;
1593 dprintf("%s\n", fac
->name
);
1595 strcpy(filename
, "ltt-facility-loader-");
1596 filename_size
= strlen(filename
);
1598 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1599 filename_size
= strlen(filename
);
1601 strncat(filename
, ".h", PATH_MAX
- filename_size
);
1602 filename_size
= strlen(filename
);
1605 fd
= fopen(filename
, "w");
1607 printf("Error opening file %s for writing : %s\n",
1608 filename
, strerror(errno
));
1612 fprintf(fd
, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
1613 fprintf(fd
, "#define _LTT_FACILITY_LOADER_%s_H_\n\n", fac
->capname
);
1614 fprintf(fd
, "#ifdef CONFIG_LTT\n\n");
1615 fprintf(fd
,"#include <linux/ltt-facilities.h>\n");
1616 fprintf(fd
,"#include <linux/ltt/ltt-facility-id-%s.h>\n\n",
1618 fprintf(fd
,"ltt_facility_t\tltt_facility_%s;\n", fac
->name
);
1619 fprintf(fd
,"ltt_facility_t\tltt_facility_%s_%X;\n\n",
1620 fac
->name
, fac
->checksum
);
1622 fprintf(fd
,"#define LTT_FACILITY_SYMBOL\t\t\t\t\t\t\tltt_facility_%s\n",
1624 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM_SYMBOL\t\tltt_facility_%s_%X\n",
1625 fac
->name
, fac
->checksum
);
1626 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM\t\t\t\t\t\t0x%X\n", fac
->checksum
);
1627 fprintf(fd
,"#define LTT_FACILITY_NAME\t\t\t\t\t\t\t\t\"%s\"\n", fac
->name
);
1628 fprintf(fd
,"#define LTT_FACILITY_NUM_EVENTS\t\t\t\t\tfacility_%s_num_events\n\n",
1630 fprintf(fd
, "#endif //CONFIG_LTT\n\n");
1631 fprintf(fd
, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
1638 /* ltt-facility-loader-name.c : generic faciilty loader
1640 int print_loader_c(facility_t
*fac
)
1642 char filename
[PATH_MAX
];
1643 unsigned int filename_size
= 0;
1645 dprintf("%s\n", fac
->name
);
1647 strcpy(filename
, "ltt-facility-loader-");
1648 filename_size
= strlen(filename
);
1650 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
1651 filename_size
= strlen(filename
);
1653 strncat(filename
, ".c", PATH_MAX
- filename_size
);
1654 filename_size
= strlen(filename
);
1657 fd
= fopen(filename
, "w");
1659 printf("Error opening file %s for writing : %s\n",
1660 filename
, strerror(errno
));
1664 fprintf(fd
, "/*\n");
1665 fprintf(fd
, " * ltt-facility-loader-%s.c\n", fac
->name
);
1666 fprintf(fd
, " *\n");
1667 fprintf(fd
, " * (C) Copyright 2005 - \n");
1668 fprintf(fd
, " * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)\n");
1669 fprintf(fd
, " *\n");
1670 fprintf(fd
, " * Contains the LTT facility loader.\n");
1671 fprintf(fd
, " *\n");
1672 fprintf(fd
, " */\n");
1675 fprintf(fd
, "#include <linux/ltt-facilities.h>\n");
1676 fprintf(fd
, "#include <linux/module.h>\n");
1677 fprintf(fd
, "#include <linux/init.h>\n");
1678 fprintf(fd
, "#include <linux/config.h>\n");
1679 fprintf(fd
, "#include \"ltt-facility-loader-%s.h\"\n", fac
->name
);
1682 fprintf(fd
, "#ifdef CONFIG_LTT\n");
1684 fprintf(fd
, "EXPORT_SYMBOL(LTT_FACILITY_SYMBOL);\n");
1685 fprintf(fd
, "EXPORT_SYMBOL(LTT_FACILITY_CHECKSUM_SYMBOL);\n");
1687 fprintf(fd
, "static const char ltt_facility_name[] = LTT_FACILITY_NAME;\n");
1689 fprintf(fd
, "#define SYMBOL_STRING(sym) #sym\n");
1691 fprintf(fd
, "static struct ltt_facility facility = {\n");
1692 fprintf(fd
, "\t.name = ltt_facility_name,\n");
1693 fprintf(fd
, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n");
1694 fprintf(fd
, "\t.checksum = LTT_FACILITY_CHECKSUM,\n");
1695 fprintf(fd
, "\t.symbol = SYMBOL_STRING(LTT_FACILITY_SYMBOL),\n");
1696 fprintf(fd
, "};\n");
1698 fprintf(fd
, "#ifndef MODULE\n");
1700 fprintf(fd
, "/* Built-in facility. */\n");
1702 fprintf(fd
, "static int __init facility_init(void)\n");
1704 fprintf(fd
, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init in kernel\\n\");\n", fac
->name
);
1706 fprintf(fd
, "\tLTT_FACILITY_SYMBOL = ltt_facility_builtin_register(&facility);\n");
1707 fprintf(fd
, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
1708 fprintf(fd
, "\t\n");
1709 fprintf(fd
, "\treturn LTT_FACILITY_SYMBOL;\n");
1711 fprintf(fd
, "__initcall(facility_init);\n");
1715 fprintf(fd
, "#else \n");
1717 fprintf(fd
, "/* Dynamic facility. */\n");
1719 fprintf(fd
, "static int __init facility_init(void)\n");
1721 fprintf(fd
, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init dynamic\\n\");\n", fac
->name
);
1723 fprintf(fd
, "\tLTT_FACILITY_SYMBOL = ltt_facility_dynamic_register(&facility);\n");
1724 fprintf(fd
, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
1726 fprintf(fd
, "\treturn LTT_FACILITY_SYMBOL;\n");
1729 fprintf(fd
, "static void __exit facility_exit(void)\n");
1731 fprintf(fd
, "\tint err;\n");
1733 fprintf(fd
, "\terr = ltt_facility_dynamic_unregister(LTT_FACILITY_SYMBOL);\n");
1734 fprintf(fd
, "\tif(err != 0)\n");
1735 fprintf(fd
, "\t\tprintk(KERN_ERR \"LTT : Error in unregistering facility.\\n\");\n");
1739 fprintf(fd
, "module_init(facility_init)\n");
1740 fprintf(fd
, "module_exit(facility_exit)\n");
1743 fprintf(fd
, "MODULE_LICENSE(\"GPL\");\n");
1744 fprintf(fd
, "MODULE_AUTHOR(\"Mathieu Desnoyers\");\n");
1745 fprintf(fd
, "MODULE_DESCRIPTION(\"Linux Trace Toolkit Facility\");\n");
1747 fprintf(fd
, "#endif //MODULE\n");
1749 fprintf(fd
, "#endif //CONFIG_LTT\n");
1759 /* code taken from ltt_facility_open in ltt/facility.c in lttv */
1761 /*****************************************************************************
1763 * ltt_facility_open : open facilities
1765 * pathname : the path name of the facility
1767 * Open the facility corresponding to the right checksum.
1769 *returns the facility on success, NULL on error.
1770 ****************************************************************************/
1771 facility_t
*ltt_facility_open(char * pathname
)
1776 facility_t
* fac
= NULL
;
1777 char buffer
[BUFFER_SIZE
];
1778 int generated
= FALSE
;
1780 in
.buffer
= &(buffer
[0]);
1782 in
.error
= error_callback
;
1786 in
.fp
= fopen(in
.name
, "r");
1793 token
= getToken(&in
);
1794 if(in
.type
== ENDFILE
) break;
1797 printf("More than one facility in the file. Only using the first one.\n");
1801 if(strcmp(token
, "<")) in
.error(&in
,"not a facility file");
1802 token
= getName(&in
);
1804 if(strcmp("facility",token
) == 0) {
1805 fac
= malloc(sizeof(facility_t
));
1807 fac
->description
= NULL
;
1808 sequence_init(&(fac
->events
));
1809 table_init(&(fac
->named_types
));
1810 sequence_init(&(fac
->unnamed_types
));
1812 parseFacility(&in
, fac
);
1814 //check if any namedType is not defined
1815 checkNamedTypesImplemented(&fac
->named_types
);
1817 generateChecksum(fac
->name
, &fac
->checksum
, &fac
->events
);
1822 printf("facility token was expected in file %s\n", in
.name
);
1833 printf("Cannot find facility %s\n", pathname
);
1840 /* Close the facility */
1841 void ltt_facility_close(facility_t
*fac
)
1845 free(fac
->description
);
1846 freeEvents(&fac
->events
);
1847 sequence_dispose(&fac
->events
);
1848 freeNamedType(&fac
->named_types
);
1849 table_dispose(&fac
->named_types
);
1850 freeTypes(&fac
->unnamed_types
);
1851 sequence_dispose(&fac
->unnamed_types
);
1857 void show_help(int argc
, char ** argv
)
1859 printf("Genevent help : \n");
1861 printf("Use %s name.xml\n", argv
[0]);
1862 printf("to create :\n");
1863 printf("ltt-facility-name.h\n");
1864 printf("ltt-facility-id-name.h\n");
1865 printf("ltt-facility-loader-name.h\n");
1866 printf("ltt-facility-loader-name.c\n");
1867 printf("In the current directory.\n");
1871 /* Parse program arguments */
1873 * 0 : continue program
1874 * -1 : stop program, return 0
1875 * > 0 : stop program, return value as exit.
1877 int check_args(int argc
, char **argv
)
1880 printf("Not enough arguments\n");
1881 show_help(argc
, argv
);
1885 if(strcmp(argv
[1], "-h") == 0) {
1886 show_help(argc
, argv
);
1893 int main(int argc
, char **argv
)
1898 err
= check_args(argc
, argv
);
1899 if(err
> 0) return err
;
1900 else if(err
< 0) return 0;
1902 /* open the facility */
1903 fac
= ltt_facility_open(argv
[1]);
1905 printf("Error opening file %s for reading : %s\n",
1906 argv
[1], strerror(errno
));
1910 /* generate the output C files */
1913 /* ltt-facility-name.h : main logging header.
1915 err
= print_log_header(fac
);
1918 /* ltt-facility-id-name.h : facility id.
1920 err
= print_id_header(fac
);
1923 /* ltt-facility-loader-name.h : facility specific loader info.
1925 err
= print_loader_header(fac
);
1928 /* ltt-facility-loader-name.c : generic faciilty loader
1930 err
= print_loader_c(fac
);
1933 /* close the facility */
1934 ltt_facility_close(fac
);
This page took 0.08131 seconds and 4 git commands to generate.