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: ",\
90 enum user_fct_types
{ USER_FCT_PROTO
, USER_FCT_DECLARATION
} ;
94 void print_tabs(unsigned int tabs
, FILE *fd
)
96 for(unsigned int i
= 0; i
<tabs
;i
++)
102 * Copied from construct_types_and_fields in LTTV facility.c */
104 int print_type(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
105 char *nest_name
, char *field_name
)
107 char basename
[PATH_MAX
];
108 unsigned int basename_len
= 0;
110 strcpy(basename
, nest_name
);
111 basename_len
= strlen(basename
);
113 /* For a named type, we use the type_name directly */
114 if(td
->type_name
!= NULL
) {
115 strncpy(basename
, td
->type_name
, PATH_MAX
);
116 basename_len
= strlen(basename
);
118 /* For a unnamed type, there must be a field name */
119 if((basename_len
!= 0)
120 && (basename
[basename_len
-1] != '_')
121 && (field_name
[0] != '\0')) {
122 strncat(basename
, "_", PATH_MAX
- basename_len
);
123 basename_len
= strlen(basename
);
125 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
130 fprintf(fd
, "%s", intOutputTypes
[getSizeindex(td
->size
)]);
133 fprintf(fd
, "%s", uintOutputTypes
[getSizeindex(td
->size
)]);
136 fprintf(fd
, "signed char");
139 fprintf(fd
, "unsigned char");
142 fprintf(fd
, "short");
145 fprintf(fd
, "unsigned short");
151 fprintf(fd
, "unsigned int");
154 fprintf(fd
, "%s", floatOutputTypes
[getSizeindex(td
->size
)]);
157 fprintf(fd
, "const void *");
163 fprintf(fd
, "unsigned long");
166 fprintf(fd
, "size_t");
169 fprintf(fd
, "ssize_t");
172 fprintf(fd
, "off_t");
175 fprintf(fd
, "const char *");
178 fprintf(fd
, "enum lttng_%s", basename
);
181 fprintf(fd
, "lttng_array_%s", basename
);
184 fprintf(fd
, "lttng_sequence_%s", basename
);
187 fprintf(fd
, "struct lttng_%s", basename
);
190 fprintf(fd
, "union lttng_%s", basename
);
193 printf("print_type : unknown type\n");
200 /* Print logging function argument */
201 int print_arg(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
202 char *nest_name
, char *field_name
)
204 char basename
[PATH_MAX
];
205 unsigned int basename_len
= 0;
207 strcpy(basename
, nest_name
);
208 basename_len
= strlen(basename
);
210 /* For a named type, we use the type_name directly */
211 if(td
->type_name
!= NULL
) {
212 strncpy(basename
, td
->type_name
, PATH_MAX
);
213 basename_len
= strlen(basename
);
215 /* For a unnamed type, there must be a field name */
216 if((basename_len
!= 0)
217 && (basename
[basename_len
-1] != '_')
218 && (field_name
[0] != '\0')) {
219 strncat(basename
, "_", PATH_MAX
- basename_len
);
220 basename_len
= strlen(basename
);
222 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
225 print_tabs(tabs
, fd
);
229 fprintf(fd
, "%s", intOutputTypes
[getSizeindex(td
->size
)]);
230 fprintf(fd
, " lttng_param_%s", field_name
);
233 fprintf(fd
, "%s", uintOutputTypes
[getSizeindex(td
->size
)]);
234 fprintf(fd
, " lttng_param_%s", field_name
);
237 fprintf(fd
, "signed char");
238 fprintf(fd
, " lttng_param_%s", field_name
);
241 fprintf(fd
, "unsigned char");
242 fprintf(fd
, " lttng_param_%s", field_name
);
245 fprintf(fd
, "short");
246 fprintf(fd
, " lttng_param_%s", field_name
);
249 fprintf(fd
, "unsigned short");
250 fprintf(fd
, " lttng_param_%s", field_name
);
254 fprintf(fd
, " lttng_param_%s", field_name
);
257 fprintf(fd
, "unsigned int");
258 fprintf(fd
, " lttng_param_%s", field_name
);
261 fprintf(fd
, "%s", floatOutputTypes
[getSizeindex(td
->size
)]);
262 fprintf(fd
, " lttng_param_%s", field_name
);
265 fprintf(fd
, "const void *");
266 fprintf(fd
, " lttng_param_%s", field_name
);
270 fprintf(fd
, " lttng_param_%s", field_name
);
273 fprintf(fd
, "unsigned long");
274 fprintf(fd
, " lttng_param_%s", field_name
);
277 fprintf(fd
, "size_t");
278 fprintf(fd
, " lttng_param_%s", field_name
);
281 fprintf(fd
, "ssize_t");
282 fprintf(fd
, " lttng_param_%s", field_name
);
285 fprintf(fd
, "off_t");
286 fprintf(fd
, " lttng_param_%s", field_name
);
289 fprintf(fd
, "const char *");
290 fprintf(fd
, " lttng_param_%s", field_name
);
293 fprintf(fd
, "enum lttng_%s", basename
);
294 fprintf(fd
, " lttng_param_%s", field_name
);
297 fprintf(fd
, "lttng_array_%s", basename
);
298 fprintf(fd
, " lttng_param_%s", field_name
);
301 fprintf(fd
, "lttng_sequence_%s *", basename
);
302 fprintf(fd
, " lttng_param_%s", field_name
);
305 fprintf(fd
, "struct lttng_%s *", basename
);
306 fprintf(fd
, " lttng_param_%s", field_name
);
309 fprintf(fd
, "union lttng_%s *", basename
);
310 fprintf(fd
, " lttng_param_%s", field_name
);
313 printf("print_type : unknown type\n");
321 /* Does the type has a fixed size ? (as know from the compiler)
324 * 0 : variable length
326 int has_type_fixed_size(type_descriptor_t
*td
)
345 case UNION
: /* The union must have fixed size children. Must be checked by
355 int has_type_fixed
= 0;
356 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
357 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
358 type_descriptor_t
*type
= field
->type
;
360 has_type_fixed
= has_type_fixed_size(type
);
361 if(!has_type_fixed
) return 0;
367 assert(td
->size
>= 0);
368 return has_type_fixed_size(((field_t
*)td
->fields
.array
[0])->type
);
371 printf("There is a type defined to NONE : bad.\n");
375 return 0; //make gcc happy.
382 /* print type declaration.
384 * Copied from construct_types_and_fields in LTTV facility.c */
386 int print_type_declaration(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
387 char *nest_name
, char *field_name
)
389 char basename
[PATH_MAX
];
390 unsigned int basename_len
= 0;
392 if(td
->custom_write
) return 0; /* Does print custom type */
394 strncpy(basename
, nest_name
, PATH_MAX
);
395 basename_len
= strlen(basename
);
397 /* For a named type, we use the type_name directly */
398 if(td
->type_name
!= NULL
) {
399 strncpy(basename
, td
->type_name
, PATH_MAX
);
400 basename_len
= strlen(basename
);
402 /* For a unnamed type, there must be a field name, except for
404 if((basename_len
!= 0)
405 && (basename
[basename_len
-1] != '_'
406 && (field_name
[0] != '\0'))) {
407 strncat(basename
, "_", PATH_MAX
- basename_len
);
408 basename_len
= strlen(basename
);
410 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
415 fprintf(fd
, "enum lttng_%s", basename
);
417 for(unsigned int i
=0;i
<td
->labels
.position
;i
++){
419 fprintf(fd
, "LTTNG_%s = %d", ((char*)td
->labels
.array
[i
]),
420 (*(int*)td
->labels_values
.array
[i
]));
428 dprintf("%s\n", basename
);
429 assert(td
->size
>= 0);
430 if(((field_t
*)td
->fields
.array
[0])->type
->type_name
== NULL
) {
431 /* Not a named nested type : we must print its declaration first */
432 if(print_type_declaration(((field_t
*)td
->fields
.array
[0])->type
,
433 fd
, 0, basename
, "")) return 1;
435 fprintf(fd
, "#define LTTNG_ARRAY_SIZE_%s %zu\n", basename
,
437 fprintf(fd
, "typedef ");
438 if(print_type(((field_t
*)td
->fields
.array
[0])->type
,
439 fd
, tabs
, basename
, "")) return 1;
440 fprintf(fd
, " lttng_array_%s[LTTNG_ARRAY_SIZE_%s];\n", basename
,
445 /* We assume that the sequence length type does not need to be declared.
447 if(((field_t
*)td
->fields
.array
[1])->type
->type_name
== NULL
) {
448 /* Not a named nested type : we must print its declaration first */
449 if(print_type_declaration(((field_t
*)td
->fields
.array
[1])->type
,
450 fd
, 0, basename
, "")) return 1;
452 fprintf(fd
, "typedef struct lttng_sequence_%s lttng_sequence_%s;\n",
455 fprintf(fd
, "struct lttng_sequence_%s", basename
);
458 if(print_type(((field_t
*)td
->fields
.array
[0])->type
,
459 fd
, tabs
, basename
, "")) return 1;
460 fprintf(fd
, " len;\n");
462 fprintf(fd
, "const ");
463 if(print_type(((field_t
*)td
->fields
.array
[1])->type
,
464 fd
, tabs
, basename
, "")) return 1;
465 fprintf(fd
, " *array;\n");
466 fprintf(fd
, "};\n"); /* We do not LTT_ALIGN, because we never copy
467 it to the buffer directly. */
472 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
473 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
474 type_descriptor_t
*type
= field
->type
;
475 if(type
->type_name
== NULL
) {
476 /* Not a named nested type : we must print its declaration first */
477 if(print_type_declaration(type
,
478 fd
, 0, basename
, field
->name
)) return 1;
481 fprintf(fd
, "struct lttng_%s", basename
);
483 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
484 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
485 type_descriptor_t
*type
= field
->type
;
487 if(print_type(type
, fd
, tabs
, basename
, field
->name
)) return 1;
489 fprintf(fd
, "%s", field
->name
);
492 fprintf(fd
, "} LTT_ALIGN;\n");
496 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
497 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
498 type_descriptor_t
*type
= field
->type
;
499 if(type
->type_name
== NULL
) {
500 /* Not a named nested type : we must print its declaration first */
501 if(print_type_declaration(type
,
502 fd
, 0, basename
, field
->name
)) return 1;
505 fprintf(fd
, "union lttng_%s", basename
);
507 for(unsigned i
=0;i
<td
->fields
.position
;i
++){
508 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
509 type_descriptor_t
*type
= field
->type
;
511 if(print_type(type
, fd
, tabs
, basename
, field
->name
)) return 1;
513 fprintf(fd
, "%s", field
->name
);
516 fprintf(fd
, "} LTT_ALIGN;\n");
520 dprintf("print_type_declaration : unknown type or nothing to declare.\n");
528 /* print type alignment.
530 * Copied from construct_types_and_fields in LTTV facility.c
532 * basename is the name which identifies the type (along with a prefix
535 int print_type_alignment(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
536 char *nest_name
, char *field_name
, char *obj_prefix
)
538 char basename
[PATH_MAX
];
539 unsigned int basename_len
= 0;
541 strncpy(basename
, nest_name
, PATH_MAX
);
542 basename_len
= strlen(basename
);
544 /* For a named type, we use the type_name directly */
545 if(td
->type_name
!= NULL
) {
546 strncpy(basename
, td
->type_name
, PATH_MAX
);
547 basename_len
= strlen(basename
);
549 /* For a unnamed type, there must be a field name, except for
551 if((basename_len
!= 0)
552 && (basename
[basename_len
-1] != '_'
553 && field_name
!= NULL
554 && (field_name
[0] != '\0'))) {
555 strncat(basename
, "_", PATH_MAX
- basename_len
);
556 basename_len
= strlen(basename
);
558 if(field_name
!= NULL
)
559 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
562 if(field_name
[0] == '\0') {
563 /* We are in a write function : it's the obj that we must align. */
566 fprintf(fd
, "lttng_get_alignment_sequence_%s(%s)", basename
,
570 fprintf(fd
, "lttng_get_alignment_struct_%s(%s)", basename
,
574 fprintf(fd
, "lttng_get_alignment_union_%s(%s)", basename
,
578 fprintf(fd
, "lttng_get_alignment_array_%s(%s)", basename
,
581 fprintf(fd
, "sizeof(char)");
599 fprintf(fd
, "sizeof(");
600 if(print_type(td
, fd
, 0, basename
, "")) return 1;
605 printf("error : type unexpected\n");
628 fprintf(fd
, "sizeof(");
629 if(print_type(td
, fd
, 0, basename
, "")) return 1;
633 fprintf(fd
, "sizeof(char)");
636 fprintf(fd
, "lttng_get_alignment_sequence_%s(&%s%s)", basename
,
637 obj_prefix
, field_name
);
640 fprintf(fd
, "lttng_get_alignment_struct_%s(&%s%s)", basename
,
641 obj_prefix
, field_name
);
644 fprintf(fd
, "lttng_get_alignment_union_%s(&%s%s)", basename
,
645 obj_prefix
, field_name
);
648 fprintf(fd
, "lttng_get_alignment_array_%s(%s%s)", basename
,
649 obj_prefix
, field_name
);
652 printf("error : type NONE unexpected\n");
663 * Copied from construct_types_and_fields in LTTV facility.c
665 * basename is the name which identifies the type (along with a prefix
668 int print_type_write(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
669 char *nest_name
, char *field_name
, char *obj_prefix
, int get_ptr
)
671 char basename
[PATH_MAX
];
672 unsigned int basename_len
= 0;
673 char get_ptr_char
[2] = "";
674 char custom
[PATH_MAX
] = "";
676 strncpy(basename
, nest_name
, PATH_MAX
);
677 basename_len
= strlen(basename
);
679 /* For a named type, we use the type_name directly */
680 if(td
->type_name
!= NULL
) {
681 strncpy(basename
, td
->type_name
, PATH_MAX
);
682 basename_len
= strlen(basename
);
684 /* For a unnamed type, there must be a field name, except for
686 if((basename_len
!= 0)
687 && (basename
[basename_len
-1] != '_'
688 && (field_name
[0] != '\0'))) {
689 strncat(basename
, "_", PATH_MAX
- basename_len
);
690 basename_len
= strlen(basename
);
692 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
696 strcpy(get_ptr_char
, "&");
699 if(td
->custom_write
) {
700 strcpy(custom
, "_custom");
720 print_tabs(tabs
, fd
);
721 fprintf(fd
, "align = ");
722 if(print_type_alignment(td
, fd
, 0, basename
, "", "obj")) return 1;
725 print_tabs(tabs
, fd
);
726 fprintf(fd
, "if (*len == 0) {\n");
727 print_tabs(tabs
+1, fd
);
728 fprintf(fd
, "*to += ltt_align(*to, align); /* align output */\n");
729 print_tabs(tabs
, fd
);
730 fprintf(fd
, "} else {\n");
731 print_tabs(tabs
+1, fd
);
732 fprintf(fd
, "*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */\n");
733 print_tabs(tabs
, fd
);
737 print_tabs(tabs
, fd
);
738 fprintf(fd
, "*len += ");
739 fprintf(fd
, "sizeof(");
740 if(print_type(td
, fd
, 0, basename
, "")) return 1;
745 print_tabs(tabs
, fd
);
747 "lttng_write%s_string_%s(buffer, to_base, to, from, len, %s%s);\n",
748 custom
, basename
, obj_prefix
, field_name
);
751 print_tabs(tabs
, fd
);
753 "lttng_write%s_sequence_%s(buffer, to_base, to, from, len, %s%s%s);",
754 custom
, basename
, get_ptr_char
, obj_prefix
, field_name
);
757 print_tabs(tabs
, fd
);
759 "lttng_write%s_struct_%s(buffer, to_base, to, from, len, %s%s%s);",
760 custom
, basename
, get_ptr_char
, obj_prefix
, field_name
);
763 print_tabs(tabs
, fd
);
765 "lttng_write%s_union_%s(buffer, to_base, to, from, len, %s%s%s);",
766 custom
, basename
, get_ptr_char
, obj_prefix
, field_name
);
769 print_tabs(tabs
, fd
);
771 "lttng_write%s_array_%s(buffer, to_base, to, from, len, %s%s);",
772 custom
, basename
, obj_prefix
, field_name
);
775 printf("Error : type NONE unexpected\n");
783 /* print need local vars ?.
785 * Copied from print_type_write
787 * Does the type_write call needs local size and from variables ?
788 * return value : 1 yes, 0 no.
791 int has_type_local(type_descriptor_t
* td
)
820 printf("Error : type NONE unexpected\n");
830 /* print type alignment function.
832 * Copied from construct_types_and_fields in LTTV facility.c
834 * basename is the name which identifies the type (along with a prefix
837 int print_type_alignment_fct(type_descriptor_t
* td
, FILE *fd
,
839 char *nest_name
, char *field_name
)
841 char basename
[PATH_MAX
];
842 unsigned int basename_len
= 0;
844 if(td
->custom_write
) return 0; /* Does print custom type */
846 strncpy(basename
, nest_name
, PATH_MAX
);
847 basename_len
= strlen(basename
);
849 /* For a named type, we use the type_name directly */
850 if(td
->type_name
!= NULL
) {
851 strncpy(basename
, td
->type_name
, PATH_MAX
);
852 basename_len
= strlen(basename
);
854 /* For a unnamed type, there must be a field name, except for
856 if((basename_len
!= 0)
857 && (basename
[basename_len
-1] != '_'
858 && (field_name
[0] != '\0'))) {
859 strncat(basename
, "_", PATH_MAX
- basename_len
);
860 basename_len
= strlen(basename
);
862 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
867 if(((field_t
*)td
->fields
.array
[1])->type
->type_name
== NULL
) {
868 /* Not a named nested type : we must print its align fct */
869 if(print_type_alignment_fct(((field_t
*)td
->fields
.array
[1])->type
, fd
,
870 0, basename
, "")) return 1;
872 /* Function header */
873 fprintf(fd
, "static inline size_t lttng_get_alignment_sequence_%s(\n",
876 if(print_type(td
, fd
, 0, basename
, "")) return 1;
877 fprintf(fd
, " *obj)\n");
880 fprintf(fd
, "size_t align=0, localign;");
883 fprintf(fd
, "localign = ");
884 if(print_type_alignment(((field_t
*)td
->fields
.array
[0])->type
,
885 fd
, 0, basename
, "len", "obj->")) return 1;
888 fprintf(fd
, "align = max(align, localign);\n");
891 fprintf(fd
, "localign = ");
892 if(print_type_alignment(((field_t
*)td
->fields
.array
[1])->type
,
893 fd
, 0, basename
, "array[0]", "obj->")) return 1;
896 fprintf(fd
, "align = max(align, localign);\n");
899 fprintf(fd
, "return align;\n");
902 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
903 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
904 type_descriptor_t
*type
= field
->type
;
905 if(type
->type_name
== NULL
) {
906 /* Not a named nested type : we must print its align fct */
907 if(print_type_alignment_fct(type
, fd
,
908 0, basename
, field
->name
)) return 1;
911 /* Function header */
912 fprintf(fd
, "static inline size_t lttng_get_alignment_struct_%s(\n",
915 if(print_type(td
, fd
, 0, basename
, "")) return 1;
916 fprintf(fd
, " *obj)\n");
919 fprintf(fd
, "size_t align=0, localign;");
921 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
922 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
923 type_descriptor_t
*type
= field
->type
;
925 fprintf(fd
, "localign = ");
926 if(print_type_alignment(type
, fd
, 0, basename
, field
->name
, "obj->"))
930 fprintf(fd
, "align = max(align, localign);\n");
934 fprintf(fd
, "return align;\n");
938 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
939 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
940 type_descriptor_t
*type
= field
->type
;
941 if(type
->type_name
== NULL
) {
942 /* Not a named nested type : we must print its align fct */
943 if(print_type_alignment_fct(type
, fd
,
944 0, basename
, field
->name
)) return 1;
947 /* Function header */
948 fprintf(fd
, "static inline size_t lttng_get_alignment_union_%s(\n",
951 if(print_type(td
, fd
, 0, basename
, "")) return 1;
952 fprintf(fd
, " *obj)\n");
955 fprintf(fd
, "size_t align=0, localign;");
957 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
958 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
959 type_descriptor_t
*type
= field
->type
;
961 fprintf(fd
, "localign = ");
962 if(print_type_alignment(type
, fd
, 0, basename
, field
->name
, "obj->"))
966 fprintf(fd
, "align = max(align, localign);\n");
970 fprintf(fd
, "return align;\n");
974 if(((field_t
*)td
->fields
.array
[0])->type
->type_name
== NULL
) {
975 /* Not a named nested type : we must print its align fct */
976 if(print_type_alignment_fct(((field_t
*)td
->fields
.array
[0])->type
, fd
,
977 0, basename
, "")) return 1;
979 /* Function header */
980 fprintf(fd
, "static inline size_t lttng_get_alignment_array_%s(\n",
983 if(print_type(td
, fd
, 0, basename
, "")) return 1;
984 fprintf(fd
, " obj)\n");
987 fprintf(fd
, "return \n");
988 if(print_type_alignment(((field_t
*)td
->fields
.array
[0])->type
,
989 fd
, 0, basename
, "", "obj[0]"))
994 dprintf("print_type_alignment_fct : type has no alignment function.\n");
1000 /* Function footer */
1007 /* print type write function.
1009 * Copied from construct_types_and_fields in LTTV facility.c
1011 * basename is the name which identifies the type (along with a prefix
1014 int print_type_write_fct(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
1015 char *nest_name
, char *field_name
)
1017 char basename
[PATH_MAX
];
1018 unsigned int basename_len
= 0;
1020 if(td
->custom_write
) return 0; /* Does print custom type */
1022 strncpy(basename
, nest_name
, PATH_MAX
);
1023 basename_len
= strlen(basename
);
1025 /* For a named type, we use the type_name directly */
1026 if(td
->type_name
!= NULL
) {
1027 strncpy(basename
, td
->type_name
, PATH_MAX
);
1028 basename_len
= strlen(basename
);
1030 /* For a unnamed type, there must be a field name, except for
1032 if((basename_len
!= 0)
1033 && (basename
[basename_len
-1] != '_'
1034 && (field_name
[0] != '\0'))) {
1035 strncat(basename
, "_", PATH_MAX
- basename_len
);
1036 basename_len
= strlen(basename
);
1038 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
1043 if(((field_t
*)td
->fields
.array
[1])->type
->type_name
== NULL
) {
1044 /* Not a named nested type : we must print its write fct */
1045 if(print_type_write_fct(((field_t
*)td
->fields
.array
[1])->type
, fd
,
1046 0, basename
, "")) return 1;
1050 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
1051 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
1052 type_descriptor_t
*type
= field
->type
;
1053 if(type
->type_name
== NULL
) {
1054 /* Not a named nested type : we must print its write fct */
1055 if(print_type_write_fct(type
, fd
,
1056 0, basename
, field
->name
)) return 1;
1061 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
1062 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
1063 type_descriptor_t
*type
= field
->type
;
1064 if(type
->type_name
== NULL
) {
1065 /* Not a named nested type : we must print its write fct */
1066 if(print_type_write_fct(type
, fd
,
1067 0, basename
, field
->name
)) return 1;
1072 if(((field_t
*)td
->fields
.array
[0])->type
->type_name
== NULL
) {
1073 /* Not a named nested type : we must print its write fct */
1074 if(print_type_write_fct(((field_t
*)td
->fields
.array
[0])->type
, fd
,
1075 0, basename
, "")) return 1;
1081 dprintf("print_type_write_fct : type has no write function.\n");
1089 fprintf(fd
, "static inline void lttng_write_sequence_%s(\n",
1093 fprintf(fd
, "static inline void lttng_write_struct_%s(\n", basename
);
1096 fprintf(fd
, "static inline void lttng_write_union_%s(\n", basename
);
1099 fprintf(fd
, "static inline void lttng_write_array_%s(\n", basename
);
1102 fprintf(fd
, "static inline void lttng_write_string_%s(\n", basename
);
1105 printf("print_type_write_fct : type has no write function.\n");
1110 fprintf(fd
, "char *buffer,\n");
1112 fprintf(fd
, "size_t *to_base,\n");
1114 fprintf(fd
, "size_t *to,\n");
1116 fprintf(fd
, "const char **from,\n");
1118 fprintf(fd
, "size_t *len,\n");
1120 if(print_type(td
, fd
, 0, basename
, "")) return 1;
1124 fprintf(fd
, " *obj)\n");
1127 fprintf(fd
, " *obj)\n");
1130 fprintf(fd
, " *obj)\n");
1133 fprintf(fd
, " obj)\n");
1136 fprintf(fd
, " obj)\n");
1139 printf("print_type_write_fct : type has no write function.\n");
1148 fprintf(fd
, "size_t size;\n");
1155 fprintf(fd
, "size_t align;\n");
1162 fprintf(fd
, "/* Flush pending memcpy */\n");
1164 fprintf(fd
, "if (*len != 0) {\n");
1166 fprintf(fd
, "if (buffer != NULL)\n");
1168 fprintf(fd
, "memcpy(buffer+*to_base+*to, *from, *len);\n");
1172 fprintf(fd
, "*to += *len;\n");
1174 fprintf(fd
, "*len = 0;\n");
1182 printf("print_type_write_fct : type has no write function.\n");
1187 fprintf(fd
, "align = ");
1188 if(print_type_alignment(td
, fd
, 0, basename
, "", "obj")) return 1;
1192 fprintf(fd
, "if (*len == 0) {\n");
1194 fprintf(fd
, "*to += ltt_align(*to, align); /* align output */\n");
1196 fprintf(fd
, "} else {\n");
1198 fprintf(fd
, "*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */\n");
1203 /* First, check if the type has a fixed size. If it is the case, then the size
1204 * to write is know by the compiler : simply use a sizeof() */
1205 if(has_type_fixed_size(td
)) {
1207 fprintf(fd
, "/* Contains only fixed size fields : use compiler sizeof() */\n");
1210 fprintf(fd
, "*len += sizeof(");
1211 if(print_type(td
, fd
, 0, basename
, field_name
)) return 1;
1212 fprintf(fd
, ");\n");
1214 /* The type contains nested variable size subtypes :
1215 * we must write field by field. */
1217 fprintf(fd
, "/* Contains variable sized fields : must explode the structure */\n");
1223 fprintf(fd
, "/* Copy members */\n");
1224 // print_tabs(1, fd);
1225 // fprintf(fd, "size = sizeof(\n");
1226 if(print_type_write(((field_t
*)td
->fields
.array
[0])->type
,
1227 fd
, 1, basename
, "len", "obj->", 1)) return 1;
1229 // fprintf(fd, ");\n");
1230 // print_tabs(1, fd);
1231 // fprintf(fd, "*to += ltt_align(*to, size);\n");
1233 fprintf(fd
, "if (buffer != NULL)\n");
1235 fprintf(fd
, "memcpy(buffer+*to_base+*to, &obj->len, *len);\n");
1237 fprintf(fd
, "*to += *len;\n");
1239 fprintf(fd
, "*len = 0;\n");
1242 /* Write the child : varlen child or not ? */
1243 if(has_type_fixed_size(((field_t
*)td
->fields
.array
[1])->type
)) {
1244 /* Fixed size len child : use a multiplication of its size */
1245 // print_tabs(1, fd);
1246 // fprintf(fd, "size = sizeof(\n");
1248 //print_tabs(1, fd);
1249 /* We know that *len does not contain alignment because of the
1250 * previous align output. len is always 0 here. */
1251 if(print_type_write(((field_t
*)td
->fields
.array
[1])->type
,
1252 fd
, 1, basename
, "array[0]", "obj->", 1))
1254 // fprintf(fd, ");\n");
1257 fprintf(fd
, "*len = obj->len * (*len);\n");
1259 fprintf(fd
, "if (buffer != NULL)\n");
1261 fprintf(fd
, "memcpy(buffer+*to_base+*to, obj->array, *len);\n");
1263 fprintf(fd
, "*to += *len;\n");
1265 fprintf(fd
, "*len = 0;\n");
1269 fprintf(fd
, "/* Variable length child : iter. */\n");
1271 fprintf(fd
, "for (unsigned int i = 0; i < obj->len; i++) {\n");
1272 if(print_type_write(((field_t
*)td
->fields
.array
[1])->type
,
1273 fd
, 2, basename
, "array[i]", "obj->", 1)) return 1;
1279 fprintf(fd
, "/* Realign the *to_base on arch size, set *to to 0 */\n");
1281 fprintf(fd
, "*to += ltt_align(*to, sizeof(void *));\n");
1283 fprintf(fd
, "*to_base = *to_base+*to;\n");
1285 fprintf(fd
, "*to = 0;\n");
1288 fprintf(fd
, "/* Put source *from just after the C sequence */\n");
1290 fprintf(fd
, "*from = (const char*)(obj+1);\n");
1294 fprintf(fd
, "size = strlen(obj) + 1; /* Include final NULL char. */\n");
1296 fprintf(fd
, "if (buffer != NULL)\n");
1298 fprintf(fd
, "memcpy(buffer+*to_base+*to, obj, size);\n");
1300 fprintf(fd
, "*to += size;\n");
1303 fprintf(fd
, "/* Realign the *to_base on arch size, set *to to 0 */\n");
1305 fprintf(fd
, "*to += ltt_align(*to, sizeof(void *));\n");
1307 fprintf(fd
, "*to_base = *to_base+*to;\n");
1309 fprintf(fd
, "*to = 0;\n");
1312 fprintf(fd
, "/* Put source *from just after the C string */\n");
1314 fprintf(fd
, "*from += size;\n");
1317 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
1318 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
1319 type_descriptor_t
*type
= field
->type
;
1320 if(print_type_write(type
,
1321 fd
, 1, basename
, field
->name
, "obj->", 1)) return 1;
1326 printf("ERROR : A union CANNOT contain a variable size child.\n");
1330 /* Write the child : varlen child or not ? */
1331 if(has_type_fixed_size(((field_t
*)td
->fields
.array
[0])->type
)) {
1332 /* Error : if an array has a variable size, then its child must also
1333 * have a variable size. */
1337 fprintf(fd
, "/* Variable length child : iter. */\n");
1339 fprintf(fd
, "for (unsigned int i = 0; i < LTTNG_ARRAY_SIZE_%s; i++) {\n", basename
);
1340 if(print_type_write(((field_t
*)td
->fields
.array
[0])->type
,
1341 fd
, 2, basename
, "", "obj->array[i]", 1)) return 1;
1347 printf("print_type_write_fct : type has no write function.\n");
1355 /* Function footer */
1363 /* Print the logging function of an event. This is the core of genevent */
1364 int print_event_logging_function(char *basename
, facility_t
*fac
,
1365 event_t
*event
, FILE *fd
)
1367 fprintf(fd
, "static inline void trace_%s(\n", basename
);
1368 int has_argument
= 0;
1369 int has_type_fixed
= 0;
1371 /* Does it support per trace tracing ? */
1372 if(event
->per_trace
) {
1374 fprintf(fd
, "struct ltt_trace_struct *dest_trace");
1378 /* Does it support per tracefile tracing ? */
1379 if(event
->per_tracefile
) {
1384 fprintf(fd
, "unsigned int tracefile_index");
1388 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
1389 /* For each field, print the function argument */
1390 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
1391 type_descriptor_t
*t
= f
->type
;
1396 if(print_arg(t
, fd
, 2, basename
, f
->name
)) return 1;
1401 fprintf(fd
, "void");
1406 "#if (!defined(CONFIG_LTT) || (!defined(CONFIG_LTT_FACILITY_%s) && !defined(CONFIG_LTT_FACILITY_%s_MODULE)))\n",
1407 fac
->capname
, fac
->capname
);
1410 fprintf(fd
,"#else\n");
1413 /* Print the function variables */
1415 fprintf(fd
, "unsigned int index;\n");
1417 fprintf(fd
, "struct ltt_channel_struct *channel;\n");
1419 fprintf(fd
, "struct ltt_trace_struct *trace;\n");
1421 fprintf(fd
, "void *transport_data;\n");
1423 fprintf(fd
, "char *buffer = NULL;\n");
1425 fprintf(fd
, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
1427 fprintf(fd
, "size_t *to_base = &real_to_base;\n");
1429 fprintf(fd
, "size_t real_to = 0;\n");
1431 fprintf(fd
, "size_t *to = &real_to;\n");
1433 fprintf(fd
, "size_t real_len = 0;\n");
1435 fprintf(fd
, "size_t *len = &real_len;\n");
1437 fprintf(fd
, "size_t reserve_size;\n");
1439 fprintf(fd
, "size_t slot_size;\n");
1442 if(event
->fields
.position
> 0) {
1443 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1444 /* Search for at least one child with fixed size. It means
1445 * we need local variables.*/
1446 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1447 type_descriptor_t
*type
= field
->type
;
1448 has_type_fixed
= has_type_local(type
);
1449 if(has_type_fixed
) break;
1452 if(has_type_fixed
) {
1453 fprintf(fd
, "size_t align;\n");
1457 fprintf(fd
, "const char *real_from;\n");
1459 fprintf(fd
, "const char **from = &real_from;\n");
1462 fprintf(fd
, "u64 tsc;\n");
1464 fprintf(fd
, "size_t before_hdr_pad, after_hdr_pad, header_size;\n");
1468 fprintf(fd
, "if (ltt_traces.num_active_traces == 0)\n");
1470 fprintf(fd
, "return;\n");
1473 /* Calculate event variable len + event data alignment offset.
1474 * Assume that the padding for alignment starts at a void*
1476 * This excludes the header size and alignment. */
1479 fprintf(fd
, "/* For each field, calculate the field size. */\n");
1481 fprintf(fd
, "/* size = *to_base + *to + *len */\n");
1483 fprintf(fd
, "/* Assume that the padding for alignment starts at a\n");
1485 fprintf(fd
, " * sizeof(void *) address. */\n");
1488 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1489 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1490 type_descriptor_t
*type
= field
->type
;
1493 switch(type
->type
) {
1499 fprintf(fd
, "*from = (const char*)lttng_param_%s;\n", field
->name
);
1502 fprintf(fd
, "*from = (const char*)<tng_param_%s;\n", field
->name
);
1506 if(print_type_write(type
,
1507 fd
, 1, basename
, field
->name
, "lttng_param_", 0)) return 1;
1511 fprintf(fd
, "reserve_size = *to_base + *to + *len;\n");
1513 /* Take locks : make sure the trace does not vanish while we write on
1514 * it. A simple preemption disabling is enough (using rcu traces). */
1516 fprintf(fd
, "preempt_disable();\n");
1518 fprintf(fd
, "ltt_nesting[smp_processor_id()]++;\n");
1520 /* Get facility index */
1522 if(event
->per_tracefile
) {
1524 fprintf(fd
, "index = tracefile_index;\n");
1528 "index = ltt_get_index_from_facility_%s(" \
1529 "\t\t\t\t\t\tevent_%s_%s);\n",
1530 fac
->name
, fac
->name
, event
->name
);
1535 /* For each trace */
1537 fprintf(fd
, "list_for_each_entry_rcu(trace, <t_traces.head, list) {\n");
1539 fprintf(fd
, "if (!trace->active)\n");
1541 fprintf(fd
, "continue;\n\n");
1543 if(event
->per_trace
) {
1545 fprintf(fd
, "if (dest_trace != trace)\n");
1547 fprintf(fd
, "continue;\n\n");
1551 fprintf(fd
, "channel = ltt_get_channel_from_index(trace, index);\n");
1556 /* If error, increment event lost counter (done by ltt_reserve_slot) and
1559 fprintf(fd
, "slot_size = 0;\n");
1561 fprintf(fd
, "buffer = ltt_reserve_slot(trace, channel, &transport_data,\n");
1563 fprintf(fd
, "reserve_size, &slot_size, &tsc,\n");
1565 fprintf(fd
, "&before_hdr_pad, &after_hdr_pad, &header_size);\n");
1566 /* If error, return */
1568 fprintf(fd
, "if (!buffer)\n");
1570 fprintf(fd
, "continue; /* buffer full */\n\n");
1571 //print_tabs(2, fd);
1573 // fprintf(fd, "goto commit; /* DEBUG : never actually write. */\n\n");
1575 fprintf(fd
, "*to_base = *to = *len = 0;\n");
1578 /* Write event header */
1580 fprintf(fd
, "ltt_write_event_header(trace, channel, buffer,\n");
1582 fprintf(fd
, "ltt_facility_%s_%X, event_%s_%s,\n", fac
->name
, fac
->checksum
,
1583 fac
->name
, event
->name
);
1585 fprintf(fd
, "reserve_size, before_hdr_pad, tsc);\n");
1587 fprintf(fd
, "*to_base += before_hdr_pad + after_hdr_pad + header_size;\n");
1592 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1593 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1594 type_descriptor_t
*type
= field
->type
;
1598 switch(type
->type
) {
1604 fprintf(fd
, "*from = (const char*)lttng_param_%s;\n", field
->name
);
1607 fprintf(fd
, "*from = (const char*)<tng_param_%s;\n", field
->name
);
1612 if(print_type_write(type
,
1613 fd
, 2, basename
, field
->name
, "lttng_param_", 0)) return 1;
1616 /* Don't forget to flush pending memcpy */
1618 fprintf(fd
, "/* Flush pending memcpy */\n");
1620 fprintf(fd
, "if (*len != 0) {\n");
1622 fprintf(fd
, "memcpy(buffer+*to_base+*to, *from, *len);\n");
1624 fprintf(fd
, "*to += *len;\n");
1625 //print_tabs(3, fd);
1626 //fprintf(fd, "from += len;\n");
1628 fprintf(fd
, "*len = 0;\n");
1637 //fprintf(fd, "commit:\n"); /* DEBUG! */
1639 fprintf(fd
, "ltt_commit_slot(channel, &transport_data, buffer, slot_size);\n\n");
1642 fprintf(fd
, "}\n\n");
1646 fprintf(fd
, "ltt_nesting[smp_processor_id()]--;\n");
1648 fprintf(fd
, "preempt_enable();\n");
1652 fprintf(fd
, "#endif //(!defined(CONFIG_LTT) || (!defined(CONFIG_LTT_FACILITY_%s) && !defined(CONFIG_LTT_FACILITY_%s_MODULE)))\n\n",
1653 fac
->capname
, fac
->capname
);
1658 int print_event_logging_function_header_user_generic(char *basename
, facility_t
*fac
,
1659 event_t
*event
, FILE *fd
, enum user_fct_types fct_type
)
1663 if(event
->no_instrument_function
&& fct_type
== USER_FCT_PROTO
) {
1664 attrib
= "__attribute__((no_instrument_function)) ";
1668 if(event
->param_buffer
) {
1669 fprintf(fd
, "static inline %sint trace_%s_param_buffer(\n", attrib
, basename
);
1671 fprintf(fd
, "static inline %sint trace_%s(\n",attrib
, basename
);
1673 int has_argument
= 0;
1675 if(event
->param_buffer
) {
1681 fprintf(fd
, "char *buffer");
1686 fprintf(fd
, "size_t reserve_size");
1688 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
1689 /* For each field, print the function argument */
1690 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
1691 type_descriptor_t
*t
= f
->type
;
1696 if(print_arg(t
, fd
, 2, basename
, f
->name
)) return 1;
1702 fprintf(fd
, "void");
1709 /* print_event_logging_function_user_generic
1710 * Print the logging function of an event for userspace tracing. This is the
1711 * core of genevent */
1712 int print_event_logging_function_user_generic(char *basename
, facility_t
*fac
,
1713 event_t
*event
, FILE *fd
)
1715 int has_type_fixed
= 0;
1717 if(print_event_logging_function_header_user_generic(basename
, fac
, event
, fd
, USER_FCT_PROTO
)) return 1;
1720 fprintf(fd
, "#ifndef LTT_TRACE_FAST\n");
1721 if(print_event_logging_function_header_user_generic(basename
, fac
, event
, fd
, USER_FCT_DECLARATION
)) return 1;
1724 "#ifndef LTT_TRACE\n");
1727 fprintf(fd
,"#else\n");
1729 /* Print the function variables */
1731 fprintf(fd
, "int ret = 0;\n");
1732 if(event
->param_buffer
) {
1733 //FIX print_tabs(1, fd);
1734 //fprintf(fd, "reserve_size = ltt_align(reserve_size, sizeof(void *));\n");
1740 fprintf(fd
, "char *buffer = NULL;\n");
1742 fprintf(fd
, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
1744 fprintf(fd
, "size_t *to_base = &real_to_base;\n");
1746 fprintf(fd
, "size_t real_to = 0;\n");
1748 fprintf(fd
, "size_t *to = &real_to;\n");
1750 fprintf(fd
, "size_t real_len = 0;\n");
1752 fprintf(fd
, "size_t *len = &real_len;\n");
1754 fprintf(fd
, "size_t reserve_size;\n");
1756 fprintf(fd
, "size_t slot_size;\n");
1759 if(event
->fields
.position
> 0) {
1760 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1761 /* Search for at least one child with fixed size. It means
1762 * we need local variables.*/
1763 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1764 type_descriptor_t
*type
= field
->type
;
1765 has_type_fixed
= has_type_local(type
);
1766 if(has_type_fixed
) break;
1769 if(has_type_fixed
) {
1770 fprintf(fd
, "size_t align;\n");
1774 fprintf(fd
, "const char *real_from;\n");
1776 fprintf(fd
, "const char **from = &real_from;\n");
1780 /* Calculate event variable len + event data alignment offset.
1781 * Assume that the padding for alignment starts at a void*
1783 * This excludes the header size and alignment. */
1786 fprintf(fd
, "/* For each field, calculate the field size. */\n");
1788 fprintf(fd
, "/* size = *to_base + *to + *len */\n");
1790 fprintf(fd
, "/* Assume that the padding for alignment starts at a\n");
1792 fprintf(fd
, " * sizeof(void *) address. */\n");
1795 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1796 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1797 type_descriptor_t
*type
= field
->type
;
1800 switch(type
->type
) {
1806 fprintf(fd
, "*from = (const char*)lttng_param_%s;\n", field
->name
);
1809 fprintf(fd
, "*from = (const char*)<tng_param_%s;\n", field
->name
);
1813 if(print_type_write(type
,
1814 fd
, 1, basename
, field
->name
, "lttng_param_", 0)) return 1;
1818 fprintf(fd
, "reserve_size = *to_base + *to + *len;\n");
1823 fprintf(fd
, "char stack_buffer[reserve_size];\n");
1825 fprintf(fd
, "buffer = stack_buffer;\n");
1829 //print_tabs(2, fd);
1831 // fprintf(fd, "goto commit; /* DEBUG : never actually write. */\n\n");
1833 fprintf(fd
, "*to_base = *to = *len = 0;\n");
1838 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1839 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1840 type_descriptor_t
*type
= field
->type
;
1844 switch(type
->type
) {
1850 fprintf(fd
, "*from = (const char*)lttng_param_%s;\n", field
->name
);
1853 fprintf(fd
, "*from = (const char*)<tng_param_%s;\n", field
->name
);
1858 if(print_type_write(type
,
1859 fd
, 2, basename
, field
->name
, "lttng_param_", 0)) return 1;
1862 /* Don't forget to flush pending memcpy */
1864 fprintf(fd
, "/* Flush pending memcpy */\n");
1866 fprintf(fd
, "if (*len != 0) {\n");
1868 fprintf(fd
, "memcpy(buffer+*to_base+*to, *from, *len);\n");
1870 fprintf(fd
, "*to += *len;\n");
1871 //print_tabs(3, fd);
1872 //fprintf(fd, "from += len;\n");
1874 fprintf(fd
, "*len = 0;\n");
1882 fprintf(fd
, "ret = ltt_trace_generic(ltt_facility_%s_%X, event_%s_%s, buffer, reserve_size, LTT_BLOCKING, %u);\n", fac
->name
, fac
->checksum
, fac
->name
, event
->name
, event
->high_priority
);
1885 fprintf(fd
, "}\n\n");
1888 fprintf(fd
, "return ret;\n\n");
1892 "#endif //LTT_TRACE\n");
1893 fprintf(fd
, "#endif //!LTT_TRACE_FAST\n\n");
1898 /* print_event_logging_function_user_fast
1899 * Print the logging function of an event for userspace tracing. This is the
1900 * core of genevent */
1901 int print_event_logging_function_user_fast(char *basename
, facility_t
*fac
,
1902 event_t
*event
, FILE *fd
)
1906 fprintf(fd
, "#ifdef LTT_TRACE_FAST\n");
1908 if(event
->no_instrument_function
) {
1909 attrib
= "__attribute__((no_instrument_function)) ";
1913 fprintf(fd
, "static inline %sint trace_%s(\n",attrib
, basename
);
1915 int has_argument
= 0;
1916 int has_type_fixed
= 0;
1918 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
1919 /* For each field, print the function argument */
1920 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
1921 type_descriptor_t
*t
= f
->type
;
1926 if(print_arg(t
, fd
, 2, basename
, f
->name
)) return 1;
1931 fprintf(fd
, "void");
1935 "#ifndef LTT_TRACE\n");
1938 fprintf(fd
,"#else\n");
1940 /* Print the function variables */
1942 fprintf(fd
, "unsigned int index;\n");
1944 fprintf(fd
, "struct ltt_trace_info *trace = thread_trace_info;\n");
1946 fprintf(fd
, "struct ltt_buf *ltt_buf;\n");
1948 fprintf(fd
, "char *buffer = NULL;\n");
1950 fprintf(fd
, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
1952 fprintf(fd
, "size_t *to_base = &real_to_base;\n");
1954 fprintf(fd
, "size_t real_to = 0;\n");
1956 fprintf(fd
, "size_t *to = &real_to;\n");
1958 fprintf(fd
, "size_t real_len = 0;\n");
1960 fprintf(fd
, "size_t *len = &real_len;\n");
1962 fprintf(fd
, "size_t reserve_size;\n");
1964 fprintf(fd
, "size_t slot_size;\n");
1967 if(event
->fields
.position
> 0) {
1968 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1969 /* Search for at least one child with fixed size. It means
1970 * we need local variables.*/
1971 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1972 type_descriptor_t
*type
= field
->type
;
1973 has_type_fixed
= has_type_local(type
);
1974 if(has_type_fixed
) break;
1977 if(has_type_fixed
) {
1978 fprintf(fd
, "size_t align;\n");
1982 fprintf(fd
, "const char *real_from;\n");
1984 fprintf(fd
, "const char **from = &real_from;\n");
1987 fprintf(fd
, "uint64_t tsc;\n");
1989 fprintf(fd
, "size_t before_hdr_pad, after_hdr_pad, header_size;\n");
1993 fprintf(fd
, "if (!trace) {\n");
1995 fprintf(fd
, "ltt_thread_init();\n");
1997 fprintf(fd
, "trace = thread_trace_info;\n");
1999 fprintf(fd
, "}\n\n");
2002 /* Calculate event variable len + event data alignment offset.
2003 * Assume that the padding for alignment starts at a void*
2005 * This excludes the header size and alignment. */
2008 fprintf(fd
, "/* For each field, calculate the field size. */\n");
2010 fprintf(fd
, "/* size = *to_base + *to + *len */\n");
2012 fprintf(fd
, "/* Assume that the padding for alignment starts at a\n");
2014 fprintf(fd
, " * sizeof(void *) address. */\n");
2017 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
2018 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
2019 type_descriptor_t
*type
= field
->type
;
2022 switch(type
->type
) {
2028 fprintf(fd
, "*from = (const char*)lttng_param_%s;\n", field
->name
);
2031 fprintf(fd
, "*from = (const char*)<tng_param_%s;\n", field
->name
);
2035 if(print_type_write(type
,
2036 fd
, 1, basename
, field
->name
, "lttng_param_", 0)) return 1;
2040 fprintf(fd
, "reserve_size = *to_base + *to + *len;\n");
2043 fprintf(fd
, "trace->nesting++;\n");
2045 /* Get facility index */
2049 "index = ltt_get_index_from_facility(ltt_facility_%s_%X,\n"\
2050 "\t\t\t\t\t\tevent_%s_%s);\n",
2051 fac
->name
, fac
->checksum
, fac
->name
, event
->name
);
2058 if(event
->per_trace
) {
2060 fprintf(fd
, "if (dest_trace != trace) continue;\n\n");
2064 fprintf(fd
, "ltt_buf = ltt_get_channel_from_index(trace, index);\n");
2069 /* If error, increment event lost counter (done by ltt_reserve_slot) and
2072 fprintf(fd
, "slot_size = 0;\n");
2074 fprintf(fd
, "buffer = ltt_reserve_slot(trace, ltt_buf,\n");
2076 fprintf(fd
, "reserve_size, &slot_size, &tsc,\n");
2078 fprintf(fd
, "&before_hdr_pad, &after_hdr_pad, &header_size);\n");
2079 /* If error, return */
2081 fprintf(fd
, "if (!buffer)\n");
2083 fprintf(fd
, "goto end; /* buffer full */\n\n");
2084 //print_tabs(2, fd);
2086 // fprintf(fd, "goto commit; /* DEBUG : never actually write. */\n\n");
2088 fprintf(fd
, "*to_base = *to = *len = 0;\n");
2091 /* Write event header */
2093 fprintf(fd
, "ltt_write_event_header(trace, ltt_buf, buffer,\n");
2095 fprintf(fd
, "ltt_facility_%s_%X, event_%s_%s,\n", fac
->name
, fac
->checksum
,
2096 fac
->name
, event
->name
);
2098 fprintf(fd
, "reserve_size, before_hdr_pad, tsc);\n");
2100 fprintf(fd
, "*to_base += before_hdr_pad + after_hdr_pad + header_size;\n");
2105 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
2106 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
2107 type_descriptor_t
*type
= field
->type
;
2111 switch(type
->type
) {
2117 fprintf(fd
, "*from = (const char*)lttng_param_%s;\n", field
->name
);
2120 fprintf(fd
, "*from = (const char*)<tng_param_%s;\n", field
->name
);
2125 if(print_type_write(type
,
2126 fd
, 2, basename
, field
->name
, "lttng_param_", 0)) return 1;
2129 /* Don't forget to flush pending memcpy */
2131 fprintf(fd
, "/* Flush pending memcpy */\n");
2133 fprintf(fd
, "if (*len != 0) {\n");
2135 fprintf(fd
, "memcpy(buffer+*to_base+*to, *from, *len);\n");
2137 fprintf(fd
, "*to += *len;\n");
2138 //print_tabs(3, fd);
2139 //fprintf(fd, "from += len;\n");
2141 fprintf(fd
, "*len = 0;\n");
2150 //fprintf(fd, "commit:\n"); /* DEBUG! */
2152 fprintf(fd
, "ltt_commit_slot(ltt_buf, buffer, slot_size);\n\n");
2154 fprintf(fd
, "}\n\n");
2156 fprintf(fd
, "end:\n");
2159 fprintf(fd
, "trace->nesting--;\n");
2164 "#endif //LTT_TRACE\n");
2165 fprintf(fd
, "#endif //LTT_TRACE_FAST\n");
2175 /* ltt-facility-name.h : main logging header.
2178 void print_log_header_head(facility_t
*fac
, FILE *fd
)
2180 fprintf(fd
, "#ifndef _LTT_FACILITY_%s_H_\n", fac
->capname
);
2181 fprintf(fd
, "#define _LTT_FACILITY_%s_H_\n\n", fac
->capname
);
2182 fprintf(fd
, "#include <linux/types.h>\n");
2184 fprintf(fd
, "#include <ltt/ltt-facility-id-%s.h>\n", fac
->name
);
2186 fprintf(fd
, "#include <ltt/ltt-facility-id-%s_%s.h>\n",
2189 fprintf(fd
, "#include <ltt/ltt-tracer.h>\n");
2193 /* ltt-facility-name.h : main logging header.
2196 void print_log_header_head_user(facility_t
*fac
, FILE *fd
)
2198 fprintf(fd
, "#ifndef _LTT_FACILITY_%s_H_\n", fac
->capname
);
2199 fprintf(fd
, "#define _LTT_FACILITY_%s_H_\n\n", fac
->capname
);
2200 fprintf(fd
, "#include <sys/types.h>\n");
2202 fprintf(fd
, "#include <ltt/ltt-facility-id-%s.h>\n", fac
->name
);
2204 fprintf(fd
, "#include <asm/ltt/ltt-facility-id-%s_%s.h>\n",
2207 fprintf(fd
, "#include <ltt/ltt-usertrace.h>\n");
2209 fprintf(fd
, "#ifdef __cplusplus\n");
2210 fprintf(fd
, "extern \"C\" {\n");
2211 fprintf(fd
, "#endif\n");
2216 int print_log_header_types(facility_t
*fac
, FILE *fd
)
2218 sequence_t
*types
= &fac
->named_types
.values
;
2219 fprintf(fd
, "/* Named types */\n");
2222 for(unsigned int i
= 0; i
< types
->position
; i
++) {
2223 /* For each named type, print the definition */
2224 if(print_type_declaration(types
->array
[i
], fd
,
2225 0, "", "")) return 1;
2226 /* Print also the align function */
2227 if(print_type_alignment_fct(types
->array
[i
], fd
,
2228 0, "", "")) return 1;
2229 /* Print also the write function */
2230 if(print_type_write_fct(types
->array
[i
], fd
,
2231 0, "", "")) return 1;
2236 int print_log_header_events(facility_t
*fac
, FILE *fd
)
2238 sequence_t
*events
= &fac
->events
;
2239 char basename
[PATH_MAX
];
2240 unsigned int facname_len
;
2242 strncpy(basename
, fac
->name
, PATH_MAX
);
2243 facname_len
= strlen(basename
);
2244 strncat(basename
, "_", PATH_MAX
-facname_len
);
2245 facname_len
= strlen(basename
);
2247 for(unsigned int i
= 0; i
< events
->position
; i
++) {
2248 event_t
*event
= (event_t
*)events
->array
[i
];
2249 strncpy(&basename
[facname_len
], event
->name
, PATH_MAX
-facname_len
);
2251 /* For each event, print structure, and then logging function */
2252 fprintf(fd
, "/* Event %s structures */\n",
2254 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
2255 /* For each unnamed type, print the definition */
2256 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
2257 type_descriptor_t
*t
= f
->type
;
2258 if(t
->type_name
== NULL
) {
2259 if((print_type_declaration(t
, fd
, 0, basename
, f
->name
))) return 1;
2260 /* Print also the align function */
2261 if((print_type_alignment_fct(t
, fd
, 0, basename
, f
->name
))) return 1;
2262 /* Print also the write function */
2263 if((print_type_write_fct(t
, fd
, 0, basename
, f
->name
))) return 1;
2269 fprintf(fd
, "/* Event %s logging function */\n",
2273 if(print_event_logging_function(basename
, fac
, event
, fd
)) return 1;
2275 if(print_event_logging_function_user_generic(basename
, fac
, event
, fd
))
2277 if(print_event_logging_function_user_fast(basename
, fac
, event
, fd
))
2288 void print_log_header_tail(facility_t
*fac
, FILE *fd
)
2290 fprintf(fd
, "#endif //_LTT_FACILITY_%s_H_\n",fac
->capname
);
2293 void print_log_header_tail_user(facility_t
*fac
, FILE *fd
)
2295 fprintf(fd
, "#ifdef __cplusplus\n");
2296 fprintf(fd
, "} /* end of extern \"C\" */\n");
2297 fprintf(fd
, "#endif\n");
2299 fprintf(fd
, "#endif //_LTT_FACILITY_%s_H_\n",fac
->capname
);
2302 int print_log_header(facility_t
*fac
)
2304 char filename
[PATH_MAX
];
2305 unsigned int filename_size
= 0;
2307 dprintf("%s\n", fac
->name
);
2309 strcpy(filename
, "ltt-facility-");
2310 filename_size
= strlen(filename
);
2312 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
2313 filename_size
= strlen(filename
);
2316 strncat(filename
, "_", PATH_MAX
- filename_size
);
2317 filename_size
= strlen(filename
);
2319 strncat(filename
, fac
->arch
, PATH_MAX
- filename_size
);
2320 filename_size
= strlen(filename
);
2323 strncat(filename
, ".h", PATH_MAX
- filename_size
);
2324 filename_size
= strlen(filename
);
2327 fd
= fopen(filename
, "w");
2329 printf("Error opening file %s for writing : %s\n",
2330 filename
, strerror(errno
));
2334 /* Print file head */
2336 print_log_header_head(fac
, fd
);
2338 print_log_header_head_user(fac
, fd
);
2340 /* print named types in declaration order */
2341 if(print_log_header_types(fac
, fd
)) return 1;
2344 if(print_log_header_events(fac
, fd
)) return 1;
2346 /* Print file tail */
2348 print_log_header_tail(fac
, fd
);
2350 print_log_header_tail_user(fac
, fd
);
2360 /* ltt-facility-id-name.h : facility id.
2362 int print_id_header(facility_t
*fac
)
2364 char filename
[PATH_MAX
];
2365 unsigned int filename_size
= 0;
2367 char basename
[PATH_MAX
];
2368 char basename_len
= 0;
2370 dprintf("%s\n", fac
->name
);
2372 strcpy(filename
, "ltt-facility-id-");
2373 filename_size
= strlen(filename
);
2375 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
2376 filename_size
= strlen(filename
);
2379 strncat(filename
, "_", PATH_MAX
- filename_size
);
2380 filename_size
= strlen(filename
);
2382 strncat(filename
, fac
->arch
, PATH_MAX
- filename_size
);
2383 filename_size
= strlen(filename
);
2386 strncat(filename
, ".h", PATH_MAX
- filename_size
);
2387 filename_size
= strlen(filename
);
2390 fd
= fopen(filename
, "w");
2392 printf("Error opening file %s for writing : %s\n",
2393 filename
, strerror(errno
));
2398 fprintf(fd
, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
2399 fprintf(fd
, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac
->capname
);
2400 fprintf(fd
, "#ifdef CONFIG_LTT\n");
2402 fprintf(fd
,"#include <linux/ltt-facilities.h>\n\n");
2404 fprintf(fd
,"/**** facility handle ****/\n\n");
2405 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s_%X;\n",
2406 fac
->name
, fac
->checksum
);
2407 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s;\n\n\n",fac
->name
);
2409 strncpy(basename
, fac
->name
, PATH_MAX
);
2410 basename_len
= strlen(basename
);
2411 strncat(basename
, "_", PATH_MAX
- basename_len
);
2414 fprintf(fd
,"/**** event index ****/\n\n");
2415 fprintf(fd
,"enum %s_event {\n",fac
->name
);
2417 for(unsigned int i
= 0; i
< fac
->events
.position
; i
++) {
2418 event_t
*event
= (event_t
*)fac
->events
.array
[i
];
2419 strncpy(basename
+basename_len
, event
->name
, PATH_MAX
-basename_len
);
2421 fprintf(fd
, "event_%s,\n", basename
);
2424 fprintf(fd
, "facility_%s_num_events\n", fac
->name
);
2425 fprintf(fd
, "};\n");
2429 fprintf(fd
, "#endif //CONFIG_LTT\n");
2430 fprintf(fd
, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
2432 fprintf(fd
, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
2433 fprintf(fd
, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac
->capname
);
2434 fprintf(fd
, "#ifdef LTT_TRACE\n");
2436 fprintf(fd
,"#include <ltt/ltt-usertrace.h>\n\n");
2438 fprintf(fd
,"/**** facility handle ****/\n\n");
2439 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s_%X;\n",
2440 fac
->name
, fac
->checksum
);
2441 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s;\n\n\n",fac
->name
);
2443 strncpy(basename
, fac
->name
, PATH_MAX
);
2444 basename_len
= strlen(basename
);
2445 strncat(basename
, "_", PATH_MAX
- basename_len
);
2448 fprintf(fd
,"/**** event index ****/\n\n");
2449 fprintf(fd
,"enum %s_event {\n",fac
->name
);
2451 for(unsigned int i
= 0; i
< fac
->events
.position
; i
++) {
2452 event_t
*event
= (event_t
*)fac
->events
.array
[i
];
2453 strncpy(basename
+basename_len
, event
->name
, PATH_MAX
-basename_len
);
2455 fprintf(fd
, "event_%s,\n", basename
);
2458 fprintf(fd
, "facility_%s_num_events\n", fac
->name
);
2459 fprintf(fd
, "};\n");
2463 fprintf(fd
, "#endif //LTT_TRACE\n");
2464 fprintf(fd
, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
2474 /* ltt-facility-loader-name.h : facility specific loader info.
2476 int print_loader_header(facility_t
*fac
)
2478 char filename
[PATH_MAX
];
2479 unsigned int filename_size
= 0;
2481 dprintf("%s\n", fac
->name
);
2483 strcpy(filename
, "ltt-facility-loader-");
2484 filename_size
= strlen(filename
);
2486 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
2487 filename_size
= strlen(filename
);
2490 strncat(filename
, "_", PATH_MAX
- filename_size
);
2491 filename_size
= strlen(filename
);
2493 strncat(filename
, fac
->arch
, PATH_MAX
- filename_size
);
2494 filename_size
= strlen(filename
);
2497 strncat(filename
, ".h", PATH_MAX
- filename_size
);
2498 filename_size
= strlen(filename
);
2501 fd
= fopen(filename
, "w");
2503 printf("Error opening file %s for writing : %s\n",
2504 filename
, strerror(errno
));
2508 fprintf(fd
, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
2509 fprintf(fd
, "#define _LTT_FACILITY_LOADER_%s_H_\n\n", fac
->capname
);
2510 fprintf(fd
, "#ifdef CONFIG_LTT\n\n");
2511 fprintf(fd
,"#include <linux/ltt-facilities.h>\n");
2513 fprintf(fd
,"#include <ltt/ltt-facility-id-%s.h>\n\n",
2516 fprintf(fd
,"#include <ltt/ltt-facility-id-%s_%s.h>\n\n",
2519 fprintf(fd
,"ltt_facility_t\tltt_facility_%s;\n", fac
->name
);
2520 fprintf(fd
,"ltt_facility_t\tltt_facility_%s_%X;\n\n",
2521 fac
->name
, fac
->checksum
);
2523 fprintf(fd
,"#define LTT_FACILITY_SYMBOL\t\tltt_facility_%s\n",
2525 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM_SYMBOL\tltt_facility_%s_%X\n",
2526 fac
->name
, fac
->checksum
);
2527 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM\t\t0x%X\n", fac
->checksum
);
2528 fprintf(fd
,"#define LTT_FACILITY_NAME\t\t\"%s\"\n", fac
->name
);
2529 fprintf(fd
,"#define LTT_FACILITY_NUM_EVENTS\tfacility_%s_num_events\n\n",
2531 fprintf(fd
, "#endif //CONFIG_LTT\n\n");
2532 fprintf(fd
, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
2539 int print_loader_header_user(facility_t
*fac
)
2541 char filename
[PATH_MAX
];
2542 unsigned int filename_size
= 0;
2544 dprintf("%s\n", fac
->name
);
2546 strcpy(filename
, "ltt-facility-loader-");
2547 filename_size
= strlen(filename
);
2549 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
2550 filename_size
= strlen(filename
);
2553 strncat(filename
, "_", PATH_MAX
- filename_size
);
2554 filename_size
= strlen(filename
);
2556 strncat(filename
, fac
->arch
, PATH_MAX
- filename_size
);
2557 filename_size
= strlen(filename
);
2560 strncat(filename
, ".h", PATH_MAX
- filename_size
);
2561 filename_size
= strlen(filename
);
2564 fd
= fopen(filename
, "w");
2566 printf("Error opening file %s for writing : %s\n",
2567 filename
, strerror(errno
));
2571 fprintf(fd
, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
2572 fprintf(fd
, "#define _LTT_FACILITY_LOADER_%s_H_\n\n", fac
->capname
);
2573 fprintf(fd
,"#include <ltt/ltt-usertrace.h>\n");
2575 fprintf(fd
,"#include <ltt/ltt-facility-id-%s.h>\n\n",
2578 fprintf(fd
,"#include <ltt/ltt-facility-id-%s_%s.h>\n\n",
2581 fprintf(fd
,"ltt_facility_t\tltt_facility_%s;\n", fac
->name
);
2582 fprintf(fd
,"ltt_facility_t\tltt_facility_%s_%X;\n\n",
2583 fac
->name
, fac
->checksum
);
2585 fprintf(fd
,"#define LTT_FACILITY_SYMBOL\t\t\t\t\t\t\tltt_facility_%s\n",
2587 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM_SYMBOL\t\tltt_facility_%s_%X\n",
2588 fac
->name
, fac
->checksum
);
2589 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM\t\t\t\t\t\t0x%X\n", fac
->checksum
);
2590 fprintf(fd
,"#define LTT_FACILITY_NAME\t\t\t\t\t\t\t\t\"%s\"\n", fac
->name
);
2591 fprintf(fd
,"#define LTT_FACILITY_NUM_EVENTS\t\t\t\t\tfacility_%s_num_events\n\n",
2593 fprintf(fd
, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
2602 /* ltt-facility-loader-name.c : generic facility loader
2604 int print_loader_c(facility_t
*fac
)
2606 char filename
[PATH_MAX
];
2607 unsigned int filename_size
= 0;
2609 dprintf("%s\n", fac
->name
);
2611 strcpy(filename
, "ltt-facility-loader-");
2612 filename_size
= strlen(filename
);
2614 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
2615 filename_size
= strlen(filename
);
2618 strncat(filename
, "_", PATH_MAX
- filename_size
);
2619 filename_size
= strlen(filename
);
2621 strncat(filename
, fac
->arch
, PATH_MAX
- filename_size
);
2622 filename_size
= strlen(filename
);
2625 strncat(filename
, ".c", PATH_MAX
- filename_size
);
2626 filename_size
= strlen(filename
);
2629 fd
= fopen(filename
, "w");
2631 printf("Error opening file %s for writing : %s\n",
2632 filename
, strerror(errno
));
2636 fprintf(fd
, "/*\n");
2638 fprintf(fd
, " * ltt-facility-loader-%s.c\n", fac
->name
);
2640 fprintf(fd
, " * ltt-facility-loader-%s_%s.c\n", fac
->name
, fac
->arch
);
2641 fprintf(fd
, " *\n");
2642 fprintf(fd
, " * (C) Copyright 2005 - \n");
2643 fprintf(fd
, " * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)\n");
2644 fprintf(fd
, " *\n");
2645 fprintf(fd
, " * Contains the LTT facility loader.\n");
2646 fprintf(fd
, " *\n");
2647 fprintf(fd
, " */\n");
2650 fprintf(fd
, "#include <linux/ltt-facilities.h>\n");
2651 fprintf(fd
, "#include <linux/module.h>\n");
2652 fprintf(fd
, "#include <linux/init.h>\n");
2654 fprintf(fd
, "#include \"ltt-facility-loader-%s.h\"\n", fac
->name
);
2656 fprintf(fd
, "#include \"ltt-facility-loader-%s_%s.h\"\n",
2657 fac
->name
, fac
->arch
);
2660 fprintf(fd
, "#ifdef CONFIG_LTT\n");
2662 fprintf(fd
, "EXPORT_SYMBOL(LTT_FACILITY_SYMBOL);\n");
2663 fprintf(fd
, "EXPORT_SYMBOL(LTT_FACILITY_CHECKSUM_SYMBOL);\n");
2665 fprintf(fd
, "static const char ltt_facility_name[] = LTT_FACILITY_NAME;\n");
2667 fprintf(fd
, "#define SYMBOL_STRING(sym) #sym\n");
2669 fprintf(fd
, "static struct ltt_facility facility = {\n");
2670 fprintf(fd
, "\t.name = ltt_facility_name,\n");
2671 fprintf(fd
, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n");
2672 fprintf(fd
, "\t.checksum = LTT_FACILITY_CHECKSUM,\n");
2673 fprintf(fd
, "\t.symbol = SYMBOL_STRING(LTT_FACILITY_SYMBOL),\n");
2674 fprintf(fd
, "};\n");
2676 fprintf(fd
, "static int __init facility_init(void)\n");
2678 fprintf(fd
, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init in kernel\\n\");\n", fac
->name
);
2680 fprintf(fd
, "\tLTT_FACILITY_SYMBOL = ltt_facility_kernel_register(&facility);\n");
2681 fprintf(fd
, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
2682 fprintf(fd
, "\t\n");
2683 fprintf(fd
, "\treturn LTT_FACILITY_SYMBOL;\n");
2686 fprintf(fd
, "#ifndef MODULE\n");
2687 fprintf(fd
, "__initcall(facility_init);\n");
2688 fprintf(fd
, "#else\n");
2689 fprintf(fd
, "module_init(facility_init);\n");
2690 fprintf(fd
, "static void __exit facility_exit(void)\n");
2692 fprintf(fd
, "\tint err;\n");
2694 fprintf(fd
, "\terr = ltt_facility_unregister(LTT_FACILITY_SYMBOL);\n");
2695 fprintf(fd
, "\tif (err != 0)\n");
2696 fprintf(fd
, "\t\tprintk(KERN_ERR \"LTT : Error in unregistering facility.\\n\");\n");
2699 fprintf(fd
, "module_exit(facility_exit)\n");
2701 fprintf(fd
, "MODULE_LICENSE(\"GPL\");\n");
2702 fprintf(fd
, "MODULE_AUTHOR(\"Mathieu Desnoyers\");\n");
2703 fprintf(fd
, "MODULE_DESCRIPTION(\"Linux Trace Toolkit Facility\");\n");
2705 fprintf(fd
, "#endif //MODULE\n");
2707 fprintf(fd
, "#endif //CONFIG_LTT\n");
2714 int print_loader_c_user(facility_t
*fac
)
2716 char filename
[PATH_MAX
];
2717 unsigned int filename_size
= 0;
2719 dprintf("%s\n", fac
->name
);
2721 strcpy(filename
, "ltt-facility-loader-");
2722 filename_size
= strlen(filename
);
2724 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
2725 filename_size
= strlen(filename
);
2728 strncat(filename
, "_", PATH_MAX
- filename_size
);
2729 filename_size
= strlen(filename
);
2731 strncat(filename
, fac
->arch
, PATH_MAX
- filename_size
);
2732 filename_size
= strlen(filename
);
2735 strncat(filename
, ".c", PATH_MAX
- filename_size
);
2736 filename_size
= strlen(filename
);
2739 fd
= fopen(filename
, "w");
2741 printf("Error opening file %s for writing : %s\n",
2742 filename
, strerror(errno
));
2746 fprintf(fd
, "/*\n");
2748 fprintf(fd
, " * ltt-facility-loader-%s.c\n", fac
->name
);
2750 fprintf(fd
, " * ltt-facility-loader-%s_%s.c\n", fac
->name
, fac
->arch
);
2751 fprintf(fd
, " *\n");
2752 fprintf(fd
, " * (C) Copyright 2005 - \n");
2753 fprintf(fd
, " * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)\n");
2754 fprintf(fd
, " *\n");
2755 fprintf(fd
, " * Contains the LTT user space facility loader.\n");
2756 fprintf(fd
, " *\n");
2757 fprintf(fd
, " */\n");
2760 fprintf(fd
, "#define LTT_TRACE\n");
2761 fprintf(fd
, "#include <error.h>\n");
2762 fprintf(fd
, "#include <stdio.h>\n");
2763 fprintf(fd
, "#include <ltt/ltt-usertrace.h>\n");
2765 fprintf(fd
, "#include \"ltt-facility-loader-%s.h\"\n", fac
->name
);
2767 fprintf(fd
, "#include \"ltt-facility-loader-%s_%s.h\"\n",
2768 fac
->name
, fac
->arch
);
2770 fprintf(fd
, "static struct user_facility_info facility = {\n");
2771 fprintf(fd
, "\t.name = LTT_FACILITY_NAME,\n");
2772 fprintf(fd
, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n");
2773 fprintf(fd
, "#ifndef LTT_PACK\n");
2774 fprintf(fd
, "\t.alignment = sizeof(void*),\n");
2775 fprintf(fd
, "#else\n");
2776 fprintf(fd
, "\t.alignment = 0,\n");
2777 fprintf(fd
, "#endif //LTT_PACK\n");
2778 fprintf(fd
, "\t.checksum = LTT_FACILITY_CHECKSUM,\n");
2779 fprintf(fd
, "\t.int_size = sizeof(int),\n");
2780 fprintf(fd
, "\t.long_size = sizeof(long),\n");
2781 fprintf(fd
, "\t.pointer_size = sizeof(void*),\n");
2782 fprintf(fd
, "\t.size_t_size = sizeof(size_t)\n");
2783 fprintf(fd
, "};\n");
2785 fprintf(fd
, "static void __attribute__((constructor)) __ltt_user_init(void)\n");
2787 fprintf(fd
, "\tint err;\n");
2788 fprintf(fd
, "#ifdef LTT_SHOW_DEBUG\n");
2789 fprintf(fd
, "\tprintf(\"LTT : ltt-facility-%s init in userspace\\n\");\n", fac
->name
);
2790 fprintf(fd
, "#endif //LTT_SHOW_DEBUG\n");
2792 fprintf(fd
, "\terr = ltt_register_generic(<T_FACILITY_SYMBOL, &facility);\n");
2793 fprintf(fd
, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
2794 fprintf(fd
, "\t\n");
2795 fprintf(fd
, "\tif (err) {\n");
2796 fprintf(fd
, "#ifdef LTT_SHOW_DEBUG\n");
2797 fprintf(fd
, "\t\tperror(\"Error in ltt_register_generic\");\n");
2798 fprintf(fd
, "#endif //LTT_SHOW_DEBUG\n");
2799 fprintf(fd
, "\t}\n");
2811 /* code taken from ltt_facility_open in ltt/facility.c in lttv */
2813 /*****************************************************************************
2815 * ltt_facility_open : open facilities
2817 * pathname : the path name of the facility
2819 * Open the facility corresponding to the right checksum.
2821 *returns the facility on success, NULL on error.
2822 ****************************************************************************/
2823 facility_t
*ltt_facility_open(char * pathname
)
2828 facility_t
* fac
= NULL
;
2829 char buffer
[BUFFER_SIZE
];
2830 int generated
= FALSE
;
2832 in
.buffer
= &(buffer
[0]);
2834 in
.error
= error_callback
;
2838 in
.fp
= fopen(in
.name
, "r");
2845 token
= getToken(&in
);
2846 if(in
.type
== ENDFILE
) break;
2849 printf("More than one facility in the file. Only using the first one.\n");
2853 if(strcmp(token
, "<")) in
.error(&in
,"not a facility file");
2854 token
= getName(&in
);
2855 if(strcmp(token
, "?")) in
.error(&in
,"not a facility file");
2856 token
= getName(&in
);
2857 if(strcmp(token
, "xml")) in
.error(&in
,"not a facility file");
2858 token
= getName(&in
);
2859 if(strcmp(token
, "version")) in
.error(&in
,"not a facility file");
2860 token
= getName(&in
);
2861 if(strcmp(token
, "=")) in
.error(&in
,"not a facility file");
2862 token
= getQuotedString(&in
);
2863 if(strcmp(token
, "1.0")) in
.error(&in
,"not a facility file");
2864 token
= getName(&in
);
2865 if(strcmp(token
, "?")) in
.error(&in
,"not a facility file");
2866 token
= getToken(&in
);
2867 if(strcmp(token
, ">")) in
.error(&in
,"not a facility file");
2869 token
= getName(&in
);
2870 if(strcmp(token
, "<")) in
.error(&in
,"not a facility file");
2871 token
= getName(&in
);
2872 if(strcmp("facility",token
) == 0) {
2873 fac
= malloc(sizeof(facility_t
));
2875 fac
->description
= NULL
;
2876 sequence_init(&(fac
->events
));
2877 table_init(&(fac
->named_types
));
2878 sequence_init(&(fac
->unnamed_types
));
2880 parseFacility(&in
, fac
);
2882 //check if any namedType is not defined
2883 checkNamedTypesImplemented(&fac
->named_types
);
2885 generateChecksum(fac
->name
, &fac
->checksum
, &fac
->events
);
2890 printf("facility token was expected in file %s\n", in
.name
);
2901 printf("Cannot find facility %s\n", pathname
);
2908 /* Close the facility */
2909 void ltt_facility_close(facility_t
*fac
)
2913 free(fac
->description
);
2914 freeEvents(&fac
->events
);
2915 sequence_dispose(&fac
->events
);
2916 freeNamedType(&fac
->named_types
);
2917 table_dispose(&fac
->named_types
);
2918 freeTypes(&fac
->unnamed_types
);
2919 sequence_dispose(&fac
->unnamed_types
);
2925 void show_help(int argc
, char ** argv
)
2927 printf("Genevent help : \n");
2929 printf("Use %s name.xml\n", argv
[0]);
2930 printf("to create :\n");
2931 printf("ltt-facility-name.h\n");
2932 printf("ltt-facility-id-name.h\n");
2933 printf("ltt-facility-loader-name.h\n");
2934 printf("ltt-facility-loader-name.c\n");
2935 printf("In the current directory.\n");
2939 /* Parse program arguments */
2941 * 0 : continue program
2942 * -1 : stop program, return 0
2943 * > 0 : stop program, return value as exit.
2945 int check_args(int argc
, char **argv
)
2948 printf("Not enough arguments\n");
2949 show_help(argc
, argv
);
2953 if(strcmp(argv
[1], "-h") == 0) {
2954 show_help(argc
, argv
);
2961 int main(int argc
, char **argv
)
2966 err
= check_args(argc
, argv
);
2967 if(err
> 0) return err
;
2968 else if(err
< 0) return 0;
2970 /* open the facility */
2971 fac
= ltt_facility_open(argv
[1]);
2973 printf("Error opening file %s for reading : %s\n",
2974 argv
[1], strerror(errno
));
2978 /* generate the output C files */
2981 /* ltt-facility-name.h : main logging header.
2983 err
= print_log_header(fac
);
2986 /* ltt-facility-id-name.h : facility id.
2988 err
= print_id_header(fac
);
2991 /* ltt-facility-loader-name.h : facility specific loader info.
2994 err
= print_loader_header(fac
);
2996 err
= print_loader_header_user(fac
);
2999 /* ltt-facility-loader-name.c : generic faciilty loader
3002 err
= print_loader_c(fac
);
3004 err
= print_loader_c_user(fac
);
3007 /* close the facility */
3008 ltt_facility_close(fac
);
This page took 0.156434 seconds and 4 git commands to generate.