libctf: create: structure and union member addition

There is one API addition here:

int ctf_add_member_bitfield (ctf_dict_t *, ctf_id_t souid,
                             const char *, ctf_id_t type,
                             unsigned long bit_offset,
                             int bit_width);

SoU addition handles the representational changes for bitfields and for
CTF_K_BIG structs (i.e. all structs you can add members to), errors out if
you add bitfields to structs that aren't created with the
CTF_ADD_STRUCT_BITFIELDS flag, and arranges to add padding as needed if
there is too much of a gap for the offsets to encode in one hop (that
part is still untested).
This commit is contained in:
Nick Alcock
2025-04-24 16:47:14 +01:00
parent cd8ea31666
commit 20e6f72dc7
5 changed files with 223 additions and 88 deletions

View File

@@ -871,7 +871,9 @@ extern int ctf_add_enumerator (ctf_dict_t *, ctf_id_t, const char *, int);
/* Add a member to a struct or union, either at the next available offset (with
suitable padding for the alignment) or at a specific offset, and possibly
with a specific encoding (creating a slice for you). Offsets need not be
unique, and need not be added in ascending order. */
unique, and need not be added in ascending order. ctf_add_member_bitfield
with a nonzero bit_width will fail unless the struct was created with
CTF_ADD_STRUCT_BITFIELDS. */
extern int ctf_add_member (ctf_dict_t *, ctf_id_t, const char *, ctf_id_t);
extern int ctf_add_member_offset (ctf_dict_t *, ctf_id_t, const char *,
@@ -879,6 +881,10 @@ extern int ctf_add_member_offset (ctf_dict_t *, ctf_id_t, const char *,
extern int ctf_add_member_encoded (ctf_dict_t *, ctf_id_t, const char *,
ctf_id_t, unsigned long,
const ctf_encoding_t);
extern int ctf_add_member_bitfield (ctf_dict_t *, ctf_id_t souid,
const char *, ctf_id_t type,
unsigned long bit_offset,
int bit_width);
extern int ctf_add_variable (ctf_dict_t *, const char *, ctf_id_t);