| 1 | /****************************************************************************** |
| 2 | * Genevent |
| 3 | * |
| 4 | * Event generator. XML to logging C code converter. |
| 5 | * |
| 6 | * Program parameters : |
| 7 | * ./genevent name.xml |
| 8 | * |
| 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. |
| 12 | * |
| 13 | * Supports : |
| 14 | * - C Alignment |
| 15 | * - C types : struct, union, enum, basic types. |
| 16 | * - Architectures : LP32, ILP32, ILP64, LLP64, LP64. |
| 17 | * |
| 18 | * Additionnal structures supported : |
| 19 | * - embedded variable size strings |
| 20 | * - embedded variable size arrays |
| 21 | * - embedded variable size sequences |
| 22 | * |
| 23 | * Notes : |
| 24 | * (1) |
| 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. |
| 29 | * |
| 30 | * (2) |
| 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. |
| 34 | * |
| 35 | * Note that, from |
| 36 | * http://www.usenix.org/publications/login/standards/10.data.html |
| 37 | * (Andrew Josey <a.josey@opengroup.org>) : |
| 38 | * |
| 39 | * Data Type LP32 ILP32 ILP64 LLP64 LP64 |
| 40 | * char 8 8 8 8 8 |
| 41 | * short 16 16 16 16 16 |
| 42 | * int32 32 |
| 43 | * int 16 32 64 32 32 |
| 44 | * long 32 32 64 32 64 |
| 45 | * long long (int64) 64 |
| 46 | * pointer 32 32 64 64 64 |
| 47 | * |
| 48 | * With these constraints : |
| 49 | * sizeof(char) <= sizeof(short) <= sizeof(int) |
| 50 | * <= sizeof(long) = sizeof(size_t) |
| 51 | * |
| 52 | * and therefore sizeof(long) <= sizeof(pointer) <= sizeof(size_t) |
| 53 | * |
| 54 | * Which means we only have to remember which is the biggest type in a structure |
| 55 | * to know the structure's alignment. |
| 56 | */ |
| 57 | |
| 58 | #define _GNU_SOURCE |
| 59 | #include <limits.h> |
| 60 | #include <stdlib.h> |
| 61 | #include <errno.h> |
| 62 | #include <sys/types.h> |
| 63 | #include <sys/stat.h> |
| 64 | #include <fcntl.h> |
| 65 | #include <stdio.h> |
| 66 | #include <string.h> |
| 67 | #include <unistd.h> |
| 68 | #include <assert.h> |
| 69 | |
| 70 | #include "genevent.h" |
| 71 | #include "parser.h" |
| 72 | |
| 73 | |
| 74 | #define TRUE 1 |
| 75 | #define FALSE (!TRUE) |
| 76 | |
| 77 | /* Debugging printf */ |
| 78 | #ifdef DEBUG |
| 79 | #define dprintf(...) \ |
| 80 | do {\ |
| 81 | printf(__FILE__ ",%u,%s: ",\ |
| 82 | __LINE__, __func__);\ |
| 83 | printf(__VA_ARGS__);\ |
| 84 | } while(0) |
| 85 | #else |
| 86 | #define dprintf(...) |
| 87 | #endif |
| 88 | |
| 89 | |
| 90 | enum user_fct_types { USER_FCT_PROTO, USER_FCT_DECLARATION } ; |
| 91 | |
| 92 | /* Code printing */ |
| 93 | |
| 94 | void print_tabs(unsigned int tabs, FILE *fd) |
| 95 | { |
| 96 | for(unsigned int i = 0; i<tabs;i++) |
| 97 | fprintf(fd, "\t"); |
| 98 | } |
| 99 | |
| 100 | /* print type. |
| 101 | * |
| 102 | * Copied from construct_types_and_fields in LTTV facility.c */ |
| 103 | |
| 104 | int print_type(type_descriptor_t * td, FILE *fd, unsigned int tabs, |
| 105 | char *nest_name, char *field_name) |
| 106 | { |
| 107 | char basename[PATH_MAX]; |
| 108 | unsigned int basename_len = 0; |
| 109 | |
| 110 | strcpy(basename, nest_name); |
| 111 | basename_len = strlen(basename); |
| 112 | |
| 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); |
| 117 | } else { |
| 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); |
| 124 | } |
| 125 | strncat(basename, field_name, PATH_MAX - basename_len); |
| 126 | } |
| 127 | |
| 128 | switch(td->type) { |
| 129 | case INT_FIXED: |
| 130 | fprintf(fd, "%s", intOutputTypes[getSizeindex(td->size)]); |
| 131 | break; |
| 132 | case UINT_FIXED: |
| 133 | fprintf(fd, "%s", uintOutputTypes[getSizeindex(td->size)]); |
| 134 | break; |
| 135 | case CHAR: |
| 136 | fprintf(fd, "signed char"); |
| 137 | break; |
| 138 | case UCHAR: |
| 139 | fprintf(fd, "unsigned char"); |
| 140 | break; |
| 141 | case SHORT: |
| 142 | fprintf(fd, "short"); |
| 143 | break; |
| 144 | case USHORT: |
| 145 | fprintf(fd, "unsigned short"); |
| 146 | break; |
| 147 | case INT: |
| 148 | fprintf(fd, "int"); |
| 149 | break; |
| 150 | case UINT: |
| 151 | fprintf(fd, "unsigned int"); |
| 152 | break; |
| 153 | case FLOAT: |
| 154 | fprintf(fd, "%s", floatOutputTypes[getSizeindex(td->size)]); |
| 155 | break; |
| 156 | case POINTER: |
| 157 | fprintf(fd, "const void *"); |
| 158 | break; |
| 159 | case LONG: |
| 160 | fprintf(fd, "long"); |
| 161 | break; |
| 162 | case ULONG: |
| 163 | fprintf(fd, "unsigned long"); |
| 164 | break; |
| 165 | case SIZE_T: |
| 166 | fprintf(fd, "size_t"); |
| 167 | break; |
| 168 | case SSIZE_T: |
| 169 | fprintf(fd, "ssize_t"); |
| 170 | break; |
| 171 | case OFF_T: |
| 172 | fprintf(fd, "off_t"); |
| 173 | break; |
| 174 | case STRING: |
| 175 | fprintf(fd, "const char *"); |
| 176 | break; |
| 177 | case ENUM: |
| 178 | fprintf(fd, "enum lttng_%s", basename); |
| 179 | break; |
| 180 | case ARRAY: |
| 181 | fprintf(fd, "lttng_array_%s", basename); |
| 182 | break; |
| 183 | case SEQUENCE: |
| 184 | fprintf(fd, "lttng_sequence_%s", basename); |
| 185 | break; |
| 186 | case STRUCT: |
| 187 | fprintf(fd, "struct lttng_%s", basename); |
| 188 | break; |
| 189 | case UNION: |
| 190 | fprintf(fd, "union lttng_%s", basename); |
| 191 | break; |
| 192 | default: |
| 193 | printf("print_type : unknown type\n"); |
| 194 | return 1; |
| 195 | } |
| 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
| 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) |
| 203 | { |
| 204 | char basename[PATH_MAX]; |
| 205 | unsigned int basename_len = 0; |
| 206 | |
| 207 | strcpy(basename, nest_name); |
| 208 | basename_len = strlen(basename); |
| 209 | |
| 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); |
| 214 | } else { |
| 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); |
| 221 | } |
| 222 | strncat(basename, field_name, PATH_MAX - basename_len); |
| 223 | } |
| 224 | |
| 225 | print_tabs(tabs, fd); |
| 226 | |
| 227 | switch(td->type) { |
| 228 | case INT_FIXED: |
| 229 | fprintf(fd, "%s", intOutputTypes[getSizeindex(td->size)]); |
| 230 | fprintf(fd, " lttng_param_%s", field_name); |
| 231 | break; |
| 232 | case UINT_FIXED: |
| 233 | fprintf(fd, "%s", uintOutputTypes[getSizeindex(td->size)]); |
| 234 | fprintf(fd, " lttng_param_%s", field_name); |
| 235 | break; |
| 236 | case CHAR: |
| 237 | fprintf(fd, "signed char"); |
| 238 | fprintf(fd, " lttng_param_%s", field_name); |
| 239 | break; |
| 240 | case UCHAR: |
| 241 | fprintf(fd, "unsigned char"); |
| 242 | fprintf(fd, " lttng_param_%s", field_name); |
| 243 | break; |
| 244 | case SHORT: |
| 245 | fprintf(fd, "short"); |
| 246 | fprintf(fd, " lttng_param_%s", field_name); |
| 247 | break; |
| 248 | case USHORT: |
| 249 | fprintf(fd, "unsigned short"); |
| 250 | fprintf(fd, " lttng_param_%s", field_name); |
| 251 | break; |
| 252 | case INT: |
| 253 | fprintf(fd, "int"); |
| 254 | fprintf(fd, " lttng_param_%s", field_name); |
| 255 | break; |
| 256 | case UINT: |
| 257 | fprintf(fd, "unsigned int"); |
| 258 | fprintf(fd, " lttng_param_%s", field_name); |
| 259 | break; |
| 260 | case FLOAT: |
| 261 | fprintf(fd, "%s", floatOutputTypes[getSizeindex(td->size)]); |
| 262 | fprintf(fd, " lttng_param_%s", field_name); |
| 263 | break; |
| 264 | case POINTER: |
| 265 | fprintf(fd, "const void *"); |
| 266 | fprintf(fd, " lttng_param_%s", field_name); |
| 267 | break; |
| 268 | case LONG: |
| 269 | fprintf(fd, "long"); |
| 270 | fprintf(fd, " lttng_param_%s", field_name); |
| 271 | break; |
| 272 | case ULONG: |
| 273 | fprintf(fd, "unsigned long"); |
| 274 | fprintf(fd, " lttng_param_%s", field_name); |
| 275 | break; |
| 276 | case SIZE_T: |
| 277 | fprintf(fd, "size_t"); |
| 278 | fprintf(fd, " lttng_param_%s", field_name); |
| 279 | break; |
| 280 | case SSIZE_T: |
| 281 | fprintf(fd, "ssize_t"); |
| 282 | fprintf(fd, " lttng_param_%s", field_name); |
| 283 | break; |
| 284 | case OFF_T: |
| 285 | fprintf(fd, "off_t"); |
| 286 | fprintf(fd, " lttng_param_%s", field_name); |
| 287 | break; |
| 288 | case STRING: |
| 289 | fprintf(fd, "const char *"); |
| 290 | fprintf(fd, " lttng_param_%s", field_name); |
| 291 | break; |
| 292 | case ENUM: |
| 293 | fprintf(fd, "enum lttng_%s", basename); |
| 294 | fprintf(fd, " lttng_param_%s", field_name); |
| 295 | break; |
| 296 | case ARRAY: |
| 297 | fprintf(fd, "lttng_array_%s", basename); |
| 298 | fprintf(fd, " lttng_param_%s", field_name); |
| 299 | break; |
| 300 | case SEQUENCE: |
| 301 | fprintf(fd, "lttng_sequence_%s *", basename); |
| 302 | fprintf(fd, " lttng_param_%s", field_name); |
| 303 | break; |
| 304 | case STRUCT: |
| 305 | fprintf(fd, "struct lttng_%s *", basename); |
| 306 | fprintf(fd, " lttng_param_%s", field_name); |
| 307 | break; |
| 308 | case UNION: |
| 309 | fprintf(fd, "union lttng_%s *", basename); |
| 310 | fprintf(fd, " lttng_param_%s", field_name); |
| 311 | break; |
| 312 | default: |
| 313 | printf("print_type : unknown type\n"); |
| 314 | return 1; |
| 315 | } |
| 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | |
| 321 | /* Does the type has a fixed size ? (as know from the compiler) |
| 322 | * |
| 323 | * 1 : fixed size |
| 324 | * 0 : variable length |
| 325 | */ |
| 326 | int has_type_fixed_size(type_descriptor_t *td) |
| 327 | { |
| 328 | switch(td->type) { |
| 329 | case INT_FIXED: |
| 330 | case UINT_FIXED: |
| 331 | case CHAR: |
| 332 | case UCHAR: |
| 333 | case SHORT: |
| 334 | case USHORT: |
| 335 | case INT: |
| 336 | case UINT: |
| 337 | case FLOAT: |
| 338 | case POINTER: |
| 339 | case LONG: |
| 340 | case ULONG: |
| 341 | case SIZE_T: |
| 342 | case SSIZE_T: |
| 343 | case OFF_T: |
| 344 | case ENUM: |
| 345 | case UNION: /* The union must have fixed size children. Must be checked by |
| 346 | the parser */ |
| 347 | return 1; |
| 348 | break; |
| 349 | case STRING: |
| 350 | case SEQUENCE: |
| 351 | return 0; |
| 352 | break; |
| 353 | case STRUCT: |
| 354 | { |
| 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; |
| 359 | |
| 360 | has_type_fixed = has_type_fixed_size(type); |
| 361 | if(!has_type_fixed) return 0; |
| 362 | } |
| 363 | return 1; |
| 364 | } |
| 365 | break; |
| 366 | case ARRAY: |
| 367 | assert(td->size >= 0); |
| 368 | return has_type_fixed_size(((field_t*)td->fields.array[0])->type); |
| 369 | break; |
| 370 | case NONE: |
| 371 | printf("There is a type defined to NONE : bad.\n"); |
| 372 | assert(0); |
| 373 | break; |
| 374 | } |
| 375 | return 0; //make gcc happy. |
| 376 | } |
| 377 | |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | /* print type declaration. |
| 383 | * |
| 384 | * Copied from construct_types_and_fields in LTTV facility.c */ |
| 385 | |
| 386 | int print_type_declaration(type_descriptor_t * td, FILE *fd, unsigned int tabs, |
| 387 | char *nest_name, char *field_name) |
| 388 | { |
| 389 | char basename[PATH_MAX]; |
| 390 | unsigned int basename_len = 0; |
| 391 | |
| 392 | if(td->custom_write) return 0; /* Does print custom type */ |
| 393 | |
| 394 | strncpy(basename, nest_name, PATH_MAX); |
| 395 | basename_len = strlen(basename); |
| 396 | |
| 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); |
| 401 | } else { |
| 402 | /* For a unnamed type, there must be a field name, except for |
| 403 | * the array. */ |
| 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); |
| 409 | } |
| 410 | strncat(basename, field_name, PATH_MAX - basename_len); |
| 411 | } |
| 412 | |
| 413 | switch(td->type) { |
| 414 | case ENUM: |
| 415 | fprintf(fd, "enum lttng_%s", basename); |
| 416 | fprintf(fd, " {\n"); |
| 417 | for(unsigned int i=0;i<td->labels.position;i++){ |
| 418 | print_tabs(1, fd); |
| 419 | fprintf(fd, "LTTNG_%s = %d", ((char*)td->labels.array[i]), |
| 420 | (*(int*)td->labels_values.array[i])); |
| 421 | fprintf(fd, ",\n"); |
| 422 | } |
| 423 | fprintf(fd, "};\n"); |
| 424 | fprintf(fd, "\n"); |
| 425 | break; |
| 426 | |
| 427 | case ARRAY: |
| 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; |
| 434 | } |
| 435 | fprintf(fd, "#define LTTNG_ARRAY_SIZE_%s %zu\n", basename, |
| 436 | td->size); |
| 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, |
| 441 | basename); |
| 442 | fprintf(fd, "\n"); |
| 443 | break; |
| 444 | case SEQUENCE: |
| 445 | /* We assume that the sequence length type does not need to be declared. |
| 446 | */ |
| 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; |
| 451 | } |
| 452 | fprintf(fd, "typedef struct lttng_sequence_%s lttng_sequence_%s;\n", |
| 453 | basename, |
| 454 | basename); |
| 455 | fprintf(fd, "struct lttng_sequence_%s", basename); |
| 456 | fprintf(fd, " {\n"); |
| 457 | print_tabs(1, fd); |
| 458 | if(print_type(((field_t*)td->fields.array[0])->type, |
| 459 | fd, tabs, basename, "")) return 1; |
| 460 | fprintf(fd, " len;\n"); |
| 461 | print_tabs(1, fd); |
| 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. */ |
| 468 | fprintf(fd, "\n"); |
| 469 | break; |
| 470 | |
| 471 | case STRUCT: |
| 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; |
| 479 | } |
| 480 | } |
| 481 | fprintf(fd, "struct lttng_%s", basename); |
| 482 | fprintf(fd, " {\n"); |
| 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; |
| 486 | print_tabs(1, fd); |
| 487 | if(print_type(type, fd, tabs, basename, field->name)) return 1; |
| 488 | fprintf(fd, " "); |
| 489 | fprintf(fd, "%s", field->name); |
| 490 | fprintf(fd, ";\n"); |
| 491 | } |
| 492 | if(td->fac->align) |
| 493 | fprintf(fd, "} LTT_ALIGN;\n"); |
| 494 | else |
| 495 | fprintf(fd, "};\n"); |
| 496 | fprintf(fd, "\n"); |
| 497 | break; |
| 498 | case UNION: |
| 499 | for(unsigned int i=0;i<td->fields.position;i++){ |
| 500 | field_t *field = (field_t*)(td->fields.array[i]); |
| 501 | type_descriptor_t *type = field->type; |
| 502 | if(type->type_name == NULL) { |
| 503 | /* Not a named nested type : we must print its declaration first */ |
| 504 | if(print_type_declaration(type, |
| 505 | fd, 0, basename, field->name)) return 1; |
| 506 | } |
| 507 | } |
| 508 | fprintf(fd, "union lttng_%s", basename); |
| 509 | fprintf(fd, " {\n"); |
| 510 | for(unsigned i=0;i<td->fields.position;i++){ |
| 511 | field_t *field = (field_t*)(td->fields.array[i]); |
| 512 | type_descriptor_t *type = field->type; |
| 513 | print_tabs(1, fd); |
| 514 | if(print_type(type, fd, tabs, basename, field->name)) return 1; |
| 515 | fprintf(fd, " "); |
| 516 | fprintf(fd, "%s", field->name); |
| 517 | fprintf(fd, ";\n"); |
| 518 | } |
| 519 | if(td->fac->align) |
| 520 | fprintf(fd, "} LTT_ALIGN;\n"); |
| 521 | else |
| 522 | fprintf(fd, "};\n"); |
| 523 | fprintf(fd, "\n"); |
| 524 | break; |
| 525 | default: |
| 526 | dprintf("print_type_declaration : unknown type or nothing to declare.\n"); |
| 527 | break; |
| 528 | } |
| 529 | |
| 530 | return 0; |
| 531 | } |
| 532 | |
| 533 | |
| 534 | /* print type alignment. |
| 535 | * |
| 536 | * Copied from construct_types_and_fields in LTTV facility.c |
| 537 | * |
| 538 | * basename is the name which identifies the type (along with a prefix |
| 539 | * (possibly)). */ |
| 540 | |
| 541 | int print_type_alignment(type_descriptor_t * td, FILE *fd, unsigned int tabs, |
| 542 | char *nest_name, char *field_name, char *obj_prefix) |
| 543 | { |
| 544 | char basename[PATH_MAX]; |
| 545 | unsigned int basename_len = 0; |
| 546 | |
| 547 | strncpy(basename, nest_name, PATH_MAX); |
| 548 | basename_len = strlen(basename); |
| 549 | |
| 550 | /* For a named type, we use the type_name directly */ |
| 551 | if(td->type_name != NULL) { |
| 552 | strncpy(basename, td->type_name, PATH_MAX); |
| 553 | basename_len = strlen(basename); |
| 554 | } else { |
| 555 | /* For a unnamed type, there must be a field name, except for |
| 556 | * the array. */ |
| 557 | if((basename_len != 0) |
| 558 | && (basename[basename_len-1] != '_' |
| 559 | && field_name != NULL |
| 560 | && (field_name[0] != '\0'))) { |
| 561 | strncat(basename, "_", PATH_MAX - basename_len); |
| 562 | basename_len = strlen(basename); |
| 563 | } |
| 564 | if(field_name != NULL) |
| 565 | strncat(basename, field_name, PATH_MAX - basename_len); |
| 566 | } |
| 567 | |
| 568 | if(field_name[0] == '\0') { |
| 569 | /* We are in a write function : it's the obj that we must align. */ |
| 570 | switch(td->type) { |
| 571 | case SEQUENCE: |
| 572 | fprintf(fd, "lttng_get_alignment_sequence_%s(%s)", basename, |
| 573 | obj_prefix); |
| 574 | break; |
| 575 | case STRUCT: |
| 576 | fprintf(fd, "lttng_get_alignment_struct_%s(%s)", basename, |
| 577 | obj_prefix); |
| 578 | break; |
| 579 | case UNION: |
| 580 | fprintf(fd, "lttng_get_alignment_union_%s(%s)", basename, |
| 581 | obj_prefix); |
| 582 | break; |
| 583 | case ARRAY: |
| 584 | fprintf(fd, "lttng_get_alignment_array_%s(%s)", basename, |
| 585 | obj_prefix); |
| 586 | case STRING: |
| 587 | fprintf(fd, "sizeof(char)"); |
| 588 | break; |
| 589 | case INT_FIXED: |
| 590 | case UINT_FIXED: |
| 591 | case CHAR: |
| 592 | case UCHAR: |
| 593 | case SHORT: |
| 594 | case USHORT: |
| 595 | case INT: |
| 596 | case UINT: |
| 597 | case FLOAT: |
| 598 | case POINTER: |
| 599 | case LONG: |
| 600 | case ULONG: |
| 601 | case SIZE_T: |
| 602 | case SSIZE_T: |
| 603 | case OFF_T: |
| 604 | case ENUM: |
| 605 | fprintf(fd, "sizeof("); |
| 606 | if(print_type(td, fd, 0, basename, "")) return 1; |
| 607 | fprintf(fd, ")"); |
| 608 | break; |
| 609 | |
| 610 | default: |
| 611 | printf("error : type unexpected\n"); |
| 612 | return 1; |
| 613 | break; |
| 614 | } |
| 615 | } else { |
| 616 | |
| 617 | switch(td->type) { |
| 618 | case INT_FIXED: |
| 619 | case UINT_FIXED: |
| 620 | case CHAR: |
| 621 | case UCHAR: |
| 622 | case SHORT: |
| 623 | case USHORT: |
| 624 | case INT: |
| 625 | case UINT: |
| 626 | case FLOAT: |
| 627 | case POINTER: |
| 628 | case LONG: |
| 629 | case ULONG: |
| 630 | case SIZE_T: |
| 631 | case SSIZE_T: |
| 632 | case OFF_T: |
| 633 | case ENUM: |
| 634 | fprintf(fd, "sizeof("); |
| 635 | if(print_type(td, fd, 0, basename, "")) return 1; |
| 636 | fprintf(fd, ")"); |
| 637 | break; |
| 638 | case STRING: |
| 639 | fprintf(fd, "sizeof(char)"); |
| 640 | break; |
| 641 | case SEQUENCE: |
| 642 | fprintf(fd, "lttng_get_alignment_sequence_%s(&%s%s)", basename, |
| 643 | obj_prefix, field_name); |
| 644 | break; |
| 645 | case STRUCT: |
| 646 | fprintf(fd, "lttng_get_alignment_struct_%s(&%s%s)", basename, |
| 647 | obj_prefix, field_name); |
| 648 | break; |
| 649 | case UNION: |
| 650 | fprintf(fd, "lttng_get_alignment_union_%s(&%s%s)", basename, |
| 651 | obj_prefix, field_name); |
| 652 | break; |
| 653 | case ARRAY: |
| 654 | fprintf(fd, "lttng_get_alignment_array_%s(%s%s)", basename, |
| 655 | obj_prefix, field_name); |
| 656 | break; |
| 657 | case NONE: |
| 658 | printf("error : type NONE unexpected\n"); |
| 659 | return 1; |
| 660 | break; |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | /* print type write. |
| 668 | * |
| 669 | * Copied from construct_types_and_fields in LTTV facility.c |
| 670 | * |
| 671 | * basename is the name which identifies the type (along with a prefix |
| 672 | * (possibly)). */ |
| 673 | |
| 674 | int print_type_write(type_descriptor_t * td, FILE *fd, unsigned int tabs, |
| 675 | char *nest_name, char *field_name, char *obj_prefix, int get_ptr) |
| 676 | { |
| 677 | char basename[PATH_MAX]; |
| 678 | unsigned int basename_len = 0; |
| 679 | char get_ptr_char[2] = ""; |
| 680 | char custom[PATH_MAX] = ""; |
| 681 | |
| 682 | strncpy(basename, nest_name, PATH_MAX); |
| 683 | basename_len = strlen(basename); |
| 684 | |
| 685 | /* For a named type, we use the type_name directly */ |
| 686 | if(td->type_name != NULL) { |
| 687 | strncpy(basename, td->type_name, PATH_MAX); |
| 688 | basename_len = strlen(basename); |
| 689 | } else { |
| 690 | /* For a unnamed type, there must be a field name, except for |
| 691 | * the array. */ |
| 692 | if((basename_len != 0) |
| 693 | && (basename[basename_len-1] != '_' |
| 694 | && (field_name[0] != '\0'))) { |
| 695 | strncat(basename, "_", PATH_MAX - basename_len); |
| 696 | basename_len = strlen(basename); |
| 697 | } |
| 698 | strncat(basename, field_name, PATH_MAX - basename_len); |
| 699 | } |
| 700 | |
| 701 | if(get_ptr) { |
| 702 | strcpy(get_ptr_char, "&"); |
| 703 | } |
| 704 | |
| 705 | if(td->custom_write) { |
| 706 | strcpy(custom, "_custom"); |
| 707 | } |
| 708 | |
| 709 | switch(td->type) { |
| 710 | case INT_FIXED: |
| 711 | case UINT_FIXED: |
| 712 | case CHAR: |
| 713 | case UCHAR: |
| 714 | case SHORT: |
| 715 | case USHORT: |
| 716 | case INT: |
| 717 | case UINT: |
| 718 | case FLOAT: |
| 719 | case POINTER: |
| 720 | case LONG: |
| 721 | case ULONG: |
| 722 | case SIZE_T: |
| 723 | case SSIZE_T: |
| 724 | case OFF_T: |
| 725 | case ENUM: |
| 726 | print_tabs(tabs, fd); |
| 727 | fprintf(fd, "align = "); |
| 728 | if(td->fac->align) { |
| 729 | if(print_type_alignment(td, fd, 0, basename, "", "obj")) return 1; |
| 730 | } else |
| 731 | fprintf(fd, "0"); |
| 732 | fprintf(fd, ";\n"); |
| 733 | fprintf(fd, "\n"); |
| 734 | print_tabs(tabs, fd); |
| 735 | fprintf(fd, "if (*len == 0) {\n"); |
| 736 | print_tabs(tabs+1, fd); |
| 737 | fprintf(fd, "*to += ltt_align(*to, align); /* align output */\n"); |
| 738 | print_tabs(tabs, fd); |
| 739 | fprintf(fd, "} else {\n"); |
| 740 | print_tabs(tabs+1, fd); |
| 741 | fprintf(fd, "*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */\n"); |
| 742 | print_tabs(tabs, fd); |
| 743 | fprintf(fd, "}\n"); |
| 744 | fprintf(fd, "\n"); |
| 745 | |
| 746 | print_tabs(tabs, fd); |
| 747 | fprintf(fd, "*len += "); |
| 748 | fprintf(fd, "sizeof("); |
| 749 | if(print_type(td, fd, 0, basename, "")) return 1; |
| 750 | fprintf(fd, ");\n"); |
| 751 | |
| 752 | break; |
| 753 | case STRING: |
| 754 | print_tabs(tabs, fd); |
| 755 | fprintf(fd, |
| 756 | "lttng_write%s_string_%s(buffer, to_base, to, from, len, %s%s);\n", |
| 757 | custom, basename, obj_prefix, field_name); |
| 758 | break; |
| 759 | case SEQUENCE: |
| 760 | print_tabs(tabs, fd); |
| 761 | fprintf(fd, |
| 762 | "lttng_write%s_sequence_%s(buffer, to_base, to, from, len, %s%s%s);", |
| 763 | custom, basename, get_ptr_char, obj_prefix, field_name); |
| 764 | break; |
| 765 | case STRUCT: |
| 766 | print_tabs(tabs, fd); |
| 767 | fprintf(fd, |
| 768 | "lttng_write%s_struct_%s(buffer, to_base, to, from, len, %s%s%s);", |
| 769 | custom, basename, get_ptr_char, obj_prefix, field_name); |
| 770 | break; |
| 771 | case UNION: |
| 772 | print_tabs(tabs, fd); |
| 773 | fprintf(fd, |
| 774 | "lttng_write%s_union_%s(buffer, to_base, to, from, len, %s%s%s);", |
| 775 | custom, basename, get_ptr_char, obj_prefix, field_name); |
| 776 | break; |
| 777 | case ARRAY: |
| 778 | print_tabs(tabs, fd); |
| 779 | fprintf(fd, |
| 780 | "lttng_write%s_array_%s(buffer, to_base, to, from, len, %s%s);", |
| 781 | custom, basename, obj_prefix, field_name); |
| 782 | break; |
| 783 | case NONE: |
| 784 | printf("Error : type NONE unexpected\n"); |
| 785 | return 1; |
| 786 | break; |
| 787 | } |
| 788 | |
| 789 | return 0; |
| 790 | } |
| 791 | |
| 792 | /* print need local vars ?. |
| 793 | * |
| 794 | * Copied from print_type_write |
| 795 | * |
| 796 | * Does the type_write call needs local size and from variables ? |
| 797 | * return value : 1 yes, 0 no. |
| 798 | */ |
| 799 | |
| 800 | int has_type_local(type_descriptor_t * td) |
| 801 | { |
| 802 | switch(td->type) { |
| 803 | case INT_FIXED: |
| 804 | case UINT_FIXED: |
| 805 | case CHAR: |
| 806 | case UCHAR: |
| 807 | case SHORT: |
| 808 | case USHORT: |
| 809 | case INT: |
| 810 | case UINT: |
| 811 | case FLOAT: |
| 812 | case POINTER: |
| 813 | case LONG: |
| 814 | case ULONG: |
| 815 | case SIZE_T: |
| 816 | case SSIZE_T: |
| 817 | case OFF_T: |
| 818 | case ENUM: |
| 819 | return 1; |
| 820 | break; |
| 821 | case STRING: |
| 822 | case SEQUENCE: |
| 823 | case STRUCT: |
| 824 | case UNION: |
| 825 | case ARRAY: |
| 826 | return 0; |
| 827 | break; |
| 828 | case NONE: |
| 829 | printf("Error : type NONE unexpected\n"); |
| 830 | return 1; |
| 831 | break; |
| 832 | } |
| 833 | |
| 834 | return 0; |
| 835 | } |
| 836 | |
| 837 | |
| 838 | |
| 839 | /* print type alignment function. |
| 840 | * |
| 841 | * Copied from construct_types_and_fields in LTTV facility.c |
| 842 | * |
| 843 | * basename is the name which identifies the type (along with a prefix |
| 844 | * (possibly)). */ |
| 845 | |
| 846 | int print_type_alignment_fct(type_descriptor_t * td, FILE *fd, |
| 847 | unsigned int tabs, |
| 848 | char *nest_name, char *field_name) |
| 849 | { |
| 850 | char basename[PATH_MAX]; |
| 851 | unsigned int basename_len = 0; |
| 852 | |
| 853 | if(td->custom_write) return 0; /* Does print custom type */ |
| 854 | if(td->fac->align == 0) return 0; |
| 855 | |
| 856 | strncpy(basename, nest_name, PATH_MAX); |
| 857 | basename_len = strlen(basename); |
| 858 | |
| 859 | /* For a named type, we use the type_name directly */ |
| 860 | if(td->type_name != NULL) { |
| 861 | strncpy(basename, td->type_name, PATH_MAX); |
| 862 | basename_len = strlen(basename); |
| 863 | } else { |
| 864 | /* For a unnamed type, there must be a field name, except for |
| 865 | * the array. */ |
| 866 | if((basename_len != 0) |
| 867 | && (basename[basename_len-1] != '_' |
| 868 | && (field_name[0] != '\0'))) { |
| 869 | strncat(basename, "_", PATH_MAX - basename_len); |
| 870 | basename_len = strlen(basename); |
| 871 | } |
| 872 | strncat(basename, field_name, PATH_MAX - basename_len); |
| 873 | } |
| 874 | |
| 875 | switch(td->type) { |
| 876 | case SEQUENCE: |
| 877 | if(((field_t*)td->fields.array[1])->type->type_name == NULL) { |
| 878 | /* Not a named nested type : we must print its align fct */ |
| 879 | if(print_type_alignment_fct(((field_t*)td->fields.array[1])->type, fd, |
| 880 | 0, basename, "")) return 1; |
| 881 | } |
| 882 | /* Function header */ |
| 883 | fprintf(fd, "static inline size_t lttng_get_alignment_sequence_%s(\n", |
| 884 | basename); |
| 885 | print_tabs(2, fd); |
| 886 | if(print_type(td, fd, 0, basename, "")) return 1; |
| 887 | fprintf(fd, " *obj)\n"); |
| 888 | fprintf(fd, "{\n"); |
| 889 | print_tabs(1, fd); |
| 890 | fprintf(fd, "size_t align=0, localign;"); |
| 891 | fprintf(fd, "\n"); |
| 892 | print_tabs(1, fd); |
| 893 | fprintf(fd, "localign = "); |
| 894 | if(print_type_alignment(((field_t*)td->fields.array[0])->type, |
| 895 | fd, 0, basename, "len", "obj->")) return 1; |
| 896 | fprintf(fd, ";\n"); |
| 897 | print_tabs(1, fd); |
| 898 | fprintf(fd, "align = max(align, localign);\n"); |
| 899 | fprintf(fd, "\n"); |
| 900 | print_tabs(1, fd); |
| 901 | fprintf(fd, "localign = "); |
| 902 | if(print_type_alignment(((field_t*)td->fields.array[1])->type, |
| 903 | fd, 0, basename, "array[0]", "obj->")) return 1; |
| 904 | fprintf(fd, ";\n"); |
| 905 | print_tabs(1, fd); |
| 906 | fprintf(fd, "align = max(align, localign);\n"); |
| 907 | fprintf(fd, "\n"); |
| 908 | print_tabs(1, fd); |
| 909 | fprintf(fd, "return align;\n"); |
| 910 | break; |
| 911 | case STRUCT: |
| 912 | for(unsigned int i=0;i<td->fields.position;i++){ |
| 913 | field_t *field = (field_t*)(td->fields.array[i]); |
| 914 | type_descriptor_t *type = field->type; |
| 915 | if(type->type_name == NULL) { |
| 916 | /* Not a named nested type : we must print its align fct */ |
| 917 | if(print_type_alignment_fct(type, fd, |
| 918 | 0, basename, field->name)) return 1; |
| 919 | } |
| 920 | } |
| 921 | /* Function header */ |
| 922 | fprintf(fd, "static inline size_t lttng_get_alignment_struct_%s(\n", |
| 923 | basename); |
| 924 | print_tabs(2, fd); |
| 925 | if(print_type(td, fd, 0, basename, "")) return 1; |
| 926 | fprintf(fd, " *obj)\n"); |
| 927 | fprintf(fd, "{\n"); |
| 928 | print_tabs(1, fd); |
| 929 | fprintf(fd, "size_t align=0, localign;"); |
| 930 | fprintf(fd, "\n"); |
| 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; |
| 934 | print_tabs(1, fd); |
| 935 | fprintf(fd, "localign = "); |
| 936 | if(print_type_alignment(type, fd, 0, basename, field->name, "obj->")) |
| 937 | return 1; |
| 938 | fprintf(fd, ";\n"); |
| 939 | print_tabs(1, fd); |
| 940 | fprintf(fd, "align = max(align, localign);\n"); |
| 941 | fprintf(fd, "\n"); |
| 942 | } |
| 943 | print_tabs(1, fd); |
| 944 | fprintf(fd, "return align;\n"); |
| 945 | |
| 946 | break; |
| 947 | case UNION: |
| 948 | for(unsigned int i=0;i<td->fields.position;i++){ |
| 949 | field_t *field = (field_t*)(td->fields.array[i]); |
| 950 | type_descriptor_t *type = field->type; |
| 951 | if(type->type_name == NULL) { |
| 952 | /* Not a named nested type : we must print its align fct */ |
| 953 | if(print_type_alignment_fct(type, fd, |
| 954 | 0, basename, field->name)) return 1; |
| 955 | } |
| 956 | } |
| 957 | /* Function header */ |
| 958 | fprintf(fd, "static inline size_t lttng_get_alignment_union_%s(\n", |
| 959 | basename); |
| 960 | print_tabs(2, fd); |
| 961 | if(print_type(td, fd, 0, basename, "")) return 1; |
| 962 | fprintf(fd, " *obj)\n"); |
| 963 | fprintf(fd, "{\n"); |
| 964 | print_tabs(1, fd); |
| 965 | fprintf(fd, "size_t align=0, localign;"); |
| 966 | fprintf(fd, "\n"); |
| 967 | for(unsigned int i=0;i<td->fields.position;i++){ |
| 968 | field_t *field = (field_t*)(td->fields.array[i]); |
| 969 | type_descriptor_t *type = field->type; |
| 970 | print_tabs(1, fd); |
| 971 | fprintf(fd, "localign = "); |
| 972 | if(print_type_alignment(type, fd, 0, basename, field->name, "obj->")) |
| 973 | return 1; |
| 974 | fprintf(fd, ";\n"); |
| 975 | print_tabs(1, fd); |
| 976 | fprintf(fd, "align = max(align, localign);\n"); |
| 977 | fprintf(fd, "\n"); |
| 978 | } |
| 979 | print_tabs(1, fd); |
| 980 | fprintf(fd, "return align;\n"); |
| 981 | |
| 982 | break; |
| 983 | case ARRAY: |
| 984 | if(((field_t*)td->fields.array[0])->type->type_name == NULL) { |
| 985 | /* Not a named nested type : we must print its align fct */ |
| 986 | if(print_type_alignment_fct(((field_t*)td->fields.array[0])->type, fd, |
| 987 | 0, basename, "")) return 1; |
| 988 | } |
| 989 | /* Function header */ |
| 990 | fprintf(fd, "static inline size_t lttng_get_alignment_array_%s(\n", |
| 991 | basename); |
| 992 | print_tabs(2, fd); |
| 993 | if(print_type(td, fd, 0, basename, "")) return 1; |
| 994 | fprintf(fd, " obj)\n"); |
| 995 | fprintf(fd, "{\n"); |
| 996 | print_tabs(1, fd); |
| 997 | fprintf(fd, "return \n"); |
| 998 | if(print_type_alignment(((field_t*)td->fields.array[0])->type, |
| 999 | fd, 0, basename, "", "obj[0]")) |
| 1000 | return 1; |
| 1001 | fprintf(fd, ";\n"); |
| 1002 | break; |
| 1003 | default: |
| 1004 | dprintf("print_type_alignment_fct : type has no alignment function.\n"); |
| 1005 | return 0; |
| 1006 | break; |
| 1007 | } |
| 1008 | |
| 1009 | |
| 1010 | /* Function footer */ |
| 1011 | fprintf(fd, "}\n"); |
| 1012 | fprintf(fd, "\n"); |
| 1013 | |
| 1014 | return 0; |
| 1015 | } |
| 1016 | |
| 1017 | /* print type write function. |
| 1018 | * |
| 1019 | * Copied from construct_types_and_fields in LTTV facility.c |
| 1020 | * |
| 1021 | * basename is the name which identifies the type (along with a prefix |
| 1022 | * (possibly)). */ |
| 1023 | |
| 1024 | int print_type_write_fct(type_descriptor_t * td, FILE *fd, unsigned int tabs, |
| 1025 | char *nest_name, char *field_name) |
| 1026 | { |
| 1027 | char basename[PATH_MAX]; |
| 1028 | unsigned int basename_len = 0; |
| 1029 | |
| 1030 | if(td->custom_write) return 0; /* Does print custom type */ |
| 1031 | |
| 1032 | strncpy(basename, nest_name, PATH_MAX); |
| 1033 | basename_len = strlen(basename); |
| 1034 | |
| 1035 | /* For a named type, we use the type_name directly */ |
| 1036 | if(td->type_name != NULL) { |
| 1037 | strncpy(basename, td->type_name, PATH_MAX); |
| 1038 | basename_len = strlen(basename); |
| 1039 | } else { |
| 1040 | /* For a unnamed type, there must be a field name, except for |
| 1041 | * the array. */ |
| 1042 | if((basename_len != 0) |
| 1043 | && (basename[basename_len-1] != '_' |
| 1044 | && (field_name[0] != '\0'))) { |
| 1045 | strncat(basename, "_", PATH_MAX - basename_len); |
| 1046 | basename_len = strlen(basename); |
| 1047 | } |
| 1048 | strncat(basename, field_name, PATH_MAX - basename_len); |
| 1049 | } |
| 1050 | |
| 1051 | switch(td->type) { |
| 1052 | case SEQUENCE: |
| 1053 | if(((field_t*)td->fields.array[1])->type->type_name == NULL) { |
| 1054 | /* Not a named nested type : we must print its write fct */ |
| 1055 | if(print_type_write_fct(((field_t*)td->fields.array[1])->type, fd, |
| 1056 | 0, basename, "")) return 1; |
| 1057 | } |
| 1058 | break; |
| 1059 | case STRUCT: |
| 1060 | for(unsigned int i=0;i<td->fields.position;i++){ |
| 1061 | field_t *field = (field_t*)(td->fields.array[i]); |
| 1062 | type_descriptor_t *type = field->type; |
| 1063 | if(type->type_name == NULL) { |
| 1064 | /* Not a named nested type : we must print its write fct */ |
| 1065 | if(print_type_write_fct(type, fd, |
| 1066 | 0, basename, field->name)) return 1; |
| 1067 | } |
| 1068 | } |
| 1069 | break; |
| 1070 | case UNION: |
| 1071 | for(unsigned int i=0;i<td->fields.position;i++){ |
| 1072 | field_t *field = (field_t*)(td->fields.array[i]); |
| 1073 | type_descriptor_t *type = field->type; |
| 1074 | if(type->type_name == NULL) { |
| 1075 | /* Not a named nested type : we must print its write fct */ |
| 1076 | if(print_type_write_fct(type, fd, |
| 1077 | 0, basename, field->name)) return 1; |
| 1078 | } |
| 1079 | } |
| 1080 | break; |
| 1081 | case ARRAY: |
| 1082 | if(((field_t*)td->fields.array[0])->type->type_name == NULL) { |
| 1083 | /* Not a named nested type : we must print its write fct */ |
| 1084 | if(print_type_write_fct(((field_t*)td->fields.array[0])->type, fd, |
| 1085 | 0, basename, "")) return 1; |
| 1086 | } |
| 1087 | break; |
| 1088 | case STRING: |
| 1089 | break; |
| 1090 | default: |
| 1091 | dprintf("print_type_write_fct : type has no write function.\n"); |
| 1092 | return 0; |
| 1093 | break; |
| 1094 | } |
| 1095 | |
| 1096 | /* Print header */ |
| 1097 | switch(td->type) { |
| 1098 | case SEQUENCE: |
| 1099 | fprintf(fd, "static inline void lttng_write_sequence_%s(\n", |
| 1100 | basename); |
| 1101 | break; |
| 1102 | case STRUCT: |
| 1103 | fprintf(fd, "static inline void lttng_write_struct_%s(\n", basename); |
| 1104 | break; |
| 1105 | case UNION: |
| 1106 | fprintf(fd, "static inline void lttng_write_union_%s(\n", basename); |
| 1107 | break; |
| 1108 | case ARRAY: |
| 1109 | fprintf(fd, "static inline void lttng_write_array_%s(\n", basename); |
| 1110 | break; |
| 1111 | case STRING: |
| 1112 | fprintf(fd, "static inline void lttng_write_string_%s(\n", basename); |
| 1113 | break; |
| 1114 | default: |
| 1115 | printf("print_type_write_fct : type has no write function.\n"); |
| 1116 | break; |
| 1117 | } |
| 1118 | |
| 1119 | print_tabs(2, fd); |
| 1120 | fprintf(fd, "char *buffer,\n"); |
| 1121 | print_tabs(2, fd); |
| 1122 | fprintf(fd, "size_t *to_base,\n"); |
| 1123 | print_tabs(2, fd); |
| 1124 | fprintf(fd, "size_t *to,\n"); |
| 1125 | print_tabs(2, fd); |
| 1126 | fprintf(fd, "const char **from,\n"); |
| 1127 | print_tabs(2, fd); |
| 1128 | fprintf(fd, "size_t *len,\n"); |
| 1129 | print_tabs(2, fd); |
| 1130 | if(print_type(td, fd, 0, basename, "")) return 1; |
| 1131 | |
| 1132 | switch(td->type) { |
| 1133 | case SEQUENCE: |
| 1134 | fprintf(fd, " *obj)\n"); |
| 1135 | break; |
| 1136 | case STRUCT: |
| 1137 | fprintf(fd, " *obj)\n"); |
| 1138 | break; |
| 1139 | case UNION: |
| 1140 | fprintf(fd, " *obj)\n"); |
| 1141 | break; |
| 1142 | case ARRAY: |
| 1143 | fprintf(fd, " obj)\n"); |
| 1144 | break; |
| 1145 | case STRING: |
| 1146 | fprintf(fd, " obj)\n"); |
| 1147 | break; |
| 1148 | default: |
| 1149 | printf("print_type_write_fct : type has no write function.\n"); |
| 1150 | break; |
| 1151 | } |
| 1152 | |
| 1153 | fprintf(fd, "{\n"); |
| 1154 | |
| 1155 | switch(td->type) { |
| 1156 | case STRING: |
| 1157 | print_tabs(1, fd); |
| 1158 | fprintf(fd, "size_t size;\n"); |
| 1159 | break; |
| 1160 | default: |
| 1161 | break; |
| 1162 | } |
| 1163 | |
| 1164 | print_tabs(1, fd); |
| 1165 | fprintf(fd, "size_t align;\n"); |
| 1166 | fprintf(fd, "\n"); |
| 1167 | |
| 1168 | switch(td->type) { |
| 1169 | case SEQUENCE: |
| 1170 | case STRING: |
| 1171 | print_tabs(1, fd); |
| 1172 | fprintf(fd, "/* Flush pending memcpy */\n"); |
| 1173 | print_tabs(1, fd); |
| 1174 | fprintf(fd, "if (*len != 0) {\n"); |
| 1175 | print_tabs(2, fd); |
| 1176 | fprintf(fd, "if (buffer != NULL)\n"); |
| 1177 | print_tabs(3, fd); |
| 1178 | fprintf(fd, "memcpy(buffer+*to_base+*to, *from, *len);\n"); |
| 1179 | print_tabs(1, fd); |
| 1180 | fprintf(fd, "}\n"); |
| 1181 | print_tabs(1, fd); |
| 1182 | fprintf(fd, "*to += *len;\n"); |
| 1183 | print_tabs(1, fd); |
| 1184 | fprintf(fd, "*len = 0;\n"); |
| 1185 | fprintf(fd, "\n"); |
| 1186 | break; |
| 1187 | case STRUCT: |
| 1188 | case UNION: |
| 1189 | case ARRAY: |
| 1190 | break; |
| 1191 | default: |
| 1192 | printf("print_type_write_fct : type has no write function.\n"); |
| 1193 | break; |
| 1194 | } |
| 1195 | |
| 1196 | print_tabs(1, fd); |
| 1197 | fprintf(fd, "align = "); |
| 1198 | if(td->fac->align) { |
| 1199 | if(print_type_alignment(td, fd, 0, basename, "", "obj")) return 1; |
| 1200 | } else |
| 1201 | fprintf(fd, "0"); |
| 1202 | fprintf(fd, ";\n"); |
| 1203 | fprintf(fd, "\n"); |
| 1204 | print_tabs(1, fd); |
| 1205 | fprintf(fd, "if (*len == 0) {\n"); |
| 1206 | print_tabs(2, fd); |
| 1207 | fprintf(fd, "*to += ltt_align(*to, align); /* align output */\n"); |
| 1208 | print_tabs(1, fd); |
| 1209 | fprintf(fd, "} else {\n"); |
| 1210 | print_tabs(2, fd); |
| 1211 | fprintf(fd, "*len += ltt_align(*to+*len, align); /* alignment, ok to do a memcpy of it */\n"); |
| 1212 | print_tabs(1, fd); |
| 1213 | fprintf(fd, "}\n"); |
| 1214 | fprintf(fd, "\n"); |
| 1215 | |
| 1216 | /* First, check if the type has a fixed size. If it is the case, then the size |
| 1217 | * to write is know by the compiler : simply use a sizeof() */ |
| 1218 | if(has_type_fixed_size(td)) { |
| 1219 | print_tabs(1, fd); |
| 1220 | fprintf(fd, "/* Contains only fixed size fields : use compiler sizeof() */\n"); |
| 1221 | fprintf(fd, "\n"); |
| 1222 | print_tabs(1, fd); |
| 1223 | fprintf(fd, "*len += sizeof("); |
| 1224 | if(print_type(td, fd, 0, basename, field_name)) return 1; |
| 1225 | fprintf(fd, ");\n"); |
| 1226 | } else { |
| 1227 | /* The type contains nested variable size subtypes : |
| 1228 | * we must write field by field. */ |
| 1229 | print_tabs(1, fd); |
| 1230 | fprintf(fd, "/* Contains variable sized fields : must explode the structure */\n"); |
| 1231 | fprintf(fd, "\n"); |
| 1232 | |
| 1233 | switch(td->type) { |
| 1234 | case SEQUENCE: |
| 1235 | print_tabs(1, fd); |
| 1236 | fprintf(fd, "/* Copy members */\n"); |
| 1237 | // print_tabs(1, fd); |
| 1238 | // fprintf(fd, "size = sizeof(\n"); |
| 1239 | if(print_type_write(((field_t*)td->fields.array[0])->type, |
| 1240 | fd, 1, basename, "len", "obj->", 1)) return 1; |
| 1241 | fprintf(fd, "\n"); |
| 1242 | // fprintf(fd, ");\n"); |
| 1243 | // print_tabs(1, fd); |
| 1244 | // fprintf(fd, "*to += ltt_align(*to, size);\n"); |
| 1245 | print_tabs(1, fd); |
| 1246 | fprintf(fd, "if (buffer != NULL)\n"); |
| 1247 | print_tabs(2, fd); |
| 1248 | fprintf(fd, "memcpy(buffer+*to_base+*to, &obj->len, *len);\n"); |
| 1249 | print_tabs(1, fd); |
| 1250 | fprintf(fd, "*to += *len;\n"); |
| 1251 | print_tabs(1, fd); |
| 1252 | fprintf(fd, "*len = 0;\n"); |
| 1253 | fprintf(fd, "\n"); |
| 1254 | |
| 1255 | /* Write the child : varlen child or not ? */ |
| 1256 | if(has_type_fixed_size(((field_t*)td->fields.array[1])->type)) { |
| 1257 | /* Fixed size len child : use a multiplication of its size */ |
| 1258 | // print_tabs(1, fd); |
| 1259 | // fprintf(fd, "size = sizeof(\n"); |
| 1260 | |
| 1261 | //print_tabs(1, fd); |
| 1262 | /* We know that *len does not contain alignment because of the |
| 1263 | * previous align output. len is always 0 here. */ |
| 1264 | if(print_type_write(((field_t*)td->fields.array[1])->type, |
| 1265 | fd, 1, basename, "array[0]", "obj->", 1)) |
| 1266 | return 1; |
| 1267 | // fprintf(fd, ");\n"); |
| 1268 | fprintf(fd, "\n"); |
| 1269 | print_tabs(1, fd); |
| 1270 | fprintf(fd, "*len = obj->len * (*len);\n"); |
| 1271 | print_tabs(1, fd); |
| 1272 | fprintf(fd, "if (buffer != NULL)\n"); |
| 1273 | print_tabs(2, fd); |
| 1274 | fprintf(fd, "memcpy(buffer+*to_base+*to, obj->array, *len);\n"); |
| 1275 | print_tabs(1, fd); |
| 1276 | fprintf(fd, "*to += *len;\n"); |
| 1277 | print_tabs(1, fd); |
| 1278 | fprintf(fd, "*len = 0;\n"); |
| 1279 | fprintf(fd, "\n"); |
| 1280 | } else { |
| 1281 | print_tabs(1, fd); |
| 1282 | fprintf(fd, "/* Variable length child : iter. */\n"); |
| 1283 | print_tabs(1, fd); |
| 1284 | fprintf(fd, "for (unsigned int i = 0; i < obj->len; i++) {\n"); |
| 1285 | if(print_type_write(((field_t*)td->fields.array[1])->type, |
| 1286 | fd, 2, basename, "array[i]", "obj->", 1)) return 1; |
| 1287 | print_tabs(1, fd); |
| 1288 | fprintf(fd, "}\n"); |
| 1289 | } |
| 1290 | fprintf(fd, "\n"); |
| 1291 | print_tabs(1, fd); |
| 1292 | fprintf(fd, "/* Realign the *to_base on arch size, set *to to 0 */\n"); |
| 1293 | print_tabs(1, fd); |
| 1294 | if(td->fac->align) |
| 1295 | fprintf(fd, "*to += ltt_align(*to, sizeof(void *));\n"); |
| 1296 | print_tabs(1, fd); |
| 1297 | fprintf(fd, "*to_base = *to_base+*to;\n"); |
| 1298 | print_tabs(1, fd); |
| 1299 | fprintf(fd, "*to = 0;\n"); |
| 1300 | fprintf(fd, "\n"); |
| 1301 | print_tabs(1, fd); |
| 1302 | fprintf(fd, "/* Put source *from just after the C sequence */\n"); |
| 1303 | print_tabs(1, fd); |
| 1304 | fprintf(fd, "*from = (const char*)(obj+1);\n"); |
| 1305 | break; |
| 1306 | case STRING: |
| 1307 | print_tabs(1, fd); |
| 1308 | fprintf(fd, "size = strlen(obj) + 1; /* Include final NULL char. */\n"); |
| 1309 | print_tabs(1, fd); |
| 1310 | fprintf(fd, "if (buffer != NULL)\n"); |
| 1311 | print_tabs(2, fd); |
| 1312 | fprintf(fd, "memcpy(buffer+*to_base+*to, obj, size);\n"); |
| 1313 | print_tabs(1, fd); |
| 1314 | fprintf(fd, "*to += size;\n"); |
| 1315 | fprintf(fd, "\n"); |
| 1316 | print_tabs(1, fd); |
| 1317 | fprintf(fd, "/* Realign the *to_base on arch size, set *to to 0 */\n"); |
| 1318 | print_tabs(1, fd); |
| 1319 | if(td->fac->align) |
| 1320 | fprintf(fd, "*to += ltt_align(*to, sizeof(void *));\n"); |
| 1321 | print_tabs(1, fd); |
| 1322 | fprintf(fd, "*to_base = *to_base+*to;\n"); |
| 1323 | print_tabs(1, fd); |
| 1324 | fprintf(fd, "*to = 0;\n"); |
| 1325 | fprintf(fd, "\n"); |
| 1326 | print_tabs(1, fd); |
| 1327 | fprintf(fd, "/* Put source *from just after the C string */\n"); |
| 1328 | print_tabs(1, fd); |
| 1329 | fprintf(fd, "*from += size;\n"); |
| 1330 | break; |
| 1331 | case STRUCT: |
| 1332 | for(unsigned int i=0;i<td->fields.position;i++){ |
| 1333 | field_t *field = (field_t*)(td->fields.array[i]); |
| 1334 | type_descriptor_t *type = field->type; |
| 1335 | if(print_type_write(type, |
| 1336 | fd, 1, basename, field->name, "obj->", 1)) return 1; |
| 1337 | fprintf(fd, "\n"); |
| 1338 | } |
| 1339 | break; |
| 1340 | case UNION: |
| 1341 | printf("ERROR : A union CANNOT contain a variable size child.\n"); |
| 1342 | return 1; |
| 1343 | break; |
| 1344 | case ARRAY: |
| 1345 | /* Write the child : varlen child or not ? */ |
| 1346 | if(has_type_fixed_size(((field_t*)td->fields.array[0])->type)) { |
| 1347 | /* Error : if an array has a variable size, then its child must also |
| 1348 | * have a variable size. */ |
| 1349 | assert(0); |
| 1350 | } else { |
| 1351 | print_tabs(1, fd); |
| 1352 | fprintf(fd, "/* Variable length child : iter. */\n"); |
| 1353 | print_tabs(1, fd); |
| 1354 | fprintf(fd, "for (unsigned int i = 0; i < LTTNG_ARRAY_SIZE_%s; i++) {\n", basename); |
| 1355 | if(print_type_write(((field_t*)td->fields.array[0])->type, |
| 1356 | fd, 2, basename, "", "obj->array[i]", 1)) return 1; |
| 1357 | print_tabs(1, fd); |
| 1358 | fprintf(fd, "}\n"); |
| 1359 | } |
| 1360 | break; |
| 1361 | default: |
| 1362 | printf("print_type_write_fct : type has no write function.\n"); |
| 1363 | break; |
| 1364 | } |
| 1365 | |
| 1366 | |
| 1367 | } |
| 1368 | |
| 1369 | |
| 1370 | /* Function footer */ |
| 1371 | fprintf(fd, "}\n"); |
| 1372 | fprintf(fd, "\n"); |
| 1373 | return 0; |
| 1374 | } |
| 1375 | |
| 1376 | |
| 1377 | |
| 1378 | /* Print the logging function of an event. This is the core of genevent */ |
| 1379 | int print_event_logging_function(char *basename, facility_t *fac, |
| 1380 | event_t *event, FILE *fd) |
| 1381 | { |
| 1382 | fprintf(fd, "static inline void trace_%s(\n", basename); |
| 1383 | int has_argument = 0; |
| 1384 | int has_type_fixed = 0; |
| 1385 | |
| 1386 | /* Does it support per trace tracing ? */ |
| 1387 | if(event->per_trace) { |
| 1388 | print_tabs(2, fd); |
| 1389 | fprintf(fd, "struct ltt_trace_struct *dest_trace"); |
| 1390 | has_argument = 1; |
| 1391 | } |
| 1392 | |
| 1393 | /* Does it support per tracefile tracing ? */ |
| 1394 | if(event->per_tracefile) { |
| 1395 | if(has_argument) { |
| 1396 | fprintf(fd, ","); |
| 1397 | fprintf(fd, "\n"); |
| 1398 | } |
| 1399 | fprintf(fd, "unsigned int tracefile_index"); |
| 1400 | has_argument = 1; |
| 1401 | } |
| 1402 | |
| 1403 | for(unsigned int j = 0; j < event->fields.position; j++) { |
| 1404 | /* For each field, print the function argument */ |
| 1405 | field_t *f = (field_t*)event->fields.array[j]; |
| 1406 | type_descriptor_t *t = f->type; |
| 1407 | if(has_argument) { |
| 1408 | fprintf(fd, ","); |
| 1409 | fprintf(fd, "\n"); |
| 1410 | } |
| 1411 | if(print_arg(t, fd, 2, basename, f->name)) return 1; |
| 1412 | has_argument = 1; |
| 1413 | } |
| 1414 | if(!has_argument) { |
| 1415 | print_tabs(2, fd); |
| 1416 | fprintf(fd, "void"); |
| 1417 | } |
| 1418 | fprintf(fd,")\n"); |
| 1419 | #if 0 |
| 1420 | fprintf(fd, |
| 1421 | "#if (!defined(CONFIG_LTT) || (!defined(CONFIG_LTT_FACILITY_%s) && !defined(CONFIG_LTT_FACILITY_%s_MODULE)))\n", |
| 1422 | fac->capname, fac->capname); |
| 1423 | fprintf(fd, "{\n"); |
| 1424 | fprintf(fd, "}\n"); |
| 1425 | fprintf(fd,"#else\n"); |
| 1426 | #endif //0 |
| 1427 | fprintf(fd, "{\n"); |
| 1428 | /* Print the function variables */ |
| 1429 | print_tabs(1, fd); |
| 1430 | fprintf(fd, "unsigned int index;\n"); |
| 1431 | print_tabs(1, fd); |
| 1432 | fprintf(fd, "struct ltt_channel_struct *channel;\n"); |
| 1433 | print_tabs(1, fd); |
| 1434 | fprintf(fd, "struct ltt_trace_struct *trace;\n"); |
| 1435 | print_tabs(1, fd); |
| 1436 | fprintf(fd, "void *transport_data;\n"); |
| 1437 | print_tabs(1, fd); |
| 1438 | fprintf(fd, "char *buffer = NULL;\n"); |
| 1439 | print_tabs(1, fd); |
| 1440 | fprintf(fd, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n"); |
| 1441 | print_tabs(1, fd); |
| 1442 | fprintf(fd, "size_t *to_base = &real_to_base;\n"); |
| 1443 | print_tabs(1, fd); |
| 1444 | fprintf(fd, "size_t real_to = 0;\n"); |
| 1445 | print_tabs(1, fd); |
| 1446 | fprintf(fd, "size_t *to = &real_to;\n"); |
| 1447 | print_tabs(1, fd); |
| 1448 | fprintf(fd, "size_t real_len = 0;\n"); |
| 1449 | print_tabs(1, fd); |
| 1450 | fprintf(fd, "size_t *len = &real_len;\n"); |
| 1451 | print_tabs(1, fd); |
| 1452 | fprintf(fd, "size_t reserve_size;\n"); |
| 1453 | print_tabs(1, fd); |
| 1454 | fprintf(fd, "size_t slot_size;\n"); |
| 1455 | print_tabs(1, fd); |
| 1456 | |
| 1457 | if(event->fields.position > 0) { |
| 1458 | for(unsigned int i=0;i<event->fields.position;i++){ |
| 1459 | /* Search for at least one child with fixed size. It means |
| 1460 | * we need local variables.*/ |
| 1461 | field_t *field = (field_t*)(event->fields.array[i]); |
| 1462 | type_descriptor_t *type = field->type; |
| 1463 | has_type_fixed = has_type_local(type); |
| 1464 | if(has_type_fixed) break; |
| 1465 | } |
| 1466 | |
| 1467 | if(has_type_fixed) { |
| 1468 | fprintf(fd, "size_t align;\n"); |
| 1469 | print_tabs(1, fd); |
| 1470 | } |
| 1471 | |
| 1472 | fprintf(fd, "const char *real_from;\n"); |
| 1473 | print_tabs(1, fd); |
| 1474 | fprintf(fd, "const char **from = &real_from;\n"); |
| 1475 | print_tabs(1, fd); |
| 1476 | } |
| 1477 | fprintf(fd, "u64 tsc;\n"); |
| 1478 | fprintf(fd, "\n"); |
| 1479 | |
| 1480 | if(!event->force) { |
| 1481 | print_tabs(1, fd); |
| 1482 | fprintf(fd, "if (ltt_traces.num_active_traces == 0)\n"); |
| 1483 | print_tabs(2, fd); |
| 1484 | fprintf(fd, "return;\n"); |
| 1485 | fprintf(fd, "\n"); |
| 1486 | } |
| 1487 | |
| 1488 | /* Calculate event variable len + event data alignment offset. |
| 1489 | * Assume that the padding for alignment starts at a void* |
| 1490 | * address. |
| 1491 | * This excludes the header size and alignment. */ |
| 1492 | |
| 1493 | print_tabs(1, fd); |
| 1494 | fprintf(fd, "/* For each field, calculate the field size. */\n"); |
| 1495 | print_tabs(1, fd); |
| 1496 | fprintf(fd, "/* size = *to_base + *to + *len */\n"); |
| 1497 | print_tabs(1, fd); |
| 1498 | fprintf(fd, "/* Assume that the padding for alignment starts at a\n"); |
| 1499 | print_tabs(1, fd); |
| 1500 | fprintf(fd, " * sizeof(void *) address. */\n"); |
| 1501 | fprintf(fd, "\n"); |
| 1502 | |
| 1503 | for(unsigned int i=0;i<event->fields.position;i++){ |
| 1504 | field_t *field = (field_t*)(event->fields.array[i]); |
| 1505 | type_descriptor_t *type = field->type; |
| 1506 | /* Set from */ |
| 1507 | print_tabs(1, fd); |
| 1508 | switch(type->type) { |
| 1509 | case SEQUENCE: |
| 1510 | case UNION: |
| 1511 | case ARRAY: |
| 1512 | case STRUCT: |
| 1513 | case STRING: |
| 1514 | fprintf(fd, "*from = (const char*)lttng_param_%s;\n", field->name); |
| 1515 | break; |
| 1516 | default: |
| 1517 | fprintf(fd, "*from = (const char*)<tng_param_%s;\n", field->name); |
| 1518 | break; |
| 1519 | } |
| 1520 | |
| 1521 | if(print_type_write(type, |
| 1522 | fd, 1, basename, field->name, "lttng_param_", 0)) return 1; |
| 1523 | fprintf(fd, "\n"); |
| 1524 | } |
| 1525 | print_tabs(1, fd); |
| 1526 | fprintf(fd, "reserve_size = *to_base + *to + *len;\n"); |
| 1527 | |
| 1528 | /* Take locks : make sure the trace does not vanish while we write on |
| 1529 | * it. A simple preemption disabling is enough (using rcu traces). */ |
| 1530 | print_tabs(1, fd); |
| 1531 | fprintf(fd, "preempt_disable();\n"); |
| 1532 | print_tabs(1, fd); |
| 1533 | fprintf(fd, "ltt_nesting[smp_processor_id()]++;\n"); |
| 1534 | |
| 1535 | /* Get facility index */ |
| 1536 | |
| 1537 | if(event->per_tracefile) { |
| 1538 | print_tabs(1, fd); |
| 1539 | fprintf(fd, "index = tracefile_index;\n"); |
| 1540 | } else { |
| 1541 | print_tabs(1, fd); |
| 1542 | fprintf(fd, |
| 1543 | "index = ltt_get_index_from_facility_%s(" \ |
| 1544 | "\t\t\t\t\t\tevent_%s_%s);\n", |
| 1545 | fac->name, fac->name, event->name); |
| 1546 | } |
| 1547 | fprintf(fd,"\n"); |
| 1548 | |
| 1549 | |
| 1550 | /* For each trace */ |
| 1551 | print_tabs(1, fd); |
| 1552 | fprintf(fd, "list_for_each_entry_rcu(trace, <t_traces.head, list) {\n"); |
| 1553 | if(!event->force) { |
| 1554 | print_tabs(2, fd); |
| 1555 | fprintf(fd, "if (!trace->active)\n"); |
| 1556 | print_tabs(3, fd); |
| 1557 | fprintf(fd, "continue;\n\n"); |
| 1558 | } |
| 1559 | |
| 1560 | if(event->per_trace) { |
| 1561 | print_tabs(2, fd); |
| 1562 | fprintf(fd, "if (dest_trace != trace)\n"); |
| 1563 | print_tabs(3, fd); |
| 1564 | fprintf(fd, "continue;\n\n"); |
| 1565 | } |
| 1566 | |
| 1567 | print_tabs(2, fd); |
| 1568 | fprintf(fd, "channel = ltt_get_channel_from_index(trace, index);\n"); |
| 1569 | fprintf(fd, "\n"); |
| 1570 | |
| 1571 | |
| 1572 | /* Relay reserve */ |
| 1573 | /* If error, increment event lost counter (done by ltt_reserve_slot) and |
| 1574 | * return */ |
| 1575 | print_tabs(2, fd); |
| 1576 | fprintf(fd, "slot_size = 0;\n"); |
| 1577 | print_tabs(2, fd); |
| 1578 | fprintf(fd, "buffer = ltt_reserve_slot(trace, channel, &transport_data,\n"); |
| 1579 | print_tabs(3, fd); |
| 1580 | fprintf(fd, "reserve_size, &slot_size, &tsc);\n"); |
| 1581 | /* If error, return */ |
| 1582 | print_tabs(2, fd); |
| 1583 | fprintf(fd, "if (!buffer)\n"); |
| 1584 | print_tabs(3, fd); |
| 1585 | fprintf(fd, "continue; /* buffer full */\n\n"); |
| 1586 | //print_tabs(2, fd); |
| 1587 | // for DEBUG only |
| 1588 | // fprintf(fd, "goto commit; /* DEBUG : never actually write. */\n\n"); |
| 1589 | print_tabs(2, fd); |
| 1590 | fprintf(fd, "*to_base = *to = *len = 0;\n"); |
| 1591 | fprintf(fd, "\n"); |
| 1592 | |
| 1593 | /* Write event header */ |
| 1594 | if(strcmp("compact", fac->name) != 0) { |
| 1595 | print_tabs(2, fd); |
| 1596 | fprintf(fd, "buffer = ltt_write_event_header(trace, channel, buffer,\n"); |
| 1597 | print_tabs(3, fd); |
| 1598 | fprintf(fd, "ltt_facility_%s_%X, event_%s_%s,\n", fac->name, fac->checksum, |
| 1599 | fac->name, event->name); |
| 1600 | print_tabs(3, fd); |
| 1601 | fprintf(fd, "reserve_size, tsc);\n"); |
| 1602 | } else { |
| 1603 | print_tabs(2, fd); |
| 1604 | fprintf(fd, "buffer = ltt_write_compact_header(trace, channel, buffer,\n"); |
| 1605 | print_tabs(3, fd); |
| 1606 | fprintf(fd, "ltt_facility_%s_%X, event_%s_%s,\n", fac->name, fac->checksum, |
| 1607 | fac->name, event->name); |
| 1608 | print_tabs(3, fd); |
| 1609 | if(event->compact_data) { |
| 1610 | assert(event->fields.position > 0); |
| 1611 | field_t *field = (field_t*)(event->fields.array[0]); |
| 1612 | fprintf(fd, "reserve_size, tsc, lttng_param_%s);\n", |
| 1613 | field->name); |
| 1614 | } else |
| 1615 | fprintf(fd, "reserve_size, tsc, 0);\n"); |
| 1616 | } |
| 1617 | |
| 1618 | /* write data. */ |
| 1619 | |
| 1620 | for(unsigned int i=0;i<event->fields.position;i++){ |
| 1621 | field_t *field = (field_t*)(event->fields.array[i]); |
| 1622 | type_descriptor_t *type = field->type; |
| 1623 | |
| 1624 | /* First param is compacted in the header */ |
| 1625 | if(event->compact_data && i == 0) |
| 1626 | continue; |
| 1627 | /* Set from */ |
| 1628 | print_tabs(2, fd); |
| 1629 | switch(type->type) { |
| 1630 | case SEQUENCE: |
| 1631 | case UNION: |
| 1632 | case ARRAY: |
| 1633 | case STRUCT: |
| 1634 | case STRING: |
| 1635 | fprintf(fd, "*from = (const char*)lttng_param_%s;\n", field->name); |
| 1636 | break; |
| 1637 | default: |
| 1638 | fprintf(fd, "*from = (const char*)<tng_param_%s;\n", field->name); |
| 1639 | break; |
| 1640 | } |
| 1641 | |
| 1642 | |
| 1643 | if(print_type_write(type, |
| 1644 | fd, 2, basename, field->name, "lttng_param_", 0)) return 1; |
| 1645 | fprintf(fd, "\n"); |
| 1646 | |
| 1647 | /* Don't forget to flush pending memcpy */ |
| 1648 | print_tabs(2, fd); |
| 1649 | fprintf(fd, "/* Flush pending memcpy */\n"); |
| 1650 | print_tabs(2, fd); |
| 1651 | fprintf(fd, "if (*len != 0) {\n"); |
| 1652 | print_tabs(3, fd); |
| 1653 | fprintf(fd, "memcpy(buffer+*to_base+*to, *from, *len);\n"); |
| 1654 | print_tabs(3, fd); |
| 1655 | fprintf(fd, "*to += *len;\n"); |
| 1656 | //print_tabs(3, fd); |
| 1657 | //fprintf(fd, "from += len;\n"); |
| 1658 | print_tabs(3, fd); |
| 1659 | fprintf(fd, "*len = 0;\n"); |
| 1660 | print_tabs(2, fd); |
| 1661 | fprintf(fd, "}\n"); |
| 1662 | fprintf(fd, "\n"); |
| 1663 | } |
| 1664 | |
| 1665 | |
| 1666 | /* commit */ |
| 1667 | // for DEBUG only. |
| 1668 | //fprintf(fd, "commit:\n"); /* DEBUG! */ |
| 1669 | print_tabs(2, fd); |
| 1670 | fprintf(fd, "ltt_commit_slot(channel, &transport_data, buffer, slot_size);\n\n"); |
| 1671 | |
| 1672 | print_tabs(1, fd); |
| 1673 | fprintf(fd, "}\n\n"); |
| 1674 | |
| 1675 | /* Release locks */ |
| 1676 | print_tabs(1, fd); |
| 1677 | fprintf(fd, "ltt_nesting[smp_processor_id()]--;\n"); |
| 1678 | print_tabs(1, fd); |
| 1679 | fprintf(fd, "preempt_enable();\n"); |
| 1680 | |
| 1681 | fprintf(fd, "}\n"); |
| 1682 | #if 0 |
| 1683 | fprintf(fd, "#endif //(!defined(CONFIG_LTT) || (!defined(CONFIG_LTT_FACILITY_%s) && !defined(CONFIG_LTT_FACILITY_%s_MODULE)))\n\n", |
| 1684 | fac->capname, fac->capname); |
| 1685 | #endif //0 |
| 1686 | return 0; |
| 1687 | } |
| 1688 | |
| 1689 | int print_event_logging_function_header_user_generic(char *basename, facility_t *fac, |
| 1690 | event_t *event, FILE *fd, enum user_fct_types fct_type) |
| 1691 | { |
| 1692 | char *attrib; |
| 1693 | |
| 1694 | if(event->no_instrument_function && fct_type == USER_FCT_PROTO) { |
| 1695 | attrib = "__attribute__((no_instrument_function)) "; |
| 1696 | } else { |
| 1697 | attrib = ""; |
| 1698 | } |
| 1699 | if(event->param_buffer) { |
| 1700 | fprintf(fd, "static inline %sint trace_%s_param_buffer(\n", attrib, basename); |
| 1701 | } else { |
| 1702 | fprintf(fd, "static inline %sint trace_%s(\n",attrib, basename); |
| 1703 | } |
| 1704 | int has_argument = 0; |
| 1705 | |
| 1706 | if(event->param_buffer) { |
| 1707 | if(has_argument) { |
| 1708 | fprintf(fd, ","); |
| 1709 | fprintf(fd, "\n"); |
| 1710 | } |
| 1711 | print_tabs(2, fd); |
| 1712 | fprintf(fd, "char *buffer"); |
| 1713 | has_argument = 1; |
| 1714 | fprintf(fd, ","); |
| 1715 | fprintf(fd, "\n"); |
| 1716 | print_tabs(2, fd); |
| 1717 | fprintf(fd, "size_t reserve_size"); |
| 1718 | } else { |
| 1719 | for(unsigned int j = 0; j < event->fields.position; j++) { |
| 1720 | /* For each field, print the function argument */ |
| 1721 | field_t *f = (field_t*)event->fields.array[j]; |
| 1722 | type_descriptor_t *t = f->type; |
| 1723 | if(has_argument) { |
| 1724 | fprintf(fd, ","); |
| 1725 | fprintf(fd, "\n"); |
| 1726 | } |
| 1727 | if(print_arg(t, fd, 2, basename, f->name)) return 1; |
| 1728 | has_argument = 1; |
| 1729 | } |
| 1730 | } |
| 1731 | if(!has_argument) { |
| 1732 | print_tabs(2, fd); |
| 1733 | fprintf(fd, "void"); |
| 1734 | } |
| 1735 | fprintf(fd,")"); |
| 1736 | return 0; |
| 1737 | } |
| 1738 | |
| 1739 | |
| 1740 | /* print_event_logging_function_user_generic |
| 1741 | * Print the logging function of an event for userspace tracing. This is the |
| 1742 | * core of genevent */ |
| 1743 | int print_event_logging_function_user_generic(char *basename, facility_t *fac, |
| 1744 | event_t *event, FILE *fd) |
| 1745 | { |
| 1746 | int has_type_fixed = 0; |
| 1747 | |
| 1748 | if(print_event_logging_function_header_user_generic(basename, fac, event, fd, USER_FCT_PROTO)) return 1; |
| 1749 | fprintf(fd,";\n"); |
| 1750 | fprintf(fd,"\n"); |
| 1751 | fprintf(fd, "#ifndef LTT_TRACE_FAST\n"); |
| 1752 | if(print_event_logging_function_header_user_generic(basename, fac, event, fd, USER_FCT_DECLARATION)) return 1; |
| 1753 | fprintf(fd,"\n"); |
| 1754 | fprintf(fd, |
| 1755 | "#ifndef LTT_TRACE\n"); |
| 1756 | fprintf(fd, "{\n"); |
| 1757 | fprintf(fd, "}\n"); |
| 1758 | fprintf(fd,"#else\n"); |
| 1759 | fprintf(fd, "{\n"); |
| 1760 | /* Print the function variables */ |
| 1761 | print_tabs(1, fd); |
| 1762 | fprintf(fd, "int ret = 0;\n"); |
| 1763 | if(event->param_buffer) { |
| 1764 | //FIX print_tabs(1, fd); |
| 1765 | //fprintf(fd, "reserve_size = ltt_align(reserve_size, sizeof(void *));\n"); |
| 1766 | print_tabs(1, fd); |
| 1767 | fprintf(fd, "{\n"); |
| 1768 | goto do_syscall; |
| 1769 | } |
| 1770 | print_tabs(1, fd); |
| 1771 | fprintf(fd, "char *buffer = NULL;\n"); |
| 1772 | print_tabs(1, fd); |
| 1773 | fprintf(fd, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n"); |
| 1774 | print_tabs(1, fd); |
| 1775 | fprintf(fd, "size_t *to_base = &real_to_base;\n"); |
| 1776 | print_tabs(1, fd); |
| 1777 | fprintf(fd, "size_t real_to = 0;\n"); |
| 1778 | print_tabs(1, fd); |
| 1779 | fprintf(fd, "size_t *to = &real_to;\n"); |
| 1780 | print_tabs(1, fd); |
| 1781 | fprintf(fd, "size_t real_len = 0;\n"); |
| 1782 | print_tabs(1, fd); |
| 1783 | fprintf(fd, "size_t *len = &real_len;\n"); |
| 1784 | print_tabs(1, fd); |
| 1785 | fprintf(fd, "size_t reserve_size;\n"); |
| 1786 | print_tabs(1, fd); |
| 1787 | fprintf(fd, "size_t slot_size;\n"); |
| 1788 | print_tabs(1, fd); |
| 1789 | |
| 1790 | if(event->fields.position > 0) { |
| 1791 | for(unsigned int i=0;i<event->fields.position;i++){ |
| 1792 | /* Search for at least one child with fixed size. It means |
| 1793 | * we need local variables.*/ |
| 1794 | field_t *field = (field_t*)(event->fields.array[i]); |
| 1795 | type_descriptor_t *type = field->type; |
| 1796 | has_type_fixed = has_type_local(type); |
| 1797 | if(has_type_fixed) break; |
| 1798 | } |
| 1799 | |
| 1800 | if(has_type_fixed) { |
| 1801 | fprintf(fd, "size_t align;\n"); |
| 1802 | print_tabs(1, fd); |
| 1803 | } |
| 1804 | |
| 1805 | fprintf(fd, "const char *real_from;\n"); |
| 1806 | print_tabs(1, fd); |
| 1807 | fprintf(fd, "const char **from = &real_from;\n"); |
| 1808 | print_tabs(1, fd); |
| 1809 | } |
| 1810 | |
| 1811 | /* Calculate event variable len + event data alignment offset. |
| 1812 | * Assume that the padding for alignment starts at a void* |
| 1813 | * address. |
| 1814 | * This excludes the header size and alignment. */ |
| 1815 | |
| 1816 | print_tabs(1, fd); |
| 1817 | fprintf(fd, "/* For each field, calculate the field size. */\n"); |
| 1818 | print_tabs(1, fd); |
| 1819 | fprintf(fd, "/* size = *to_base + *to + *len */\n"); |
| 1820 | print_tabs(1, fd); |
| 1821 | fprintf(fd, "/* Assume that the padding for alignment starts at a\n"); |
| 1822 | print_tabs(1, fd); |
| 1823 | fprintf(fd, " * sizeof(void *) address. */\n"); |
| 1824 | fprintf(fd, "\n"); |
| 1825 | |
| 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; |
| 1829 | /* Set from */ |
| 1830 | print_tabs(1, fd); |
| 1831 | switch(type->type) { |
| 1832 | case SEQUENCE: |
| 1833 | case UNION: |
| 1834 | case ARRAY: |
| 1835 | case STRUCT: |
| 1836 | case STRING: |
| 1837 | fprintf(fd, "*from = (const char*)lttng_param_%s;\n", field->name); |
| 1838 | break; |
| 1839 | default: |
| 1840 | fprintf(fd, "*from = (const char*)<tng_param_%s;\n", field->name); |
| 1841 | break; |
| 1842 | } |
| 1843 | |
| 1844 | if(print_type_write(type, |
| 1845 | fd, 1, basename, field->name, "lttng_param_", 0)) return 1; |
| 1846 | fprintf(fd, "\n"); |
| 1847 | } |
| 1848 | print_tabs(1, fd); |
| 1849 | fprintf(fd, "reserve_size = *to_base + *to + *len;\n"); |
| 1850 | |
| 1851 | print_tabs(1, fd); |
| 1852 | fprintf(fd, "{\n"); |
| 1853 | print_tabs(2, fd); |
| 1854 | fprintf(fd, "char stack_buffer[reserve_size];\n"); |
| 1855 | print_tabs(2, fd); |
| 1856 | fprintf(fd, "buffer = stack_buffer;\n"); |
| 1857 | fprintf(fd, "\n"); |
| 1858 | |
| 1859 | |
| 1860 | //print_tabs(2, fd); |
| 1861 | // for DEBUG only |
| 1862 | // fprintf(fd, "goto commit; /* DEBUG : never actually write. */\n\n"); |
| 1863 | print_tabs(2, fd); |
| 1864 | fprintf(fd, "*to_base = *to = *len = 0;\n"); |
| 1865 | fprintf(fd, "\n"); |
| 1866 | |
| 1867 | /* write data. */ |
| 1868 | |
| 1869 | for(unsigned int i=0;i<event->fields.position;i++){ |
| 1870 | field_t *field = (field_t*)(event->fields.array[i]); |
| 1871 | type_descriptor_t *type = field->type; |
| 1872 | |
| 1873 | /* Set from */ |
| 1874 | print_tabs(2, fd); |
| 1875 | switch(type->type) { |
| 1876 | case SEQUENCE: |
| 1877 | case UNION: |
| 1878 | case ARRAY: |
| 1879 | case STRUCT: |
| 1880 | case STRING: |
| 1881 | fprintf(fd, "*from = (const char*)lttng_param_%s;\n", field->name); |
| 1882 | break; |
| 1883 | default: |
| 1884 | fprintf(fd, "*from = (const char*)<tng_param_%s;\n", field->name); |
| 1885 | break; |
| 1886 | } |
| 1887 | |
| 1888 | |
| 1889 | if(print_type_write(type, |
| 1890 | fd, 2, basename, field->name, "lttng_param_", 0)) return 1; |
| 1891 | fprintf(fd, "\n"); |
| 1892 | |
| 1893 | /* Don't forget to flush pending memcpy */ |
| 1894 | print_tabs(2, fd); |
| 1895 | fprintf(fd, "/* Flush pending memcpy */\n"); |
| 1896 | print_tabs(2, fd); |
| 1897 | fprintf(fd, "if (*len != 0) {\n"); |
| 1898 | print_tabs(3, fd); |
| 1899 | fprintf(fd, "memcpy(buffer+*to_base+*to, *from, *len);\n"); |
| 1900 | print_tabs(3, fd); |
| 1901 | fprintf(fd, "*to += *len;\n"); |
| 1902 | //print_tabs(3, fd); |
| 1903 | //fprintf(fd, "from += len;\n"); |
| 1904 | print_tabs(3, fd); |
| 1905 | fprintf(fd, "*len = 0;\n"); |
| 1906 | print_tabs(2, fd); |
| 1907 | fprintf(fd, "}\n"); |
| 1908 | fprintf(fd, "\n"); |
| 1909 | } |
| 1910 | |
| 1911 | do_syscall: |
| 1912 | print_tabs(2, fd); |
| 1913 | fprintf(fd, "ret = ltt_trace_generic(ltt_facility_%s_%X, event_%s_%s, buffer, reserve_size, LTT_BLOCKING, %u);\n", fac->name, fac->checksum, fac->name, event->name, event->high_priority); |
| 1914 | |
| 1915 | print_tabs(1, fd); |
| 1916 | fprintf(fd, "}\n\n"); |
| 1917 | |
| 1918 | print_tabs(1, fd); |
| 1919 | fprintf(fd, "return ret;\n\n"); |
| 1920 | |
| 1921 | fprintf(fd, "}\n"); |
| 1922 | fprintf(fd, |
| 1923 | "#endif //LTT_TRACE\n"); |
| 1924 | fprintf(fd, "#endif //!LTT_TRACE_FAST\n\n"); |
| 1925 | |
| 1926 | return 0; |
| 1927 | } |
| 1928 | |
| 1929 | /* print_event_logging_function_user_fast |
| 1930 | * Print the logging function of an event for userspace tracing. This is the |
| 1931 | * core of genevent */ |
| 1932 | int print_event_logging_function_user_fast(char *basename, facility_t *fac, |
| 1933 | event_t *event, FILE *fd) |
| 1934 | { |
| 1935 | char *attrib; |
| 1936 | |
| 1937 | fprintf(fd, "#ifdef LTT_TRACE_FAST\n"); |
| 1938 | |
| 1939 | if(event->no_instrument_function) { |
| 1940 | attrib = "__attribute__((no_instrument_function)) "; |
| 1941 | } else { |
| 1942 | attrib = ""; |
| 1943 | } |
| 1944 | fprintf(fd, "static inline %sint trace_%s(\n",attrib, basename); |
| 1945 | |
| 1946 | int has_argument = 0; |
| 1947 | int has_type_fixed = 0; |
| 1948 | |
| 1949 | for(unsigned int j = 0; j < event->fields.position; j++) { |
| 1950 | /* For each field, print the function argument */ |
| 1951 | field_t *f = (field_t*)event->fields.array[j]; |
| 1952 | type_descriptor_t *t = f->type; |
| 1953 | if(has_argument) { |
| 1954 | fprintf(fd, ","); |
| 1955 | fprintf(fd, "\n"); |
| 1956 | } |
| 1957 | if(print_arg(t, fd, 2, basename, f->name)) return 1; |
| 1958 | has_argument = 1; |
| 1959 | } |
| 1960 | if(!has_argument) { |
| 1961 | print_tabs(2, fd); |
| 1962 | fprintf(fd, "void"); |
| 1963 | } |
| 1964 | fprintf(fd,")\n"); |
| 1965 | fprintf(fd, |
| 1966 | "#ifndef LTT_TRACE\n"); |
| 1967 | fprintf(fd, "{\n"); |
| 1968 | fprintf(fd, "}\n"); |
| 1969 | fprintf(fd,"#else\n"); |
| 1970 | fprintf(fd, "{\n"); |
| 1971 | /* Print the function variables */ |
| 1972 | print_tabs(1, fd); |
| 1973 | fprintf(fd, "unsigned int index;\n"); |
| 1974 | print_tabs(1, fd); |
| 1975 | fprintf(fd, "struct ltt_trace_info *trace = thread_trace_info;\n"); |
| 1976 | print_tabs(1, fd); |
| 1977 | fprintf(fd, "struct ltt_buf *ltt_buf;\n"); |
| 1978 | print_tabs(1, fd); |
| 1979 | fprintf(fd, "char *buffer = NULL;\n"); |
| 1980 | print_tabs(1, fd); |
| 1981 | fprintf(fd, "size_t real_to_base = 0; /* The buffer is allocated on arch_size alignment */\n"); |
| 1982 | print_tabs(1, fd); |
| 1983 | fprintf(fd, "size_t *to_base = &real_to_base;\n"); |
| 1984 | print_tabs(1, fd); |
| 1985 | fprintf(fd, "size_t real_to = 0;\n"); |
| 1986 | print_tabs(1, fd); |
| 1987 | fprintf(fd, "size_t *to = &real_to;\n"); |
| 1988 | print_tabs(1, fd); |
| 1989 | fprintf(fd, "size_t real_len = 0;\n"); |
| 1990 | print_tabs(1, fd); |
| 1991 | fprintf(fd, "size_t *len = &real_len;\n"); |
| 1992 | print_tabs(1, fd); |
| 1993 | fprintf(fd, "size_t reserve_size;\n"); |
| 1994 | print_tabs(1, fd); |
| 1995 | fprintf(fd, "size_t slot_size;\n"); |
| 1996 | print_tabs(1, fd); |
| 1997 | |
| 1998 | if(event->fields.position > 0) { |
| 1999 | for(unsigned int i=0;i<event->fields.position;i++){ |
| 2000 | /* Search for at least one child with fixed size. It means |
| 2001 | * we need local variables.*/ |
| 2002 | field_t *field = (field_t*)(event->fields.array[i]); |
| 2003 | type_descriptor_t *type = field->type; |
| 2004 | has_type_fixed = has_type_local(type); |
| 2005 | if(has_type_fixed) break; |
| 2006 | } |
| 2007 | |
| 2008 | if(has_type_fixed) { |
| 2009 | fprintf(fd, "size_t align;\n"); |
| 2010 | print_tabs(1, fd); |
| 2011 | } |
| 2012 | |
| 2013 | fprintf(fd, "const char *real_from;\n"); |
| 2014 | print_tabs(1, fd); |
| 2015 | fprintf(fd, "const char **from = &real_from;\n"); |
| 2016 | print_tabs(1, fd); |
| 2017 | } |
| 2018 | fprintf(fd, "uint64_t tsc;\n"); |
| 2019 | print_tabs(1, fd); |
| 2020 | |
| 2021 | print_tabs(1, fd); |
| 2022 | fprintf(fd, "if (!trace) {\n"); |
| 2023 | print_tabs(2, fd); |
| 2024 | fprintf(fd, "ltt_thread_init();\n"); |
| 2025 | print_tabs(2, fd); |
| 2026 | fprintf(fd, "trace = thread_trace_info;\n"); |
| 2027 | print_tabs(1, fd); |
| 2028 | fprintf(fd, "}\n\n"); |
| 2029 | fprintf(fd, "\n"); |
| 2030 | |
| 2031 | /* Calculate event variable len + event data alignment offset. |
| 2032 | * Assume that the padding for alignment starts at a void* |
| 2033 | * address. |
| 2034 | * This excludes the header size and alignment. */ |
| 2035 | |
| 2036 | print_tabs(1, fd); |
| 2037 | fprintf(fd, "/* For each field, calculate the field size. */\n"); |
| 2038 | print_tabs(1, fd); |
| 2039 | fprintf(fd, "/* size = *to_base + *to + *len */\n"); |
| 2040 | print_tabs(1, fd); |
| 2041 | fprintf(fd, "/* Assume that the padding for alignment starts at a\n"); |
| 2042 | print_tabs(1, fd); |
| 2043 | fprintf(fd, " * sizeof(void *) address. */\n"); |
| 2044 | fprintf(fd, "\n"); |
| 2045 | |
| 2046 | for(unsigned int i=0;i<event->fields.position;i++){ |
| 2047 | field_t *field = (field_t*)(event->fields.array[i]); |
| 2048 | type_descriptor_t *type = field->type; |
| 2049 | /* Set from */ |
| 2050 | print_tabs(1, fd); |
| 2051 | switch(type->type) { |
| 2052 | case SEQUENCE: |
| 2053 | case UNION: |
| 2054 | case ARRAY: |
| 2055 | case STRUCT: |
| 2056 | case STRING: |
| 2057 | fprintf(fd, "*from = (const char*)lttng_param_%s;\n", field->name); |
| 2058 | break; |
| 2059 | default: |
| 2060 | fprintf(fd, "*from = (const char*)<tng_param_%s;\n", field->name); |
| 2061 | break; |
| 2062 | } |
| 2063 | |
| 2064 | if(print_type_write(type, |
| 2065 | fd, 1, basename, field->name, "lttng_param_", 0)) return 1; |
| 2066 | fprintf(fd, "\n"); |
| 2067 | } |
| 2068 | print_tabs(1, fd); |
| 2069 | fprintf(fd, "reserve_size = *to_base + *to + *len;\n"); |
| 2070 | |
| 2071 | print_tabs(1, fd); |
| 2072 | fprintf(fd, "trace->nesting++;\n"); |
| 2073 | |
| 2074 | /* Get facility index */ |
| 2075 | |
| 2076 | print_tabs(1, fd); |
| 2077 | fprintf(fd, |
| 2078 | "index = ltt_get_index_from_facility(ltt_facility_%s_%X,\n"\ |
| 2079 | "\t\t\t\t\t\tevent_%s_%s);\n", |
| 2080 | fac->name, fac->checksum, fac->name, event->name); |
| 2081 | fprintf(fd,"\n"); |
| 2082 | |
| 2083 | |
| 2084 | print_tabs(1, fd); |
| 2085 | fprintf(fd, "{\n"); |
| 2086 | |
| 2087 | if(event->per_trace) { |
| 2088 | print_tabs(2, fd); |
| 2089 | fprintf(fd, "if (dest_trace != trace) continue;\n\n"); |
| 2090 | } |
| 2091 | |
| 2092 | print_tabs(2, fd); |
| 2093 | fprintf(fd, "ltt_buf = ltt_get_channel_from_index(trace, index);\n"); |
| 2094 | print_tabs(2, fd); |
| 2095 | |
| 2096 | |
| 2097 | /* Relay reserve */ |
| 2098 | /* If error, increment event lost counter (done by ltt_reserve_slot) and |
| 2099 | * return */ |
| 2100 | print_tabs(2, fd); |
| 2101 | fprintf(fd, "slot_size = 0;\n"); |
| 2102 | print_tabs(2, fd); |
| 2103 | fprintf(fd, "buffer = ltt_reserve_slot(trace, ltt_buf,\n"); |
| 2104 | print_tabs(3, fd); |
| 2105 | fprintf(fd, "reserve_size, &slot_size, &tsc);\n"); |
| 2106 | /* If error, return */ |
| 2107 | print_tabs(2, fd); |
| 2108 | fprintf(fd, "if (!buffer)\n"); |
| 2109 | print_tabs(3, fd); |
| 2110 | fprintf(fd, "goto end; /* buffer full */\n\n"); |
| 2111 | //print_tabs(2, fd); |
| 2112 | // for DEBUG only |
| 2113 | // fprintf(fd, "goto commit; /* DEBUG : never actually write. */\n\n"); |
| 2114 | print_tabs(2, fd); |
| 2115 | fprintf(fd, "*to_base = *to = *len = 0;\n"); |
| 2116 | fprintf(fd, "\n"); |
| 2117 | |
| 2118 | /* Write event header */ |
| 2119 | print_tabs(2, fd); |
| 2120 | fprintf(fd, "buffer = ltt_write_event_header(trace, ltt_buf, buffer,\n"); |
| 2121 | print_tabs(3, fd); |
| 2122 | fprintf(fd, "ltt_facility_%s_%X, event_%s_%s,\n", fac->name, fac->checksum, |
| 2123 | fac->name, event->name); |
| 2124 | print_tabs(3, fd); |
| 2125 | fprintf(fd, "reserve_size, tsc);\n"); |
| 2126 | |
| 2127 | /* write data. */ |
| 2128 | |
| 2129 | for(unsigned int i=0;i<event->fields.position;i++){ |
| 2130 | field_t *field = (field_t*)(event->fields.array[i]); |
| 2131 | type_descriptor_t *type = field->type; |
| 2132 | |
| 2133 | /* Set from */ |
| 2134 | print_tabs(2, fd); |
| 2135 | switch(type->type) { |
| 2136 | case SEQUENCE: |
| 2137 | case UNION: |
| 2138 | case ARRAY: |
| 2139 | case STRUCT: |
| 2140 | case STRING: |
| 2141 | fprintf(fd, "*from = (const char*)lttng_param_%s;\n", field->name); |
| 2142 | break; |
| 2143 | default: |
| 2144 | fprintf(fd, "*from = (const char*)<tng_param_%s;\n", field->name); |
| 2145 | break; |
| 2146 | } |
| 2147 | |
| 2148 | |
| 2149 | if(print_type_write(type, |
| 2150 | fd, 2, basename, field->name, "lttng_param_", 0)) return 1; |
| 2151 | fprintf(fd, "\n"); |
| 2152 | |
| 2153 | /* Don't forget to flush pending memcpy */ |
| 2154 | print_tabs(2, fd); |
| 2155 | fprintf(fd, "/* Flush pending memcpy */\n"); |
| 2156 | print_tabs(2, fd); |
| 2157 | fprintf(fd, "if (*len != 0) {\n"); |
| 2158 | print_tabs(3, fd); |
| 2159 | fprintf(fd, "memcpy(buffer+*to_base+*to, *from, *len);\n"); |
| 2160 | print_tabs(3, fd); |
| 2161 | fprintf(fd, "*to += *len;\n"); |
| 2162 | //print_tabs(3, fd); |
| 2163 | //fprintf(fd, "from += len;\n"); |
| 2164 | print_tabs(3, fd); |
| 2165 | fprintf(fd, "*len = 0;\n"); |
| 2166 | print_tabs(2, fd); |
| 2167 | fprintf(fd, "}\n"); |
| 2168 | fprintf(fd, "\n"); |
| 2169 | } |
| 2170 | |
| 2171 | |
| 2172 | /* commit */ |
| 2173 | // for DEBUG only. |
| 2174 | //fprintf(fd, "commit:\n"); /* DEBUG! */ |
| 2175 | print_tabs(2, fd); |
| 2176 | fprintf(fd, "ltt_commit_slot(ltt_buf, buffer, slot_size);\n\n"); |
| 2177 | |
| 2178 | fprintf(fd, "}\n\n"); |
| 2179 | |
| 2180 | fprintf(fd, "end:\n"); |
| 2181 | /* Release locks */ |
| 2182 | print_tabs(1, fd); |
| 2183 | fprintf(fd, "trace->nesting--;\n"); |
| 2184 | |
| 2185 | |
| 2186 | fprintf(fd, "}\n"); |
| 2187 | fprintf(fd, |
| 2188 | "#endif //LTT_TRACE\n"); |
| 2189 | fprintf(fd, "#endif //LTT_TRACE_FAST\n"); |
| 2190 | |
| 2191 | return 0; |
| 2192 | } |
| 2193 | |
| 2194 | |
| 2195 | |
| 2196 | |
| 2197 | |
| 2198 | |
| 2199 | /* ltt-facility-name.h : main logging header. |
| 2200 | * log_header */ |
| 2201 | |
| 2202 | void print_log_header_head(facility_t *fac, FILE *fd) |
| 2203 | { |
| 2204 | fprintf(fd, "#ifndef _LTT_FACILITY_%s_H_\n", fac->capname); |
| 2205 | fprintf(fd, "#define _LTT_FACILITY_%s_H_\n\n", fac->capname); |
| 2206 | fprintf(fd, "#include <linux/types.h>\n"); |
| 2207 | if(!fac->arch) |
| 2208 | fprintf(fd, "#include <ltt/ltt-facility-id-%s.h>\n", fac->name); |
| 2209 | else |
| 2210 | fprintf(fd, "#include <ltt/ltt-facility-id-%s_%s.h>\n", |
| 2211 | fac->name, |
| 2212 | fac->arch); |
| 2213 | fprintf(fd, "#include <ltt/ltt-tracer.h>\n"); |
| 2214 | fprintf(fd, "\n"); |
| 2215 | } |
| 2216 | |
| 2217 | /* ltt-facility-name.h : main logging header. |
| 2218 | * log_header */ |
| 2219 | |
| 2220 | void print_log_header_head_user(facility_t *fac, FILE *fd) |
| 2221 | { |
| 2222 | fprintf(fd, "#ifndef _LTT_FACILITY_%s_H_\n", fac->capname); |
| 2223 | fprintf(fd, "#define _LTT_FACILITY_%s_H_\n\n", fac->capname); |
| 2224 | fprintf(fd, "#include <sys/types.h>\n"); |
| 2225 | if(!fac->arch) |
| 2226 | fprintf(fd, "#include <ltt/ltt-facility-id-%s.h>\n", fac->name); |
| 2227 | else |
| 2228 | fprintf(fd, "#include <asm/ltt/ltt-facility-id-%s_%s.h>\n", |
| 2229 | fac->name, |
| 2230 | fac->arch); |
| 2231 | fprintf(fd, "#include <ltt/ltt-usertrace.h>\n"); |
| 2232 | fprintf(fd, "\n"); |
| 2233 | fprintf(fd, "#ifdef __cplusplus\n"); |
| 2234 | fprintf(fd, "extern \"C\" {\n"); |
| 2235 | fprintf(fd, "#endif\n"); |
| 2236 | fprintf(fd, "\n"); |
| 2237 | } |
| 2238 | |
| 2239 | |
| 2240 | int print_log_header_types(facility_t *fac, FILE *fd) |
| 2241 | { |
| 2242 | sequence_t *types = &fac->named_types.values; |
| 2243 | fprintf(fd, "/* Named types */\n"); |
| 2244 | fprintf(fd, "\n"); |
| 2245 | |
| 2246 | for(unsigned int i = 0; i < types->position; i++) { |
| 2247 | /* For each named type, print the definition */ |
| 2248 | if(print_type_declaration(types->array[i], fd, |
| 2249 | 0, "", "")) return 1; |
| 2250 | /* Print also the align function */ |
| 2251 | if(((type_descriptor_t*)types->array[i])->fac->align) |
| 2252 | if(print_type_alignment_fct(types->array[i], fd, |
| 2253 | 0, "", "")) return 1; |
| 2254 | /* Print also the write function */ |
| 2255 | if(print_type_write_fct(types->array[i], fd, |
| 2256 | 0, "", "")) return 1; |
| 2257 | } |
| 2258 | return 0; |
| 2259 | } |
| 2260 | |
| 2261 | int print_log_header_events(facility_t *fac, FILE *fd) |
| 2262 | { |
| 2263 | sequence_t *events = &fac->events; |
| 2264 | char basename[PATH_MAX]; |
| 2265 | unsigned int facname_len; |
| 2266 | |
| 2267 | strncpy(basename, fac->name, PATH_MAX); |
| 2268 | facname_len = strlen(basename); |
| 2269 | strncat(basename, "_", PATH_MAX-facname_len); |
| 2270 | facname_len = strlen(basename); |
| 2271 | |
| 2272 | for(unsigned int i = 0; i < events->position; i++) { |
| 2273 | event_t *event = (event_t*)events->array[i]; |
| 2274 | strncpy(&basename[facname_len], event->name, PATH_MAX-facname_len); |
| 2275 | |
| 2276 | /* For each event, print structure, and then logging function */ |
| 2277 | fprintf(fd, "/* Event %s structures */\n", |
| 2278 | event->name); |
| 2279 | for(unsigned int j = 0; j < event->fields.position; j++) { |
| 2280 | /* For each unnamed type, print the definition */ |
| 2281 | field_t *f = (field_t*)event->fields.array[j]; |
| 2282 | type_descriptor_t *t = f->type; |
| 2283 | if(t->type_name == NULL) { |
| 2284 | if((print_type_declaration(t, fd, 0, basename, f->name))) return 1; |
| 2285 | /* Print also the align function */ |
| 2286 | if(fac->align) { |
| 2287 | if((print_type_alignment_fct(t, fd, 0, basename, f->name))) return 1; |
| 2288 | } |
| 2289 | /* Print also the write function */ |
| 2290 | if((print_type_write_fct(t, fd, 0, basename, f->name))) return 1; |
| 2291 | } |
| 2292 | } |
| 2293 | |
| 2294 | fprintf(fd, "\n"); |
| 2295 | |
| 2296 | fprintf(fd, "/* Event %s logging function */\n", |
| 2297 | event->name); |
| 2298 | |
| 2299 | if(!fac->user) { |
| 2300 | if(print_event_logging_function(basename, fac, event, fd)) return 1; |
| 2301 | } else { |
| 2302 | if(print_event_logging_function_user_generic(basename, fac, event, fd)) |
| 2303 | return 1; |
| 2304 | if(print_event_logging_function_user_fast(basename, fac, event, fd)) |
| 2305 | return 1; |
| 2306 | } |
| 2307 | |
| 2308 | fprintf(fd, "\n"); |
| 2309 | } |
| 2310 | |
| 2311 | return 0; |
| 2312 | } |
| 2313 | |
| 2314 | |
| 2315 | void print_log_header_tail(facility_t *fac, FILE *fd) |
| 2316 | { |
| 2317 | fprintf(fd, "#endif //_LTT_FACILITY_%s_H_\n",fac->capname); |
| 2318 | } |
| 2319 | |
| 2320 | void print_log_header_tail_user(facility_t *fac, FILE *fd) |
| 2321 | { |
| 2322 | fprintf(fd, "#ifdef __cplusplus\n"); |
| 2323 | fprintf(fd, "} /* end of extern \"C\" */\n"); |
| 2324 | fprintf(fd, "#endif\n"); |
| 2325 | fprintf(fd, "\n"); |
| 2326 | fprintf(fd, "#endif //_LTT_FACILITY_%s_H_\n",fac->capname); |
| 2327 | } |
| 2328 | |
| 2329 | int print_log_header(facility_t *fac) |
| 2330 | { |
| 2331 | char filename[PATH_MAX]; |
| 2332 | unsigned int filename_size = 0; |
| 2333 | FILE *fd; |
| 2334 | dprintf("%s\n", fac->name); |
| 2335 | |
| 2336 | strcpy(filename, "ltt-facility-"); |
| 2337 | filename_size = strlen(filename); |
| 2338 | |
| 2339 | strncat(filename, fac->name, PATH_MAX - filename_size); |
| 2340 | filename_size = strlen(filename); |
| 2341 | |
| 2342 | if(fac->arch) { |
| 2343 | strncat(filename, "_", PATH_MAX - filename_size); |
| 2344 | filename_size = strlen(filename); |
| 2345 | |
| 2346 | strncat(filename, fac->arch, PATH_MAX - filename_size); |
| 2347 | filename_size = strlen(filename); |
| 2348 | } |
| 2349 | |
| 2350 | strncat(filename, ".h", PATH_MAX - filename_size); |
| 2351 | filename_size = strlen(filename); |
| 2352 | |
| 2353 | |
| 2354 | fd = fopen(filename, "w"); |
| 2355 | if(fd == NULL) { |
| 2356 | printf("Error opening file %s for writing : %s\n", |
| 2357 | filename, strerror(errno)); |
| 2358 | return errno; |
| 2359 | } |
| 2360 | |
| 2361 | /* Print file head */ |
| 2362 | if(!fac->user) |
| 2363 | print_log_header_head(fac, fd); |
| 2364 | else |
| 2365 | print_log_header_head_user(fac, fd); |
| 2366 | |
| 2367 | /* print named types in declaration order */ |
| 2368 | if(print_log_header_types(fac, fd)) return 1; |
| 2369 | |
| 2370 | /* Print events */ |
| 2371 | if(print_log_header_events(fac, fd)) return 1; |
| 2372 | |
| 2373 | /* Print file tail */ |
| 2374 | if(!fac->user) |
| 2375 | print_log_header_tail(fac, fd); |
| 2376 | else |
| 2377 | print_log_header_tail_user(fac, fd); |
| 2378 | |
| 2379 | |
| 2380 | |
| 2381 | fclose(fd); |
| 2382 | |
| 2383 | return 0; |
| 2384 | } |
| 2385 | |
| 2386 | |
| 2387 | /* ltt-facility-id-name.h : facility id. |
| 2388 | * log_id_header */ |
| 2389 | int print_id_header(facility_t *fac) |
| 2390 | { |
| 2391 | char filename[PATH_MAX]; |
| 2392 | unsigned int filename_size = 0; |
| 2393 | FILE *fd; |
| 2394 | char basename[PATH_MAX]; |
| 2395 | char basename_len = 0; |
| 2396 | |
| 2397 | dprintf("%s\n", fac->name); |
| 2398 | |
| 2399 | strcpy(filename, "ltt-facility-id-"); |
| 2400 | filename_size = strlen(filename); |
| 2401 | |
| 2402 | strncat(filename, fac->name, PATH_MAX - filename_size); |
| 2403 | filename_size = strlen(filename); |
| 2404 | |
| 2405 | if(fac->arch) { |
| 2406 | strncat(filename, "_", PATH_MAX - filename_size); |
| 2407 | filename_size = strlen(filename); |
| 2408 | |
| 2409 | strncat(filename, fac->arch, PATH_MAX - filename_size); |
| 2410 | filename_size = strlen(filename); |
| 2411 | } |
| 2412 | |
| 2413 | strncat(filename, ".h", PATH_MAX - filename_size); |
| 2414 | filename_size = strlen(filename); |
| 2415 | |
| 2416 | |
| 2417 | fd = fopen(filename, "w"); |
| 2418 | if(fd == NULL) { |
| 2419 | printf("Error opening file %s for writing : %s\n", |
| 2420 | filename, strerror(errno)); |
| 2421 | return errno; |
| 2422 | } |
| 2423 | |
| 2424 | if(!fac->user) { |
| 2425 | fprintf(fd, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac->capname); |
| 2426 | fprintf(fd, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac->capname); |
| 2427 | fprintf(fd, "#ifdef CONFIG_LTT\n"); |
| 2428 | |
| 2429 | fprintf(fd,"#include <linux/ltt-facilities.h>\n\n"); |
| 2430 | |
| 2431 | fprintf(fd,"/**** facility handle ****/\n\n"); |
| 2432 | fprintf(fd,"extern ltt_facility_t ltt_facility_%s_%X;\n", |
| 2433 | fac->name, fac->checksum); |
| 2434 | fprintf(fd,"extern ltt_facility_t ltt_facility_%s;\n\n\n",fac->name); |
| 2435 | |
| 2436 | strncpy(basename, fac->name, PATH_MAX); |
| 2437 | basename_len = strlen(basename); |
| 2438 | strncat(basename, "_", PATH_MAX - basename_len); |
| 2439 | basename_len++; |
| 2440 | |
| 2441 | fprintf(fd,"/**** event index ****/\n\n"); |
| 2442 | fprintf(fd,"enum %s_event {\n",fac->name); |
| 2443 | |
| 2444 | for(unsigned int i = 0; i < fac->events.position; i++) { |
| 2445 | event_t *event = (event_t*)fac->events.array[i]; |
| 2446 | strncpy(basename+basename_len, event->name, PATH_MAX-basename_len); |
| 2447 | print_tabs(1, fd); |
| 2448 | fprintf(fd, "event_%s,\n", basename); |
| 2449 | } |
| 2450 | print_tabs(1, fd); |
| 2451 | fprintf(fd, "facility_%s_num_events\n", fac->name); |
| 2452 | fprintf(fd, "};\n"); |
| 2453 | fprintf(fd, "\n"); |
| 2454 | |
| 2455 | |
| 2456 | fprintf(fd, "#endif //CONFIG_LTT\n"); |
| 2457 | fprintf(fd, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac->capname); |
| 2458 | } else { |
| 2459 | fprintf(fd, "#ifndef _LTT_FACILITY_ID_%s_H_\n",fac->capname); |
| 2460 | fprintf(fd, "#define _LTT_FACILITY_ID_%s_H_\n\n",fac->capname); |
| 2461 | fprintf(fd, "#ifdef LTT_TRACE\n"); |
| 2462 | |
| 2463 | fprintf(fd,"#include <ltt/ltt-usertrace.h>\n\n"); |
| 2464 | |
| 2465 | fprintf(fd,"/**** facility handle ****/\n\n"); |
| 2466 | fprintf(fd,"extern ltt_facility_t ltt_facility_%s_%X;\n", |
| 2467 | fac->name, fac->checksum); |
| 2468 | fprintf(fd,"extern ltt_facility_t ltt_facility_%s;\n\n\n",fac->name); |
| 2469 | |
| 2470 | strncpy(basename, fac->name, PATH_MAX); |
| 2471 | basename_len = strlen(basename); |
| 2472 | strncat(basename, "_", PATH_MAX - basename_len); |
| 2473 | basename_len++; |
| 2474 | |
| 2475 | fprintf(fd,"/**** event index ****/\n\n"); |
| 2476 | fprintf(fd,"enum %s_event {\n",fac->name); |
| 2477 | |
| 2478 | for(unsigned int i = 0; i < fac->events.position; i++) { |
| 2479 | event_t *event = (event_t*)fac->events.array[i]; |
| 2480 | strncpy(basename+basename_len, event->name, PATH_MAX-basename_len); |
| 2481 | print_tabs(1, fd); |
| 2482 | fprintf(fd, "event_%s,\n", basename); |
| 2483 | } |
| 2484 | print_tabs(1, fd); |
| 2485 | fprintf(fd, "facility_%s_num_events\n", fac->name); |
| 2486 | fprintf(fd, "};\n"); |
| 2487 | fprintf(fd, "\n"); |
| 2488 | |
| 2489 | |
| 2490 | fprintf(fd, "#endif //LTT_TRACE\n"); |
| 2491 | fprintf(fd, "#endif //_LTT_FACILITY_ID_%s_H_\n",fac->capname); |
| 2492 | } |
| 2493 | |
| 2494 | |
| 2495 | fclose(fd); |
| 2496 | |
| 2497 | return 0; |
| 2498 | } |
| 2499 | |
| 2500 | |
| 2501 | /* ltt-facility-loader-name.h : facility specific loader info. |
| 2502 | * loader_header */ |
| 2503 | int print_loader_header(facility_t *fac) |
| 2504 | { |
| 2505 | char filename[PATH_MAX]; |
| 2506 | unsigned int filename_size = 0; |
| 2507 | FILE *fd; |
| 2508 | dprintf("%s\n", fac->name); |
| 2509 | |
| 2510 | strcpy(filename, "ltt-facility-loader-"); |
| 2511 | filename_size = strlen(filename); |
| 2512 | |
| 2513 | strncat(filename, fac->name, PATH_MAX - filename_size); |
| 2514 | filename_size = strlen(filename); |
| 2515 | |
| 2516 | if(fac->arch) { |
| 2517 | strncat(filename, "_", PATH_MAX - filename_size); |
| 2518 | filename_size = strlen(filename); |
| 2519 | |
| 2520 | strncat(filename, fac->arch, PATH_MAX - filename_size); |
| 2521 | filename_size = strlen(filename); |
| 2522 | } |
| 2523 | |
| 2524 | strncat(filename, ".h", PATH_MAX - filename_size); |
| 2525 | filename_size = strlen(filename); |
| 2526 | |
| 2527 | |
| 2528 | fd = fopen(filename, "w"); |
| 2529 | if(fd == NULL) { |
| 2530 | printf("Error opening file %s for writing : %s\n", |
| 2531 | filename, strerror(errno)); |
| 2532 | return errno; |
| 2533 | } |
| 2534 | |
| 2535 | fprintf(fd, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n", fac->capname); |
| 2536 | fprintf(fd, "#define _LTT_FACILITY_LOADER_%s_H_\n\n", fac->capname); |
| 2537 | fprintf(fd, "#ifdef CONFIG_LTT\n\n"); |
| 2538 | fprintf(fd,"#include <linux/ltt-facilities.h>\n"); |
| 2539 | if(!fac->arch) |
| 2540 | fprintf(fd,"#include <ltt/ltt-facility-id-%s.h>\n\n", |
| 2541 | fac->name); |
| 2542 | else |
| 2543 | fprintf(fd,"#include <ltt/ltt-facility-id-%s_%s.h>\n\n", |
| 2544 | fac->name, |
| 2545 | fac->arch); |
| 2546 | fprintf(fd,"ltt_facility_t\tltt_facility_%s;\n", fac->name); |
| 2547 | fprintf(fd,"ltt_facility_t\tltt_facility_%s_%X;\n\n", |
| 2548 | fac->name, fac->checksum); |
| 2549 | fprintf(fd,"extern unsigned int ltt_get_channel_index_%s(u8 eID);\n\n", |
| 2550 | fac->name); |
| 2551 | |
| 2552 | fprintf(fd,"#define LTT_FACILITY_SYMBOL\t\tltt_facility_%s\n", |
| 2553 | fac->name); |
| 2554 | fprintf(fd,"#define LTT_FACILITY_CHECKSUM_SYMBOL\tltt_facility_%s_%X\n", |
| 2555 | fac->name, fac->checksum); |
| 2556 | fprintf(fd,"#define LTT_FACILITY_CHECKSUM\t\t0x%X\n", fac->checksum); |
| 2557 | fprintf(fd,"#define LTT_FACILITY_NAME\t\t\"%s\"\n", fac->name); |
| 2558 | fprintf(fd,"#define LTT_FACILITY_NUM_EVENTS\tfacility_%s_num_events\n\n", |
| 2559 | fac->name); |
| 2560 | fprintf(fd,"#define LTT_FACILITY_ALIGNMENT\t\t%u\n\n", |
| 2561 | fac->align); |
| 2562 | fprintf(fd,"#define LTT_FACILITY_SELECT\t\tltt_get_channel_index_%s\n\n", |
| 2563 | fac->name); |
| 2564 | fprintf(fd, "#endif //CONFIG_LTT\n\n"); |
| 2565 | fprintf(fd, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac->capname); |
| 2566 | |
| 2567 | fclose(fd); |
| 2568 | |
| 2569 | return 0; |
| 2570 | } |
| 2571 | |
| 2572 | int print_loader_header_user(facility_t *fac) |
| 2573 | { |
| 2574 | char filename[PATH_MAX]; |
| 2575 | unsigned int filename_size = 0; |
| 2576 | FILE *fd; |
| 2577 | dprintf("%s\n", fac->name); |
| 2578 | |
| 2579 | strcpy(filename, "ltt-facility-loader-"); |
| 2580 | filename_size = strlen(filename); |
| 2581 | |
| 2582 | strncat(filename, fac->name, PATH_MAX - filename_size); |
| 2583 | filename_size = strlen(filename); |
| 2584 | |
| 2585 | if(fac->arch) { |
| 2586 | strncat(filename, "_", PATH_MAX - filename_size); |
| 2587 | filename_size = strlen(filename); |
| 2588 | |
| 2589 | strncat(filename, fac->arch, PATH_MAX - filename_size); |
| 2590 | filename_size = strlen(filename); |
| 2591 | } |
| 2592 | |
| 2593 | strncat(filename, ".h", PATH_MAX - filename_size); |
| 2594 | filename_size = strlen(filename); |
| 2595 | |
| 2596 | |
| 2597 | fd = fopen(filename, "w"); |
| 2598 | if(fd == NULL) { |
| 2599 | printf("Error opening file %s for writing : %s\n", |
| 2600 | filename, strerror(errno)); |
| 2601 | return errno; |
| 2602 | } |
| 2603 | |
| 2604 | fprintf(fd, "#ifndef _LTT_FACILITY_LOADER_%s_H_\n", fac->capname); |
| 2605 | fprintf(fd, "#define _LTT_FACILITY_LOADER_%s_H_\n\n", fac->capname); |
| 2606 | fprintf(fd,"#include <ltt/ltt-usertrace.h>\n"); |
| 2607 | if(!fac->arch) |
| 2608 | fprintf(fd,"#include <ltt/ltt-facility-id-%s.h>\n\n", |
| 2609 | fac->name); |
| 2610 | else |
| 2611 | fprintf(fd,"#include <ltt/ltt-facility-id-%s_%s.h>\n\n", |
| 2612 | fac->name, |
| 2613 | fac->arch); |
| 2614 | fprintf(fd,"ltt_facility_t\tltt_facility_%s;\n", fac->name); |
| 2615 | fprintf(fd,"ltt_facility_t\tltt_facility_%s_%X;\n\n", |
| 2616 | fac->name, fac->checksum); |
| 2617 | |
| 2618 | fprintf(fd,"#define LTT_FACILITY_SYMBOL\t\t\t\t\t\t\tltt_facility_%s\n", |
| 2619 | fac->name); |
| 2620 | fprintf(fd,"#define LTT_FACILITY_CHECKSUM_SYMBOL\t\tltt_facility_%s_%X\n", |
| 2621 | fac->name, fac->checksum); |
| 2622 | fprintf(fd,"#define LTT_FACILITY_CHECKSUM\t\t\t\t\t\t0x%X\n", fac->checksum); |
| 2623 | fprintf(fd,"#define LTT_FACILITY_NAME\t\t\t\t\t\t\t\t\"%s\"\n", fac->name); |
| 2624 | fprintf(fd,"#define LTT_FACILITY_NUM_EVENTS\t\t\t\t\tfacility_%s_num_events\n\n", |
| 2625 | fac->name); |
| 2626 | fprintf(fd,"#define LTT_FACILITY_ALIGNMENT\t\t\t\t\t%u\n\n", |
| 2627 | fac->align); |
| 2628 | fprintf(fd, "#endif //_LTT_FACILITY_LOADER_%s_H_\n", fac->capname); |
| 2629 | |
| 2630 | fclose(fd); |
| 2631 | |
| 2632 | return 0; |
| 2633 | } |
| 2634 | |
| 2635 | |
| 2636 | |
| 2637 | /* ltt-facility-loader-name.c : generic facility loader |
| 2638 | * loader_c */ |
| 2639 | int print_loader_c(facility_t *fac) |
| 2640 | { |
| 2641 | char filename[PATH_MAX]; |
| 2642 | unsigned int filename_size = 0; |
| 2643 | FILE *fd; |
| 2644 | dprintf("%s\n", fac->name); |
| 2645 | |
| 2646 | strcpy(filename, "ltt-facility-loader-"); |
| 2647 | filename_size = strlen(filename); |
| 2648 | |
| 2649 | strncat(filename, fac->name, PATH_MAX - filename_size); |
| 2650 | filename_size = strlen(filename); |
| 2651 | |
| 2652 | if(fac->arch) { |
| 2653 | strncat(filename, "_", PATH_MAX - filename_size); |
| 2654 | filename_size = strlen(filename); |
| 2655 | |
| 2656 | strncat(filename, fac->arch, PATH_MAX - filename_size); |
| 2657 | filename_size = strlen(filename); |
| 2658 | } |
| 2659 | |
| 2660 | strncat(filename, ".c", PATH_MAX - filename_size); |
| 2661 | filename_size = strlen(filename); |
| 2662 | |
| 2663 | |
| 2664 | fd = fopen(filename, "w"); |
| 2665 | if(fd == NULL) { |
| 2666 | printf("Error opening file %s for writing : %s\n", |
| 2667 | filename, strerror(errno)); |
| 2668 | return errno; |
| 2669 | } |
| 2670 | |
| 2671 | fprintf(fd, "/*\n"); |
| 2672 | if(!fac->arch) |
| 2673 | fprintf(fd, " * ltt-facility-loader-%s.c\n", fac->name); |
| 2674 | else |
| 2675 | fprintf(fd, " * ltt-facility-loader-%s_%s.c\n", fac->name, fac->arch); |
| 2676 | fprintf(fd, " *\n"); |
| 2677 | fprintf(fd, " * (C) Copyright 2005 - \n"); |
| 2678 | fprintf(fd, " * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)\n"); |
| 2679 | fprintf(fd, " *\n"); |
| 2680 | fprintf(fd, " * Contains the LTT facility loader.\n"); |
| 2681 | fprintf(fd, " *\n"); |
| 2682 | fprintf(fd, " */\n"); |
| 2683 | fprintf(fd, "\n"); |
| 2684 | fprintf(fd, "\n"); |
| 2685 | fprintf(fd, "#include <linux/ltt-facilities.h>\n"); |
| 2686 | fprintf(fd, "#include <linux/module.h>\n"); |
| 2687 | fprintf(fd, "#include <linux/init.h>\n"); |
| 2688 | if(!fac->arch) |
| 2689 | fprintf(fd, "#include \"ltt-facility-loader-%s.h\"\n", fac->name); |
| 2690 | else |
| 2691 | fprintf(fd, "#include \"ltt-facility-loader-%s_%s.h\"\n", |
| 2692 | fac->name, fac->arch); |
| 2693 | fprintf(fd, "\n"); |
| 2694 | fprintf(fd, "\n"); |
| 2695 | fprintf(fd, "#ifdef CONFIG_LTT\n"); |
| 2696 | fprintf(fd, "\n"); |
| 2697 | fprintf(fd, "EXPORT_SYMBOL(LTT_FACILITY_SYMBOL);\n"); |
| 2698 | fprintf(fd, "EXPORT_SYMBOL(LTT_FACILITY_CHECKSUM_SYMBOL);\n"); |
| 2699 | fprintf(fd, "\n"); |
| 2700 | fprintf(fd, "static const char ltt_facility_name[] = LTT_FACILITY_NAME;\n"); |
| 2701 | fprintf(fd, "\n"); |
| 2702 | fprintf(fd, "#define SYMBOL_STRING(sym) #sym\n"); |
| 2703 | fprintf(fd, "\n"); |
| 2704 | fprintf(fd, "static struct ltt_facility facility = {\n"); |
| 2705 | fprintf(fd, "\t.name = ltt_facility_name,\n"); |
| 2706 | fprintf(fd, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n"); |
| 2707 | fprintf(fd, "\t.checksum = LTT_FACILITY_CHECKSUM,\n"); |
| 2708 | fprintf(fd, "\t.symbol = SYMBOL_STRING(LTT_FACILITY_SYMBOL),\n"); |
| 2709 | fprintf(fd, "\t.alignment = LTT_FACILITY_ALIGNMENT,\n"); |
| 2710 | fprintf(fd, "\t.select = LTT_FACILITY_SELECT,\n"); |
| 2711 | fprintf(fd, "};\n"); |
| 2712 | fprintf(fd, "\n"); |
| 2713 | fprintf(fd, "static int __init facility_init(void)\n"); |
| 2714 | fprintf(fd, "{\n"); |
| 2715 | fprintf(fd, "\tprintk(KERN_INFO \"LTT : ltt-facility-%s init in kernel\\n\");\n", fac->name); |
| 2716 | fprintf(fd, "\n"); |
| 2717 | fprintf(fd, "\tLTT_FACILITY_SYMBOL = ltt_facility_kernel_register(&facility);\n"); |
| 2718 | fprintf(fd, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n"); |
| 2719 | fprintf(fd, "\t\n"); |
| 2720 | fprintf(fd, "\treturn LTT_FACILITY_SYMBOL;\n"); |
| 2721 | fprintf(fd, "}\n"); |
| 2722 | fprintf(fd, "\n"); |
| 2723 | fprintf(fd, "#ifndef MODULE\n"); |
| 2724 | fprintf(fd, "__initcall(facility_init);\n"); |
| 2725 | fprintf(fd, "#else\n"); |
| 2726 | fprintf(fd, "module_init(facility_init);\n"); |
| 2727 | fprintf(fd, "static void __exit facility_exit(void)\n"); |
| 2728 | fprintf(fd, "{\n"); |
| 2729 | fprintf(fd, "\tint err;\n"); |
| 2730 | fprintf(fd, "\n"); |
| 2731 | fprintf(fd, "\terr = ltt_facility_unregister(LTT_FACILITY_SYMBOL);\n"); |
| 2732 | fprintf(fd, "\tif (err != 0)\n"); |
| 2733 | fprintf(fd, "\t\tprintk(KERN_ERR \"LTT : Error in unregistering facility.\\n\");\n"); |
| 2734 | fprintf(fd, "\n"); |
| 2735 | fprintf(fd, "}\n"); |
| 2736 | fprintf(fd, "module_exit(facility_exit)\n"); |
| 2737 | fprintf(fd, "\n"); |
| 2738 | fprintf(fd, "MODULE_LICENSE(\"GPL\");\n"); |
| 2739 | fprintf(fd, "MODULE_AUTHOR(\"Mathieu Desnoyers\");\n"); |
| 2740 | fprintf(fd, "MODULE_DESCRIPTION(\"Linux Trace Toolkit Facility\");\n"); |
| 2741 | fprintf(fd, "\n"); |
| 2742 | fprintf(fd, "#endif //MODULE\n"); |
| 2743 | fprintf(fd, "\n"); |
| 2744 | fprintf(fd, "#endif //CONFIG_LTT\n"); |
| 2745 | |
| 2746 | fclose(fd); |
| 2747 | |
| 2748 | return 0; |
| 2749 | } |
| 2750 | |
| 2751 | int print_loader_c_user(facility_t *fac) |
| 2752 | { |
| 2753 | char filename[PATH_MAX]; |
| 2754 | unsigned int filename_size = 0; |
| 2755 | FILE *fd; |
| 2756 | dprintf("%s\n", fac->name); |
| 2757 | |
| 2758 | strcpy(filename, "ltt-facility-loader-"); |
| 2759 | filename_size = strlen(filename); |
| 2760 | |
| 2761 | strncat(filename, fac->name, PATH_MAX - filename_size); |
| 2762 | filename_size = strlen(filename); |
| 2763 | |
| 2764 | if(fac->arch) { |
| 2765 | strncat(filename, "_", PATH_MAX - filename_size); |
| 2766 | filename_size = strlen(filename); |
| 2767 | |
| 2768 | strncat(filename, fac->arch, PATH_MAX - filename_size); |
| 2769 | filename_size = strlen(filename); |
| 2770 | } |
| 2771 | |
| 2772 | strncat(filename, ".c", PATH_MAX - filename_size); |
| 2773 | filename_size = strlen(filename); |
| 2774 | |
| 2775 | |
| 2776 | fd = fopen(filename, "w"); |
| 2777 | if(fd == NULL) { |
| 2778 | printf("Error opening file %s for writing : %s\n", |
| 2779 | filename, strerror(errno)); |
| 2780 | return errno; |
| 2781 | } |
| 2782 | |
| 2783 | fprintf(fd, "/*\n"); |
| 2784 | if(!fac->arch) |
| 2785 | fprintf(fd, " * ltt-facility-loader-%s.c\n", fac->name); |
| 2786 | else |
| 2787 | fprintf(fd, " * ltt-facility-loader-%s_%s.c\n", fac->name, fac->arch); |
| 2788 | fprintf(fd, " *\n"); |
| 2789 | fprintf(fd, " * (C) Copyright 2005 - \n"); |
| 2790 | fprintf(fd, " * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)\n"); |
| 2791 | fprintf(fd, " *\n"); |
| 2792 | fprintf(fd, " * Contains the LTT user space facility loader.\n"); |
| 2793 | fprintf(fd, " *\n"); |
| 2794 | fprintf(fd, " */\n"); |
| 2795 | fprintf(fd, "\n"); |
| 2796 | fprintf(fd, "\n"); |
| 2797 | fprintf(fd, "#define LTT_TRACE\n"); |
| 2798 | fprintf(fd, "#include <error.h>\n"); |
| 2799 | fprintf(fd, "#include <stdio.h>\n"); |
| 2800 | fprintf(fd, "#include <ltt/ltt-usertrace.h>\n"); |
| 2801 | if(!fac->arch) |
| 2802 | fprintf(fd, "#include \"ltt-facility-loader-%s.h\"\n", fac->name); |
| 2803 | else |
| 2804 | fprintf(fd, "#include \"ltt-facility-loader-%s_%s.h\"\n", |
| 2805 | fac->name, fac->arch); |
| 2806 | fprintf(fd, "\n"); |
| 2807 | fprintf(fd, "static struct user_facility_info facility = {\n"); |
| 2808 | fprintf(fd, "\t.name = LTT_FACILITY_NAME,\n"); |
| 2809 | fprintf(fd, "\t.num_events = LTT_FACILITY_NUM_EVENTS,\n"); |
| 2810 | fprintf(fd, "#ifndef LTT_PACK\n"); |
| 2811 | fprintf(fd, "\t.alignment = LTT_FACILITY_ALIGNMENT?sizeof(void*):0,\n"); |
| 2812 | fprintf(fd, "#else\n"); |
| 2813 | fprintf(fd, "\t.alignment = 0,\n"); |
| 2814 | fprintf(fd, "#endif //LTT_PACK\n"); |
| 2815 | fprintf(fd, "\t.checksum = LTT_FACILITY_CHECKSUM,\n"); |
| 2816 | fprintf(fd, "\t.int_size = sizeof(int),\n"); |
| 2817 | fprintf(fd, "\t.long_size = sizeof(long),\n"); |
| 2818 | fprintf(fd, "\t.pointer_size = sizeof(void*),\n"); |
| 2819 | fprintf(fd, "\t.size_t_size = sizeof(size_t)\n"); |
| 2820 | fprintf(fd, "};\n"); |
| 2821 | fprintf(fd, "\n"); |
| 2822 | fprintf(fd, "static void __attribute__((constructor)) __ltt_user_init(void)\n"); |
| 2823 | fprintf(fd, "{\n"); |
| 2824 | fprintf(fd, "\tint err;\n"); |
| 2825 | fprintf(fd, "#ifdef LTT_SHOW_DEBUG\n"); |
| 2826 | fprintf(fd, "\tprintf(\"LTT : ltt-facility-%s init in userspace\\n\");\n", fac->name); |
| 2827 | fprintf(fd, "#endif //LTT_SHOW_DEBUG\n"); |
| 2828 | fprintf(fd, "\n"); |
| 2829 | fprintf(fd, "\terr = ltt_register_generic(<T_FACILITY_SYMBOL, &facility);\n"); |
| 2830 | fprintf(fd, "\tLTT_FACILITY_CHECKSUM_SYMBOL = LTT_FACILITY_SYMBOL;\n"); |
| 2831 | fprintf(fd, "\t\n"); |
| 2832 | fprintf(fd, "\tif (err) {\n"); |
| 2833 | fprintf(fd, "#ifdef LTT_SHOW_DEBUG\n"); |
| 2834 | fprintf(fd, "\t\tperror(\"Error in ltt_register_generic\");\n"); |
| 2835 | fprintf(fd, "#endif //LTT_SHOW_DEBUG\n"); |
| 2836 | fprintf(fd, "\t}\n"); |
| 2837 | fprintf(fd, "}\n"); |
| 2838 | fprintf(fd, "\n"); |
| 2839 | |
| 2840 | fclose(fd); |
| 2841 | |
| 2842 | return 0; |
| 2843 | } |
| 2844 | |
| 2845 | |
| 2846 | |
| 2847 | /* open facility */ |
| 2848 | /* code taken from ltt_facility_open in ltt/facility.c in lttv */ |
| 2849 | |
| 2850 | /***************************************************************************** |
| 2851 | *Function name |
| 2852 | * ltt_facility_open : open facilities |
| 2853 | *Input params |
| 2854 | * pathname : the path name of the facility |
| 2855 | * |
| 2856 | * Open the facility corresponding to the right checksum. |
| 2857 | * |
| 2858 | *returns the facility on success, NULL on error. |
| 2859 | ****************************************************************************/ |
| 2860 | facility_t *ltt_facility_open(char * pathname) |
| 2861 | { |
| 2862 | int ret = 0; |
| 2863 | char *token; |
| 2864 | parse_file_t in; |
| 2865 | facility_t * fac = NULL; |
| 2866 | char buffer[BUFFER_SIZE]; |
| 2867 | int generated = FALSE; |
| 2868 | |
| 2869 | in.buffer = &(buffer[0]); |
| 2870 | in.lineno = 0; |
| 2871 | in.error = error_callback; |
| 2872 | in.name = pathname; |
| 2873 | in.unget = 0; |
| 2874 | |
| 2875 | in.fp = fopen(in.name, "r"); |
| 2876 | if(in.fp == NULL) { |
| 2877 | ret = 1; |
| 2878 | goto open_error; |
| 2879 | } |
| 2880 | |
| 2881 | while(1){ |
| 2882 | token = getToken(&in); |
| 2883 | if(in.type == ENDFILE) break; |
| 2884 | |
| 2885 | if(generated) { |
| 2886 | printf("More than one facility in the file. Only using the first one.\n"); |
| 2887 | break; |
| 2888 | } |
| 2889 | |
| 2890 | if(strcmp(token, "<")) in.error(&in,"not a facility file"); |
| 2891 | token = getName(&in); |
| 2892 | if(strcmp(token, "?")) in.error(&in,"not a facility file"); |
| 2893 | token = getName(&in); |
| 2894 | if(strcmp(token, "xml")) in.error(&in,"not a facility file"); |
| 2895 | token = getName(&in); |
| 2896 | if(strcmp(token, "version")) in.error(&in,"not a facility file"); |
| 2897 | token = getName(&in); |
| 2898 | if(strcmp(token, "=")) in.error(&in,"not a facility file"); |
| 2899 | token = getQuotedString(&in); |
| 2900 | if(strcmp(token, "1.0")) in.error(&in,"not a facility file"); |
| 2901 | token = getName(&in); |
| 2902 | if(strcmp(token, "?")) in.error(&in,"not a facility file"); |
| 2903 | token = getToken(&in); |
| 2904 | if(strcmp(token, ">")) in.error(&in,"not a facility file"); |
| 2905 | |
| 2906 | token = getName(&in); |
| 2907 | if(strcmp(token, "<")) in.error(&in,"not a facility file"); |
| 2908 | token = getName(&in); |
| 2909 | if(strcmp("facility",token) == 0) { |
| 2910 | fac = malloc(sizeof(facility_t)); |
| 2911 | fac->name = NULL; |
| 2912 | fac->description = NULL; |
| 2913 | sequence_init(&(fac->events)); |
| 2914 | table_init(&(fac->named_types)); |
| 2915 | sequence_init(&(fac->unnamed_types)); |
| 2916 | |
| 2917 | parseFacility(&in, fac); |
| 2918 | |
| 2919 | //check if any namedType is not defined |
| 2920 | checkNamedTypesImplemented(&fac->named_types); |
| 2921 | |
| 2922 | generateChecksum(fac->name, &fac->checksum, &fac->events); |
| 2923 | |
| 2924 | generated = TRUE; |
| 2925 | } |
| 2926 | else { |
| 2927 | printf("facility token was expected in file %s\n", in.name); |
| 2928 | ret = 1; |
| 2929 | goto parse_error; |
| 2930 | } |
| 2931 | } |
| 2932 | |
| 2933 | parse_error: |
| 2934 | fclose(in.fp); |
| 2935 | open_error: |
| 2936 | |
| 2937 | if(!generated) { |
| 2938 | printf("Cannot find facility %s\n", pathname); |
| 2939 | fac = NULL; |
| 2940 | } |
| 2941 | |
| 2942 | return fac; |
| 2943 | } |
| 2944 | |
| 2945 | /* Close the facility */ |
| 2946 | void ltt_facility_close(facility_t *fac) |
| 2947 | { |
| 2948 | free(fac->name); |
| 2949 | free(fac->capname); |
| 2950 | free(fac->description); |
| 2951 | freeEvents(&fac->events); |
| 2952 | sequence_dispose(&fac->events); |
| 2953 | freeNamedType(&fac->named_types); |
| 2954 | table_dispose(&fac->named_types); |
| 2955 | freeTypes(&fac->unnamed_types); |
| 2956 | sequence_dispose(&fac->unnamed_types); |
| 2957 | free(fac); |
| 2958 | } |
| 2959 | |
| 2960 | |
| 2961 | /* Show help */ |
| 2962 | void show_help(int argc, char ** argv) |
| 2963 | { |
| 2964 | printf("Genevent help : \n"); |
| 2965 | printf("\n"); |
| 2966 | printf("Use %s name.xml\n", argv[0]); |
| 2967 | printf("to create :\n"); |
| 2968 | printf("ltt-facility-name.h\n"); |
| 2969 | printf("ltt-facility-id-name.h\n"); |
| 2970 | printf("ltt-facility-loader-name.h\n"); |
| 2971 | printf("ltt-facility-loader-name.c\n"); |
| 2972 | printf("In the current directory.\n"); |
| 2973 | printf("\n"); |
| 2974 | } |
| 2975 | |
| 2976 | /* Parse program arguments */ |
| 2977 | /* Return values : |
| 2978 | * 0 : continue program |
| 2979 | * -1 : stop program, return 0 |
| 2980 | * > 0 : stop program, return value as exit. |
| 2981 | */ |
| 2982 | int check_args(int argc, char **argv) |
| 2983 | { |
| 2984 | if(argc < 2) { |
| 2985 | printf("Not enough arguments\n"); |
| 2986 | show_help(argc, argv); |
| 2987 | return EINVAL; |
| 2988 | } |
| 2989 | |
| 2990 | if(strcmp(argv[1], "-h") == 0) { |
| 2991 | show_help(argc, argv); |
| 2992 | return -1; |
| 2993 | } |
| 2994 | |
| 2995 | return 0; |
| 2996 | } |
| 2997 | |
| 2998 | int main(int argc, char **argv) |
| 2999 | { |
| 3000 | int err = 0; |
| 3001 | facility_t *fac; |
| 3002 | |
| 3003 | err = check_args(argc, argv); |
| 3004 | if(err > 0) return err; |
| 3005 | else if(err < 0) return 0; |
| 3006 | |
| 3007 | /* open the facility */ |
| 3008 | fac = ltt_facility_open(argv[1]); |
| 3009 | if(fac == NULL) { |
| 3010 | printf("Error opening file %s for reading : %s\n", |
| 3011 | argv[1], strerror(errno)); |
| 3012 | return errno; |
| 3013 | } |
| 3014 | |
| 3015 | /* generate the output C files */ |
| 3016 | |
| 3017 | |
| 3018 | /* ltt-facility-name.h : main logging header. |
| 3019 | * log_header */ |
| 3020 | err = print_log_header(fac); |
| 3021 | if(err) return err; |
| 3022 | |
| 3023 | /* ltt-facility-id-name.h : facility id. |
| 3024 | * log_id_header */ |
| 3025 | err = print_id_header(fac); |
| 3026 | if(err) return err; |
| 3027 | |
| 3028 | /* ltt-facility-loader-name.h : facility specific loader info. |
| 3029 | * loader_header */ |
| 3030 | if(!fac->user) |
| 3031 | err = print_loader_header(fac); |
| 3032 | else |
| 3033 | err = print_loader_header_user(fac); |
| 3034 | if(err) return err; |
| 3035 | |
| 3036 | /* ltt-facility-loader-name.c : generic faciilty loader |
| 3037 | * loader_c */ |
| 3038 | if(!fac->user) |
| 3039 | err = print_loader_c(fac); |
| 3040 | else |
| 3041 | err = print_loader_c_user(fac); |
| 3042 | if(err) return err; |
| 3043 | |
| 3044 | /* close the facility */ |
| 3045 | ltt_facility_close(fac); |
| 3046 | |
| 3047 | return 0; |
| 3048 | } |
| 3049 | |
| 3050 | |