From: Nick Alcock Date: Thu, 24 Apr 2025 13:17:19 +0000 (+0100) Subject: libctf: ctf-lookup: support prefixes in ctf_lookup_by_id X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2ef95540239a6687ef032839c936cf1a49454b98;p=thirdparty%2Fbinutils-gdb.git libctf: ctf-lookup: support prefixes in ctf_lookup_by_id ctf_lookup_by_id now has a new optional suffix argument, which, if set, returns the suffix of a prefixed type: the ctf_type_t it returns remains (as ever) the first one in the type (i.e. it may be a prefix type). This is most convenient because the prefix is the ctf_type_t that LCTF_KIND and other LCTF functions taking ctf_type_t's expect. Callers not yet adjusted. --- diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h index 9833f6c3377..456d9d75967 100644 --- a/libctf/ctf-impl.h +++ b/libctf/ctf-impl.h @@ -622,8 +622,9 @@ extern ctf_id_t ctf_index_to_type (const ctf_dict_t *, uint32_t); #define LCTF_PRESERIALIZED 0x0020 /* Already serialized all but the strtab. */ extern ctf_dynhash_t *ctf_name_table (ctf_dict_t *, int); -extern const ctf_type_t *ctf_lookup_by_id (ctf_dict_t **, ctf_id_t); extern ctf_id_t ctf_lookup_variable_here (ctf_dict_t *fp, const char *name); +extern const ctf_type_t *ctf_lookup_by_id (ctf_dict_t **, ctf_id_t, + const ctf_type_t **suffix); extern ctf_id_t ctf_lookup_by_sym_or_name (ctf_dict_t *, unsigned long symidx, const char *symname, int try_parent, int is_function); diff --git a/libctf/ctf-lookup.c b/libctf/ctf-lookup.c index da3e949962e..ac874fca200 100644 --- a/libctf/ctf-lookup.c +++ b/libctf/ctf-lookup.c @@ -371,12 +371,16 @@ ctf_lookup_by_name (ctf_dict_t *fp, const char *name) return ctf_lookup_by_name_internal (fp, NULL, name); } -/* Return the pointer to the internal CTF type data corresponding to the - given type ID. If the ID is invalid, the function returns NULL. +/* Return the pointer to the internal CTF type data corresponding to the given + type ID. If the ID is invalid, the function returns NULL. The type data + returned is the prefix, if this is a a prefixed kind: if SUFFIX is set, also + provide the suffix. If there is no prefix, the SUFFIX is the same as the + return value. (See ctf-open.c's dictops for why.) + This function is not exported outside of the library. */ const ctf_type_t * -ctf_lookup_by_id (ctf_dict_t **fpp, ctf_id_t type) +ctf_lookup_by_id (ctf_dict_t **fpp, ctf_id_t type, const ctf_type_t **suffix) { ctf_dict_t *fp = *fpp; ctf_id_t idx; @@ -388,14 +392,38 @@ ctf_lookup_by_id (ctf_dict_t **fpp, ctf_id_t type) } idx = ctf_type_to_index (fp, type); - if (idx > 0 && (unsigned long) idx <= fp->ctf_typemax) + if ((unsigned long) idx > fp->ctf_typemax) { - *fpp = fp; /* Possibly the parent CTF dict. */ - return (LCTF_INDEX_TO_TYPEPTR (fp, idx)); + ctf_set_errno (*fpp, ECTF_BADID); + return NULL; } - (void) ctf_set_errno (*fpp, ECTF_BADID); - return NULL; + *fpp = fp; /* Possibly the parent CTF dict. */ + if (idx > fp->ctf_stypes) + { + ctf_dtdef_t *dtd; + + dtd = ctf_dtd_lookup (fp, ctf_index_to_type (fp, idx)); + if (suffix) + *suffix = dtd->dtd_data; + return dtd->dtd_buf; + } + else + { + ctf_type_t *tp = fp->ctf_txlate[idx]; + + if (suffix) + { + ctf_type_t *suff; + + suff = tp; + while (LCTF_IS_PREFIXED_INFO (suff->ctt_info)) + suff++; + + *suffix = suff; + } + return tp; + } } typedef struct ctf_lookup_idx_key