forked from Imagelibrary/binutils-gdb
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. */
This commit is contained in:
@@ -161,7 +161,7 @@ typedef struct ctf_arinfo
|
|||||||
{
|
{
|
||||||
ctf_id_t ctr_contents; /* Type of array contents. */
|
ctf_id_t ctr_contents; /* Type of array contents. */
|
||||||
ctf_id_t ctr_index; /* Type of array index. */
|
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;
|
} ctf_arinfo_t;
|
||||||
|
|
||||||
typedef struct ctf_funcinfo
|
typedef struct ctf_funcinfo
|
||||||
|
|||||||
@@ -865,19 +865,18 @@ ctf_id_t
|
|||||||
ctf_add_array (ctf_dict_t *fp, uint32_t flag, const ctf_arinfo_t *arp)
|
ctf_add_array (ctf_dict_t *fp, uint32_t flag, const ctf_arinfo_t *arp)
|
||||||
{
|
{
|
||||||
ctf_dtdef_t *dtd;
|
ctf_dtdef_t *dtd;
|
||||||
ctf_array_t cta;
|
ctf_array_t *cta;
|
||||||
ctf_id_t type;
|
|
||||||
ctf_dict_t *tmp = fp;
|
ctf_dict_t *tmp = fp;
|
||||||
|
|
||||||
if (arp == NULL)
|
if (arp == NULL)
|
||||||
return (ctf_set_typed_errno (fp, EINVAL));
|
return (ctf_set_typed_errno (fp, EINVAL));
|
||||||
|
|
||||||
if (arp->ctr_contents != 0
|
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. */
|
return CTF_ERR; /* errno is set for us. */
|
||||||
|
|
||||||
tmp = fp;
|
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. */
|
return CTF_ERR; /* errno is set for us. */
|
||||||
|
|
||||||
if (ctf_type_kind (fp, arp->ctr_index) == CTF_K_FORWARD)
|
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));
|
return (ctf_set_typed_errno (fp, ECTF_INCOMPLETE));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((type = ctf_add_generic (fp, flag, NULL, CTF_K_ARRAY,
|
if ((dtd = ctf_add_generic (fp, flag, NULL, CTF_K_ARRAY, 0,
|
||||||
sizeof (ctf_array_t), &dtd)) == CTF_ERR)
|
sizeof (ctf_array_t), 0, NULL)) == NULL)
|
||||||
return CTF_ERR; /* errno is set for us. */
|
return CTF_ERR; /* errno is set for us. */
|
||||||
|
|
||||||
memset (&cta, 0, 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;
|
||||||
|
|
||||||
dtd->dtd_data.ctt_info = CTF_TYPE_INFO (CTF_K_ARRAY, flag, 0);
|
return dtd->dtd_type;
|
||||||
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));
|
|
||||||
|
|
||||||
return type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ctf_set_array (ctf_dict_t *fp, ctf_id_t type, const ctf_arinfo_t *arp)
|
ctf_set_array (ctf_dict_t *fp, ctf_id_t type, const ctf_arinfo_t *arp)
|
||||||
{
|
{
|
||||||
ctf_dict_t *ofp = fp;
|
ctf_dict_t *ofp = fp;
|
||||||
ctf_dtdef_t *dtd = ctf_dtd_lookup (fp, type);
|
ctf_dtdef_t *dtd;
|
||||||
ctf_array_t *vlen;
|
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
|
/* You can only call ctf_set_array on a type you have added, not a
|
||||||
type that was read in via ctf_open(). */
|
type that was read in via ctf_open. */
|
||||||
if (type < fp->ctf_stypes)
|
if (idx < fp->ctf_stypes)
|
||||||
return (ctf_set_errno (ofp, ECTF_RDONLY));
|
return (ctf_set_errno (ofp, ECTF_RDONLY));
|
||||||
|
|
||||||
if (dtd == NULL
|
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));
|
return (ctf_set_errno (ofp, ECTF_BADID));
|
||||||
|
|
||||||
vlen = (ctf_array_t *) dtd->dtd_vlen;
|
vlen = (ctf_array_t *) dtd->dtd_vlen;
|
||||||
|
|||||||
@@ -2195,23 +2195,18 @@ ctf_array_info (ctf_dict_t *fp, ctf_id_t type, ctf_arinfo_t *arp)
|
|||||||
{
|
{
|
||||||
ctf_dict_t *ofp = fp;
|
ctf_dict_t *ofp = fp;
|
||||||
const ctf_type_t *tp;
|
const ctf_type_t *tp;
|
||||||
|
unsigned char *vlen;
|
||||||
const ctf_array_t *ap;
|
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. */
|
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));
|
return (ctf_set_errno (ofp, ECTF_NOTARRAY));
|
||||||
|
|
||||||
if ((dtd = ctf_dynamic_type (ofp, type)) != NULL)
|
vlen = ctf_vlen (fp, type, tp, NULL);
|
||||||
ap = (const ctf_array_t *) dtd->dtd_vlen;
|
ap = (const ctf_array_t *) vlen;
|
||||||
else
|
|
||||||
{
|
|
||||||
ctf_get_ctt_size (fp, tp, NULL, &increment);
|
|
||||||
ap = (const ctf_array_t *) ((uintptr_t) tp + increment);
|
|
||||||
}
|
|
||||||
arp->ctr_contents = ap->cta_contents;
|
arp->ctr_contents = ap->cta_contents;
|
||||||
arp->ctr_index = ap->cta_index;
|
arp->ctr_index = ap->cta_index;
|
||||||
arp->ctr_nelems = ap->cta_nelems;
|
arp->ctr_nelems = ap->cta_nelems;
|
||||||
|
|||||||
Reference in New Issue
Block a user