1 1.1 christos /* Make sure unnamed field offsets are relative to the containing struct. */ 2 1.1 christos 3 1.1 christos #include <ctf-api.h> 4 1.1 christos #include <stddef.h> 5 1.1 christos #include <stdio.h> 6 1.1 christos #include <stdlib.h> 7 1.1 christos 8 1.1 christos #include "unnamed-field-info-ctf.c" 9 1.1 christos 10 1.1 christos static void 11 1.1 christos verify_offsetof_matching (ctf_dict_t *fp, ctf_id_t type, const char *name, size_t offset) 12 1.1 christos { 13 1.1 christos ctf_membinfo_t mi; 14 1.1 christos 15 1.1 christos if (ctf_member_info (fp, type, name, &mi) < 0) 16 1.1 christos goto err; 17 1.1 christos 18 1.1 christos if (mi.ctm_offset != offset * 8) 19 1.1.1.2 christos fprintf (stderr, "field %s inconsistency: offsetof() says %zi bits, CTF says %li\n", 20 1.1 christos name, offset * 8, mi.ctm_offset); 21 1.1 christos 22 1.1 christos return; 23 1.1 christos 24 1.1 christos err: 25 1.1 christos fprintf (stderr, "Cannot look up field %s: %s\n", name, 26 1.1 christos ctf_errmsg (ctf_errno (fp))); 27 1.1 christos return; 28 1.1 christos } 29 1.1 christos 30 1.1 christos int 31 1.1 christos main (int argc, char *argv[]) 32 1.1 christos { 33 1.1 christos ctf_dict_t *fp; 34 1.1 christos ctf_archive_t *ctf; 35 1.1 christos ctf_id_t type; 36 1.1 christos int err; 37 1.1 christos 38 1.1 christos if (argc != 2) 39 1.1 christos { 40 1.1 christos fprintf (stderr, "Syntax: %s PROGRAM\n", argv[0]); 41 1.1 christos exit(1); 42 1.1 christos } 43 1.1 christos 44 1.1 christos if ((ctf = ctf_open (argv[1], NULL, &err)) == NULL) 45 1.1 christos goto open_err; 46 1.1 christos if ((fp = ctf_dict_open (ctf, NULL, &err)) == NULL) 47 1.1 christos goto open_err; 48 1.1 christos 49 1.1 christos /* Dig out some structure members by name. */ 50 1.1 christos 51 1.1 christos if ((type = ctf_lookup_by_name (fp, "struct A") ) == CTF_ERR) 52 1.1 christos goto err; 53 1.1 christos 54 1.1 christos verify_offsetof_matching (fp, type, "a", offsetof (struct A, a)); 55 1.1 christos verify_offsetof_matching (fp, type, "b", offsetof (struct A, b)); 56 1.1 christos verify_offsetof_matching (fp, type, "one", offsetof (struct A, one)); 57 1.1 christos verify_offsetof_matching (fp, type, "two", offsetof (struct A, two)); 58 1.1 christos verify_offsetof_matching (fp, type, "three", offsetof (struct A, three)); 59 1.1 christos verify_offsetof_matching (fp, type, "four", offsetof (struct A, four)); 60 1.1 christos verify_offsetof_matching (fp, type, "x", offsetof (struct A, x)); 61 1.1 christos verify_offsetof_matching (fp, type, "y", offsetof (struct A, y)); 62 1.1 christos verify_offsetof_matching (fp, type, "z", offsetof (struct A, z)); 63 1.1 christos verify_offsetof_matching (fp, type, "aleph", offsetof (struct A, aleph)); 64 1.1 christos 65 1.1 christos ctf_dict_close (fp); 66 1.1 christos ctf_arc_close (ctf); 67 1.1 christos 68 1.1 christos printf ("Offset validation complete.\n"); 69 1.1 christos 70 1.1 christos return 0; 71 1.1 christos 72 1.1 christos open_err: 73 1.1 christos fprintf (stderr, "%s: cannot open: %s\n", argv[0], ctf_errmsg (err)); 74 1.1 christos return 1; 75 1.1 christos 76 1.1 christos err: 77 1.1 christos fprintf (stderr, "Cannot look up type: %s\n", ctf_errmsg (ctf_errno (fp))); 78 1.1 christos return 1; 79 1.1 christos } 80