#include #include #include typedef struct ctf_stype { uint32_t ctt_name; /* reference to name in string table */ uint16_t ctt_info; /* encoded kind, variant length (see below) */ union { uint16_t _size; /* size of entire type in bytes */ uint16_t _type; /* reference to another type */ } _u; } ctf_stype_t; /* * type sizes, measured in bytes, come in two flavors. 99% of them fit within * (USHRT_MAX - 1), and thus can be stored in the ctt_size member of a * ctf_stype_t. The maximum value for these sizes is CTF_MAX_SIZE. The sizes * larger than CTF_MAX_SIZE must be stored in the ctt_lsize member of a * ctf_type_t. Use of this member is indicated by the presence of * CTF_LSIZE_SENT in ctt_size. */ typedef struct ctf_type { uint32_t ctt_name; /* reference to name in string table */ uint16_t ctt_info; /* encoded kind, variant length (see below) */ union { uint16_t _size; /* always CTF_LSIZE_SENT */ uint16_t _type; /* do not use */ } _u; uint32_t ctt_lsizehi; /* high 32 bits of type size in bytes */ uint32_t ctt_lsizelo; /* low 32 bits of type size in bytes */ } ctf_type_t; #define ctt_size _u._size /* for fundamental types that have a size */ #define ctt_type _u._type /* for types that reference another type */ typedef struct ctf_array { uint16_t cta_contents; /* reference to type of array contents */ uint16_t cta_index; /* reference to type of array index */ uint32_t cta_nelems; /* number of elements */ } ctf_array_t; typedef struct ctf_member { uint32_t ctm_name; /* reference to name in string table */ uint16_t ctm_type; /* reference to type of member */ uint16_t ctm_offset; /* offset of this member in bits */ } ctf_member_t; typedef struct ctf_lmember { uint32_t ctlm_name; /* reference to name in string table */ uint16_t ctlm_type; /* reference to type of member */ uint16_t ctlm_pad; /* padding */ uint32_t ctlm_offsethi; /* high 32 bits of member offset in bits */ uint32_t ctlm_offsetlo; /* low 32 bits of member offset in bits */ } ctf_lmember_t; typedef struct ctf_enum { uint32_t cte_name; /* reference to name in string table */ int cte_value; /* value associated with this name */ } ctf_enum_t; char tmp[offsetof(ctf_type_t, ctt_info)]; uint32_t ctf_enum_desc[] = { sizeof(ctf_enum_t), offsetof(ctf_enum_t, cte_name), offsetof(ctf_enum_t, cte_value) }; int main(int argc, const char *argv[]) { union { ctf_type_t t; ctf_stype_t st; ctf_array_t a; ctf_lmember_t lm; ctf_member_t m; ctf_enum_t e; } _u; printf("ctf_stype_t:%d:%d:%d:%d\n", sizeof(ctf_stype_t), offsetof(ctf_stype_t, ctt_name), offsetof(ctf_stype_t, ctt_info), offsetof(ctf_stype_t, ctt_size)); printf("ctf_type_t:%d:%d:%d:%d:%d:%d\n", sizeof(ctf_type_t), offsetof(ctf_type_t, ctt_name), offsetof(ctf_type_t, ctt_info), offsetof(ctf_type_t, ctt_size), offsetof(ctf_type_t, ctt_lsizehi), offsetof(ctf_type_t, ctt_lsizelo)); printf("ctf_array_t:%d:%d:%d:%d\n", sizeof(ctf_array_t), offsetof(ctf_array_t, cta_contents), offsetof(ctf_array_t, cta_index), offsetof(ctf_array_t, cta_nelems)); printf("ctf_member_t:%d:%d:%d:%d\n", sizeof(ctf_member_t), offsetof(ctf_member_t, ctm_name), offsetof(ctf_member_t, ctm_type), offsetof(ctf_member_t, ctm_offset)); printf("ctf_lmember_t:%d:%d:%d:%d:%d\n", sizeof(ctf_lmember_t), offsetof(ctf_lmember_t, ctlm_name), offsetof(ctf_lmember_t, ctlm_type), offsetof(ctf_lmember_t, ctlm_offsethi), offsetof(ctf_lmember_t, ctlm_offsetlo)); printf("ctf_enum_t:%d:%d:%d\n", sizeof(ctf_enum_t), offsetof(ctf_enum_t, cte_name), offsetof(ctf_enum_t, cte_value)); return 0; }