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");
1405 "#if (!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_%s))\n",
1409 fprintf(fd
,"#else\n");
1411 /* Print the function variables */
1413 fprintf(fd
, "unsigned int index;\n");
1415 fprintf(fd
, "struct ltt_channel_struct *channel;\n");
1417 fprintf(fd
, "struct ltt_trace_struct *trace;\n");
1419 fprintf(fd
, "void *transport_data;\n");
1421 fprintf(fd
, "char *buffer = NULL;\n");
1423 fprintf(fd
, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
1425 fprintf(fd
, "size_t *to_base = &real_to_base;\n");
1427 fprintf(fd
, "size_t real_to = 0;\n");
1429 fprintf(fd
, "size_t *to = &real_to;\n");
1431 fprintf(fd
, "size_t real_len = 0;\n");
1433 fprintf(fd
, "size_t *len = &real_len;\n");
1435 fprintf(fd
, "size_t reserve_size;\n");
1437 fprintf(fd
, "size_t slot_size;\n");
1440 if(event
->fields
.position
> 0) {
1441 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1442 /* Search for at least one child with fixed size. It means
1443 * we need local variables.*/
1444 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1445 type_descriptor_t
*type
= field
->type
;
1446 has_type_fixed
= has_type_local(type
);
1447 if(has_type_fixed
) break;
1450 if(has_type_fixed
) {
1451 fprintf(fd
, "size_t align;\n");
1455 fprintf(fd
, "const char *real_from;\n");
1457 fprintf(fd
, "const char **from = &real_from;\n");
1460 fprintf(fd
, "u64 tsc;\n");
1462 fprintf(fd
, "size_t before_hdr_pad, after_hdr_pad, header_size;\n");
1466 fprintf(fd
, "if(ltt_traces.num_active_traces == 0) return;\n");
1469 /* Calculate event variable len + event data alignment offset.
1470 * Assume that the padding for alignment starts at a void*
1472 * This excludes the header size and alignment. */
1475 fprintf(fd
, "/* For each field, calculate the field size. */\n");
1477 fprintf(fd
, "/* size = *to_base + *to + *len */\n");
1479 fprintf(fd
, "/* Assume that the padding for alignment starts at a\n");
1481 fprintf(fd
, " * sizeof(void *) address. */\n");
1484 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1485 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1486 type_descriptor_t
*type
= field
->type
;
1489 switch(type
->type
) {
1495 fprintf(fd
, "*from = (const char*)lttng_param_%s;\n", field
->name
);
1498 fprintf(fd
, "*from = (const char*)<tng_param_%s;\n", field
->name
);
1502 if(print_type_write(type
,
1503 fd
, 1, basename
, field
->name
, "lttng_param_", 0)) return 1;
1507 fprintf(fd
, "reserve_size = *to_base + *to + *len;\n");
1509 /* Take locks : make sure the trace does not vanish while we write on
1510 * it. A simple preemption disabling is enough (using rcu traces). */
1512 fprintf(fd
, "preempt_disable();\n");
1514 fprintf(fd
, "ltt_nesting[smp_processor_id()]++;\n");
1516 /* Get facility index */
1518 if(event
->per_tracefile
) {
1520 fprintf(fd
, "index = tracefile_index;\n");
1524 "index = ltt_get_index_from_facility(ltt_facility_%s_%X,\n"\
1525 "\t\t\t\t\t\tevent_%s_%s);\n",
1526 fac
->name
, fac
->checksum
, fac
->name
, event
->name
);
1531 /* For each trace */
1533 fprintf(fd
, "list_for_each_entry_rcu(trace, <t_traces.head, list) {\n");
1535 fprintf(fd
, "if(!trace->active) continue;\n\n");
1537 if(event
->per_trace
) {
1539 fprintf(fd
, "if(dest_trace != trace) continue;\n\n");
1543 fprintf(fd
, "channel = ltt_get_channel_from_index(trace, index);\n");
1548 /* If error, increment event lost counter (done by ltt_reserve_slot) and
1551 fprintf(fd
, "slot_size = 0;\n");
1553 fprintf(fd
, "buffer = ltt_reserve_slot(trace, channel, &transport_data,\n");
1555 fprintf(fd
, "reserve_size, &slot_size, &tsc,\n");
1557 fprintf(fd
, "&before_hdr_pad, &after_hdr_pad, &header_size);\n");
1558 /* If error, return */
1560 fprintf(fd
, "if(!buffer) continue; /* buffer full */\n\n");
1561 //print_tabs(2, fd);
1563 // fprintf(fd, "goto commit; /* DEBUG : never actually write. */\n\n");
1565 fprintf(fd
, "*to_base = *to = *len = 0;\n");
1568 /* Write event header */
1570 fprintf(fd
, "ltt_write_event_header(trace, channel, buffer,\n");
1572 fprintf(fd
, "ltt_facility_%s_%X, event_%s_%s,\n", fac
->name
, fac
->checksum
,
1573 fac
->name
, event
->name
);
1575 fprintf(fd
, "reserve_size, before_hdr_pad, tsc);\n");
1577 fprintf(fd
, "*to_base += before_hdr_pad + after_hdr_pad + header_size;\n");
1582 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1583 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1584 type_descriptor_t
*type
= field
->type
;
1588 switch(type
->type
) {
1594 fprintf(fd
, "*from = (const char*)lttng_param_%s;\n", field
->name
);
1597 fprintf(fd
, "*from = (const char*)<tng_param_%s;\n", field
->name
);
1602 if(print_type_write(type
,
1603 fd
, 2, basename
, field
->name
, "lttng_param_", 0)) return 1;
1606 /* Don't forget to flush pending memcpy */
1608 fprintf(fd
, "/* Flush pending memcpy */\n");
1610 fprintf(fd
, "if(*len != 0) {\n");
1612 fprintf(fd
, "memcpy(buffer+*to_base+*to, *from, *len);\n");
1614 fprintf(fd
, "*to += *len;\n");
1615 //print_tabs(3, fd);
1616 //fprintf(fd, "from += len;\n");
1618 fprintf(fd
, "*len = 0;\n");
1627 //fprintf(fd, "commit:\n"); /* DEBUG! */
1629 fprintf(fd
, "ltt_commit_slot(channel, &transport_data, buffer, slot_size);\n\n");
1632 fprintf(fd
, "}\n\n");
1636 fprintf(fd
, "ltt_nesting[smp_processor_id()]--;\n");
1638 fprintf(fd
, "preempt_enable_no_resched();\n");
1641 fprintf(fd
, "#endif //(!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_%s))\n\n",
1646 int print_event_logging_function_header_user_generic(char *basename
, facility_t
*fac
,
1647 event_t
*event
, FILE *fd
, enum user_fct_types fct_type
)
1651 if(event
->no_instrument_function
&& fct_type
== USER_FCT_PROTO
) {
1652 attrib
= "__attribute__((no_instrument_function)) ";
1656 if(event
->param_buffer
) {
1657 fprintf(fd
, "static inline %sint trace_%s_param_buffer(\n", attrib
, basename
);
1659 fprintf(fd
, "static inline %sint trace_%s(\n",attrib
, basename
);
1661 int has_argument
= 0;
1663 if(event
->param_buffer
) {
1669 fprintf(fd
, "char *buffer");
1674 fprintf(fd
, "size_t reserve_size");
1676 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
1677 /* For each field, print the function argument */
1678 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
1679 type_descriptor_t
*t
= f
->type
;
1684 if(print_arg(t
, fd
, 2, basename
, f
->name
)) return 1;
1690 fprintf(fd
, "void");
1697 /* print_event_logging_function_user_generic
1698 * Print the logging function of an event for userspace tracing. This is the
1699 * core of genevent */
1700 int print_event_logging_function_user_generic(char *basename
, facility_t
*fac
,
1701 event_t
*event
, FILE *fd
)
1703 int has_type_fixed
= 0;
1705 if(print_event_logging_function_header_user_generic(basename
, fac
, event
, fd
, USER_FCT_PROTO
)) return 1;
1708 fprintf(fd
, "#ifndef LTT_TRACE_FAST\n");
1709 if(print_event_logging_function_header_user_generic(basename
, fac
, event
, fd
, USER_FCT_DECLARATION
)) return 1;
1712 "#ifndef LTT_TRACE\n");
1715 fprintf(fd
,"#else\n");
1717 /* Print the function variables */
1719 fprintf(fd
, "int ret = 0;\n");
1720 if(event
->param_buffer
) {
1721 //FIX print_tabs(1, fd);
1722 //fprintf(fd, "reserve_size = ltt_align(reserve_size, sizeof(void *));\n");
1728 fprintf(fd
, "char *buffer = NULL;\n");
1730 fprintf(fd
, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
1732 fprintf(fd
, "size_t *to_base = &real_to_base;\n");
1734 fprintf(fd
, "size_t real_to = 0;\n");
1736 fprintf(fd
, "size_t *to = &real_to;\n");
1738 fprintf(fd
, "size_t real_len = 0;\n");
1740 fprintf(fd
, "size_t *len = &real_len;\n");
1742 fprintf(fd
, "size_t reserve_size;\n");
1744 fprintf(fd
, "size_t slot_size;\n");
1747 if(event
->fields
.position
> 0) {
1748 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1749 /* Search for at least one child with fixed size. It means
1750 * we need local variables.*/
1751 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1752 type_descriptor_t
*type
= field
->type
;
1753 has_type_fixed
= has_type_local(type
);
1754 if(has_type_fixed
) break;
1757 if(has_type_fixed
) {
1758 fprintf(fd
, "size_t align;\n");
1762 fprintf(fd
, "const char *real_from;\n");
1764 fprintf(fd
, "const char **from = &real_from;\n");
1768 /* Calculate event variable len + event data alignment offset.
1769 * Assume that the padding for alignment starts at a void*
1771 * This excludes the header size and alignment. */
1774 fprintf(fd
, "/* For each field, calculate the field size. */\n");
1776 fprintf(fd
, "/* size = *to_base + *to + *len */\n");
1778 fprintf(fd
, "/* Assume that the padding for alignment starts at a\n");
1780 fprintf(fd
, " * sizeof(void *) address. */\n");
1783 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1784 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1785 type_descriptor_t
*type
= field
->type
;
1788 switch(type
->type
) {
1794 fprintf(fd
, "*from = (const char*)lttng_param_%s;\n", field
->name
);
1797 fprintf(fd
, "*from = (const char*)<tng_param_%s;\n", field
->name
);
1801 if(print_type_write(type
,
1802 fd
, 1, basename
, field
->name
, "lttng_param_", 0)) return 1;
1806 fprintf(fd
, "reserve_size = *to_base + *to + *len;\n");
1811 fprintf(fd
, "char stack_buffer[reserve_size];\n");
1813 fprintf(fd
, "buffer = stack_buffer;\n");
1817 //print_tabs(2, fd);
1819 // fprintf(fd, "goto commit; /* DEBUG : never actually write. */\n\n");
1821 fprintf(fd
, "*to_base = *to = *len = 0;\n");
1826 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1827 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1828 type_descriptor_t
*type
= field
->type
;
1832 switch(type
->type
) {
1838 fprintf(fd
, "*from = (const char*)lttng_param_%s;\n", field
->name
);
1841 fprintf(fd
, "*from = (const char*)<tng_param_%s;\n", field
->name
);
1846 if(print_type_write(type
,
1847 fd
, 2, basename
, field
->name
, "lttng_param_", 0)) return 1;
1850 /* Don't forget to flush pending memcpy */
1852 fprintf(fd
, "/* Flush pending memcpy */\n");
1854 fprintf(fd
, "if(*len != 0) {\n");
1856 fprintf(fd
, "memcpy(buffer+*to_base+*to, *from, *len);\n");
1858 fprintf(fd
, "*to += *len;\n");
1859 //print_tabs(3, fd);
1860 //fprintf(fd, "from += len;\n");
1862 fprintf(fd
, "*len = 0;\n");
1870 fprintf(fd
, "ret = ltt_trace_generic(ltt_facility_%s_%X, event_%s_%s, buffer, reserve_size, LTT_BLOCKING);\n", fac
->name
, fac
->checksum
, fac
->name
, event
->name
);
1873 fprintf(fd
, "}\n\n");
1876 fprintf(fd
, "return ret;\n\n");
1880 "#endif //LTT_TRACE\n");
1881 fprintf(fd
, "#endif //!LTT_TRACE_FAST\n\n");
1886 /* print_event_logging_function_user_fast
1887 * Print the logging function of an event for userspace tracing. This is the
1888 * core of genevent */
1889 int print_event_logging_function_user_fast(char *basename
, facility_t
*fac
,
1890 event_t
*event
, FILE *fd
)
1894 fprintf(fd
, "#ifdef LTT_TRACE_FAST\n");
1896 if(event
->no_instrument_function
) {
1897 attrib
= "__attribute__((no_instrument_function)) ";
1901 fprintf(fd
, "static inline %sint trace_%s(\n",attrib
, basename
);
1903 int has_argument
= 0;
1904 int has_type_fixed
= 0;
1906 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
1907 /* For each field, print the function argument */
1908 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
1909 type_descriptor_t
*t
= f
->type
;
1914 if(print_arg(t
, fd
, 2, basename
, f
->name
)) return 1;
1919 fprintf(fd
, "void");
1923 "#ifndef LTT_TRACE\n");
1926 fprintf(fd
,"#else\n");
1928 /* Print the function variables */
1930 fprintf(fd
, "unsigned int index;\n");
1932 fprintf(fd
, "struct ltt_trace_info *trace = thread_trace_info;\n");
1934 fprintf(fd
, "struct ltt_buf *ltt_buf;\n");
1936 fprintf(fd
, "char *buffer = NULL;\n");
1938 fprintf(fd
, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
1940 fprintf(fd
, "size_t *to_base = &real_to_base;\n");
1942 fprintf(fd
, "size_t real_to = 0;\n");
1944 fprintf(fd
, "size_t *to = &real_to;\n");
1946 fprintf(fd
, "size_t real_len = 0;\n");
1948 fprintf(fd
, "size_t *len = &real_len;\n");
1950 fprintf(fd
, "size_t reserve_size;\n");
1952 fprintf(fd
, "size_t slot_size;\n");
1955 if(event
->fields
.position
> 0) {
1956 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1957 /* Search for at least one child with fixed size. It means
1958 * we need local variables.*/
1959 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1960 type_descriptor_t
*type
= field
->type
;
1961 has_type_fixed
= has_type_local(type
);
1962 if(has_type_fixed
) break;
1965 if(has_type_fixed
) {
1966 fprintf(fd
, "size_t align;\n");
1970 fprintf(fd
, "const char *real_from;\n");
1972 fprintf(fd
, "const char **from = &real_from;\n");
1975 fprintf(fd
, "uint64_t tsc;\n");
1977 fprintf(fd
, "size_t before_hdr_pad, after_hdr_pad, header_size;\n");
1981 fprintf(fd
, "if(!trace) {\n");
1983 fprintf(fd
, "ltt_thread_init();\n");
1985 fprintf(fd
, "trace = thread_trace_info;\n");
1987 fprintf(fd
, "}\n\n");
1990 /* Calculate event variable len + event data alignment offset.
1991 * Assume that the padding for alignment starts at a void*
1993 * This excludes the header size and alignment. */
1996 fprintf(fd
, "/* For each field, calculate the field size. */\n");
1998 fprintf(fd
, "/* size = *to_base + *to + *len */\n");
2000 fprintf(fd
, "/* Assume that the padding for alignment starts at a\n");
2002 fprintf(fd
, " * sizeof(void *) address. */\n");
2005 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
2006 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
2007 type_descriptor_t
*type
= field
->type
;
2010 switch(type
->type
) {
2016 fprintf(fd
, "*from = (const char*)lttng_param_%s;\n", field
->name
);
2019 fprintf(fd
, "*from = (const char*)<tng_param_%s;\n", field
->name
);
2023 if(print_type_write(type
,
2024 fd
, 1, basename
, field
->name
, "lttng_param_", 0)) return 1;
2028 fprintf(fd
, "reserve_size = *to_base + *to + *len;\n");
2031 fprintf(fd
, "trace->nesting++;\n");
2033 /* Get facility index */
2037 "index = ltt_get_index_from_facility(ltt_facility_%s_%X,\n"\
2038 "\t\t\t\t\t\tevent_%s_%s);\n",
2039 fac
->name
, fac
->checksum
, fac
->name
, event
->name
);
2046 if(event
->per_trace
) {
2048 fprintf(fd
, "if(dest_trace != trace) continue;\n\n");
2052 fprintf(fd
, "ltt_buf = ltt_get_channel_from_index(trace, index);\n");
2057 /* If error, increment event lost counter (done by ltt_reserve_slot) and
2060 fprintf(fd
, "slot_size = 0;\n");
2062 fprintf(fd
, "buffer = ltt_reserve_slot(trace, ltt_buf,\n");
2064 fprintf(fd
, "reserve_size, &slot_size, &tsc,\n");
2066 fprintf(fd
, "&before_hdr_pad, &after_hdr_pad, &header_size);\n");
2067 /* If error, return */
2069 fprintf(fd
, "if(!buffer) goto end; /* buffer full */\n\n");
2070 //print_tabs(2, fd);
2072 // fprintf(fd, "goto commit; /* DEBUG : never actually write. */\n\n");
2074 fprintf(fd
, "*to_base = *to = *len = 0;\n");
2077 /* Write event header */
2079 fprintf(fd
, "ltt_write_event_header(trace, ltt_buf, buffer,\n");
2081 fprintf(fd
, "ltt_facility_%s_%X, event_%s_%s,\n", fac
->name
, fac
->checksum
,
2082 fac
->name
, event
->name
);
2084 fprintf(fd
, "reserve_size, before_hdr_pad, tsc);\n");
2086 fprintf(fd
, "*to_base += before_hdr_pad + after_hdr_pad + header_size;\n");
2091 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
2092 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
2093 type_descriptor_t
*type
= field
->type
;
2097 switch(type
->type
) {
2103 fprintf(fd
, "*from = (const char*)lttng_param_%s;\n", field
->name
);
2106 fprintf(fd
, "*from = (const char*)<tng_param_%s;\n", field
->name
);
2111 if(print_type_write(type
,
2112 fd
, 2, basename
, field
->name
, "lttng_param_", 0)) return 1;
2115 /* Don't forget to flush pending memcpy */
2117 fprintf(fd
, "/* Flush pending memcpy */\n");
2119 fprintf(fd
, "if(*len != 0) {\n");
2121 fprintf(fd
, "memcpy(buffer+*to_base+*to, *from, *len);\n");
2123 fprintf(fd
, "*to += *len;\n");
2124 //print_tabs(3, fd);
2125 //fprintf(fd, "from += len;\n");
2127 fprintf(fd
, "*len = 0;\n");
2136 //fprintf(fd, "commit:\n"); /* DEBUG! */
2138 fprintf(fd
, "ltt_commit_slot(ltt_buf, buffer, slot_size);\n\n");
2140 fprintf(fd
, "}\n\n");
2142 fprintf(fd
, "end:\n");
2145 fprintf(fd
, "trace->nesting--;\n");
2150 "#endif //LTT_TRACE\n");
2151 fprintf(fd
, "#endif //LTT_TRACE_FAST\n");
2161 /* ltt-facility-name.h : main logging header.
2164 void print_log_header_head(facility_t
*fac
, FILE *fd
)
2166 fprintf(fd
, "#ifndef _LTT_FACILITY_%s_H_\n", fac
->capname
);
2167 fprintf(fd
, "#define _LTT_FACILITY_%s_H_\n\n", fac
->capname
);
2168 fprintf(fd
, "#include <linux/types.h>\n");
2170 fprintf(fd
, "#include <linux/ltt/ltt-facility-id-%s.h>\n", fac
->name
);
2172 fprintf(fd
, "#include <asm/ltt/ltt-facility-id-%s_%s.h>\n",
2175 fprintf(fd
, "#include <linux/ltt-core.h>\n");
2179 /* ltt-facility-name.h : main logging header.
2182 void print_log_header_head_user(facility_t
*fac
, FILE *fd
)
2184 fprintf(fd
, "#ifndef _LTT_FACILITY_%s_H_\n", fac
->capname
);
2185 fprintf(fd
, "#define _LTT_FACILITY_%s_H_\n\n", fac
->capname
);
2186 fprintf(fd
, "#include <sys/types.h>\n");
2188 fprintf(fd
, "#include <ltt/ltt-facility-id-%s.h>\n", fac
->name
);
2190 fprintf(fd
, "#include <asm/ltt/ltt-facility-id-%s_%s.h>\n",
2193 fprintf(fd
, "#include <ltt/ltt-usertrace.h>\n");
2195 fprintf(fd
, "#ifdef __cplusplus\n");
2196 fprintf(fd
, "extern \"C\" {\n");
2197 fprintf(fd
, "#endif\n");
2202 int print_log_header_types(facility_t
*fac
, FILE *fd
)
2204 sequence_t
*types
= &fac
->named_types
.values
;
2205 fprintf(fd
, "/* Named types */\n");
2208 for(unsigned int i
= 0; i
< types
->position
; i
++) {
2209 /* For each named type, print the definition */
2210 if(print_type_declaration(types
->array
[i
], fd
,
2211 0, "", "")) return 1;
2212 /* Print also the align function */
2213 if(print_type_alignment_fct(types
->array
[i
], fd
,
2214 0, "", "")) return 1;
2215 /* Print also the write function */
2216 if(print_type_write_fct(types
->array
[i
], fd
,
2217 0, "", "")) return 1;
2222 int print_log_header_events(facility_t
*fac
, FILE *fd
)
2224 sequence_t
*events
= &fac
->events
;
2225 char basename
[PATH_MAX
];
2226 unsigned int facname_len
;
2228 strncpy(basename
, fac
->name
, PATH_MAX
);
2229 facname_len
= strlen(basename
);
2230 strncat(basename
, "_", PATH_MAX
-facname_len
);
2231 facname_len
= strlen(basename
);
2233 for(unsigned int i
= 0; i
< events
->position
; i
++) {
2234 event_t
*event
= (event_t
*)events
->array
[i
];
2235 strncpy(&basename
[facname_len
], event
->name
, PATH_MAX
-facname_len
);
2237 /* For each event, print structure, and then logging function */
2238 fprintf(fd
, "/* Event %s structures */\n",
2240 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
2241 /* For each unnamed type, print the definition */
2242 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
2243 type_descriptor_t
*t
= f
->type
;
2244 if(t
->type_name
== NULL
) {
2245 if((print_type_declaration(t
, fd
, 0, basename
, f
->name
))) return 1;
2246 /* Print also the align function */
2247 if((print_type_alignment_fct(t
, fd
, 0, basename
, f
->name
))) return 1;
2248 /* Print also the write function */
2249 if((print_type_write_fct(t
, fd
, 0, basename
, f
->name
))) return 1;
2255 fprintf(fd
, "/* Event %s logging function */\n",
2259 if(print_event_logging_function(basename
, fac
, event
, fd
)) return 1;
2261 if(print_event_logging_function_user_generic(basename
, fac
, event
, fd
))
2263 if(print_event_logging_function_user_fast(basename
, fac
, event
, fd
))
2274 void print_log_header_tail(facility_t
*fac
, FILE *fd
)
2276 fprintf(fd
, "#endif //_LTT_FACILITY_%s_H_\n",fac
->capname
);
2279 void print_log_header_tail_user(facility_t
*fac
, FILE *fd
)
2281 fprintf(fd
, "#ifdef __cplusplus\n");
2282 fprintf(fd
, "} /* end of extern \"C\" */\n");
2283 fprintf(fd
, "#endif\n");
2285 fprintf(fd
, "#endif //_LTT_FACILITY_%s_H_\n",fac
->capname
);
2288 int print_log_header(facility_t
*fac
)
2290 char filename
[PATH_MAX
];
2291 unsigned int filename_size
= 0;
2293 dprintf("%s\n", fac
->name
);
2295 strcpy(filename
, "ltt-facility-");
2296 filename_size
= strlen(filename
);
2298 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
2299 filename_size
= strlen(filename
);
2302 strncat(filename
, "_", PATH_MAX
- filename_size
);
2303 filename_size
= strlen(filename
);
2305 strncat(filename
, fac
->arch
, PATH_MAX
- filename_size
);
2306 filename_size
= strlen(filename
);
2309 strncat(filename
, ".h", PATH_MAX
- filename_size
);
2310 filename_size
= strlen(filename
);
2313 fd
= fopen(filename
, "w");
2315 printf("Error opening file %s for writing : %s\n",
2316 filename
, strerror(errno
));
2320 /* Print file head */
2322 print_log_header_head(fac
, fd
);
2324 print_log_header_head_user(fac
, fd
);
2326 /* print named types in declaration order */
2327 if(print_log_header_types(fac
, fd
)) return 1;
2330 if(print_log_header_events(fac
, fd
)) return 1;
2332 /* Print file tail */
2334 print_log_header_tail(fac
, fd
);
2336 print_log_header_tail_user(fac
, fd
);
2346 /* ltt-facility-id-name.h : facility id.
2348 int print_id_header(facility_t
*fac
)
2350 char filename
[PATH_MAX
];
2351 unsigned int filename_size
= 0;
2353 char basename
[PATH_MAX
];
2354 char basename_len
= 0;
2356 dprintf("%s\n", fac
->name
);
2358 strcpy(filename
, "ltt-facility-id-");
2359 filename_size
= strlen(filename
);
2361 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
2362 filename_size
= strlen(filename
);
2365 strncat(filename
, "_", PATH_MAX
- filename_size
);
2366 filename_size
= strlen(filename
);
2368 strncat(filename
, fac
->arch
, PATH_MAX
- filename_size
);
2369 filename_size
= strlen(filename
);
2372 strncat(filename
, ".h", PATH_MAX
- filename_size
);
2373 filename_size
= strlen(filename
);
2376 fd
= fopen(filename
, "w");
2378 printf("Error opening file %s for writing : %s\n",
2379 filename
, strerror(errno
));
2384 fprintf(fd
, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
2385 fprintf(fd
, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac
->capname
);
2386 fprintf(fd
, "#ifdef CONFIG_LTT\n");
2388 fprintf(fd
,"#include <linux/ltt-facilities.h>\n\n");
2390 fprintf(fd
,"/**** facility handle ****/\n\n");
2391 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s_%X;\n",
2392 fac
->name
, fac
->checksum
);
2393 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s;\n\n\n",fac
->name
);
2395 strncpy(basename
, fac
->name
, PATH_MAX
);
2396 basename_len
= strlen(basename
);
2397 strncat(basename
, "_", PATH_MAX
- basename_len
);
2400 fprintf(fd
,"/**** event index ****/\n\n");
2401 fprintf(fd
,"enum %s_event {\n",fac
->name
);
2403 for(unsigned int i
= 0; i
< fac
->events
.position
; i
++) {
2404 event_t
*event
= (event_t
*)fac
->events
.array
[i
];
2405 strncpy(basename
+basename_len
, event
->name
, PATH_MAX
-basename_len
);
2407 fprintf(fd
, "event_%s,\n", basename
);
2410 fprintf(fd
, "facility_%s_num_events\n", fac
->name
);
2411 fprintf(fd
, "};\n");
2415 fprintf(fd
, "#endif //CONFIG_LTT\n");
2416 fprintf(fd
, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
2418 fprintf(fd
, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
2419 fprintf(fd
, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac
->capname
);
2420 fprintf(fd
, "#ifdef LTT_TRACE\n");
2422 fprintf(fd
,"#include <ltt/ltt-usertrace.h>\n\n");
2424 fprintf(fd
,"/**** facility handle ****/\n\n");
2425 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s_%X;\n",
2426 fac
->name
, fac
->checksum
);
2427 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s;\n\n\n",fac
->name
);
2429 strncpy(basename
, fac
->name
, PATH_MAX
);
2430 basename_len
= strlen(basename
);
2431 strncat(basename
, "_", PATH_MAX
- basename_len
);
2434 fprintf(fd
,"/**** event index ****/\n\n");
2435 fprintf(fd
,"enum %s_event {\n",fac
->name
);
2437 for(unsigned int i
= 0; i
< fac
->events
.position
; i
++) {
2438 event_t
*event
= (event_t
*)fac
->events
.array
[i
];
2439 strncpy(basename
+basename_len
, event
->name
, PATH_MAX
-basename_len
);
2441 fprintf(fd
, "event_%s,\n", basename
);
2444 fprintf(fd
, "facility_%s_num_events\n", fac
->name
);
2445 fprintf(fd
, "};\n");
2449 fprintf(fd
, "#endif //LTT_TRACE\n");
2450 fprintf(fd
, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
2460 /* ltt-facility-loader-name.h : facility specific loader info.
2462 int print_loader_header(facility_t
*fac
)
2464 char filename
[PATH_MAX
];
2465 unsigned int filename_size
= 0;
2467 dprintf("%s\n", fac
->name
);
2469 strcpy(filename
, "ltt-facility-loader-");
2470 filename_size
= strlen(filename
);
2472 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
2473 filename_size
= strlen(filename
);
2476 strncat(filename
, "_", PATH_MAX
- filename_size
);
2477 filename_size
= strlen(filename
);
2479 strncat(filename
, fac
->arch
, PATH_MAX
- filename_size
);
2480 filename_size
= strlen(filename
);
2483 strncat(filename
, ".h", PATH_MAX
- filename_size
);
2484 filename_size
= strlen(filename
);
2487 fd
= fopen(filename
, "w");
2489 printf("Error opening file %s for writing : %s\n",
2490 filename
, strerror(errno
));
2494 fprintf(fd
, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
2495 fprintf(fd
, "#define _LTT_FACILITY_LOADER_%s_H_\n\n", fac
->capname
);
2496 fprintf(fd
, "#ifdef CONFIG_LTT\n\n");
2497 fprintf(fd
,"#include <linux/ltt-facilities.h>\n");
2499 fprintf(fd
,"#include <linux/ltt/ltt-facility-id-%s.h>\n\n",
2502 fprintf(fd
,"#include <asm/ltt/ltt-facility-id-%s_%s.h>\n\n",
2505 fprintf(fd
,"ltt_facility_t\tltt_facility_%s;\n", fac
->name
);
2506 fprintf(fd
,"ltt_facility_t\tltt_facility_%s_%X;\n\n",
2507 fac
->name
, fac
->checksum
);
2509 fprintf(fd
,"#define LTT_FACILITY_SYMBOL\t\tltt_facility_%s\n",
2511 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM_SYMBOL\tltt_facility_%s_%X\n",
2512 fac
->name
, fac
->checksum
);
2513 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM\t\t0x%X\n", fac
->checksum
);
2514 fprintf(fd
,"#define LTT_FACILITY_NAME\t\t\"%s\"\n", fac
->name
);
2515 fprintf(fd
,"#define LTT_FACILITY_NUM_EVENTS\tfacility_%s_num_events\n\n",
2517 fprintf(fd
, "#endif //CONFIG_LTT\n\n");
2518 fprintf(fd
, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
2525 int print_loader_header_user(facility_t
*fac
)
2527 char filename
[PATH_MAX
];
2528 unsigned int filename_size
= 0;
2530 dprintf("%s\n", fac
->name
);
2532 strcpy(filename
, "ltt-facility-loader-");
2533 filename_size
= strlen(filename
);
2535 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
2536 filename_size
= strlen(filename
);
2539 strncat(filename
, "_", PATH_MAX
- filename_size
);
2540 filename_size
= strlen(filename
);
2542 strncat(filename
, fac
->arch
, PATH_MAX
- filename_size
);
2543 filename_size
= strlen(filename
);
2546 strncat(filename
, ".h", PATH_MAX
- filename_size
);
2547 filename_size
= strlen(filename
);
2550 fd
= fopen(filename
, "w");
2552 printf("Error opening file %s for writing : %s\n",
2553 filename
, strerror(errno
));
2557 fprintf(fd
, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
2558 fprintf(fd
, "#define _LTT_FACILITY_LOADER_%s_H_\n\n", fac
->capname
);
2559 fprintf(fd
,"#include <ltt/ltt-usertrace.h>\n");
2561 fprintf(fd
,"#include <ltt/ltt-facility-id-%s.h>\n\n",
2564 fprintf(fd
,"#include <asm/ltt/ltt-facility-id-%s_%s.h>\n\n",
2567 fprintf(fd
,"ltt_facility_t\tltt_facility_%s;\n", fac
->name
);
2568 fprintf(fd
,"ltt_facility_t\tltt_facility_%s_%X;\n\n",
2569 fac
->name
, fac
->checksum
);
2571 fprintf(fd
,"#define LTT_FACILITY_SYMBOL\t\t\t\t\t\t\tltt_facility_%s\n",
2573 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM_SYMBOL\t\tltt_facility_%s_%X\n",
2574 fac
->name
, fac
->checksum
);
2575 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM\t\t\t\t\t\t0x%X\n", fac
->checksum
);
2576 fprintf(fd
,"#define LTT_FACILITY_NAME\t\t\t\t\t\t\t\t\"%s\"\n", fac
->name
);
2577 fprintf(fd
,"#define LTT_FACILITY_NUM_EVENTS\t\t\t\t\tfacility_%s_num_events\n\n",
2579 fprintf(fd
, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
2588 /* ltt-facility-loader-name.c : generic facility loader
2590 int print_loader_c(facility_t
*fac
)
2592 char filename
[PATH_MAX
];
2593 unsigned int filename_size
= 0;
2595 dprintf("%s\n", fac
->name
);
2597 strcpy(filename
, "ltt-facility-loader-");
2598 filename_size
= strlen(filename
);
2600 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
2601 filename_size
= strlen(filename
);
2604 strncat(filename
, "_", PATH_MAX
- filename_size
);
2605 filename_size
= strlen(filename
);
2607 strncat(filename
, fac
->arch
, PATH_MAX
- filename_size
);
2608 filename_size
= strlen(filename
);
2611 strncat(filename
, ".c", PATH_MAX
- filename_size
);
2612 filename_size
= strlen(filename
);
2615 fd
= fopen(filename
, "w");
2617 printf("Error opening file %s for writing : %s\n",
2618 filename
, strerror(errno
));
2622 fprintf(fd
, "/*\n");
2624 fprintf(fd
, " * ltt-facility-loader-%s.c\n", fac
->name
);
2626 fprintf(fd
, " * ltt-facility-loader-%s_%s.c\n", fac
->name
, fac
->arch
);
2627 fprintf(fd
, " *\n");
2628 fprintf(fd
, " * (C) Copyright 2005 - \n");
2629 fprintf(fd
, " * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)\n");
2630 fprintf(fd
, " *\n");
2631 fprintf(fd
, " * Contains the LTT facility loader.\n");
2632 fprintf(fd
, " *\n");
2633 fprintf(fd
, " */\n");
2636 fprintf(fd
, "#include <linux/ltt-facilities.h>\n");
2637 fprintf(fd
, "#include <linux/module.h>\n");
2638 fprintf(fd
, "#include <linux/init.h>\n");
2639 fprintf(fd
, "#include <linux/config.h>\n");
2641 fprintf(fd
, "#include \"ltt-facility-loader-%s.h\"\n", fac
->name
);
2643 fprintf(fd
, "#include \"ltt-facility-loader-%s_%s.h\"\n",
2644 fac
->name
, fac
->arch
);
2647 fprintf(fd
, "#ifdef CONFIG_LTT\n");
2649 fprintf(fd
, "EXPORT_SYMBOL(LTT_FACILITY_SYMBOL);\n");
2650 fprintf(fd
, "EXPORT_SYMBOL(LTT_FACILITY_CHECKSUM_SYMBOL);\n");
2652 fprintf(fd
, "static const char ltt_facility_name[] = LTT_FACILITY_NAME;\n");
2654 fprintf(fd
, "#define SYMBOL_STRING(sym) #sym\n");
2656 fprintf(fd
, "static struct ltt_facility facility = {\n");
2657 fprintf(fd
, "\t.name = ltt_facility_name,\n");
2658 fprintf(fd
, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n");
2659 fprintf(fd
, "\t.checksum = LTT_FACILITY_CHECKSUM,\n");
2660 fprintf(fd
, "\t.symbol = SYMBOL_STRING(LTT_FACILITY_SYMBOL),\n");
2661 fprintf(fd
, "};\n");
2663 fprintf(fd
, "static int __init facility_init(void)\n");
2665 fprintf(fd
, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init in kernel\\n\");\n", fac
->name
);
2667 fprintf(fd
, "\tLTT_FACILITY_SYMBOL = ltt_facility_kernel_register(&facility);\n");
2668 fprintf(fd
, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
2669 fprintf(fd
, "\t\n");
2670 fprintf(fd
, "\treturn LTT_FACILITY_SYMBOL;\n");
2673 fprintf(fd
, "#ifndef MODULE\n");
2674 fprintf(fd
, "__initcall(facility_init);\n");
2675 fprintf(fd
, "#else\n");
2676 fprintf(fd
, "module_init(facility_init);\n");
2677 fprintf(fd
, "static void __exit facility_exit(void)\n");
2679 fprintf(fd
, "\tint err;\n");
2681 fprintf(fd
, "\terr = ltt_facility_unregister(LTT_FACILITY_SYMBOL);\n");
2682 fprintf(fd
, "\tif(err != 0)\n");
2683 fprintf(fd
, "\t\tprintk(KERN_ERR \"LTT : Error in unregistering facility.\\n\");\n");
2686 fprintf(fd
, "module_exit(facility_exit)\n");
2688 fprintf(fd
, "MODULE_LICENSE(\"GPL\");\n");
2689 fprintf(fd
, "MODULE_AUTHOR(\"Mathieu Desnoyers\");\n");
2690 fprintf(fd
, "MODULE_DESCRIPTION(\"Linux Trace Toolkit Facility\");\n");
2692 fprintf(fd
, "#endif //MODULE\n");
2694 fprintf(fd
, "#endif //CONFIG_LTT\n");
2701 int print_loader_c_user(facility_t
*fac
)
2703 char filename
[PATH_MAX
];
2704 unsigned int filename_size
= 0;
2706 dprintf("%s\n", fac
->name
);
2708 strcpy(filename
, "ltt-facility-loader-");
2709 filename_size
= strlen(filename
);
2711 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
2712 filename_size
= strlen(filename
);
2715 strncat(filename
, "_", PATH_MAX
- filename_size
);
2716 filename_size
= strlen(filename
);
2718 strncat(filename
, fac
->arch
, PATH_MAX
- filename_size
);
2719 filename_size
= strlen(filename
);
2722 strncat(filename
, ".c", PATH_MAX
- filename_size
);
2723 filename_size
= strlen(filename
);
2726 fd
= fopen(filename
, "w");
2728 printf("Error opening file %s for writing : %s\n",
2729 filename
, strerror(errno
));
2733 fprintf(fd
, "/*\n");
2735 fprintf(fd
, " * ltt-facility-loader-%s.c\n", fac
->name
);
2737 fprintf(fd
, " * ltt-facility-loader-%s_%s.c\n", fac
->name
, fac
->arch
);
2738 fprintf(fd
, " *\n");
2739 fprintf(fd
, " * (C) Copyright 2005 - \n");
2740 fprintf(fd
, " * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)\n");
2741 fprintf(fd
, " *\n");
2742 fprintf(fd
, " * Contains the LTT user space facility loader.\n");
2743 fprintf(fd
, " *\n");
2744 fprintf(fd
, " */\n");
2747 fprintf(fd
, "#define LTT_TRACE\n");
2748 fprintf(fd
, "#include <error.h>\n");
2749 fprintf(fd
, "#include <stdio.h>\n");
2750 fprintf(fd
, "#include <ltt/ltt-usertrace.h>\n");
2752 fprintf(fd
, "#include \"ltt-facility-loader-%s.h\"\n", fac
->name
);
2754 fprintf(fd
, "#include \"ltt-facility-loader-%s_%s.h\"\n",
2755 fac
->name
, fac
->arch
);
2757 fprintf(fd
, "static struct user_facility_info facility = {\n");
2758 fprintf(fd
, "\t.name = LTT_FACILITY_NAME,\n");
2759 fprintf(fd
, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n");
2760 fprintf(fd
, "#ifndef LTT_PACK\n");
2761 fprintf(fd
, "\t.alignment = sizeof(void*),\n");
2762 fprintf(fd
, "#else\n");
2763 fprintf(fd
, "\t.alignment = 0,\n");
2764 fprintf(fd
, "#endif //LTT_PACK\n");
2765 fprintf(fd
, "\t.checksum = LTT_FACILITY_CHECKSUM,\n");
2766 fprintf(fd
, "\t.int_size = sizeof(int),\n");
2767 fprintf(fd
, "\t.long_size = sizeof(long),\n");
2768 fprintf(fd
, "\t.pointer_size = sizeof(void*),\n");
2769 fprintf(fd
, "\t.size_t_size = sizeof(size_t)\n");
2770 fprintf(fd
, "};\n");
2772 fprintf(fd
, "static void __attribute__((constructor)) __ltt_user_init(void)\n");
2774 fprintf(fd
, "\tint err;\n");
2775 fprintf(fd
, "#ifdef LTT_SHOW_DEBUG\n");
2776 fprintf(fd
, "\tprintf(\"LTT : ltt-facility-%s init in userspace\\n\");\n", fac
->name
);
2777 fprintf(fd
, "#endif //LTT_SHOW_DEBUG\n");
2779 fprintf(fd
, "\terr = ltt_register_generic(<T_FACILITY_SYMBOL, &facility);\n");
2780 fprintf(fd
, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
2781 fprintf(fd
, "\t\n");
2782 fprintf(fd
, "\tif(err) {\n");
2783 fprintf(fd
, "#ifdef LTT_SHOW_DEBUG\n");
2784 fprintf(fd
, "\t\tperror(\"Error in ltt_register_generic\");\n");
2785 fprintf(fd
, "#endif //LTT_SHOW_DEBUG\n");
2786 fprintf(fd
, "\t}\n");
2798 /* code taken from ltt_facility_open in ltt/facility.c in lttv */
2800 /*****************************************************************************
2802 * ltt_facility_open : open facilities
2804 * pathname : the path name of the facility
2806 * Open the facility corresponding to the right checksum.
2808 *returns the facility on success, NULL on error.
2809 ****************************************************************************/
2810 facility_t
*ltt_facility_open(char * pathname
)
2815 facility_t
* fac
= NULL
;
2816 char buffer
[BUFFER_SIZE
];
2817 int generated
= FALSE
;
2819 in
.buffer
= &(buffer
[0]);
2821 in
.error
= error_callback
;
2825 in
.fp
= fopen(in
.name
, "r");
2832 token
= getToken(&in
);
2833 if(in
.type
== ENDFILE
) break;
2836 printf("More than one facility in the file. Only using the first one.\n");
2840 if(strcmp(token
, "<")) in
.error(&in
,"not a facility file");
2841 token
= getName(&in
);
2842 if(strcmp(token
, "?")) in
.error(&in
,"not a facility file");
2843 token
= getName(&in
);
2844 if(strcmp(token
, "xml")) in
.error(&in
,"not a facility file");
2845 token
= getName(&in
);
2846 if(strcmp(token
, "version")) in
.error(&in
,"not a facility file");
2847 token
= getName(&in
);
2848 if(strcmp(token
, "=")) in
.error(&in
,"not a facility file");
2849 token
= getQuotedString(&in
);
2850 if(strcmp(token
, "1.0")) in
.error(&in
,"not a facility file");
2851 token
= getName(&in
);
2852 if(strcmp(token
, "?")) in
.error(&in
,"not a facility file");
2853 token
= getToken(&in
);
2854 if(strcmp(token
, ">")) in
.error(&in
,"not a facility file");
2856 token
= getName(&in
);
2857 if(strcmp(token
, "<")) in
.error(&in
,"not a facility file");
2858 token
= getName(&in
);
2859 if(strcmp("facility",token
) == 0) {
2860 fac
= malloc(sizeof(facility_t
));
2862 fac
->description
= NULL
;
2863 sequence_init(&(fac
->events
));
2864 table_init(&(fac
->named_types
));
2865 sequence_init(&(fac
->unnamed_types
));
2867 parseFacility(&in
, fac
);
2869 //check if any namedType is not defined
2870 checkNamedTypesImplemented(&fac
->named_types
);
2872 generateChecksum(fac
->name
, &fac
->checksum
, &fac
->events
);
2877 printf("facility token was expected in file %s\n", in
.name
);
2888 printf("Cannot find facility %s\n", pathname
);
2895 /* Close the facility */
2896 void ltt_facility_close(facility_t
*fac
)
2900 free(fac
->description
);
2901 freeEvents(&fac
->events
);
2902 sequence_dispose(&fac
->events
);
2903 freeNamedType(&fac
->named_types
);
2904 table_dispose(&fac
->named_types
);
2905 freeTypes(&fac
->unnamed_types
);
2906 sequence_dispose(&fac
->unnamed_types
);
2912 void show_help(int argc
, char ** argv
)
2914 printf("Genevent help : \n");
2916 printf("Use %s name.xml\n", argv
[0]);
2917 printf("to create :\n");
2918 printf("ltt-facility-name.h\n");
2919 printf("ltt-facility-id-name.h\n");
2920 printf("ltt-facility-loader-name.h\n");
2921 printf("ltt-facility-loader-name.c\n");
2922 printf("In the current directory.\n");
2926 /* Parse program arguments */
2928 * 0 : continue program
2929 * -1 : stop program, return 0
2930 * > 0 : stop program, return value as exit.
2932 int check_args(int argc
, char **argv
)
2935 printf("Not enough arguments\n");
2936 show_help(argc
, argv
);
2940 if(strcmp(argv
[1], "-h") == 0) {
2941 show_help(argc
, argv
);
2948 int main(int argc
, char **argv
)
2953 err
= check_args(argc
, argv
);
2954 if(err
> 0) return err
;
2955 else if(err
< 0) return 0;
2957 /* open the facility */
2958 fac
= ltt_facility_open(argv
[1]);
2960 printf("Error opening file %s for reading : %s\n",
2961 argv
[1], strerror(errno
));
2965 /* generate the output C files */
2968 /* ltt-facility-name.h : main logging header.
2970 err
= print_log_header(fac
);
2973 /* ltt-facility-id-name.h : facility id.
2975 err
= print_id_header(fac
);
2978 /* ltt-facility-loader-name.h : facility specific loader info.
2981 err
= print_loader_header(fac
);
2983 err
= print_loader_header_user(fac
);
2986 /* ltt-facility-loader-name.c : generic faciilty loader
2989 err
= print_loader_c(fac
);
2991 err
= print_loader_c_user(fac
);
2994 /* close the facility */
2995 ltt_facility_close(fac
);
This page took 0.094513 seconds and 4 git commands to generate.