]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
libctf: decl, types: revise ctf_decl*, ctf_type_*name
authorNick Alcock <nick.alcock@oracle.com>
Fri, 25 Apr 2025 10:03:16 +0000 (11:03 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Fri, 25 Apr 2025 17:07:42 +0000 (18:07 +0100)
These all need fairly trivial revisions for prefix types.  While
we're at it, we can add explicit handling of nonrepresentable types,
returning CTF_K_UNKNOWN for such types rather than throwing an error,
so that type printing prints (nonrepresentable type) for such types
as it always intended to.

libctf/ctf-decl.c
libctf/ctf-types.c

index 9e11913da86e7cef12a24b963ccaa05bcd6d70f5..f021130b2b8c999691678d9d5fb079ac53a9269c 100644 (file)
@@ -34,7 +34,7 @@
 
    The functions in this file build a set of stacks from the type graph nodes
    corresponding to the C operator precedence levels in the appropriate order.
-   The code in ctf_type_name() can then iterate over the levels and nodes in
+   The code in ctf_type_aname() can then iterate over the levels and nodes in
    lexical precedence order and construct the final C declaration string.  */
 
 #include <ctf-impl.h>
@@ -79,16 +79,22 @@ ctf_decl_push (ctf_decl_t *cd, ctf_dict_t *fp, ctf_id_t type)
   uint32_t kind, n = 1;
   int is_qual = 0;
 
-  const ctf_type_t *tp;
+  const ctf_type_t *tp, *suffix;
   ctf_arinfo_t ar;
 
-  if ((tp = ctf_lookup_by_id (&fp, type)) == NULL)
+  if ((tp = ctf_lookup_by_id (&fp, type, &suffix)) == NULL)
     {
-      cd->cd_err = fp->ctf_errno;
-      return;
+      if (ctf_errno (fp) != ECTF_NONREPRESENTABLE)
+       {
+         cd->cd_err = fp->ctf_errno;
+         return;
+       }
+      kind = CTF_K_UNKNOWN;
     }
+  else
+    kind = ctf_type_kind (fp, type);
 
-  switch (kind = LCTF_INFO_KIND (fp, tp->ctt_info))
+  switch (kind)
     {
     case CTF_K_ARRAY:
       (void) ctf_array_info (fp, type, &ar);
@@ -98,21 +104,21 @@ ctf_decl_push (ctf_decl_t *cd, ctf_dict_t *fp, ctf_id_t type)
       break;
 
     case CTF_K_TYPEDEF:
-      if (ctf_strptr (fp, tp->ctt_name)[0] == '\0')
+      if (ctf_strptr (fp, suffix->ctt_name)[0] == '\0')
        {
-         ctf_decl_push (cd, fp, tp->ctt_type);
+         ctf_decl_push (cd, fp, suffix->ctt_type);
          return;
        }
       prec = CTF_PREC_BASE;
       break;
 
     case CTF_K_FUNCTION:
-      ctf_decl_push (cd, fp, tp->ctt_type);
+      ctf_decl_push (cd, fp, suffix->ctt_type);
       prec = CTF_PREC_FUNCTION;
       break;
 
     case CTF_K_POINTER:
-      ctf_decl_push (cd, fp, tp->ctt_type);
+      ctf_decl_push (cd, fp, suffix->ctt_type);
       prec = CTF_PREC_POINTER;
       break;
 
@@ -125,7 +131,7 @@ ctf_decl_push (ctf_decl_t *cd, ctf_dict_t *fp, ctf_id_t type)
     case CTF_K_VOLATILE:
     case CTF_K_CONST:
     case CTF_K_RESTRICT:
-      ctf_decl_push (cd, fp, tp->ctt_type);
+      ctf_decl_push (cd, fp, suffix->ctt_type);
       prec = cd->cd_qualp;
       is_qual++;
       break;
index 09c0baefdbaca3715cd91bfc2fac983af8607a11..00cbd96f0d83e07801a9bad7d9d4f3a103a9840f 100644 (file)
@@ -853,8 +853,12 @@ ctf_type_aname (ctf_dict_t *fp, ctf_id_t type)
           cdp != NULL; cdp = ctf_list_next (cdp))
        {
          ctf_dict_t *rfp = fp;
-         const ctf_type_t *tp = ctf_lookup_by_id (&rfp, cdp->cd_type);
-         const char *name = ctf_strptr (rfp, tp->ctt_name);
+         const ctf_type_t *tp = NULL;
+         const char *name;
+
+         ctf_lookup_by_id (&rfp, cdp->cd_type, &tp);
+         assert (tp);
+         name = ctf_strptr (rfp, tp->ctt_name);
 
          if (k != CTF_K_POINTER && k != CTF_K_ARRAY)
            ctf_decl_sprintf (&cd, " ");
@@ -976,6 +980,7 @@ ctf_type_aname (ctf_dict_t *fp, ctf_id_t type)
            case CTF_K_RESTRICT:
              ctf_decl_sprintf (&cd, "restrict");
              break;
+
            case CTF_K_UNKNOWN:
              if (name[0] == '\0')
                ctf_decl_sprintf (&cd, _("(nonrepresentable type)"));
@@ -1050,7 +1055,7 @@ ctf_type_name_raw (ctf_dict_t *fp, ctf_id_t type)
       return NULL;
     }
 
-  if ((tp = ctf_lookup_by_id (&fp, type)) == NULL)
+  if (ctf_lookup_by_id (&fp, type, &tp) == NULL)
     return NULL;               /* errno is set for us.  */
 
   if (tp->ctt_name == 0)