libctf: simplify ctf_txlate

Before now, this critical internal structure was an array mapping from a
type ID to the type index of the type with that ID.  This was critical for
the old world in which ctf_update() reserialized the entire dict, so things
moved around in memory all the time: but these days, a ctf_type_t * never
moves after creation, so we can just make ctf_txlate an array of ctf_type_t *
and be done with it.

This lets us point type indexes anywhere in memory, not just to entries
in the ctf_buf, which means we can have synthetic ones for various purposes.
And we will.
This commit is contained in:
Nick Alcock
2025-04-03 15:21:47 +01:00
parent 1d70873382
commit a80b903b45
2 changed files with 5 additions and 6 deletions

View File

@@ -402,7 +402,7 @@ struct ctf_dict
uint32_t *ctf_sxlate; /* Translation table for unindexed symtypetab
entries. */
unsigned long ctf_nsyms; /* Number of entries in symtab xlate table. */
uint32_t *ctf_txlate; /* Translation table for type IDs. */
ctf_type_t **ctf_txlate; /* Translation table for type IDs. */
uint32_t *ctf_ptrtab; /* Translation table for pointer-to lookups. */
size_t ctf_ptrtab_len; /* Num types storable in ptrtab currently. */
uint32_t *ctf_pptrtab; /* Parent types pointed to by child dicts. */
@@ -592,8 +592,8 @@ extern ctf_id_t ctf_index_to_type (const ctf_dict_t *, uint32_t);
#define LCTF_INDEX_TO_TYPEPTR(fp, i) \
((i > fp->ctf_stypes) ? \
&(ctf_dtd_lookup (fp, ctf_index_to_type (fp, i))->dtd_data) : \
(ctf_type_t *)((uintptr_t)(fp)->ctf_buf + (fp)->ctf_txlate[(i)]))
ctf_dtd_lookup (fp, ctf_index_to_type (fp, i))->dtd_data : \
(fp)->ctf_txlate[(i)])
/* The non *INFO variants of these macros acquire the relevant info from the
suffixed type, if the type is prefixed. (Internally to libctf, all types