forked from Imagelibrary/binutils-gdb
libctf: types: access to raw type data
This new API lets users ask for the raw type data associated with a type (either the whole lot including prefixes, or just the suffix if this is not a CTF_K_BIG type), and then they can manipulate it using ctf.h functions or whatever else they like. Doing this does not preclude using libctf querying functions at the same time (just don't change the type! It's const for a reason). New API: +const ctf_type_t *ctf_type_data (ctf_dict_t *, ctf_id_t, int prefix); This function was unimplementable before the DTD changes, because the ctf_type_t and vlen were separated in memory: but now they're always stored in a single buffer, it's reliable and simple, indeed trivial.
This commit is contained in:
@@ -1019,6 +1019,35 @@ ctf_id_t ctf_lookup_by_rawname (ctf_dict_t *fp, int kind, const char *name)
|
||||
ctf_dynhash_lookup (ctf_name_table (fp, kind), name);
|
||||
}
|
||||
|
||||
/* Retrieve raw type data. */
|
||||
|
||||
const ctf_type_t *
|
||||
ctf_type_data (ctf_dict_t *fp, ctf_id_t type, int prefix)
|
||||
{
|
||||
const ctf_type_t *tp, *suffix, *big;
|
||||
|
||||
if (fp->ctf_flags & LCTF_NO_STR)
|
||||
{
|
||||
ctf_set_errno (fp, ECTF_NOPARENT);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((tp = ctf_lookup_by_id (&fp, type, &suffix)) == NULL)
|
||||
return NULL; /* errno is set for us. */
|
||||
|
||||
if (!prefix && ((big = ctf_find_prefix (fp, tp, CTF_K_BIG)) != NULL)
|
||||
&& ((CTF_INFO_VLEN (big->ctt_info) != 0) || (big->ctt_size != 0)))
|
||||
{
|
||||
ctf_set_errno (fp, ECTF_TOOLARGE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (prefix)
|
||||
return tp;
|
||||
else
|
||||
return suffix;
|
||||
}
|
||||
|
||||
/* Lookup the given type ID and return its name as a new dynamically-allocated
|
||||
string. */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user