aboutsummaryrefslogtreecommitdiff
path: root/libctf/ctf-impl.h
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2021-03-18 12:37:52 +0000
committerNick Alcock <nick.alcock@oracle.com>2021-03-18 12:40:36 +0000
commit7879dd88efdabc5a2e93b71f488f09303117a0a9 (patch)
treea120f390349fe8cd5e8cdbe74e3f54fc625b737b /libctf/ctf-impl.h
parenteefe721eadf78a5f68c38ea9ca0272c7be06e0c0 (diff)
downloadgdb-7879dd88efdabc5a2e93b71f488f09303117a0a9.zip
gdb-7879dd88efdabc5a2e93b71f488f09303117a0a9.tar.gz
gdb-7879dd88efdabc5a2e93b71f488f09303117a0a9.tar.bz2
libctf: eliminate dtd_u, part 1: int/float/slice
This series eliminates a lot of special-case code to handle dynamic types (types added to writable dicts and not yet serialized). Historically, when such types have variable-length data in their final CTF representations, libctf has always worked by adding such types to a special union (ctf_dtdef_t.dtd_u) in the dynamic type definition structure, then picking the members out of this structure at serialization time and packing them into their final form. This has the advantage that the ctf_add_* code doesn't need to know anything about the final CTF representation, but the significant disadvantage that all code that looks up types in any way needs two code paths, one for dynamic types, one for all others. Historically libctf "handled" this by not supporting most type lookups on dynamic types at all until ctf_update was called to do a complete reserialization of the entire dict (it didn't emit an error, it just emitted wrong results). Since commit 676c3ecbad6e9c4, which eliminated ctf_update in favour of the internal-only ctf_serialize function, all the type-lookup paths grew an extra branch to handle dynamic types. We can eliminate this branch again by dropping the dtd_u stuff and simply writing out the vlen in (close to) its final form at ctf_add_* time: type lookup for types using this approach is then identical for types in writable dicts and types that are in read-only ones, and serialization is also simplified (we just need to write out the vlen we already created). The only complexity lies in type kinds for which multiple vlen representations are valid depending on properties of the type, e.g. structures. But we can start simple, adjusting ints, floats, and slices to work this way, and leaving everything else as is. libctf/ChangeLog 2021-03-18 Nick Alcock <nick.alcock@oracle.com> * ctf-impl.h (ctf_dtdef_t) <dtd_u.dtu_enc>: Remove. <dtd_u.dtu_slice>: Likewise. <dtd_vlen>: New. * ctf-create.c (ctf_add_generic): Perhaps allocate it. All callers adjusted. (ctf_dtd_delete): Free it. (ctf_add_slice): Use the dtd_vlen, not dtu_enc. (ctf_add_encoded): Likewise. Assert that this must be an int or float. * ctf-serialize.c (ctf_emit_type_sect): Just copy the dtd_vlen. * ctf-dedup.c (ctf_dedup_rhash_type): Use the dtd_vlen, not dtu_slice. * ctf-types.c (ctf_type_reference): Likewise. (ctf_type_encoding): Remove most dynamic-type-specific code: just get the vlen from the right place. Report failure to look up the underlying type's encoding.
Diffstat (limited to 'libctf/ctf-impl.h')
-rw-r--r--libctf/ctf-impl.h3
1 files changed, 1 insertions, 2 deletions
diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h
index 5567b4c..742b4b3 100644
--- a/libctf/ctf-impl.h
+++ b/libctf/ctf-impl.h
@@ -192,13 +192,12 @@ typedef struct ctf_dtdef
ctf_list_t dtd_list; /* List forward/back pointers. */
ctf_id_t dtd_type; /* Type identifier for this definition. */
ctf_type_t dtd_data; /* Type node, including name. */
+ unsigned char *dtd_vlen; /* Variable-length data for this type. */
union
{
ctf_list_t dtu_members; /* struct, union, or enum */
ctf_arinfo_t dtu_arr; /* array */
- ctf_encoding_t dtu_enc; /* integer or float */
uint32_t *dtu_argv; /* function */
- ctf_slice_t dtu_slice; /* slice */
} dtd_u;
} ctf_dtdef_t;