]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
libctf: ctf-lookup: support prefixes in ctf_lookup_by_id
authorNick Alcock <nick.alcock@oracle.com>
Thu, 24 Apr 2025 13:17:19 +0000 (14:17 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Fri, 25 Apr 2025 17:07:41 +0000 (18:07 +0100)
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.

libctf/ctf-impl.h
libctf/ctf-lookup.c

index 9833f6c3377d0f0a3cdd7f51a79b50e4066f9ed4..456d9d75967b2e5963596efcdf27698fb99c70d7 100644 (file)
@@ -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);
index da3e949962e54e8e0351c8c0364e279a9c4f0964..ac874fca2006cd1e83ef2904ec21f388c5157e64 100644 (file)
@@ -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