From: Nick Alcock Date: Fri, 25 Apr 2025 10:38:11 +0000 (+0100) Subject: libctf: create, types: arrays X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0cd5118024fa7847c6c37327e92df88ffc3b99aa;p=thirdparty%2Fbinutils-gdb.git libctf: create, types: arrays The same internal API changes for arrays. There is one ABI change here, to ctf_arinfo_t: - uint32_t ctr_nelems; /* Number of elements. */ + size_t ctr_nelems; /* Number of elements. */ --- diff --git a/include/ctf-api.h b/include/ctf-api.h index dd159c3836c..770196f3ced 100644 --- a/include/ctf-api.h +++ b/include/ctf-api.h @@ -161,7 +161,7 @@ typedef struct ctf_arinfo { ctf_id_t ctr_contents; /* Type of array contents. */ ctf_id_t ctr_index; /* Type of array index. */ - uint32_t ctr_nelems; /* Number of elements. */ + size_t ctr_nelems; /* Number of elements. */ } ctf_arinfo_t; typedef struct ctf_funcinfo diff --git a/libctf/ctf-create.c b/libctf/ctf-create.c index f2b98b8ddb9..d08109083d7 100644 --- a/libctf/ctf-create.c +++ b/libctf/ctf-create.c @@ -865,19 +865,18 @@ ctf_id_t ctf_add_array (ctf_dict_t *fp, uint32_t flag, const ctf_arinfo_t *arp) { ctf_dtdef_t *dtd; - ctf_array_t cta; - ctf_id_t type; + ctf_array_t *cta; ctf_dict_t *tmp = fp; if (arp == NULL) return (ctf_set_typed_errno (fp, EINVAL)); if (arp->ctr_contents != 0 - && ctf_lookup_by_id (&tmp, arp->ctr_contents) == NULL) + && ctf_lookup_by_id (&tmp, arp->ctr_contents, NULL) == NULL) return CTF_ERR; /* errno is set for us. */ tmp = fp; - if (ctf_lookup_by_id (&tmp, arp->ctr_index) == NULL) + if (ctf_lookup_by_id (&tmp, arp->ctr_index, NULL) == NULL) return CTF_ERR; /* errno is set for us. */ if (ctf_type_kind (fp, arp->ctr_index) == CTF_K_FORWARD) @@ -888,38 +887,41 @@ ctf_add_array (ctf_dict_t *fp, uint32_t flag, const ctf_arinfo_t *arp) return (ctf_set_typed_errno (fp, ECTF_INCOMPLETE)); } - if ((type = ctf_add_generic (fp, flag, NULL, CTF_K_ARRAY, - sizeof (ctf_array_t), &dtd)) == CTF_ERR) + if ((dtd = ctf_add_generic (fp, flag, NULL, CTF_K_ARRAY, 0, + sizeof (ctf_array_t), 0, NULL)) == NULL) return CTF_ERR; /* errno is set for us. */ - memset (&cta, 0, sizeof (ctf_array_t)); - - dtd->dtd_data.ctt_info = CTF_TYPE_INFO (CTF_K_ARRAY, flag, 0); - dtd->dtd_data.ctt_size = 0; - cta.cta_contents = (uint32_t) arp->ctr_contents; - cta.cta_index = (uint32_t) arp->ctr_index; - cta.cta_nelems = arp->ctr_nelems; - memcpy (dtd->dtd_vlen, &cta, sizeof (ctf_array_t)); + cta = (ctf_array_t *) dtd->dtd_vlen; + dtd->dtd_data->ctt_info = CTF_TYPE_INFO (CTF_K_ARRAY, 0, 0); + dtd->dtd_data->ctt_size = 0; + cta->cta_contents = (uint32_t) arp->ctr_contents; + cta->cta_index = (uint32_t) arp->ctr_index; + cta->cta_nelems = arp->ctr_nelems; - return type; + return dtd->dtd_type; } int ctf_set_array (ctf_dict_t *fp, ctf_id_t type, const ctf_arinfo_t *arp) { ctf_dict_t *ofp = fp; - ctf_dtdef_t *dtd = ctf_dtd_lookup (fp, type); + ctf_dtdef_t *dtd; ctf_array_t *vlen; + uint32_t idx; - fp = ctf_get_dict (fp, type); + if (ctf_lookup_by_id (&fp, type, NULL) == NULL) + return -1; /* errno is set for us. */ + + idx = ctf_type_to_index (fp, type); + dtd = ctf_dtd_lookup (fp, type); /* You can only call ctf_set_array on a type you have added, not a - type that was read in via ctf_open(). */ - if (type < fp->ctf_stypes) + type that was read in via ctf_open. */ + if (idx < fp->ctf_stypes) return (ctf_set_errno (ofp, ECTF_RDONLY)); if (dtd == NULL - || LCTF_INFO_KIND (fp, dtd->dtd_data.ctt_info) != CTF_K_ARRAY) + || LCTF_KIND (fp, dtd->dtd_buf) != CTF_K_ARRAY) return (ctf_set_errno (ofp, ECTF_BADID)); vlen = (ctf_array_t *) dtd->dtd_vlen; diff --git a/libctf/ctf-types.c b/libctf/ctf-types.c index 2ee073e37a6..7423d0d9d2f 100644 --- a/libctf/ctf-types.c +++ b/libctf/ctf-types.c @@ -2195,23 +2195,18 @@ ctf_array_info (ctf_dict_t *fp, ctf_id_t type, ctf_arinfo_t *arp) { ctf_dict_t *ofp = fp; const ctf_type_t *tp; + unsigned char *vlen; const ctf_array_t *ap; - const ctf_dtdef_t *dtd; - ssize_t increment; - if ((tp = ctf_lookup_by_id (&fp, type)) == NULL) + if ((tp = ctf_lookup_by_id (&fp, type, NULL)) == NULL) return -1; /* errno is set for us. */ - if (LCTF_INFO_KIND (fp, tp->ctt_info) != CTF_K_ARRAY) + if (LCTF_KIND (fp, tp) != CTF_K_ARRAY) return (ctf_set_errno (ofp, ECTF_NOTARRAY)); - if ((dtd = ctf_dynamic_type (ofp, type)) != NULL) - ap = (const ctf_array_t *) dtd->dtd_vlen; - else - { - ctf_get_ctt_size (fp, tp, NULL, &increment); - ap = (const ctf_array_t *) ((uintptr_t) tp + increment); - } + vlen = ctf_vlen (fp, type, tp, NULL); + ap = (const ctf_array_t *) vlen; + arp->ctr_contents = ap->cta_contents; arp->ctr_index = ap->cta_index; arp->ctr_nelems = ap->cta_nelems;