]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
libctf: create, types: arrays
authorNick Alcock <nick.alcock@oracle.com>
Fri, 25 Apr 2025 10:38:11 +0000 (11:38 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Fri, 25 Apr 2025 17:07:43 +0000 (18:07 +0100)
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.  */

include/ctf-api.h
libctf/ctf-create.c
libctf/ctf-types.c

index dd159c3836c4d0b28380b592e746a33866fb2c8d..770196f3cedc8e542cf41cfa321c23fcad7df096 100644 (file)
@@ -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
index f2b98b8ddb9bf23eea1c88eb63a155ec9af27bcc..d08109083d7100286b6c8f20238ab43f87acb4eb 100644 (file)
@@ -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;
index 2ee073e37a65b81fc70a48e01dc110b8171e1d7b..7423d0d9d2f9c23a190313bdac4778117bd8ae25 100644 (file)
@@ -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;