1 /******************************************************************************
4 * Event generator. XML to logging C code converter.
9 * Will generate ltt-facility-name.h, ltt-facility-id-name.h
10 * ltt-facility-loader-name.c, ltt-facility-loader-name.h
11 * in the current directory.
15 * - C types : struct, union, enum, basic types.
16 * - Architectures : LP32, ILP32, ILP64, LLP64, LP64.
18 * Additionnal structures supported :
19 * - embedded variable size strings
20 * - embedded variable size arrays
21 * - embedded variable size sequences
25 * enums are limited to integer type, as this is what is used in C. Note,
26 * however, that ISO/IEC 9899:TC2 specify that the type of enum can be char,
27 * unsigned int or int. This is implementation defined (compiler). That's why we
28 * add a check for sizeof enum.
31 * Because of archtecture defined type sizes, we need to ask for ltt_align
32 * (which gives the alignment) by passing basic types, not their actual sizes.
33 * It's up to ltt_align to determine sizes of types.
36 * http://www.usenix.org/publications/login/standards/10.data.html
37 * (Andrew Josey <a.josey@opengroup.org>) :
39 * Data Type LP32 ILP32 ILP64 LLP64 LP64
41 * short 16 16 16 16 16
45 * long long (int64) 64
46 * pointer 32 32 64 64 64
48 * With these constraints :
49 * sizeof(char) <= sizeof(short) <= sizeof(int)
50 * <= sizeof(long) = sizeof(size_t)
52 * and therefore sizeof(long) <= sizeof(pointer) <= sizeof(size_t)
54 * Which means we only have to remember which is the biggest type in a structure
55 * to know the structure's alignment.
62 #include <sys/types.h>
77 /* Debugging printf */
79 #define dprintf(...) \
81 printf(__FILE__ ",%u,%s: ",\
91 void print_tabs(unsigned int tabs
, FILE *fd
)
93 for(unsigned int i
= 0; i
<tabs
;i
++)
99 * Copied from construct_types_and_fields in LTTV facility.c */
101 int print_type(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
102 char *nest_name
, char *field_name
)
104 char basename
[PATH_MAX
];
105 unsigned int basename_len
= 0;
107 strcpy(basename
, nest_name
);
108 basename_len
= strlen(basename
);
110 /* For a named type, we use the type_name directly */
111 if(td
->type_name
!= NULL
) {
112 strncpy(basename
, td
->type_name
, PATH_MAX
);
113 basename_len
= strlen(basename
);
115 /* For a unnamed type, there must be a field name */
116 if((basename_len
!= 0)
117 && (basename
[basename_len
-1] != '_')
118 && (field_name
[0] != '\0')) {
119 strncat(basename
, "_", PATH_MAX
- basename_len
);
120 basename_len
= strlen(basename
);
122 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
127 fprintf(fd
, "%s", intOutputTypes
[getSizeindex(td
->size
)]);
130 fprintf(fd
, "%s", uintOutputTypes
[getSizeindex(td
->size
)]);
133 fprintf(fd
, "signed char");
136 fprintf(fd
, "unsigned char");
139 fprintf(fd
, "short");
142 fprintf(fd
, "unsigned short");
148 fprintf(fd
, "unsigned int");
151 fprintf(fd
, "%s", floatOutputTypes
[getSizeindex(td
->size
)]);
154 fprintf(fd
, "const void *");
160 fprintf(fd
, "unsigned long");
163 fprintf(fd
, "size_t");
166 fprintf(fd
, "ssize_t");
169 fprintf(fd
, "off_t");
172 fprintf(fd
, "const char *");
175 fprintf(fd
, "enum lttng_%s", basename
);
178 fprintf(fd
, "lttng_array_%s", basename
);
181 fprintf(fd
, "lttng_sequence_%s", basename
);
184 fprintf(fd
, "struct lttng_%s", basename
);
187 fprintf(fd
, "union lttng_%s", basename
);
190 printf("print_type : unknown type\n");
197 /* Print logging function argument */
198 int print_arg(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
199 char *nest_name
, char *field_name
)
201 char basename
[PATH_MAX
];
202 unsigned int basename_len
= 0;
204 strcpy(basename
, nest_name
);
205 basename_len
= strlen(basename
);
207 /* For a named type, we use the type_name directly */
208 if(td
->type_name
!= NULL
) {
209 strncpy(basename
, td
->type_name
, PATH_MAX
);
210 basename_len
= strlen(basename
);
212 /* For a unnamed type, there must be a field name */
213 if((basename_len
!= 0)
214 && (basename
[basename_len
-1] != '_')
215 && (field_name
[0] != '\0')) {
216 strncat(basename
, "_", PATH_MAX
- basename_len
);
217 basename_len
= strlen(basename
);
219 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
222 print_tabs(tabs
, fd
);
226 fprintf(fd
, "%s", intOutputTypes
[getSizeindex(td
->size
)]);
227 fprintf(fd
, "lttng_param_%s", field_name
);
230 fprintf(fd
, "%s", uintOutputTypes
[getSizeindex(td
->size
)]);
231 fprintf(fd
, "lttng_param_%s", field_name
);
234 fprintf(fd
, "signed char");
235 fprintf(fd
, " lttng_param_%s", field_name
);
238 fprintf(fd
, "unsigned char");
239 fprintf(fd
, " lttng_param_%s", field_name
);
242 fprintf(fd
, "short");
243 fprintf(fd
, " lttng_param_%s", field_name
);
246 fprintf(fd
, "unsigned short");
247 fprintf(fd
, " lttng_param_%s", field_name
);
251 fprintf(fd
, " lttng_param_%s", field_name
);
254 fprintf(fd
, "unsigned int");
255 fprintf(fd
, " lttng_param_%s", field_name
);
258 fprintf(fd
, "%s", floatOutputTypes
[getSizeindex(td
->size
)]);
259 fprintf(fd
, " lttng_param_%s", field_name
);
262 fprintf(fd
, "const void *");
263 fprintf(fd
, " lttng_param_%s", field_name
);
267 fprintf(fd
, " lttng_param_%s", field_name
);
270 fprintf(fd
, "unsigned long");
271 fprintf(fd
, " lttng_param_%s", field_name
);
274 fprintf(fd
, "size_t");
275 fprintf(fd
, " lttng_param_%s", field_name
);
278 fprintf(fd
, "ssize_t");
279 fprintf(fd
, " lttng_param_%s", field_name
);
282 fprintf(fd
, "off_t");
283 fprintf(fd
, " lttng_param_%s", field_name
);
286 fprintf(fd
, "const char *");
287 fprintf(fd
, " lttng_param_%s", field_name
);
290 fprintf(fd
, "enum lttng_%s", basename
);
291 fprintf(fd
, " lttng_param_%s", field_name
);
294 fprintf(fd
, "lttng_array_%s", basename
);
295 fprintf(fd
, " lttng_param_%s", field_name
);
298 fprintf(fd
, "lttng_sequence_%s *", basename
);
299 fprintf(fd
, " lttng_param_%s", field_name
);
302 fprintf(fd
, "struct lttng_%s *", basename
);
303 fprintf(fd
, " lttng_param_%s", field_name
);
306 fprintf(fd
, "union lttng_%s *", basename
);
307 fprintf(fd
, " lttng_param_%s", field_name
);
310 printf("print_type : unknown type\n");
318 /* Does the type has a fixed size ? (as know from the compiler)
321 * 0 : variable length
323 int has_type_fixed_size(type_descriptor_t
*td
)
342 case UNION
: /* The union must have fixed size children. Must be checked by
352 int has_type_fixed
= 0;
353 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
354 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
355 type_descriptor_t
*type
= field
->type
;
357 has_type_fixed
= has_type_fixed_size(type
);
358 if(!has_type_fixed
) return 0;
364 assert(td
->size
>= 0);
365 return has_type_fixed_size(((field_t
*)td
->fields
.array
[0])->type
);
368 printf("There is a type defined to NONE : bad.\n");
372 return 0; //make gcc happy.
379 /* print type declaration.
381 * Copied from construct_types_and_fields in LTTV facility.c */
383 int print_type_declaration(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
384 char *nest_name
, char *field_name
)
386 char basename
[PATH_MAX
];
387 unsigned int basename_len
= 0;
389 if(td
->custom_write
) return 0; /* Does print custom type */
391 strncpy(basename
, nest_name
, PATH_MAX
);
392 basename_len
= strlen(basename
);
394 /* For a named type, we use the type_name directly */
395 if(td
->type_name
!= NULL
) {
396 strncpy(basename
, td
->type_name
, PATH_MAX
);
397 basename_len
= strlen(basename
);
399 /* For a unnamed type, there must be a field name, except for
401 if((basename_len
!= 0)
402 && (basename
[basename_len
-1] != '_'
403 && (field_name
[0] != '\0'))) {
404 strncat(basename
, "_", PATH_MAX
- basename_len
);
405 basename_len
= strlen(basename
);
407 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
412 fprintf(fd
, "enum lttng_%s", basename
);
414 for(unsigned int i
=0;i
<td
->labels
.position
;i
++){
416 fprintf(fd
, "LTTNG_%s = %d", ((char*)td
->labels
.array
[i
]),
417 (*(int*)td
->labels_values
.array
[i
]));
425 dprintf("%s\n", basename
);
426 assert(td
->size
>= 0);
427 if(((field_t
*)td
->fields
.array
[0])->type
->type_name
== NULL
) {
428 /* Not a named nested type : we must print its declaration first */
429 if(print_type_declaration(((field_t
*)td
->fields
.array
[0])->type
,
430 fd
, 0, basename
, "")) return 1;
432 fprintf(fd
, "#define LTTNG_ARRAY_SIZE_%s %zu\n", basename
,
434 fprintf(fd
, "typedef ");
435 if(print_type(((field_t
*)td
->fields
.array
[0])->type
,
436 fd
, tabs
, basename
, "")) return 1;
437 fprintf(fd
, " lttng_array_%s[LTTNG_ARRAY_SIZE_%s];\n", basename
,
442 /* We assume that the sequence length type does not need to be declared.
444 if(((field_t
*)td
->fields
.array
[1])->type
->type_name
== NULL
) {
445 /* Not a named nested type : we must print its declaration first */
446 if(print_type_declaration(((field_t
*)td
->fields
.array
[1])->type
,
447 fd
, 0, basename
, "")) return 1;
449 fprintf(fd
, "typedef struct lttng_sequence_%s lttng_sequence_%s;\n",
452 fprintf(fd
, "struct lttng_sequence_%s", basename
);
455 if(print_type(((field_t
*)td
->fields
.array
[0])->type
,
456 fd
, tabs
, basename
, "")) return 1;
457 fprintf(fd
, " len;\n");
459 fprintf(fd
, "const ");
460 if(print_type(((field_t
*)td
->fields
.array
[1])->type
,
461 fd
, tabs
, basename
, "")) return 1;
462 fprintf(fd
, " *array;\n");
463 fprintf(fd
, "};\n"); /* We do not LTT_ALIGN, because we never copy
464 it to the buffer directly. */
469 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
470 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
471 type_descriptor_t
*type
= field
->type
;
472 if(type
->type_name
== NULL
) {
473 /* Not a named nested type : we must print its declaration first */
474 if(print_type_declaration(type
,
475 fd
, 0, basename
, field
->name
)) return 1;
478 fprintf(fd
, "struct lttng_%s", basename
);
480 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
481 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
482 type_descriptor_t
*type
= field
->type
;
484 if(print_type(type
, fd
, tabs
, basename
, field
->name
)) return 1;
486 fprintf(fd
, "%s", field
->name
);
489 fprintf(fd
, "} LTT_ALIGN;\n");
493 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
494 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
495 type_descriptor_t
*type
= field
->type
;
496 if(type
->type_name
== NULL
) {
497 /* Not a named nested type : we must print its declaration first */
498 if(print_type_declaration(type
,
499 fd
, 0, basename
, field
->name
)) return 1;
502 fprintf(fd
, "union lttng_%s", basename
);
504 for(unsigned i
=0;i
<td
->fields
.position
;i
++){
505 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
506 type_descriptor_t
*type
= field
->type
;
508 if(print_type(type
, fd
, tabs
, basename
, field
->name
)) return 1;
510 fprintf(fd
, "%s", field
->name
);
513 fprintf(fd
, "} LTT_ALIGN;\n");
517 dprintf("print_type_declaration : unknown type or nothing to declare.\n");
525 /* print type alignment.
527 * Copied from construct_types_and_fields in LTTV facility.c
529 * basename is the name which identifies the type (along with a prefix
532 int print_type_alignment(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
533 char *nest_name
, char *field_name
, char *obj_prefix
)
535 char basename
[PATH_MAX
];
536 unsigned int basename_len
= 0;
538 strncpy(basename
, nest_name
, PATH_MAX
);
539 basename_len
= strlen(basename
);
541 /* For a named type, we use the type_name directly */
542 if(td
->type_name
!= NULL
) {
543 strncpy(basename
, td
->type_name
, PATH_MAX
);
544 basename_len
= strlen(basename
);
546 /* For a unnamed type, there must be a field name, except for
548 if((basename_len
!= 0)
549 && (basename
[basename_len
-1] != '_'
550 && field_name
!= NULL
551 && (field_name
[0] != '\0'))) {
552 strncat(basename
, "_", PATH_MAX
- basename_len
);
553 basename_len
= strlen(basename
);
555 if(field_name
!= NULL
)
556 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
559 if(field_name
[0] == '\0') {
560 /* We are in a write function : it's the obj that we must align. */
563 fprintf(fd
, "lttng_get_alignment_sequence_%s(%s)", basename
,
567 fprintf(fd
, "lttng_get_alignment_struct_%s(%s)", basename
,
571 fprintf(fd
, "lttng_get_alignment_union_%s(%s)", basename
,
575 fprintf(fd
, "lttng_get_alignment_array_%s(%s)", basename
,
578 fprintf(fd
, "sizeof(char)");
596 fprintf(fd
, "sizeof(");
597 if(print_type(td
, fd
, 0, basename
, "")) return 1;
602 printf("error : type unexpected\n");
625 fprintf(fd
, "sizeof(");
626 if(print_type(td
, fd
, 0, basename
, "")) return 1;
630 fprintf(fd
, "sizeof(char)");
633 fprintf(fd
, "lttng_get_alignment_sequence_%s(&%s%s)", basename
,
634 obj_prefix
, field_name
);
637 fprintf(fd
, "lttng_get_alignment_struct_%s(&%s%s)", basename
,
638 obj_prefix
, field_name
);
641 fprintf(fd
, "lttng_get_alignment_union_%s(&%s%s)", basename
,
642 obj_prefix
, field_name
);
645 fprintf(fd
, "lttng_get_alignment_array_%s(%s%s)", basename
,
646 obj_prefix
, field_name
);
649 printf("error : type NONE unexpected\n");
660 * Copied from construct_types_and_fields in LTTV facility.c
662 * basename is the name which identifies the type (along with a prefix
665 int print_type_write(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
666 char *nest_name
, char *field_name
, char *obj_prefix
, int get_ptr
)
668 char basename
[PATH_MAX
];
669 unsigned int basename_len
= 0;
670 char get_ptr_char
[2] = "";
671 char custom
[PATH_MAX
] = "";
673 strncpy(basename
, nest_name
, PATH_MAX
);
674 basename_len
= strlen(basename
);
676 /* For a named type, we use the type_name directly */
677 if(td
->type_name
!= NULL
) {
678 strncpy(basename
, td
->type_name
, PATH_MAX
);
679 basename_len
= strlen(basename
);
681 /* For a unnamed type, there must be a field name, except for
683 if((basename_len
!= 0)
684 && (basename
[basename_len
-1] != '_'
685 && (field_name
[0] != '\0'))) {
686 strncat(basename
, "_", PATH_MAX
- basename_len
);
687 basename_len
= strlen(basename
);
689 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
693 strcpy(get_ptr_char
, "&");
696 if(td
->custom_write
) {
697 strcpy(custom
, "_custom");
717 print_tabs(tabs
, fd
);
718 fprintf(fd
, "align = ");
719 if(print_type_alignment(td
, fd
, 0, basename
, "", "obj")) return 1;
722 print_tabs(tabs
, fd
);
723 fprintf(fd
, "if(*len == 0) {\n");
724 print_tabs(tabs
+1, fd
);
725 fprintf(fd
, "*to += ltt_align(*to, align); /* align output */\n");
726 print_tabs(tabs
, fd
);
727 fprintf(fd
, "} else {\n");
728 print_tabs(tabs
+1, fd
);
729 fprintf(fd
, "*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */\n");
730 print_tabs(tabs
, fd
);
734 print_tabs(tabs
, fd
);
735 fprintf(fd
, "*len += ");
736 fprintf(fd
, "sizeof(");
737 if(print_type(td
, fd
, 0, basename
, "")) return 1;
742 print_tabs(tabs
, fd
);
744 "lttng_write%s_string_%s(buffer, to_base, to, from, len, %s%s);\n",
745 custom
, basename
, obj_prefix
, field_name
);
748 print_tabs(tabs
, fd
);
750 "lttng_write%s_sequence_%s(buffer, to_base, to, from, len, %s%s%s);",
751 custom
, basename
, get_ptr_char
, obj_prefix
, field_name
);
754 print_tabs(tabs
, fd
);
756 "lttng_write%s_struct_%s(buffer, to_base, to, from, len, %s%s%s);",
757 custom
, basename
, get_ptr_char
, obj_prefix
, field_name
);
760 print_tabs(tabs
, fd
);
762 "lttng_write%s_union_%s(buffer, to_base, to, from, len, %s%s%s);",
763 custom
, basename
, get_ptr_char
, obj_prefix
, field_name
);
766 print_tabs(tabs
, fd
);
768 "lttng_write%s_array_%s(buffer, to_base, to, from, len, %s%s);",
769 custom
, basename
, obj_prefix
, field_name
);
772 printf("Error : type NONE unexpected\n");
780 /* print need local vars ?.
782 * Copied from print_type_write
784 * Does the type_write call needs local size and from variables ?
785 * return value : 1 yes, 0 no.
788 int has_type_local(type_descriptor_t
* td
)
817 printf("Error : type NONE unexpected\n");
827 /* print type alignment function.
829 * Copied from construct_types_and_fields in LTTV facility.c
831 * basename is the name which identifies the type (along with a prefix
834 int print_type_alignment_fct(type_descriptor_t
* td
, FILE *fd
,
836 char *nest_name
, char *field_name
)
838 char basename
[PATH_MAX
];
839 unsigned int basename_len
= 0;
841 if(td
->custom_write
) return 0; /* Does print custom type */
843 strncpy(basename
, nest_name
, PATH_MAX
);
844 basename_len
= strlen(basename
);
846 /* For a named type, we use the type_name directly */
847 if(td
->type_name
!= NULL
) {
848 strncpy(basename
, td
->type_name
, PATH_MAX
);
849 basename_len
= strlen(basename
);
851 /* For a unnamed type, there must be a field name, except for
853 if((basename_len
!= 0)
854 && (basename
[basename_len
-1] != '_'
855 && (field_name
[0] != '\0'))) {
856 strncat(basename
, "_", PATH_MAX
- basename_len
);
857 basename_len
= strlen(basename
);
859 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
864 /* Function header */
865 fprintf(fd
, "static inline size_t lttng_get_alignment_sequence_%s(\n",
868 if(print_type(td
, fd
, 0, basename
, "")) return 1;
869 fprintf(fd
, " *obj)\n");
872 fprintf(fd
, "size_t align=0, localign;");
875 fprintf(fd
, "localign = ");
876 if(print_type_alignment(((field_t
*)td
->fields
.array
[0])->type
,
877 fd
, 0, basename
, "len", "obj->")) return 1;
880 fprintf(fd
, "align = max(align, localign);\n");
883 fprintf(fd
, "localign = ");
884 if(print_type_alignment(((field_t
*)td
->fields
.array
[1])->type
,
885 fd
, 0, basename
, "array[0]", "obj->")) return 1;
888 fprintf(fd
, "align = max(align, localign);\n");
891 fprintf(fd
, "return align;\n");
894 /* Function header */
895 fprintf(fd
, "static inline size_t lttng_get_alignment_struct_%s(\n",
898 if(print_type(td
, fd
, 0, basename
, "")) return 1;
899 fprintf(fd
, " *obj)\n");
902 fprintf(fd
, "size_t align=0, localign;");
904 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
905 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
906 type_descriptor_t
*type
= field
->type
;
908 fprintf(fd
, "localign = ");
909 if(print_type_alignment(type
, fd
, 0, basename
, field
->name
, "obj->"))
913 fprintf(fd
, "align = max(align, localign);\n");
917 fprintf(fd
, "return align;\n");
921 /* Function header */
922 fprintf(fd
, "static inline size_t lttng_get_alignment_union_%s(\n",
925 if(print_type(td
, fd
, 0, basename
, "")) return 1;
926 fprintf(fd
, " *obj)\n");
929 fprintf(fd
, "size_t align=0, localign;");
931 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
932 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
933 type_descriptor_t
*type
= field
->type
;
935 fprintf(fd
, "localign = ");
936 if(print_type_alignment(type
, fd
, 0, basename
, field
->name
, "obj->"))
940 fprintf(fd
, "align = max(align, localign);\n");
944 fprintf(fd
, "return align;\n");
948 /* Function header */
949 fprintf(fd
, "static inline size_t lttng_get_alignment_array_%s(\n",
952 if(print_type(td
, fd
, 0, basename
, "")) return 1;
953 fprintf(fd
, " obj)\n");
956 fprintf(fd
, "return \n");
957 if(print_type_alignment(((field_t
*)td
->fields
.array
[0])->type
,
958 fd
, 0, basename
, "", "obj[0]"))
963 dprintf("print_type_alignment_fct : type has no alignment function.\n");
969 /* Function footer */
976 /* print type write function.
978 * Copied from construct_types_and_fields in LTTV facility.c
980 * basename is the name which identifies the type (along with a prefix
983 int print_type_write_fct(type_descriptor_t
* td
, FILE *fd
, unsigned int tabs
,
984 char *nest_name
, char *field_name
)
986 char basename
[PATH_MAX
];
987 unsigned int basename_len
= 0;
989 if(td
->custom_write
) return 0; /* Does print custom type */
991 strncpy(basename
, nest_name
, PATH_MAX
);
992 basename_len
= strlen(basename
);
994 /* For a named type, we use the type_name directly */
995 if(td
->type_name
!= NULL
) {
996 strncpy(basename
, td
->type_name
, PATH_MAX
);
997 basename_len
= strlen(basename
);
999 /* For a unnamed type, there must be a field name, except for
1001 if((basename_len
!= 0)
1002 && (basename
[basename_len
-1] != '_'
1003 && (field_name
[0] != '\0'))) {
1004 strncat(basename
, "_", PATH_MAX
- basename_len
);
1005 basename_len
= strlen(basename
);
1007 strncat(basename
, field_name
, PATH_MAX
- basename_len
);
1018 dprintf("print_type_write_fct : type has no write function.\n");
1026 fprintf(fd
, "static inline void lttng_write_sequence_%s(\n",
1030 fprintf(fd
, "static inline void lttng_write_struct_%s(\n", basename
);
1033 fprintf(fd
, "static inline void lttng_write_union_%s(\n", basename
);
1036 fprintf(fd
, "static inline void lttng_write_array_%s(\n", basename
);
1039 fprintf(fd
, "static inline void lttng_write_string_%s(\n", basename
);
1042 printf("print_type_write_fct : type has no write function.\n");
1047 fprintf(fd
, "void *buffer,\n");
1049 fprintf(fd
, "size_t *to_base,\n");
1051 fprintf(fd
, "size_t *to,\n");
1053 fprintf(fd
, "const void **from,\n");
1055 fprintf(fd
, "size_t *len,\n");
1057 if(print_type(td
, fd
, 0, basename
, "")) return 1;
1061 fprintf(fd
, " *obj)\n");
1064 fprintf(fd
, " *obj)\n");
1067 fprintf(fd
, " *obj)\n");
1070 fprintf(fd
, " obj)\n");
1073 fprintf(fd
, " obj)\n");
1076 printf("print_type_write_fct : type has no write function.\n");
1085 fprintf(fd
, "size_t size;\n");
1092 fprintf(fd
, "size_t align;\n");
1099 fprintf(fd
, "/* Flush pending memcpy */\n");
1101 fprintf(fd
, "if(*len != 0) {\n");
1103 fprintf(fd
, "if(buffer != NULL)\n");
1105 fprintf(fd
, "memcpy(buffer+*to_base+*to, *from, *len);\n");
1109 fprintf(fd
, "*to += *len;\n");
1111 fprintf(fd
, "*len = 0;\n");
1119 printf("print_type_write_fct : type has no write function.\n");
1124 fprintf(fd
, "align = ");
1125 if(print_type_alignment(td
, fd
, 0, basename
, "", "obj")) return 1;
1129 fprintf(fd
, "if(*len == 0) {\n");
1131 fprintf(fd
, "*to += ltt_align(*to, align); /* align output */\n");
1133 fprintf(fd
, "} else {\n");
1135 fprintf(fd
, "*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */\n");
1140 /* First, check if the type has a fixed size. If it is the case, then the size
1141 * to write is know by the compiler : simply use a sizeof() */
1142 if(has_type_fixed_size(td
)) {
1144 fprintf(fd
, "/* Contains only fixed size fields : use compiler sizeof() */\n");
1147 fprintf(fd
, "*len += sizeof(");
1148 if(print_type(td
, fd
, 0, basename
, field_name
)) return 1;
1149 fprintf(fd
, ");\n");
1151 /* The type contains nested variable size subtypes :
1152 * we must write field by field. */
1154 fprintf(fd
, "/* Contains variable sized fields : must explode the structure */\n");
1160 fprintf(fd
, "/* Copy members */\n");
1161 // print_tabs(1, fd);
1162 // fprintf(fd, "size = sizeof(\n");
1163 if(print_type_write(((field_t
*)td
->fields
.array
[0])->type
,
1164 fd
, 1, basename
, "len", "obj->", 1)) return 1;
1166 // fprintf(fd, ");\n");
1167 // print_tabs(1, fd);
1168 // fprintf(fd, "*to += ltt_align(*to, size);\n");
1170 fprintf(fd
, "if(buffer != NULL)\n");
1172 fprintf(fd
, "memcpy(buffer+*to_base+*to, &obj->len, *len);\n");
1174 fprintf(fd
, "*to += *len;\n");
1176 fprintf(fd
, "*len = 0;\n");
1179 /* Write the child : varlen child or not ? */
1180 if(has_type_fixed_size(((field_t
*)td
->fields
.array
[1])->type
)) {
1181 /* Fixed size len child : use a multiplication of its size */
1182 // print_tabs(1, fd);
1183 // fprintf(fd, "size = sizeof(\n");
1185 //print_tabs(1, fd);
1186 /* We know that *len does not contain alignment because of the
1187 * previous align output. len is always 0 here. */
1188 if(print_type_write(((field_t
*)td
->fields
.array
[1])->type
,
1189 fd
, 1, basename
, "array[0]", "obj->", 1))
1191 // fprintf(fd, ");\n");
1194 fprintf(fd
, "*len = obj->len * (*len);\n");
1196 fprintf(fd
, "if(buffer != NULL)\n");
1198 fprintf(fd
, "memcpy(buffer+*to_base+*to, obj->array, *len);\n");
1200 fprintf(fd
, "*to += *len;\n");
1202 fprintf(fd
, "*len = 0;\n");
1206 fprintf(fd
, "/* Variable length child : iter. */\n");
1208 fprintf(fd
, "for(unsigned int i=0; i<obj->len; i++) {\n");
1209 if(print_type_write(((field_t
*)td
->fields
.array
[1])->type
,
1210 fd
, 2, basename
, "array[i]", "obj->", 1)) return 1;
1216 fprintf(fd
, "/* Realign the *to_base on arch size, set *to to 0 */\n");
1218 fprintf(fd
, "*to += ltt_align(*to, sizeof(void *));\n");
1220 fprintf(fd
, "*to_base = *to_base+*to;\n");
1222 fprintf(fd
, "*to = 0;\n");
1225 fprintf(fd
, "/* Put source *from just after the C sequence */\n");
1227 fprintf(fd
, "*from = obj+1;\n");
1231 fprintf(fd
, "size = strlen(obj) + 1; /* Include final NULL char. */\n");
1233 fprintf(fd
, "if(buffer != NULL)\n");
1235 fprintf(fd
, "memcpy(buffer+*to_base+*to, obj, size);\n");
1237 fprintf(fd
, "*to += size;\n");
1240 fprintf(fd
, "/* Realign the *to_base on arch size, set *to to 0 */\n");
1242 fprintf(fd
, "*to += ltt_align(*to, sizeof(void *));\n");
1244 fprintf(fd
, "*to_base = *to_base+*to;\n");
1246 fprintf(fd
, "*to = 0;\n");
1249 fprintf(fd
, "/* Put source *from just after the C string */\n");
1251 fprintf(fd
, "*from += size;\n");
1254 for(unsigned int i
=0;i
<td
->fields
.position
;i
++){
1255 field_t
*field
= (field_t
*)(td
->fields
.array
[i
]);
1256 type_descriptor_t
*type
= field
->type
;
1257 if(print_type_write(type
,
1258 fd
, 1, basename
, field
->name
, "obj->", 1)) return 1;
1263 printf("ERROR : A union CANNOT contain a variable size child.\n");
1267 /* Write the child : varlen child or not ? */
1268 if(has_type_fixed_size(((field_t
*)td
->fields
.array
[0])->type
)) {
1269 /* Error : if an array has a variable size, then its child must also
1270 * have a variable size. */
1274 fprintf(fd
, "/* Variable length child : iter. */\n");
1276 fprintf(fd
, "for(unsigned int i=0; i<LTTNG_ARRAY_SIZE_%s; i++) {\n", basename
);
1277 if(print_type_write(((field_t
*)td
->fields
.array
[0])->type
,
1278 fd
, 2, basename
, "", "obj->array[i]", 1)) return 1;
1284 printf("print_type_write_fct : type has no write function.\n");
1292 /* Function footer */
1300 /* Print the logging function of an event. This is the core of genevent */
1301 int print_event_logging_function(char *basename
, facility_t
*fac
,
1302 event_t
*event
, FILE *fd
)
1304 fprintf(fd
, "static inline void trace_%s(\n", basename
);
1305 int has_argument
= 0;
1306 int has_type_fixed
= 0;
1308 /* Does it support per trace tracing ? */
1309 if(event
->per_trace
) {
1311 fprintf(fd
, "struct ltt_trace_struct *dest_trace");
1315 /* Does it support per tracefile tracing ? */
1316 if(event
->per_tracefile
) {
1321 fprintf(fd
, "unsigned int tracefile_index");
1325 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
1326 /* For each field, print the function argument */
1327 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
1328 type_descriptor_t
*t
= f
->type
;
1333 if(print_arg(t
, fd
, 2, basename
, f
->name
)) return 1;
1338 fprintf(fd
, "void");
1342 "#if (!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_%s))\n",
1346 fprintf(fd
,"#else\n");
1348 /* Print the function variables */
1350 fprintf(fd
, "unsigned int index;\n");
1352 fprintf(fd
, "struct ltt_channel_struct *channel;\n");
1354 fprintf(fd
, "struct ltt_trace_struct *trace;\n");
1356 fprintf(fd
, "struct rchan_buf *relayfs_buf;\n");
1358 fprintf(fd
, "void *buffer = NULL;\n");
1360 fprintf(fd
, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
1362 fprintf(fd
, "size_t *to_base = &real_to_base;\n");
1364 fprintf(fd
, "size_t real_to = 0;\n");
1366 fprintf(fd
, "size_t *to = &real_to;\n");
1368 fprintf(fd
, "size_t real_len = 0;\n");
1370 fprintf(fd
, "size_t *len = &real_len;\n");
1372 fprintf(fd
, "size_t reserve_size;\n");
1374 fprintf(fd
, "size_t slot_size;\n");
1377 if(event
->fields
.position
> 0) {
1378 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1379 /* Search for at least one child with fixed size. It means
1380 * we need local variables.*/
1381 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1382 type_descriptor_t
*type
= field
->type
;
1383 has_type_fixed
= has_type_local(type
);
1384 if(has_type_fixed
) break;
1387 if(has_type_fixed
) {
1388 fprintf(fd
, "size_t align;\n");
1392 fprintf(fd
, "const void *real_from;\n");
1394 fprintf(fd
, "const void **from = &real_from;\n");
1397 fprintf(fd
, "u64 tsc;\n");
1399 fprintf(fd
, "size_t before_hdr_pad, after_hdr_pad, header_size;\n");
1403 fprintf(fd
, "if(ltt_traces.num_active_traces == 0) return;\n");
1406 /* Calculate event variable len + event data alignment offset.
1407 * Assume that the padding for alignment starts at a void*
1409 * This excludes the header size and alignment. */
1412 fprintf(fd
, "/* For each field, calculate the field size. */\n");
1414 fprintf(fd
, "/* size = *to_base + *to + *len */\n");
1416 fprintf(fd
, "/* Assume that the padding for alignment starts at a\n");
1418 fprintf(fd
, " * sizeof(void *) address. */\n");
1421 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1422 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1423 type_descriptor_t
*type
= field
->type
;
1426 switch(type
->type
) {
1432 fprintf(fd
, "*from = lttng_param_%s;\n", field
->name
);
1435 fprintf(fd
, "*from = <tng_param_%s;\n", field
->name
);
1439 if(print_type_write(type
,
1440 fd
, 1, basename
, field
->name
, "lttng_param_", 0)) return 1;
1444 fprintf(fd
, "reserve_size = *to_base + *to + *len;\n");
1446 /* Take locks : make sure the trace does not vanish while we write on
1447 * it. A simple preemption disabling is enough (using rcu traces). */
1449 fprintf(fd
, "preempt_disable();\n");
1451 fprintf(fd
, "ltt_nesting[smp_processor_id()]++;\n");
1453 /* Get facility index */
1455 if(event
->per_tracefile
) {
1457 fprintf(fd
, "index = tracefile_index;\n");
1461 "index = ltt_get_index_from_facility(ltt_facility_%s_%X,\n"\
1462 "\t\t\t\t\t\tevent_%s_%s);\n",
1463 fac
->name
, fac
->checksum
, fac
->name
, event
->name
);
1468 /* For each trace */
1470 fprintf(fd
, "list_for_each_entry_rcu(trace, <t_traces.head, list) {\n");
1472 fprintf(fd
, "if(!trace->active) continue;\n\n");
1474 if(event
->per_trace
) {
1476 fprintf(fd
, "if(dest_trace != trace) continue;\n\n");
1480 fprintf(fd
, "channel = ltt_get_channel_from_index(trace, index);\n");
1482 fprintf(fd
, "relayfs_buf = channel->rchan->buf[smp_processor_id()];\n");
1487 /* If error, increment event lost counter (done by ltt_reserve_slot) and
1490 fprintf(fd
, "slot_size = 0;\n");
1492 fprintf(fd
, "buffer = ltt_reserve_slot(trace, relayfs_buf,\n");
1494 fprintf(fd
, "reserve_size, &slot_size, &tsc,\n");
1496 fprintf(fd
, "&before_hdr_pad, &after_hdr_pad, &header_size);\n");
1497 /* If error, return */
1499 fprintf(fd
, "if(!buffer) continue; /* buffer full */\n\n");
1500 //print_tabs(2, fd);
1502 // fprintf(fd, "goto commit; /* DEBUG : never actually write. */\n\n");
1504 fprintf(fd
, "*to_base = *to = *len = 0;\n");
1507 /* Write event header */
1509 fprintf(fd
, "ltt_write_event_header(trace, channel, buffer,\n");
1511 fprintf(fd
, "ltt_facility_%s_%X, event_%s_%s,\n", fac
->name
, fac
->checksum
,
1512 fac
->name
, event
->name
);
1514 fprintf(fd
, "reserve_size, before_hdr_pad, tsc);\n");
1516 fprintf(fd
, "*to_base += before_hdr_pad + after_hdr_pad + header_size;\n");
1521 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1522 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1523 type_descriptor_t
*type
= field
->type
;
1527 switch(type
->type
) {
1533 fprintf(fd
, "*from = lttng_param_%s;\n", field
->name
);
1536 fprintf(fd
, "*from = <tng_param_%s;\n", field
->name
);
1541 if(print_type_write(type
,
1542 fd
, 2, basename
, field
->name
, "lttng_param_", 0)) return 1;
1545 /* Don't forget to flush pending memcpy */
1547 fprintf(fd
, "/* Flush pending memcpy */\n");
1549 fprintf(fd
, "if(*len != 0) {\n");
1551 fprintf(fd
, "memcpy(buffer+*to_base+*to, *from, *len);\n");
1553 fprintf(fd
, "*to += *len;\n");
1554 //print_tabs(3, fd);
1555 //fprintf(fd, "from += len;\n");
1557 fprintf(fd
, "*len = 0;\n");
1566 //fprintf(fd, "commit:\n"); /* DEBUG! */
1568 fprintf(fd
, "ltt_commit_slot(relayfs_buf, buffer, slot_size);\n\n");
1571 fprintf(fd
, "}\n\n");
1575 fprintf(fd
, "ltt_nesting[smp_processor_id()]--;\n");
1577 fprintf(fd
, "preempt_enable_no_resched();\n");
1580 fprintf(fd
, "#endif //(!defined(CONFIG_LTT) || !defined(CONFIG_LTT_FACILITY_%s))\n\n",
1585 /* print_event_logging_function_user_generic
1586 * Print the logging function of an event for userspace tracing. This is the
1587 * core of genevent */
1588 int print_event_logging_function_user_generic(char *basename
, facility_t
*fac
,
1589 event_t
*event
, FILE *fd
)
1593 fprintf(fd
, "#ifndef LTT_TRACE_FAST\n");
1595 if(event
->no_instrument_function
) {
1596 attrib
= "__attribute__((no_instrument_function)) ";
1600 if(event
->param_buffer
) {
1601 fprintf(fd
, "static inline %sint trace_%s_param_buffer(\n", attrib
, basename
);
1603 fprintf(fd
, "static inline %sint trace_%s(\n",attrib
, basename
);
1605 int has_argument
= 0;
1606 int has_type_fixed
= 0;
1608 if(event
->param_buffer
) {
1614 fprintf(fd
, "void *buffer");
1619 fprintf(fd
, "size_t reserve_size");
1621 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
1622 /* For each field, print the function argument */
1623 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
1624 type_descriptor_t
*t
= f
->type
;
1629 if(print_arg(t
, fd
, 2, basename
, f
->name
)) return 1;
1635 fprintf(fd
, "void");
1639 "#ifndef LTT_TRACE\n");
1642 fprintf(fd
,"#else\n");
1644 /* Print the function variables */
1646 fprintf(fd
, "int ret = 0;\n");
1647 if(event
->param_buffer
) {
1649 fprintf(fd
, "reserve_size = ltt_align(reserve_size, sizeof(void *));\n");
1655 fprintf(fd
, "void *buffer = NULL;\n");
1657 fprintf(fd
, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
1659 fprintf(fd
, "size_t *to_base = &real_to_base;\n");
1661 fprintf(fd
, "size_t real_to = 0;\n");
1663 fprintf(fd
, "size_t *to = &real_to;\n");
1665 fprintf(fd
, "size_t real_len = 0;\n");
1667 fprintf(fd
, "size_t *len = &real_len;\n");
1669 fprintf(fd
, "size_t reserve_size;\n");
1671 fprintf(fd
, "size_t slot_size;\n");
1674 if(event
->fields
.position
> 0) {
1675 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1676 /* Search for at least one child with fixed size. It means
1677 * we need local variables.*/
1678 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1679 type_descriptor_t
*type
= field
->type
;
1680 has_type_fixed
= has_type_local(type
);
1681 if(has_type_fixed
) break;
1684 if(has_type_fixed
) {
1685 fprintf(fd
, "size_t align;\n");
1689 fprintf(fd
, "const void *real_from;\n");
1691 fprintf(fd
, "const void **from = &real_from;\n");
1695 /* Calculate event variable len + event data alignment offset.
1696 * Assume that the padding for alignment starts at a void*
1698 * This excludes the header size and alignment. */
1701 fprintf(fd
, "/* For each field, calculate the field size. */\n");
1703 fprintf(fd
, "/* size = *to_base + *to + *len */\n");
1705 fprintf(fd
, "/* Assume that the padding for alignment starts at a\n");
1707 fprintf(fd
, " * sizeof(void *) address. */\n");
1710 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1711 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1712 type_descriptor_t
*type
= field
->type
;
1715 switch(type
->type
) {
1721 fprintf(fd
, "*from = lttng_param_%s;\n", field
->name
);
1724 fprintf(fd
, "*from = <tng_param_%s;\n", field
->name
);
1728 if(print_type_write(type
,
1729 fd
, 1, basename
, field
->name
, "lttng_param_", 0)) return 1;
1733 fprintf(fd
, "reserve_size = *to_base + *to + *len;\n");
1738 fprintf(fd
, "char stack_buffer[reserve_size];\n");
1740 fprintf(fd
, "buffer = stack_buffer;\n");
1744 //print_tabs(2, fd);
1746 // fprintf(fd, "goto commit; /* DEBUG : never actually write. */\n\n");
1748 fprintf(fd
, "*to_base = *to = *len = 0;\n");
1753 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1754 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1755 type_descriptor_t
*type
= field
->type
;
1759 switch(type
->type
) {
1765 fprintf(fd
, "*from = lttng_param_%s;\n", field
->name
);
1768 fprintf(fd
, "*from = <tng_param_%s;\n", field
->name
);
1773 if(print_type_write(type
,
1774 fd
, 2, basename
, field
->name
, "lttng_param_", 0)) return 1;
1777 /* Don't forget to flush pending memcpy */
1779 fprintf(fd
, "/* Flush pending memcpy */\n");
1781 fprintf(fd
, "if(*len != 0) {\n");
1783 fprintf(fd
, "memcpy(buffer+*to_base+*to, *from, *len);\n");
1785 fprintf(fd
, "*to += *len;\n");
1786 //print_tabs(3, fd);
1787 //fprintf(fd, "from += len;\n");
1789 fprintf(fd
, "*len = 0;\n");
1797 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
);
1800 fprintf(fd
, "}\n\n");
1803 fprintf(fd
, "return ret;\n\n");
1807 "#endif //LTT_TRACE\n");
1808 fprintf(fd
, "#endif //!LTT_TRACE_FAST\n\n");
1813 /* print_event_logging_function_user_fast
1814 * Print the logging function of an event for userspace tracing. This is the
1815 * core of genevent */
1816 int print_event_logging_function_user_fast(char *basename
, facility_t
*fac
,
1817 event_t
*event
, FILE *fd
)
1821 fprintf(fd
, "#ifdef LTT_TRACE_FAST\n");
1823 if(event
->no_instrument_function
) {
1824 attrib
= "__attribute__((no_instrument_function)) ";
1828 fprintf(fd
, "static inline %sint trace_%s(\n",attrib
, basename
);
1830 int has_argument
= 0;
1831 int has_type_fixed
= 0;
1833 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
1834 /* For each field, print the function argument */
1835 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
1836 type_descriptor_t
*t
= f
->type
;
1841 if(print_arg(t
, fd
, 2, basename
, f
->name
)) return 1;
1846 fprintf(fd
, "void");
1850 "#ifndef LTT_TRACE\n");
1853 fprintf(fd
,"#else\n");
1855 /* Print the function variables */
1857 fprintf(fd
, "unsigned int index;\n");
1859 fprintf(fd
, "struct ltt_trace_info *trace = thread_trace_info;\n");
1861 fprintf(fd
, "struct ltt_buf *ltt_buf;\n");
1863 fprintf(fd
, "void *buffer = NULL;\n");
1865 fprintf(fd
, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n");
1867 fprintf(fd
, "size_t *to_base = &real_to_base;\n");
1869 fprintf(fd
, "size_t real_to = 0;\n");
1871 fprintf(fd
, "size_t *to = &real_to;\n");
1873 fprintf(fd
, "size_t real_len = 0;\n");
1875 fprintf(fd
, "size_t *len = &real_len;\n");
1877 fprintf(fd
, "size_t reserve_size;\n");
1879 fprintf(fd
, "size_t slot_size;\n");
1882 if(event
->fields
.position
> 0) {
1883 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1884 /* Search for at least one child with fixed size. It means
1885 * we need local variables.*/
1886 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1887 type_descriptor_t
*type
= field
->type
;
1888 has_type_fixed
= has_type_local(type
);
1889 if(has_type_fixed
) break;
1892 if(has_type_fixed
) {
1893 fprintf(fd
, "size_t align;\n");
1897 fprintf(fd
, "const void *real_from;\n");
1899 fprintf(fd
, "const void **from = &real_from;\n");
1902 fprintf(fd
, "uint64_t tsc;\n");
1904 fprintf(fd
, "size_t before_hdr_pad, after_hdr_pad, header_size;\n");
1908 fprintf(fd
, "if(!trace) {\n");
1910 fprintf(fd
, "ltt_thread_init();\n");
1912 fprintf(fd
, "trace = thread_trace_info;\n");
1914 fprintf(fd
, "}\n\n");
1917 /* Calculate event variable len + event data alignment offset.
1918 * Assume that the padding for alignment starts at a void*
1920 * This excludes the header size and alignment. */
1923 fprintf(fd
, "/* For each field, calculate the field size. */\n");
1925 fprintf(fd
, "/* size = *to_base + *to + *len */\n");
1927 fprintf(fd
, "/* Assume that the padding for alignment starts at a\n");
1929 fprintf(fd
, " * sizeof(void *) address. */\n");
1932 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
1933 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
1934 type_descriptor_t
*type
= field
->type
;
1937 switch(type
->type
) {
1943 fprintf(fd
, "*from = lttng_param_%s;\n", field
->name
);
1946 fprintf(fd
, "*from = <tng_param_%s;\n", field
->name
);
1950 if(print_type_write(type
,
1951 fd
, 1, basename
, field
->name
, "lttng_param_", 0)) return 1;
1955 fprintf(fd
, "reserve_size = *to_base + *to + *len;\n");
1958 fprintf(fd
, "trace->nesting++;\n");
1960 /* Get facility index */
1964 "index = ltt_get_index_from_facility(ltt_facility_%s_%X,\n"\
1965 "\t\t\t\t\t\tevent_%s_%s);\n",
1966 fac
->name
, fac
->checksum
, fac
->name
, event
->name
);
1973 if(event
->per_trace
) {
1975 fprintf(fd
, "if(dest_trace != trace) continue;\n\n");
1979 fprintf(fd
, "ltt_buf = ltt_get_channel_from_index(trace, index);\n");
1984 /* If error, increment event lost counter (done by ltt_reserve_slot) and
1987 fprintf(fd
, "slot_size = 0;\n");
1989 fprintf(fd
, "buffer = ltt_reserve_slot(trace, ltt_buf,\n");
1991 fprintf(fd
, "reserve_size, &slot_size, &tsc,\n");
1993 fprintf(fd
, "&before_hdr_pad, &after_hdr_pad, &header_size);\n");
1994 /* If error, return */
1996 fprintf(fd
, "if(!buffer) goto end; /* buffer full */\n\n");
1997 //print_tabs(2, fd);
1999 // fprintf(fd, "goto commit; /* DEBUG : never actually write. */\n\n");
2001 fprintf(fd
, "*to_base = *to = *len = 0;\n");
2004 /* Write event header */
2006 fprintf(fd
, "ltt_write_event_header(trace, ltt_buf, buffer,\n");
2008 fprintf(fd
, "ltt_facility_%s_%X, event_%s_%s,\n", fac
->name
, fac
->checksum
,
2009 fac
->name
, event
->name
);
2011 fprintf(fd
, "reserve_size, before_hdr_pad, tsc);\n");
2013 fprintf(fd
, "*to_base += before_hdr_pad + after_hdr_pad + header_size;\n");
2018 for(unsigned int i
=0;i
<event
->fields
.position
;i
++){
2019 field_t
*field
= (field_t
*)(event
->fields
.array
[i
]);
2020 type_descriptor_t
*type
= field
->type
;
2024 switch(type
->type
) {
2030 fprintf(fd
, "*from = lttng_param_%s;\n", field
->name
);
2033 fprintf(fd
, "*from = <tng_param_%s;\n", field
->name
);
2038 if(print_type_write(type
,
2039 fd
, 2, basename
, field
->name
, "lttng_param_", 0)) return 1;
2042 /* Don't forget to flush pending memcpy */
2044 fprintf(fd
, "/* Flush pending memcpy */\n");
2046 fprintf(fd
, "if(*len != 0) {\n");
2048 fprintf(fd
, "memcpy(buffer+*to_base+*to, *from, *len);\n");
2050 fprintf(fd
, "*to += *len;\n");
2051 //print_tabs(3, fd);
2052 //fprintf(fd, "from += len;\n");
2054 fprintf(fd
, "*len = 0;\n");
2063 //fprintf(fd, "commit:\n"); /* DEBUG! */
2065 fprintf(fd
, "ltt_commit_slot(ltt_buf, buffer, slot_size);\n\n");
2067 fprintf(fd
, "}\n\n");
2069 fprintf(fd
, "end:\n");
2072 fprintf(fd
, "trace->nesting--;\n");
2077 "#endif //LTT_TRACE\n");
2078 fprintf(fd
, "#endif //LTT_TRACE_FAST\n");
2088 /* ltt-facility-name.h : main logging header.
2091 void print_log_header_head(facility_t
*fac
, FILE *fd
)
2093 fprintf(fd
, "#ifndef _LTT_FACILITY_%s_H_\n", fac
->capname
);
2094 fprintf(fd
, "#define _LTT_FACILITY_%s_H_\n\n", fac
->capname
);
2095 fprintf(fd
, "#include <linux/types.h>\n");
2097 fprintf(fd
, "#include <linux/ltt/ltt-facility-id-%s.h>\n", fac
->name
);
2099 fprintf(fd
, "#include <asm/ltt/ltt-facility-id-%s_%s.h>\n",
2102 fprintf(fd
, "#include <linux/ltt-core.h>\n");
2106 /* ltt-facility-name.h : main logging header.
2109 void print_log_header_head_user(facility_t
*fac
, FILE *fd
)
2111 fprintf(fd
, "#ifndef _LTT_FACILITY_%s_H_\n", fac
->capname
);
2112 fprintf(fd
, "#define _LTT_FACILITY_%s_H_\n\n", fac
->capname
);
2113 fprintf(fd
, "#include <sys/types.h>\n");
2115 fprintf(fd
, "#include <ltt/ltt-facility-id-%s.h>\n", fac
->name
);
2117 fprintf(fd
, "#include <asm/ltt/ltt-facility-id-%s_%s.h>\n",
2120 fprintf(fd
, "#include <ltt/ltt-generic.h>\n");
2125 int print_log_header_types(facility_t
*fac
, FILE *fd
)
2127 sequence_t
*types
= &fac
->named_types
.values
;
2128 fprintf(fd
, "/* Named types */\n");
2131 for(unsigned int i
= 0; i
< types
->position
; i
++) {
2132 /* For each named type, print the definition */
2133 if(print_type_declaration(types
->array
[i
], fd
,
2134 0, "", "")) return 1;
2135 /* Print also the align function */
2136 if(print_type_alignment_fct(types
->array
[i
], fd
,
2137 0, "", "")) return 1;
2138 /* Print also the write function */
2139 if(print_type_write_fct(types
->array
[i
], fd
,
2140 0, "", "")) return 1;
2145 int print_log_header_events(facility_t
*fac
, FILE *fd
)
2147 sequence_t
*events
= &fac
->events
;
2148 char basename
[PATH_MAX
];
2149 unsigned int facname_len
;
2151 strncpy(basename
, fac
->name
, PATH_MAX
);
2152 facname_len
= strlen(basename
);
2153 strncat(basename
, "_", PATH_MAX
-facname_len
);
2154 facname_len
= strlen(basename
);
2156 for(unsigned int i
= 0; i
< events
->position
; i
++) {
2157 event_t
*event
= (event_t
*)events
->array
[i
];
2158 strncpy(&basename
[facname_len
], event
->name
, PATH_MAX
-facname_len
);
2160 /* For each event, print structure, and then logging function */
2161 fprintf(fd
, "/* Event %s structures */\n",
2163 for(unsigned int j
= 0; j
< event
->fields
.position
; j
++) {
2164 /* For each unnamed type, print the definition */
2165 field_t
*f
= (field_t
*)event
->fields
.array
[j
];
2166 type_descriptor_t
*t
= f
->type
;
2167 if(t
->type_name
== NULL
) {
2168 if((print_type_declaration(t
, fd
, 0, basename
, f
->name
))) return 1;
2169 /* Print also the align function */
2170 if((print_type_alignment_fct(t
, fd
, 0, basename
, f
->name
))) return 1;
2171 /* Print also the write function */
2172 if((print_type_write_fct(t
, fd
, 0, basename
, f
->name
))) return 1;
2178 fprintf(fd
, "/* Event %s logging function */\n",
2182 if(print_event_logging_function(basename
, fac
, event
, fd
)) return 1;
2184 if(print_event_logging_function_user_generic(basename
, fac
, event
, fd
))
2186 if(print_event_logging_function_user_fast(basename
, fac
, event
, fd
))
2197 void print_log_header_tail(facility_t
*fac
, FILE *fd
)
2199 fprintf(fd
, "#endif //_LTT_FACILITY_%s_H_\n",fac
->capname
);
2202 void print_log_header_tail_user(facility_t
*fac
, FILE *fd
)
2204 fprintf(fd
, "#endif //_LTT_FACILITY_%s_H_\n",fac
->capname
);
2207 int print_log_header(facility_t
*fac
)
2209 char filename
[PATH_MAX
];
2210 unsigned int filename_size
= 0;
2212 dprintf("%s\n", fac
->name
);
2214 strcpy(filename
, "ltt-facility-");
2215 filename_size
= strlen(filename
);
2217 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
2218 filename_size
= strlen(filename
);
2221 strncat(filename
, "_", PATH_MAX
- filename_size
);
2222 filename_size
= strlen(filename
);
2224 strncat(filename
, fac
->arch
, PATH_MAX
- filename_size
);
2225 filename_size
= strlen(filename
);
2228 strncat(filename
, ".h", PATH_MAX
- filename_size
);
2229 filename_size
= strlen(filename
);
2232 fd
= fopen(filename
, "w");
2234 printf("Error opening file %s for writing : %s\n",
2235 filename
, strerror(errno
));
2239 /* Print file head */
2241 print_log_header_head(fac
, fd
);
2243 print_log_header_head_user(fac
, fd
);
2245 /* print named types in declaration order */
2246 if(print_log_header_types(fac
, fd
)) return 1;
2249 if(print_log_header_events(fac
, fd
)) return 1;
2251 /* Print file tail */
2253 print_log_header_tail(fac
, fd
);
2255 print_log_header_tail_user(fac
, fd
);
2265 /* ltt-facility-id-name.h : facility id.
2267 int print_id_header(facility_t
*fac
)
2269 char filename
[PATH_MAX
];
2270 unsigned int filename_size
= 0;
2272 char basename
[PATH_MAX
];
2273 char basename_len
= 0;
2275 dprintf("%s\n", fac
->name
);
2277 strcpy(filename
, "ltt-facility-id-");
2278 filename_size
= strlen(filename
);
2280 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
2281 filename_size
= strlen(filename
);
2284 strncat(filename
, "_", PATH_MAX
- filename_size
);
2285 filename_size
= strlen(filename
);
2287 strncat(filename
, fac
->arch
, PATH_MAX
- filename_size
);
2288 filename_size
= strlen(filename
);
2291 strncat(filename
, ".h", PATH_MAX
- filename_size
);
2292 filename_size
= strlen(filename
);
2295 fd
= fopen(filename
, "w");
2297 printf("Error opening file %s for writing : %s\n",
2298 filename
, strerror(errno
));
2303 fprintf(fd
, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
2304 fprintf(fd
, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac
->capname
);
2305 fprintf(fd
, "#ifdef CONFIG_LTT\n");
2307 fprintf(fd
,"#include <linux/ltt-facilities.h>\n\n");
2309 fprintf(fd
,"/**** facility handle ****/\n\n");
2310 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s_%X;\n",
2311 fac
->name
, fac
->checksum
);
2312 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s;\n\n\n",fac
->name
);
2314 strncpy(basename
, fac
->name
, PATH_MAX
);
2315 basename_len
= strlen(basename
);
2316 strncat(basename
, "_", PATH_MAX
- basename_len
);
2319 fprintf(fd
,"/**** event index ****/\n\n");
2320 fprintf(fd
,"enum %s_event {\n",fac
->name
);
2322 for(unsigned int i
= 0; i
< fac
->events
.position
; i
++) {
2323 event_t
*event
= (event_t
*)fac
->events
.array
[i
];
2324 strncpy(basename
+basename_len
, event
->name
, PATH_MAX
-basename_len
);
2326 fprintf(fd
, "event_%s,\n", basename
);
2329 fprintf(fd
, "facility_%s_num_events\n", fac
->name
);
2330 fprintf(fd
, "};\n");
2334 fprintf(fd
, "#endif //CONFIG_LTT\n");
2335 fprintf(fd
, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
2337 fprintf(fd
, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
2338 fprintf(fd
, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac
->capname
);
2339 fprintf(fd
, "#ifdef LTT_TRACE\n");
2341 fprintf(fd
,"#include <ltt/ltt-generic.h>\n\n");
2343 fprintf(fd
,"/**** facility handle ****/\n\n");
2344 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s_%X;\n",
2345 fac
->name
, fac
->checksum
);
2346 fprintf(fd
,"extern ltt_facility_t ltt_facility_%s;\n\n\n",fac
->name
);
2348 strncpy(basename
, fac
->name
, PATH_MAX
);
2349 basename_len
= strlen(basename
);
2350 strncat(basename
, "_", PATH_MAX
- basename_len
);
2353 fprintf(fd
,"/**** event index ****/\n\n");
2354 fprintf(fd
,"enum %s_event {\n",fac
->name
);
2356 for(unsigned int i
= 0; i
< fac
->events
.position
; i
++) {
2357 event_t
*event
= (event_t
*)fac
->events
.array
[i
];
2358 strncpy(basename
+basename_len
, event
->name
, PATH_MAX
-basename_len
);
2360 fprintf(fd
, "event_%s,\n", basename
);
2363 fprintf(fd
, "facility_%s_num_events\n", fac
->name
);
2364 fprintf(fd
, "};\n");
2368 fprintf(fd
, "#endif //LTT_TRACE\n");
2369 fprintf(fd
, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac
->capname
);
2379 /* ltt-facility-loader-name.h : facility specific loader info.
2381 int print_loader_header(facility_t
*fac
)
2383 char filename
[PATH_MAX
];
2384 unsigned int filename_size
= 0;
2386 dprintf("%s\n", fac
->name
);
2388 strcpy(filename
, "ltt-facility-loader-");
2389 filename_size
= strlen(filename
);
2391 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
2392 filename_size
= strlen(filename
);
2395 strncat(filename
, "_", PATH_MAX
- filename_size
);
2396 filename_size
= strlen(filename
);
2398 strncat(filename
, fac
->arch
, PATH_MAX
- filename_size
);
2399 filename_size
= strlen(filename
);
2402 strncat(filename
, ".h", PATH_MAX
- filename_size
);
2403 filename_size
= strlen(filename
);
2406 fd
= fopen(filename
, "w");
2408 printf("Error opening file %s for writing : %s\n",
2409 filename
, strerror(errno
));
2413 fprintf(fd
, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
2414 fprintf(fd
, "#define _LTT_FACILITY_LOADER_%s_H_\n\n", fac
->capname
);
2415 fprintf(fd
, "#ifdef CONFIG_LTT\n\n");
2416 fprintf(fd
,"#include <linux/ltt-facilities.h>\n");
2418 fprintf(fd
,"#include <linux/ltt/ltt-facility-id-%s.h>\n\n",
2421 fprintf(fd
,"#include <asm/ltt/ltt-facility-id-%s_%s.h>\n\n",
2424 fprintf(fd
,"ltt_facility_t\tltt_facility_%s;\n", fac
->name
);
2425 fprintf(fd
,"ltt_facility_t\tltt_facility_%s_%X;\n\n",
2426 fac
->name
, fac
->checksum
);
2428 fprintf(fd
,"#define LTT_FACILITY_SYMBOL\t\t\t\t\t\t\tltt_facility_%s\n",
2430 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM_SYMBOL\t\tltt_facility_%s_%X\n",
2431 fac
->name
, fac
->checksum
);
2432 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM\t\t\t\t\t\t0x%X\n", fac
->checksum
);
2433 fprintf(fd
,"#define LTT_FACILITY_NAME\t\t\t\t\t\t\t\t\"%s\"\n", fac
->name
);
2434 fprintf(fd
,"#define LTT_FACILITY_NUM_EVENTS\t\t\t\t\tfacility_%s_num_events\n\n",
2436 fprintf(fd
, "#endif //CONFIG_LTT\n\n");
2437 fprintf(fd
, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
2444 int print_loader_header_user(facility_t
*fac
)
2446 char filename
[PATH_MAX
];
2447 unsigned int filename_size
= 0;
2449 dprintf("%s\n", fac
->name
);
2451 strcpy(filename
, "ltt-facility-loader-");
2452 filename_size
= strlen(filename
);
2454 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
2455 filename_size
= strlen(filename
);
2458 strncat(filename
, "_", PATH_MAX
- filename_size
);
2459 filename_size
= strlen(filename
);
2461 strncat(filename
, fac
->arch
, PATH_MAX
- filename_size
);
2462 filename_size
= strlen(filename
);
2465 strncat(filename
, ".h", PATH_MAX
- filename_size
);
2466 filename_size
= strlen(filename
);
2469 fd
= fopen(filename
, "w");
2471 printf("Error opening file %s for writing : %s\n",
2472 filename
, strerror(errno
));
2476 fprintf(fd
, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
2477 fprintf(fd
, "#define _LTT_FACILITY_LOADER_%s_H_\n\n", fac
->capname
);
2478 fprintf(fd
,"#include <ltt/ltt-generic.h>\n");
2480 fprintf(fd
,"#include <ltt/ltt-facility-id-%s.h>\n\n",
2483 fprintf(fd
,"#include <asm/ltt/ltt-facility-id-%s_%s.h>\n\n",
2486 fprintf(fd
,"ltt_facility_t\tltt_facility_%s;\n", fac
->name
);
2487 fprintf(fd
,"ltt_facility_t\tltt_facility_%s_%X;\n\n",
2488 fac
->name
, fac
->checksum
);
2490 fprintf(fd
,"#define LTT_FACILITY_SYMBOL\t\t\t\t\t\t\tltt_facility_%s\n",
2492 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM_SYMBOL\t\tltt_facility_%s_%X\n",
2493 fac
->name
, fac
->checksum
);
2494 fprintf(fd
,"#define LTT_FACILITY_CHECKSUM\t\t\t\t\t\t0x%X\n", fac
->checksum
);
2495 fprintf(fd
,"#define LTT_FACILITY_NAME\t\t\t\t\t\t\t\t\"%s\"\n", fac
->name
);
2496 fprintf(fd
,"#define LTT_FACILITY_NUM_EVENTS\t\t\t\t\tfacility_%s_num_events\n\n",
2498 fprintf(fd
, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac
->capname
);
2507 /* ltt-facility-loader-name.c : generic facility loader
2509 int print_loader_c(facility_t
*fac
)
2511 char filename
[PATH_MAX
];
2512 unsigned int filename_size
= 0;
2514 dprintf("%s\n", fac
->name
);
2516 strcpy(filename
, "ltt-facility-loader-");
2517 filename_size
= strlen(filename
);
2519 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
2520 filename_size
= strlen(filename
);
2523 strncat(filename
, "_", PATH_MAX
- filename_size
);
2524 filename_size
= strlen(filename
);
2526 strncat(filename
, fac
->arch
, PATH_MAX
- filename_size
);
2527 filename_size
= strlen(filename
);
2530 strncat(filename
, ".c", PATH_MAX
- filename_size
);
2531 filename_size
= strlen(filename
);
2534 fd
= fopen(filename
, "w");
2536 printf("Error opening file %s for writing : %s\n",
2537 filename
, strerror(errno
));
2541 fprintf(fd
, "/*\n");
2543 fprintf(fd
, " * ltt-facility-loader-%s.c\n", fac
->name
);
2545 fprintf(fd
, " * ltt-facility-loader-%s_%s.c\n", fac
->name
, fac
->arch
);
2546 fprintf(fd
, " *\n");
2547 fprintf(fd
, " * (C) Copyright 2005 - \n");
2548 fprintf(fd
, " * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)\n");
2549 fprintf(fd
, " *\n");
2550 fprintf(fd
, " * Contains the LTT facility loader.\n");
2551 fprintf(fd
, " *\n");
2552 fprintf(fd
, " */\n");
2555 fprintf(fd
, "#include <linux/ltt-facilities.h>\n");
2556 fprintf(fd
, "#include <linux/module.h>\n");
2557 fprintf(fd
, "#include <linux/init.h>\n");
2558 fprintf(fd
, "#include <linux/config.h>\n");
2560 fprintf(fd
, "#include \"ltt-facility-loader-%s.h\"\n", fac
->name
);
2562 fprintf(fd
, "#include \"ltt-facility-loader-%s_%s.h\"\n",
2563 fac
->name
, fac
->arch
);
2566 fprintf(fd
, "#ifdef CONFIG_LTT\n");
2568 fprintf(fd
, "EXPORT_SYMBOL(LTT_FACILITY_SYMBOL);\n");
2569 fprintf(fd
, "EXPORT_SYMBOL(LTT_FACILITY_CHECKSUM_SYMBOL);\n");
2571 fprintf(fd
, "static const char ltt_facility_name[] = LTT_FACILITY_NAME;\n");
2573 fprintf(fd
, "#define SYMBOL_STRING(sym) #sym\n");
2575 fprintf(fd
, "static struct ltt_facility facility = {\n");
2576 fprintf(fd
, "\t.name = ltt_facility_name,\n");
2577 fprintf(fd
, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n");
2578 fprintf(fd
, "\t.checksum = LTT_FACILITY_CHECKSUM,\n");
2579 fprintf(fd
, "\t.symbol = SYMBOL_STRING(LTT_FACILITY_SYMBOL),\n");
2580 fprintf(fd
, "};\n");
2582 fprintf(fd
, "static int __init facility_init(void)\n");
2584 fprintf(fd
, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init in kernel\\n\");\n", fac
->name
);
2586 fprintf(fd
, "\tLTT_FACILITY_SYMBOL = ltt_facility_kernel_register(&facility);\n");
2587 fprintf(fd
, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
2588 fprintf(fd
, "\t\n");
2589 fprintf(fd
, "\treturn LTT_FACILITY_SYMBOL;\n");
2591 fprintf(fd
, "__initcall(facility_init);\n");
2594 fprintf(fd
, "#ifndef MODULE\n");
2596 fprintf(fd
, "static void __exit facility_exit(void)\n");
2598 fprintf(fd
, "\tint err;\n");
2600 fprintf(fd
, "\terr = ltt_facility_unregister(LTT_FACILITY_SYMBOL);\n");
2601 fprintf(fd
, "\tif(err != 0)\n");
2602 fprintf(fd
, "\t\tprintk(KERN_ERR \"LTT : Error in unregistering facility.\\n\");\n");
2606 fprintf(fd
, "module_exit(facility_exit)\n");
2609 fprintf(fd
, "MODULE_LICENSE(\"GPL\");\n");
2610 fprintf(fd
, "MODULE_AUTHOR(\"Mathieu Desnoyers\");\n");
2611 fprintf(fd
, "MODULE_DESCRIPTION(\"Linux Trace Toolkit Facility\");\n");
2613 fprintf(fd
, "#endif //MODULE\n");
2615 fprintf(fd
, "#endif //CONFIG_LTT\n");
2622 int print_loader_c_user(facility_t
*fac
)
2624 char filename
[PATH_MAX
];
2625 unsigned int filename_size
= 0;
2627 dprintf("%s\n", fac
->name
);
2629 strcpy(filename
, "ltt-facility-loader-");
2630 filename_size
= strlen(filename
);
2632 strncat(filename
, fac
->name
, PATH_MAX
- filename_size
);
2633 filename_size
= strlen(filename
);
2636 strncat(filename
, "_", PATH_MAX
- filename_size
);
2637 filename_size
= strlen(filename
);
2639 strncat(filename
, fac
->arch
, PATH_MAX
- filename_size
);
2640 filename_size
= strlen(filename
);
2643 strncat(filename
, ".c", PATH_MAX
- filename_size
);
2644 filename_size
= strlen(filename
);
2647 fd
= fopen(filename
, "w");
2649 printf("Error opening file %s for writing : %s\n",
2650 filename
, strerror(errno
));
2654 fprintf(fd
, "/*\n");
2656 fprintf(fd
, " * ltt-facility-loader-%s.c\n", fac
->name
);
2658 fprintf(fd
, " * ltt-facility-loader-%s_%s.c\n", fac
->name
, fac
->arch
);
2659 fprintf(fd
, " *\n");
2660 fprintf(fd
, " * (C) Copyright 2005 - \n");
2661 fprintf(fd
, " * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)\n");
2662 fprintf(fd
, " *\n");
2663 fprintf(fd
, " * Contains the LTT user space facility loader.\n");
2664 fprintf(fd
, " *\n");
2665 fprintf(fd
, " */\n");
2668 fprintf(fd
, "#define LTT_TRACE\n");
2669 fprintf(fd
, "#include <error.h>\n");
2670 fprintf(fd
, "#include <stdio.h>\n");
2671 fprintf(fd
, "#include <ltt/ltt-generic.h>\n");
2673 fprintf(fd
, "#include \"ltt-facility-loader-%s.h\"\n", fac
->name
);
2675 fprintf(fd
, "#include \"ltt-facility-loader-%s_%s.h\"\n",
2676 fac
->name
, fac
->arch
);
2678 fprintf(fd
, "static struct user_facility_info facility = {\n");
2679 fprintf(fd
, "\t.name = LTT_FACILITY_NAME,\n");
2680 fprintf(fd
, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n");
2681 fprintf(fd
, "#ifndef LTT_PACK\n");
2682 fprintf(fd
, "\t.alignment = sizeof(void*),\n");
2683 fprintf(fd
, "#else\n");
2684 fprintf(fd
, "\t.alignment = 0,\n");
2685 fprintf(fd
, "#endif //LTT_PACK\n");
2686 fprintf(fd
, "\t.checksum = LTT_FACILITY_CHECKSUM,\n");
2687 fprintf(fd
, "\t.int_size = sizeof(int),\n");
2688 fprintf(fd
, "\t.long_size = sizeof(long),\n");
2689 fprintf(fd
, "\t.pointer_size = sizeof(void*),\n");
2690 fprintf(fd
, "\t.size_t_size = sizeof(size_t)\n");
2691 fprintf(fd
, "};\n");
2693 fprintf(fd
, "static void __attribute__((constructor)) __ltt_user_init(void)\n");
2695 fprintf(fd
, "\tint err;\n");
2696 fprintf(fd
, "#ifdef LTT_SHOW_DEBUG\n");
2697 fprintf(fd
, "\tprintf(\"LTT : ltt-facility-%s init in userspace\\n\");\n", fac
->name
);
2698 fprintf(fd
, "#endif //LTT_SHOW_DEBUG\n");
2700 fprintf(fd
, "\terr = ltt_register_generic(<T_FACILITY_SYMBOL, &facility);\n");
2701 fprintf(fd
, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n");
2702 fprintf(fd
, "\t\n");
2703 fprintf(fd
, "\tif(err) {\n");
2704 fprintf(fd
, "#ifdef LTT_SHOW_DEBUG\n");
2705 fprintf(fd
, "\t\tperror(\"Error in ltt_register_generic\");\n");
2706 fprintf(fd
, "#endif //LTT_SHOW_DEBUG\n");
2707 fprintf(fd
, "\t}\n");
2719 /* code taken from ltt_facility_open in ltt/facility.c in lttv */
2721 /*****************************************************************************
2723 * ltt_facility_open : open facilities
2725 * pathname : the path name of the facility
2727 * Open the facility corresponding to the right checksum.
2729 *returns the facility on success, NULL on error.
2730 ****************************************************************************/
2731 facility_t
*ltt_facility_open(char * pathname
)
2736 facility_t
* fac
= NULL
;
2737 char buffer
[BUFFER_SIZE
];
2738 int generated
= FALSE
;
2740 in
.buffer
= &(buffer
[0]);
2742 in
.error
= error_callback
;
2746 in
.fp
= fopen(in
.name
, "r");
2753 token
= getToken(&in
);
2754 if(in
.type
== ENDFILE
) break;
2757 printf("More than one facility in the file. Only using the first one.\n");
2761 if(strcmp(token
, "<")) in
.error(&in
,"not a facility file");
2762 token
= getName(&in
);
2764 if(strcmp("facility",token
) == 0) {
2765 fac
= malloc(sizeof(facility_t
));
2767 fac
->description
= NULL
;
2768 sequence_init(&(fac
->events
));
2769 table_init(&(fac
->named_types
));
2770 sequence_init(&(fac
->unnamed_types
));
2772 parseFacility(&in
, fac
);
2774 //check if any namedType is not defined
2775 checkNamedTypesImplemented(&fac
->named_types
);
2777 generateChecksum(fac
->name
, &fac
->checksum
, &fac
->events
);
2782 printf("facility token was expected in file %s\n", in
.name
);
2793 printf("Cannot find facility %s\n", pathname
);
2800 /* Close the facility */
2801 void ltt_facility_close(facility_t
*fac
)
2805 free(fac
->description
);
2806 freeEvents(&fac
->events
);
2807 sequence_dispose(&fac
->events
);
2808 freeNamedType(&fac
->named_types
);
2809 table_dispose(&fac
->named_types
);
2810 freeTypes(&fac
->unnamed_types
);
2811 sequence_dispose(&fac
->unnamed_types
);
2817 void show_help(int argc
, char ** argv
)
2819 printf("Genevent help : \n");
2821 printf("Use %s name.xml\n", argv
[0]);
2822 printf("to create :\n");
2823 printf("ltt-facility-name.h\n");
2824 printf("ltt-facility-id-name.h\n");
2825 printf("ltt-facility-loader-name.h\n");
2826 printf("ltt-facility-loader-name.c\n");
2827 printf("In the current directory.\n");
2831 /* Parse program arguments */
2833 * 0 : continue program
2834 * -1 : stop program, return 0
2835 * > 0 : stop program, return value as exit.
2837 int check_args(int argc
, char **argv
)
2840 printf("Not enough arguments\n");
2841 show_help(argc
, argv
);
2845 if(strcmp(argv
[1], "-h") == 0) {
2846 show_help(argc
, argv
);
2853 int main(int argc
, char **argv
)
2858 err
= check_args(argc
, argv
);
2859 if(err
> 0) return err
;
2860 else if(err
< 0) return 0;
2862 /* open the facility */
2863 fac
= ltt_facility_open(argv
[1]);
2865 printf("Error opening file %s for reading : %s\n",
2866 argv
[1], strerror(errno
));
2870 /* generate the output C files */
2873 /* ltt-facility-name.h : main logging header.
2875 err
= print_log_header(fac
);
2878 /* ltt-facility-id-name.h : facility id.
2880 err
= print_id_header(fac
);
2883 /* ltt-facility-loader-name.h : facility specific loader info.
2886 err
= print_loader_header(fac
);
2888 err
= print_loader_header_user(fac
);
2891 /* ltt-facility-loader-name.c : generic faciilty loader
2894 err
= print_loader_c(fac
);
2896 err
= print_loader_c_user(fac
);
2899 /* close the facility */
2900 ltt_facility_close(fac
);
This page took 0.090957 seconds and 4 git commands to generate.