]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
libctf, include, gdb: introduce ctf_kind_t enum for type kinds
authorNick Alcock <nick.alcock@oracle.com>
Thu, 6 Nov 2025 20:27:45 +0000 (20:27 +0000)
committerNick Alcock <nick.alcock@oracle.com>
Tue, 9 Dec 2025 13:02:30 +0000 (13:02 +0000)
This lets us validate that switches on type kinds cover all possible
options, and serves as documentation that another class of mysterious
ints in the public API is a type kind rather than a random integer.

14 files changed:
gdb/ctfread.c
include/ctf-api.h
include/ctf.h
libctf/ctf-create.c
libctf/ctf-decl.c
libctf/ctf-dedup.c
libctf/ctf-dump.c
libctf/ctf-impl.h
libctf/ctf-inlines.h
libctf/ctf-lookup.c
libctf/ctf-open-compat.c
libctf/ctf-open.c
libctf/ctf-serialize.c
libctf/ctf-types.c

index e7855705bda0f0211f26a5e2b4ec1876fc034ee1..8beb9945c1951c9f72b20e1c00ce47dd7ac460fc 100644 (file)
@@ -329,7 +329,7 @@ ctf_add_member_cb (ctf_dict_t *dict,
   struct ctf_nextfield new_field;
   struct field *fp;
   struct type *t;
-  uint32_t kind;
+  ctf_kind_t kind;
 
   fp = &new_field.field;
   fp->set_name (name);
@@ -414,7 +414,7 @@ new_type_symbol (struct ctf_context *ccp, struct type *type, ctf_id_t tid)
       if (type != nullptr)
        sym->set_type (type);
 
-      uint32_t kind = ctf_type_kind (dict, tid);
+      ctf_kind_t kind = ctf_type_kind (dict, tid);
       switch (kind)
        {
          case CTF_K_STRUCT:
@@ -422,6 +422,7 @@ new_type_symbol (struct ctf_context *ccp, struct type *type, ctf_id_t tid)
          case CTF_K_ENUM:
            sym->set_domain (STRUCT_DOMAIN);
            break;
+         default:;
        }
 
       add_symbol_to_list (sym, ccp->builder->get_global_symbols ());
@@ -439,7 +440,7 @@ read_base_type (struct ctf_context *ccp, ctf_id_t tid)
   ctf_encoding_t cet;
   struct type *type = nullptr;
   const char *name;
-  uint32_t kind;
+  ctf_kind_t kind;
 
   if (ctf_type_encoding (dict, tid, &cet))
     {
@@ -531,7 +532,7 @@ read_structure_type (struct ctf_context *ccp, ctf_id_t tid)
   struct objfile *of = ccp->of;
   ctf_dict_t *dict = ccp->dict;
   struct type *type;
-  uint32_t kind;
+  ctf_kind_t kind;
 
   type = type_allocator (of, language_c).new_type ();
 
@@ -898,7 +899,7 @@ read_forward_type (struct ctf_context *ccp, ctf_id_t tid)
   struct objfile *of = ccp->of;
   ctf_dict_t *dict = ccp->dict;
   struct type *type;
-  uint32_t kind;
+  ctf_kind_t kind;
 
   type = type_allocator (of, language_c).new_type ();
 
@@ -924,7 +925,7 @@ static struct type *
 read_type_record (struct ctf_context *ccp, ctf_id_t tid)
 {
   ctf_dict_t *dict = ccp->dict;
-  uint32_t kind;
+  ctf_kind_t kind;
   struct type *type = nullptr;
   ctf_id_t btid;
 
@@ -989,7 +990,7 @@ static void
 ctf_add_type_cb (ctf_dict_t *fp, ctf_id_t tid, struct ctf_context *ccp)
 {
   struct type *type;
-  uint32_t kind;
+  ctf_kind_t kind;
 
   /* Check if tid's type has already been defined.  */
   type = get_tid_type (ccp->of, tid);
@@ -1053,7 +1054,7 @@ ctf_add_var_cb (ctf_dict_t *fp, const char *name, ctf_id_t id,
 {
   struct symbol *sym = nullptr;
   struct type *type;
-  uint32_t kind;
+  ctf_kind_t kind;
 
   type = get_tid_type (ccp->of, id);
 
@@ -1175,7 +1176,7 @@ ctf_psymtab_add_stt_entries (ctf_dict_t *dict, ctf_psymtab *pst,
 
   while ((tid = ctf_symbol_next (dict, &i, &tname, functions)) != CTF_ERR)
     {
-      uint32_t kind = ctf_type_kind (dict, tid);
+      ctf_kind_t kind = ctf_type_kind (dict, tid);
       location_class loc_class;
       domain_enum tdomain = functions ? FUNCTION_DOMAIN : VAR_DOMAIN;
 
@@ -1326,7 +1327,7 @@ create_partial_symtab (const char *name,
 static void
 ctf_psymtab_type_cb (ctf_dict_t *fp, ctf_id_t tid, struct ctf_context *ccp)
 {
-  uint32_t kind;
+  ctf_kind_t kind;
   int section = -1;
 
   domain_enum domain = UNDEF_DOMAIN;
@@ -1355,7 +1356,7 @@ ctf_psymtab_type_cb (ctf_dict_t *fp, ctf_id_t tid, struct ctf_context *ccp)
       domain = TYPE_DOMAIN;
       loc_class = LOC_TYPEDEF;
       break;
-    case CTF_K_UNKNOWN:
+    default:
       return;
     }
 
@@ -1376,7 +1377,7 @@ static void
 ctf_psymtab_var_cb (ctf_dict_t *fp, const char *name, ctf_id_t id,
                    struct ctf_context *ccp)
 {
-  uint32_t kind = ctf_type_kind (ccp->dict, id);
+  ctf_kind_t kind = ctf_type_kind (ccp->dict, id);
 
   ccp->pst->add_psymbol (name, true,
                         kind == CTF_K_FUNCTION
index 90c915443adb59c66dd681277f2071ec4b798118..376218932a510fd433e8c2082514c15e5297ba59 100644 (file)
@@ -644,7 +644,7 @@ extern ctf_id_t ctf_lookup_enumerator (ctf_dict_t *, const char *,
    CTF_K_TYPE_TAG and CTF_K_DECL_TAG, since they may be associated with many
    types: use ctf_tag_next. */
 
-extern ctf_id_t ctf_lookup_by_kind (ctf_dict_t *, int kind, const char *);
+extern ctf_id_t ctf_lookup_by_kind (ctf_dict_t *, ctf_kind_t kind, const char *);
 
 /* Type lookup functions.  */
 
@@ -707,13 +707,13 @@ extern ssize_t ctf_type_align (ctf_dict_t *, ctf_id_t);
    CTFv4 note: forwards to enums also return CTF_K_FORWARD, even though they
    are encoded differently.  */
 
-extern int ctf_type_kind (ctf_dict_t *, ctf_id_t);
+extern ctf_kind_t ctf_type_kind (ctf_dict_t *, ctf_id_t);
 
 /* Return the kind of a type (CTF_K_* constant).  Slices are considered to be
    the kind they are a slice of; forwards are considered to be the kind they are
    a forward of.  */
 
-extern int ctf_type_kind_forwarded (ctf_dict_t *, ctf_id_t);
+extern ctf_kind_t ctf_type_kind_forwarded (ctf_dict_t *, ctf_id_t);
 
 /* Return nonzero if this type is conflicting, zero if it's not, < 0 on error; if
    CUNAME is set, set it to the name of the conflicting compilation unit for the
@@ -866,7 +866,7 @@ extern ctf_id_t ctf_arc_lookup_enumerator_next (ctf_archive_t *, const char *nam
 
 extern ctf_id_t ctf_type_next (ctf_dict_t *, ctf_next_t **,
                               int *flag, int want_hidden);
-extern ctf_id_t ctf_type_kind_next (ctf_dict_t *, ctf_next_t **, int kind);
+extern ctf_id_t ctf_type_kind_next (ctf_dict_t *, ctf_next_t **, ctf_kind_t kind);
 extern ctf_id_t ctf_variable_next (ctf_dict_t *, ctf_next_t **,
                                   const char **);
 extern ctf_id_t ctf_datasec_var_next (ctf_dict_t *, ctf_id_t, ctf_next_t **,
@@ -957,7 +957,7 @@ extern ctf_id_t ctf_add_btf_float (ctf_dict_t *, uint32_t,
 extern ctf_id_t ctf_add_float (ctf_dict_t *, uint32_t,
                               const char *, const ctf_encoding_t *);
 extern ctf_id_t ctf_add_forward (ctf_dict_t *, uint32_t, const char *,
-                                uint32_t);
+                                ctf_kind_t);
 extern ctf_id_t ctf_add_integer (ctf_dict_t *, uint32_t, const char *,
                                 const ctf_encoding_t *);
 
@@ -1100,7 +1100,7 @@ extern ctf_error_t ctf_arc_write_fd (int, ctf_dict_t **, size_t, const char **,
 /* Prohibit writeout of this type kind: attempts to write it out cause
    an ECTF_KIND_PROHIBITED error.  */
 
-extern ctf_ret_t ctf_write_suppress_kind (ctf_dict_t *fp, int kind,
+extern ctf_ret_t ctf_write_suppress_kind (ctf_dict_t *fp, ctf_kind_t kind,
                                          int prohibited);
 
 /* Linking.  These functions are used by ld to link .ctf sections in input
index de8afad3ec16696894b56379ed923a346c5c8af8..99380314a8c9799ac8a454351a45d37a962ce1fc 100644 (file)
@@ -523,76 +523,81 @@ union
    CTF_INFO_VLEN() will extract the number of elements in the list, and
    the type of each element is shown in the comments below.  */
 
-#define CTF_V3_K_UNKNOWN 0     /* Unknown type (used for padding and
+typedef enum ctf_v3_kind
+  {
+    CTF_V3_K_UNKNOWN  = 0,     /* Unknown type (used for padding and
                                   unrepresentable types).  */
-#define CTF_V3_K_INTEGER 1     /* Variant data is CTF_INT_DATA (see below).  */
-#define CTF_V3_K_FLOAT   2     /* Variant data is CTF_FP_DATA (see below).  */
-#define CTF_V3_K_POINTER 3     /* ctt_type is referenced type.  */
-#define CTF_V3_K_ARRAY   4     /* Variant data is single ctf_array_t.  */
-#define CTF_V3_K_FUNCTION 5    /* ctt_type is return type, variant data is
+    CTF_V3_K_INTEGER  = 1,     /* Variant data is CTF_INT_DATA (see below).  */
+    CTF_V3_K_FLOAT    = 2,     /* Variant data is CTF_FP_DATA (see below).  */
+    CTF_V3_K_POINTER  = 3,     /* ctt_type is referenced type.  */
+    CTF_V3_K_ARRAY    = 4,     /* Variant data is single ctf_array_t.  */
+    CTF_V3_K_FUNCTION = 5,     /* ctt_type is return type, variant data is
                                   list of argument types (unsigned short's for v1,
                                   uint32_t's for v2).  */
-#define CTF_V3_K_STRUCT  6     /* Variant data is list of ctf_member_t's.  */
-#define CTF_V3_K_UNION   7     /* Variant data is list of ctf_member_t's.  */
-#define CTF_V3_K_ENUM    8     /* Variant data is list of ctf_enum_t's.  */
-#define CTF_V3_K_FORWARD 9     /* No additional data; ctt_name is tag.  */
-#define CTF_V3_K_TYPEDEF 10    /* ctt_type is referenced type.  */
-#define CTF_V3_K_VOLATILE 11   /* ctt_type is base type.  */
-#define CTF_V3_K_CONST   12    /* ctt_type is base type.  */
-#define CTF_V3_K_RESTRICT 13   /* ctt_type is base type.  */
-#define CTF_V3_K_SLICE   14    /* Variant data is a ctf_slice_t.  */
-
-#define CTF_V3_K_MAX   14      /* Maximum possible (V3) CTF_K_* value.  */
+    CTF_V3_K_STRUCT   = 6,     /* Variant data is list of ctf_member_t's.  */
+    CTF_V3_K_UNION    = 7,     /* Variant data is list of ctf_member_t's.  */
+    CTF_V3_K_ENUM     = 8,     /* Variant data is list of ctf_enum_t's.  */
+    CTF_V3_K_FORWARD  = 9,     /* No additional data; ctt_name is tag.  */
+    CTF_V3_K_TYPEDEF  = 10,    /* ctt_type is referenced type.  */
+    CTF_V3_K_VOLATILE = 11,    /* ctt_type is base type.  */
+    CTF_V3_K_CONST    = 12,    /* ctt_type is base type.  */
+    CTF_V3_K_RESTRICT = 13,    /* ctt_type is base type.  */
+    CTF_V3_K_SLICE    = 14,    /* Variant data is a ctf_slice_t.  */
+
+    CTF_V3_K_MAX      = 14     /* Maximum possible (V3) CTF_K_* value.  */
+  } ctf_v3_kind_t;
 
 /* Values for CTF_TYPE_KIND() for BTF, shared by CTFv4.  Kind names as unchanged
    as possible, since they are user-exposed, but their values all differ.  */
 
-#define CTF_K_UNKNOWN  0       /* Unknown type (used for padding and
-                                  unrepresentable and suppressed types).  */
-#define CTF_K_INTEGER  1       /* Variant data is CTF_INT_DATA (see below).  */
-#define CTF_K_POINTER  2       /* ctt_type is referenced type.  */
-#define CTF_K_ARRAY    3       /* Variant data is single ctf_array_t.  */
-#define CTF_K_STRUCT   4       /* Variant data is list of ctf_member_t's;
-                                  kind_flag 1 if bitfields present.  */
-#define CTF_K_UNION    5       /* Ditto.  */
-#define CTF_K_ENUM     6       /* Variant data is list of ctf_enum_t's: if 0,
-                                  this is a forward.  kflag 1 is signed.  */
-#define CTF_K_FORWARD  7       /* No additional data; kind_flag 1 for unions.  */
-#define CTF_K_TYPEDEF  8       /* ctt_type is referenced type.  */
-#define CTF_K_VOLATILE 9       /* ctt_type is base type.  */
-#define CTF_K_CONST    10      /* ctt_type is base type.  */
-#define CTF_K_RESTRICT 11      /* ctt_type is base type.  */
-#define CTF_K_FUNC_LINKAGE 12  /* Literal vlen field is ctf_linkage_t.ctl.linkage;
-                                  ctt_type is CTF_K_FUNCTION.  Named.  */
-#define CTF_K_FUNCTION 13      /* ctt_type is return type, variant data is
-                                  list of ctf_param_t.  Unnamed.  */
-#define CTF_K_VAR      14      /* Variable.  ctt_type is variable type.
-                                  Variant data is ctf_linkage_t.  */
-#define CTF_K_DATASEC  15      /* Variant data is list of ctf_var_secinfo_t.  */
-#define CTF_K_BTF_FLOAT 16     /* No data beyond a size.  */
-#define CTF_K_DECL_TAG 17      /* ctt_type is referenced type.  Variant data is
-                                  ctf_decl_tag_t.  */
-#define CTF_K_TYPE_TAG 18      /* ctt_type is referenced type.  */
-#define CTF_K_ENUM64  19       /* Variant data is list of ctf_enum64_t.  kflag
-                                  1 is signed.  */
+typedef enum ctf_kind
+  {
+    CTF_K_UNKNOWN  = 0,        /* Unknown type (used for padding and
+                          unrepresentable and suppressed types).  */
+    CTF_K_INTEGER  = 1,        /* Variant data is CTF_INT_DATA (see below).  */
+    CTF_K_POINTER  = 2,        /* ctt_type is referenced type.  */
+    CTF_K_ARRAY    = 3,        /* Variant data is single ctf_array_t.  */
+    CTF_K_STRUCT   = 4,        /* Variant data is list of ctf_member_t's;
+                          kind_flag 1 if bitfields present.  */
+    CTF_K_UNION    = 5,        /* Ditto.  */
+    CTF_K_ENUM     = 6,        /* Variant data is list of ctf_enum_t's: if 0,
+                          this is a forward.  kflag 1 is signed.  */
+    CTF_K_FORWARD  = 7,        /* No additional data; kind_flag 1 for unions.  */
+    CTF_K_TYPEDEF  = 8,        /* ctt_type is referenced type.  */
+    CTF_K_VOLATILE = 9,        /* ctt_type is base type.  */
+    CTF_K_CONST    = 10, /* ctt_type is base type.  */
+    CTF_K_RESTRICT = 11, /* ctt_type is base type.  */
+    CTF_K_FUNC_LINKAGE = 12, /* Literal vlen field is ctf_linkage_t.ctl.linkage;
+                               ctt_type is CTF_K_FUNCTION.  Named.  */
+    CTF_K_FUNCTION = 13, /* ctt_type is return type, variant data is
+                           list of ctf_param_t.  Unnamed.  */
+    CTF_K_VAR      = 14, /* Variable.  ctt_type is variable type.
+                           Variant data is ctf_linkage_t.  */
+    CTF_K_DATASEC  = 15, /* Variant data is list of ctf_var_secinfo_t.  */
+    CTF_K_BTF_FLOAT = 16,/* No data beyond a size.  */
+    CTF_K_DECL_TAG = 17, /* ctt_type is referenced type.  Variant data is
+                           ctf_decl_tag_t.  */
+    CTF_K_TYPE_TAG = 18, /* ctt_type is referenced type.  */
+    CTF_K_ENUM64 = 19,  /* Variant data is list of ctf_enum64_t.  kflag
+                           1 is signed.  */
 
 /* Values for CTF_TYPE_KIND() for CTFv4.  Count down from the top of the ID
    space, */
 
-#define CTF_K_FLOAT   31       /* Variant data is a CTF_FP_* value.  */
-#define CTF_K_SLICE   30       /* Variant data is a ctf_slice_t.  */
-#define CTF_K_BIG     29       /* Prefix type.
-                                  vlen is high 16 bits of type vlen;
-                                  size is high 32 bits of type size.  */
-#define CTF_K_CONFLICTING 28   /* Prefix type.  Name is disambiguator for
+    CTF_K_FLOAT  = 31, /* Variant data is a CTF_FP_* value.  */
+    CTF_K_SLICE  = 30, /* Variant data is a ctf_slice_t.  */
+    CTF_K_BIG    = 29, /* Prefix type.
+                          vlen is high 16 bits of type vlen;
+                          size is high 32 bits of type size.  */
+    CTF_K_CONFLICTING = 28,    /* Prefix type.  Name is disambiguator for
                                   conflicting type (e.g. translation unit
                                   name).
 
                                   If a type is both CONFLICTING and BIG,
                                   CONFLICTING will always prefix BIG.  */
-#define CTF_BTF_K_MAX  19      /* Maximum possible (V4) BTF_K_* value.  */
-#define CTF_K_MAX      31      /* Maximum possible (V4) CTF_K_* value.  */
-
+    CTF_BTF_K_MAX = 19,        /* Maximum possible (V4) BTF_K_* value.  */
+    CTF_K_MAX    = 31  /* Maximum possible (V4) CTF_K_* value.  */
+  } ctf_kind_t;
 
 #define CTF_PREFIX_KIND(kind) ((kind) == CTF_K_BIG || (kind) == CTF_K_CONFLICTING)
 
index e8e7bb8eb72ef42a6bef8018589810456674d5fd..86123122c370d67fc7adf0d7395c5306763e2091 100644 (file)
@@ -260,7 +260,7 @@ ctf_update (ctf_dict_t *fp)
 }
 
 ctf_dynhash_t *
-ctf_name_table (ctf_dict_t *fp, int kind)
+ctf_name_table (ctf_dict_t *fp, ctf_kind_t kind)
 {
   switch (kind)
     {
@@ -283,7 +283,7 @@ ctf_name_table (ctf_dict_t *fp, int kind)
 
 int
 ctf_insert_type_decl_tag (ctf_dict_t *fp, ctf_id_t type, const char *name,
-                         int kind)
+                         ctf_kind_t kind)
 {
   ctf_dynset_t *types;
   ctf_dynhash_t *h = ctf_name_table (fp, kind);
@@ -313,7 +313,7 @@ ctf_insert_type_decl_tag (ctf_dict_t *fp, ctf_id_t type, const char *name,
 }
 
 int
-ctf_dtd_insert (ctf_dict_t *fp, ctf_dtdef_t *dtd, int flag, int kind)
+ctf_dtd_insert (ctf_dict_t *fp, ctf_dtdef_t *dtd, int flag, ctf_kind_t kind)
 {
   const char *name;
   if (ctf_dynhash_insert (fp->ctf_dthash, (void *) (uintptr_t) dtd->dtd_type,
@@ -348,7 +348,7 @@ void
 ctf_dtd_delete (ctf_dict_t *fp, ctf_dtdef_t *dtd)
 {
   const char *name = ctf_type_name_raw (fp, dtd->dtd_type);
-  int name_kind = ctf_type_kind_forwarded (fp, dtd->dtd_type);
+  ctf_kind_t name_kind = ctf_type_kind_forwarded (fp, dtd->dtd_type);
 
   /* Repeated calls should do nothing.  */
   if (name_kind < 0 && ctf_errno (fp) == ECTF_BADID)
@@ -556,9 +556,9 @@ ctf_assign_id (ctf_dict_t *fp)
    or to the first prefix requested by PREFIXES, if nonzero.  */
 
 static ctf_dtdef_t *
-ctf_add_generic (ctf_dict_t *fp, uint32_t flag, const char *name, int kind,
-                int prefixes, size_t vbytes, size_t vbytes_extra,
-                ctf_type_t **typep)
+ctf_add_generic (ctf_dict_t *fp, uint32_t flag, const char *name,
+                ctf_kind_t kind, int prefixes, size_t vbytes,
+                size_t vbytes_extra, ctf_type_t **typep)
 {
   ctf_dtdef_t *dtd;
   ctf_id_t type;
@@ -699,7 +699,7 @@ clp2 (size_t x)
 
 ctf_id_t
 ctf_add_encoded (ctf_dict_t *fp, uint32_t flag,
-                const char *name, const ctf_encoding_t *ep, uint32_t kind)
+                const char *name, const ctf_encoding_t *ep, ctf_kind_t kind)
 {
   ctf_dtdef_t *dtd;
   uint32_t encoding;
@@ -737,7 +737,7 @@ ctf_add_encoded (ctf_dict_t *fp, uint32_t flag,
 }
 
 ctf_id_t
-ctf_add_reftype (ctf_dict_t *fp, uint32_t flag, ctf_id_t ref, uint32_t kind)
+ctf_add_reftype (ctf_dict_t *fp, uint32_t flag, ctf_id_t ref, ctf_kind_t kind)
 {
   ctf_dtdef_t *dtd;
   ctf_dict_t *typedict = fp;
@@ -786,7 +786,7 @@ ctf_add_slice (ctf_dict_t *fp, uint32_t flag, ctf_id_t ref,
   ctf_dtdef_t *dtd;
   ctf_slice_t slice;
   ctf_id_t resolved_ref = ref;
-  int kind;
+  ctf_kind_t kind;
   ctf_dict_t *tmp = fp;
 
   if (ep == NULL)
@@ -976,8 +976,8 @@ ctf_add_tag (ctf_dict_t *fp, uint32_t flag, ctf_id_t type, const char *tag,
 {
   ctf_dtdef_t *dtd;
   size_t vlen_size = 0;
-  int kind = is_decl ? CTF_K_DECL_TAG : CTF_K_TYPE_TAG;
-  int ref_kind = ctf_type_kind (fp, type);
+  ctf_kind_t kind = is_decl ? CTF_K_DECL_TAG : CTF_K_TYPE_TAG;
+  ctf_kind_t ref_kind = ctf_type_kind (fp, type);
 
   if (component_idx < -1)
     return (ctf_set_typed_errno (fp, ECTF_BADCOMPONENT));
@@ -1179,7 +1179,7 @@ ctf_add_function_linkage (ctf_dict_t *fp, uint32_t flag,
 
 static ctf_id_t
 ctf_add_sou_sized (ctf_dict_t *fp, uint32_t flag, const char *name,
-                  size_t size, int kind)
+                  size_t size, ctf_kind_t kind)
 {
   ctf_dtdef_t *dtd;
   ctf_type_t *prefix;
@@ -1249,7 +1249,7 @@ ctf_add_union (ctf_dict_t *fp, uint32_t flag, const char *name)
 
 static ctf_id_t
 ctf_add_enum_internal (ctf_dict_t *fp, uint32_t flag, const char *name,
-                      int kind, int is_signed)
+                      ctf_kind_t kind, int is_signed)
 {
   ctf_dtdef_t *dtd;
   ctf_id_t type = 0;
@@ -1311,7 +1311,7 @@ ctf_add_enum64 (ctf_dict_t *fp, uint32_t flag, const char *name)
 
 static ctf_id_t
 ctf_add_enum_encoded_internal (ctf_dict_t *fp, uint32_t flag, const char *name,
-                              int kind, const ctf_encoding_t *ep)
+                              ctf_kind_t kind, const ctf_encoding_t *ep)
 {
   ctf_id_t type = 0;
   int is_signed = ((ep->cte_format & CTF_INT_SIGNED) != 0);
@@ -1364,7 +1364,7 @@ ctf_add_enum64_encoded (ctf_dict_t *fp, uint32_t flag, const char *name,
 
 ctf_id_t
 ctf_add_forward (ctf_dict_t *fp, uint32_t flag, const char *name,
-                uint32_t kind)
+                ctf_kind_t kind)
 {
   ctf_dtdef_t *dtd;
   ctf_id_t type = 0;
@@ -1490,7 +1490,8 @@ ctf_add_enumerator (ctf_dict_t *fp, ctf_id_t enid, const char *name,
   ctf_dict_t *ofp = fp;
   ctf_dtdef_t *dtd;
 
-  uint32_t kind, vlen, root, en_name;
+  ctf_kind_t kind;
+  uint32_t vlen, root, en_name;
 
   if (name == NULL)
     return (ctf_set_errno (fp, EINVAL));
@@ -1624,7 +1625,8 @@ ctf_add_member_bitfield (ctf_dict_t *fp, ctf_id_t souid, const char *name,
   ctf_type_t *prefix;
 
   ssize_t msize, ssize;
-  uint32_t kind, kflag;
+  ctf_kind_t kind;
+  uint32_t kflag;
   size_t vlen;
   size_t i;
   int is_incomplete = 0;
@@ -1856,8 +1858,8 @@ ctf_add_member_encoded (ctf_dict_t *fp, ctf_id_t souid, const char *name,
                        const ctf_encoding_t encoding)
 {
   ctf_dtdef_t *dtd = ctf_dtd_lookup (fp, type);
-  int kind;
-  int otype = type;
+  ctf_kind_t kind;
+  ctf_id_t otype = type;
 
   if (dtd == NULL)
     return (ctf_set_errno (fp, ECTF_BADID));
@@ -1933,7 +1935,8 @@ ctf_add_section_variable (ctf_dict_t *fp, uint32_t flag, const char *datasec,
   ctf_dtdef_t *sec_dtd = NULL;
   ctf_dtdef_t *var_dtd = NULL;
 
-  uint32_t kind, kflag;
+  ctf_kind_t kind;
+  uint32_t kflag;
   size_t vlen;
 
   ctf_linkage_t *l;
@@ -2405,13 +2408,14 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
                       ctf_dict_t *proc_tracking_fp)
 {
   ctf_id_t dst_type = CTF_ERR;
-  uint32_t dst_kind = CTF_K_UNKNOWN;
+  ctf_kind_t dst_kind = CTF_K_UNKNOWN;
   ctf_dict_t *tmp_fp = dst_fp;
   ctf_id_t tmp;
 
   const char *name;
-  uint32_t kind, forward_kind, flag, bitfields;
-  uint32_t isroot;
+  ctf_kind_t kind, forward_kind;
+  uint32_t isroot, bitfields;
+  int flag;
   size_t vlen;
 
   const ctf_type_t *src_prefix, *src_tp, *dst_prefix;
@@ -2452,7 +2456,7 @@ ctf_add_type_internal (ctf_dict_t *dst_fp, ctf_dict_t *src_fp, ctf_id_t src_type
         same kind and (if a struct or union) has the same number of members,
         hand it straight back.  */
 
-      if (ctf_type_kind_unsliced (tmp_fp, tmp) == (int) kind)
+      if (ctf_type_kind_unsliced (tmp_fp, tmp) == kind)
        {
          if (kind == CTF_K_STRUCT || kind == CTF_K_UNION
              || kind == CTF_K_ENUM)
index d483174c25e5f591370802c5cdd464fac094eda4..be53bc813bd065b3e6676ad81edf2edf2b498ce9 100644 (file)
@@ -76,7 +76,8 @@ ctf_decl_push (ctf_decl_t *cd, ctf_dict_t *fp, ctf_id_t type)
 {
   ctf_decl_node_t *cdp;
   ctf_decl_prec_t prec;
-  uint32_t kind, n = 1;
+  ctf_kind_t kind;
+  uint32_t n = 1;
   int is_qual = 0;
 
   const ctf_type_t *tp, *suffix;
index 4a16a34e28a4d8714f794ecd9a526375483eeede..4486478cbc5c9217d1719c22f51b34858fefe861 100644 (file)
@@ -450,7 +450,7 @@ intern (ctf_dict_t *fp, char *atom)
    while allowing for the four C namespaces (normal, struct, union, enum).
    Return a pointer into the cd_decorated_names atoms table.  */
 static const char *
-ctf_decorate_type_name (ctf_dict_t *fp, const char *name, int kind)
+ctf_decorate_type_name (ctf_dict_t *fp, const char *name, ctf_kind_t kind)
 {
   ctf_dedup_t *d = &fp->ctf_dedup;
   const char *ret;
@@ -593,7 +593,7 @@ ctf_dedup_hash_type (ctf_dict_t *fp, ctf_dict_t *input,
 /* Determine whether this type is being hashed as a stub (in which case it is
    unsafe to cache it).  */
 static int
-ctf_dedup_is_stub (const char *name, int kind, int fwdkind, int flags)
+ctf_dedup_is_stub (const char *name, ctf_kind_t kind, ctf_kind_t fwdkind, int flags)
 {
   /* We can cache all types unless we are recursing to children and are hashing
      in a tagged struct, union or forward, all of which are replaced with their
@@ -647,7 +647,7 @@ static const char *
 ctf_dedup_rhash_type (ctf_dict_t *fp, ctf_dict_t *input, ctf_dict_t **inputs,
                      int input_num, ctf_id_t type, void *type_id,
                      const ctf_type_t *tp, const char *name,
-                     const char *decorated, int kind, int flags,
+                     const char *decorated, ctf_kind_t kind, int flags,
                      unsigned long depth,
                      int (*populate_fun) (ctf_dict_t *fp,
                                           ctf_dict_t *input,
@@ -668,6 +668,7 @@ ctf_dedup_rhash_type (ctf_dict_t *fp, ctf_dict_t *input, ctf_dict_t **inputs,
   const char *whaterr;
   ctf_error_t err = 0;
   int64_t component_idx = -1;
+  uint32_t ukind = (uint32_t) kind;
 
   /* "citer" is for types that reference only one other type: "citers" can store
      many of them, but is more expensive to both populate and traverse.  */
@@ -773,6 +774,9 @@ ctf_dedup_rhash_type (ctf_dict_t *fp, ctf_dict_t *input, ctf_dict_t **inputs,
     case CTF_K_RESTRICT:
     case CTF_K_SLICE:
       name = NULL;
+      break;
+    default:;
+      /* No need to annul anything else.  */
     }
 
   /* Mix in invariant stuff, transforming the type kind if needed.  Note that
@@ -793,7 +797,8 @@ ctf_dedup_rhash_type (ctf_dict_t *fp, ctf_dict_t *input, ctf_dict_t **inputs,
   ctf_sha1_init (&hash);
   if (name)
     ctf_dedup_sha1_add (&hash, name, strlen (name) + 1, "name", depth);
-  ctf_dedup_sha1_add (&hash, &kind, sizeof (uint32_t), "kind", depth);
+  /* Force the kind hash to rely on an arch-independent, explicitly-sized type.  */
+  ctf_dedup_sha1_add (&hash, &ukind, sizeof (ukind), "kind", depth);
 
   /* Hash content of this type.  */
   switch (kind)
@@ -803,10 +808,10 @@ ctf_dedup_rhash_type (ctf_dict_t *fp, ctf_dict_t *input, ctf_dict_t **inputs,
       break;
     case CTF_K_FORWARD:
       {
-       int fwdkind = ctf_type_kind_forwarded_tp (input, tp);
+       uint32_t ufwdkind = ctf_type_kind_forwarded_tp (input, tp);
 
        /* Add the forwarded kind.  */
-       ctf_dedup_sha1_add (&hash, &fwdkind, sizeof (fwdkind), "forwarded kind",
+       ctf_dedup_sha1_add (&hash, &ufwdkind, sizeof (ufwdkind), "forwarded kind",
                            depth);
        break;
       }
@@ -881,7 +886,7 @@ ctf_dedup_rhash_type (ctf_dict_t *fp, ctf_dict_t *input, ctf_dict_t **inputs,
 
       if (kind == CTF_K_DECL_TAG && component_idx > -1)
        {
-         int child_kind = ctf_type_kind (input, child_type);
+         ctf_kind_t child_kind = ctf_type_kind (input, child_type);
 
          if (child_kind == CTF_K_STRUCT || child_kind == CTF_K_UNION)
            {
@@ -1402,7 +1407,7 @@ ctf_dedup_hash_type (ctf_dict_t *fp, ctf_dict_t *input,
   const char *name;
   const char *whaterr;
   const char *decorated = NULL;
-  uint32_t kind, fwdkind;
+  ctf_kind_t kind, fwdkind;
   int isroot;
 
   depth++;
@@ -1541,7 +1546,7 @@ ctf_dedup_populate_mappings (ctf_dict_t *fp, ctf_dict_t *input _libctf_unused_,
   ctf_dedup_t *d = &fp->ctf_dedup;
   ctf_dynset_t *type_ids;
   void *root_visible;
-  int kind;
+  ctf_kind_t kind;
 
 #ifdef ENABLE_LIBCTF_HASH_DEBUGGING
   ctf_dprintf ("Hash %s, %s, into output mapping for %i/%lx @ %s\n",
@@ -1594,7 +1599,7 @@ ctf_dedup_populate_mappings (ctf_dict_t *fp, ctf_dict_t *input _libctf_unused_,
     ctf_error_t err;
     const void *one_id;
     ctf_next_t *i = NULL;
-    int orig_kind = ctf_type_kind_unsliced (input, type);
+    ctf_kind_t orig_kind = ctf_type_kind_unsliced (input, type);
     int orig_first_tu;
 
     orig_first_tu = CTF_DEDUP_GID_TO_INPUT
@@ -1791,7 +1796,7 @@ ctf_dedup_count_name (ctf_dict_t *fp, const char *name, void *id)
 
 /* Look up a type kind from the output mapping, given a type hash value.
    Optionally return its GID as well.  */
-static int
+static ctf_kind_t
 ctf_dedup_hash_kind_gid (ctf_dict_t *fp, ctf_dict_t **inputs, const char *hash,
                         void **gid)
 {
@@ -1884,7 +1889,7 @@ ctf_dedup_mark_conflicting_hash (ctf_dict_t *fp, ctf_dict_t **inputs,
 {
   ctf_dedup_t *d = &fp->ctf_dedup;
   const char *name;
-  int kind;
+  ctf_kind_t kind;
   void *id;
   ctf_dict_t *input;
 
@@ -1953,7 +1958,7 @@ static int
 ctf_dedup_count_types (void *key_, void *value _libctf_unused_, void *arg_)
 {
   const char *hval = (const char *) key_;
-  int kind;
+  ctf_kind_t kind;
   ctf_dedup_type_counter_t *arg = (ctf_dedup_type_counter_t *) arg_;
 
   kind = ctf_dedup_hash_kind_gid (arg->fp, arg->inputs, hval, NULL);
@@ -2025,7 +2030,7 @@ ctf_dedup_detect_name_ambiguity (ctf_dict_t *fp, ctf_dict_t **inputs)
                  const char *hval = (const char *) hval_;
                  ctf_dynset_t *type_ids;
                  void *id;
-                 int kind;
+                 ctf_kind_t kind;
 
                  /* Dig through the types in this hash to find the non-forwards
                     and mark them ambiguous.  */
@@ -2371,7 +2376,7 @@ ctf_dedup_multiple_input_dicts (ctf_dict_t *output, ctf_dict_t **inputs,
   ctf_id_t input_id;
   const char *name;
   const char *decorated;
-  int fwdkind;
+  ctf_kind_t fwdkind;
   int multiple = 0;
   ctf_error_t err;
 
@@ -2647,7 +2652,7 @@ ctf_dedup (ctf_dict_t *output, ctf_dict_t **inputs, uint32_t ninputs,
 static int
 ctf_dedup_member_decl_tag (ctf_dict_t *fp, ctf_id_t type)
 {
-  int ref_kind = ctf_type_kind (fp, ctf_type_reference (fp, type));
+  ctf_kind_t ref_kind = ctf_type_kind (fp, ctf_type_reference (fp, type));
 
   if (ref_kind == CTF_K_STRUCT || ref_kind == CTF_K_UNION)
     {
@@ -3142,8 +3147,7 @@ ctf_dedup_maybe_synthesize_forward (ctf_dict_t *output, ctf_dict_t *target,
 {
   ctf_dedup_t *od = &output->ctf_dedup;
   ctf_dedup_t *td = &target->ctf_dedup;
-  int kind;
-  int fwdkind;
+  ctf_kind_t kind, fwdkind;
   const char *name = ctf_type_name_raw (input, id);
   const char *decorated;
   void *v;
@@ -3330,7 +3334,7 @@ ctf_dedup_emit_type (const char *hval, ctf_dict_t *output, ctf_dict_t **inputs,
                     void *arg)
 {
   ctf_dedup_t *d = &output->ctf_dedup;
-  int kind = ctf_type_kind_unsliced (input, type);
+  ctf_kind_t kind = ctf_type_kind_unsliced (input, type);
   const char *name;
   ctf_dict_t *target = output;
   ctf_dict_t *real_input;
index f57667835416165414433325d3c065cb8afaa81b..8a43d43cd8d4092e63aed7fd69023f0c71444fb9 100644 (file)
@@ -97,7 +97,7 @@ ctf_dump_format_type (ctf_dict_t *fp, ctf_id_t id, int flag)
     {
       ctf_encoding_t ep;
       ctf_arinfo_t ar;
-      int kind, unsliced_kind;
+      ctf_kind_t kind, unsliced_kind;
       ssize_t size, align;
       const char *nonroot_leader = "";
       const char *nonroot_trailer = "";
index 4d733adedef6e2e579292b7b9ca58505a6917afa..98812f68de30ba383b5269ade5bc169fbaba6fe9 100644 (file)
@@ -166,7 +166,7 @@ typedef struct ctf_decl_node
 {
   ctf_list_t cd_list;          /* Linked list pointers.  */
   ctf_id_t cd_type;            /* Type identifier.  */
-  uint32_t cd_kind;            /* Type kind.  */
+  ctf_kind_t cd_kind;          /* Type kind.  */
   uint32_t cd_n;               /* Type dimension if array.  */
 } ctf_decl_node_t;
 
@@ -673,15 +673,15 @@ extern ctf_id_t ctf_index_to_type (const ctf_dict_t *, uint32_t);
 #define LCTF_NO_TYPE           0x0010  /* No type additions possible.  */
 #define LCTF_PRESERIALIZED     0x0020  /* Already serialized all but the strtab.  */
 
-extern ctf_dynhash_t *ctf_name_table (ctf_dict_t *, int);
+extern ctf_dynhash_t *ctf_name_table (ctf_dict_t *, ctf_kind_t);
 extern const ctf_type_t *ctf_lookup_by_id (ctf_dict_t **, ctf_id_t,
                                           const ctf_type_t **suffix);
 extern const ctf_type_t *ctf_find_prefix (ctf_dict_t *, const ctf_type_t *,
-                                         int kind);
+                                         ctf_kind_t kind);
 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);
-extern ctf_id_t ctf_lookup_by_rawname (ctf_dict_t *, int, const char *);
+extern ctf_id_t ctf_lookup_by_rawname (ctf_dict_t *, ctf_kind_t, const char *);
 extern ctf_id_t ctf_lookup_by_symbol (ctf_dict_t *, unsigned long);
 extern ctf_id_t ctf_lookup_by_symbol_name (ctf_dict_t *, const char *);
 
@@ -782,20 +782,20 @@ extern void ctf_list_delete (ctf_list_t *, void *);
 extern void ctf_list_splice (ctf_list_t *, ctf_list_t *);
 extern int ctf_list_empty_p (ctf_list_t *lp);
 
-extern int ctf_dtd_insert (ctf_dict_t *, ctf_dtdef_t *, int flag, int kind);
+extern int ctf_dtd_insert (ctf_dict_t *, ctf_dtdef_t *, int flag, ctf_kind_t kind);
 extern void ctf_dtd_delete (ctf_dict_t *, ctf_dtdef_t *);
 extern ctf_dtdef_t *ctf_dtd_lookup (const ctf_dict_t *, ctf_id_t);
 extern ctf_dtdef_t *ctf_dynamic_type (const ctf_dict_t *, ctf_id_t);
 
 extern ctf_id_t ctf_add_encoded (ctf_dict_t *, uint32_t, const char *,
-                                const ctf_encoding_t *, uint32_t kind);
+                                const ctf_encoding_t *, ctf_kind_t kind);
 extern ctf_id_t ctf_add_reftype (ctf_dict_t *, uint32_t, ctf_id_t,
-                                uint32_t kind);
+                                ctf_kind_t kind);
 extern ctf_ret_t ctf_add_funcobjt_sym_forced (ctf_dict_t *, int is_function,
                                              const char *, ctf_id_t);
 
 extern int ctf_insert_type_decl_tag (ctf_dict_t *, ctf_id_t, const char *,
-                                    int kind);
+                                    ctf_kind_t kind);
 extern ctf_ret_t ctf_track_enumerator (ctf_dict_t *, ctf_id_t, const char *);
 
 extern int ctf_dedup_atoms_init (ctf_dict_t *);
@@ -860,10 +860,10 @@ extern char *ctf_str_append_noerr (char *, const char *);
 
 extern ctf_id_t ctf_type_resolve_unsliced (ctf_dict_t *, ctf_id_t);
 extern ctf_id_t ctf_type_resolve_nonrepresentable (ctf_dict_t *, ctf_id_t, int allow_zero);
-extern int ctf_type_kind_unsliced (ctf_dict_t *, ctf_id_t);
-extern int ctf_type_kind_unsliced_tp (ctf_dict_t *, const ctf_type_t *);
-extern int ctf_type_kind_tp (ctf_dict_t *, const ctf_type_t *);
-extern int ctf_type_kind_forwarded_tp (ctf_dict_t *, const ctf_type_t *);
+extern ctf_kind_t ctf_type_kind_unsliced (ctf_dict_t *, ctf_id_t);
+extern ctf_kind_t ctf_type_kind_unsliced_tp (ctf_dict_t *, const ctf_type_t *);
+extern ctf_kind_t ctf_type_kind_tp (ctf_dict_t *, const ctf_type_t *);
+extern ctf_kind_t ctf_type_kind_forwarded_tp (ctf_dict_t *, const ctf_type_t *);
 extern ssize_t ctf_type_align_natural (ctf_dict_t *fp, ctf_id_t prev_type,
                                       ctf_id_t type, ssize_t bit_offset);
 extern ctf_var_secinfo_t *ctf_datasec_entry (ctf_dict_t *, ctf_id_t,
index c11f5e312e24452bbb73550425074b01d0031f6b..f6ba6967c4ac944600b9f9990b1308814ecf1c4f 100644 (file)
@@ -40,8 +40,8 @@ ctf_get_ctt_size (const ctf_dict_t *fp,
   return (fp->ctf_dictops->ctfo_get_ctt_size (fp, tp, sizep, incrementp));
 }
 
-static inline int
-ctf_forwardable_kind (int kind)
+static inline ctf_kind_t
+ctf_forwardable_kind (ctf_kind_t kind)
 {
   return (kind == CTF_K_STRUCT || kind == CTF_K_UNION || kind == CTF_K_ENUM);
 }
index f996e1d2d68de781548e8a096b8297a46c665eff..318b544fd9674d6085fae31875fb3c4e30cadc9b 100644 (file)
@@ -428,9 +428,9 @@ ctf_lookup_by_id (ctf_dict_t **fpp, ctf_id_t type, const ctf_type_t **suffix)
 
 /* Find a given prefix in some type, if any.  */
 const ctf_type_t *
-ctf_find_prefix (ctf_dict_t *fp, const ctf_type_t *tp, int kind)
+ctf_find_prefix (ctf_dict_t *fp, const ctf_type_t *tp, ctf_kind_t kind)
 {
-  uint32_t kind_ = kind;
+  ctf_kind_t kind_ = kind;
 
   while (LCTF_IS_PREFIXED_INFO (tp->ctt_info)
         && CTF_INFO_KIND (tp->ctt_info) != kind_)
@@ -452,7 +452,7 @@ typedef struct ctf_lookup_idx_key
 /* Look up some kind of thing in the name tables.  */
 
 ctf_id_t
-ctf_lookup_by_kind (ctf_dict_t *fp, int kind, const char *name)
+ctf_lookup_by_kind (ctf_dict_t *fp, ctf_kind_t kind, const char *name)
 {
   ctf_id_t type;
 
@@ -581,7 +581,7 @@ ctf_lookup_enumerator_next (ctf_dict_t *fp, const char *name,
        {
          const ctf_type_t *tp;
          ctf_dtdef_t *dtd;
-         int kind;
+         ctf_kind_t kind;
          unsigned char *vlen;
 
          /* It's a shame we can't use ctf_type_kind_next here, but we're
index 4e5b9948c9156ac898633defe726f6615376c1d7..25039c6802210b3036e86882158581e35f69a1f5 100644 (file)
@@ -1,4 +1,4 @@
-/* Opening CTF files: back-compatibility.
+kind/* Opening CTF files: back-compatibility.
    (TODO: not yet implemented, not yet tied in to build system.)
    Copyright (C) 2019-2025 Free Software Foundation, Inc.
 
@@ -121,7 +121,7 @@ upgrade_types_v1 (ctf_dict_t *fp, ctf_header_t *cth)
   for (tp = tbuf; tp < tend;
        tp = (ctf_type_v1_t *) ((uintptr_t) tp + increment + vbytes))
     {
-      unsigned short kind = CTF_V1_INFO_KIND (tp->ctt_info);
+      ctf_kind_t kind = CTF_V1_INFO_KIND (tp->ctt_info);
       unsigned long vlen = CTF_V1_INFO_VLEN (tp->ctt_info);
 
       size = get_ctt_size_v1 (fp, (const ctf_type_t *) tp, NULL, &increment);
@@ -175,7 +175,7 @@ upgrade_types_v1 (ctf_dict_t *fp, ctf_header_t *cth)
        tp = (ctf_type_v1_t *) ((uintptr_t) tp + increment + vbytes),
        t2p = (ctf_type_t *) ((uintptr_t) t2p + v2increment + v2bytes))
     {
-      unsigned short kind = CTF_V1_INFO_KIND (tp->ctt_info);
+      ctf_kind_t kind = CTF_V1_INFO_KIND (tp->ctt_info);
       int isroot = CTF_V1_INFO_ISROOT (tp->ctt_info);
       unsigned long vlen = CTF_V1_INFO_VLEN (tp->ctt_info);
       ssize_t v2size;
@@ -355,7 +355,7 @@ flip_types_v3 (ctf_dict_t *fp, void *start, size_t len, int to_foreign)
 
   while ((uintptr_t) t < ((uintptr_t) start) + len)
     {
-      uint32_t kind;
+      ctf_kind_t kind;
       size_t size;
       uint32_t vlen;
       size_t vbytes;
index 0341b20dd072874ffc24377e986259e8b953ec6e..001dfac942e53f3e2cd9bb9913bc33bbbcb2dc95 100644 (file)
@@ -252,7 +252,7 @@ get_ctt_size_v4 (const ctf_dict_t *fp _libctf_unused_, const ctf_type_t *tp,
 }
 
 static ssize_t
-get_vbytes_old (ctf_dict_t *fp, unsigned short kind, size_t vlen)
+get_vbytes_old (ctf_dict_t *fp, uint32_t kind, size_t vlen)
 {
   switch (kind)
     {
@@ -281,7 +281,7 @@ get_vbytes_old (ctf_dict_t *fp, unsigned short kind, size_t vlen)
 static ssize_t
 get_vbytes_v1 (ctf_dict_t *fp, const ctf_type_t *tp, ssize_t size)
 {
-  unsigned short kind = CTF_V1_INFO_KIND (tp->ctt_info);
+  uint32_t kind = CTF_V1_INFO_KIND (tp->ctt_info);
   size_t vlen = CTF_V1_INFO_VLEN (tp->ctt_info);
 
   switch (kind)
@@ -304,7 +304,7 @@ get_vbytes_v1 (ctf_dict_t *fp, const ctf_type_t *tp, ssize_t size)
 static ssize_t
 get_vbytes_v2 (ctf_dict_t *fp, const ctf_type_t *tp, ssize_t size)
 {
-  unsigned short kind = CTF_V2_INFO_KIND (tp->ctt_info);
+  uint32_t kind = CTF_V2_INFO_KIND (tp->ctt_info);
   size_t vlen = CTF_V2_INFO_VLEN (tp->ctt_info);
 
   switch (kind)
@@ -328,7 +328,7 @@ static ssize_t
 get_vbytes_v4 (ctf_dict_t *fp, const ctf_type_t *tp,
               ssize_t size _libctf_unused_)
 {
-  unsigned short kind = LCTF_KIND (fp, tp);
+  uint32_t kind = LCTF_KIND (fp, tp);
   ssize_t vlen = LCTF_VLEN (fp, tp);
 
   switch (kind)
@@ -627,7 +627,7 @@ init_static_types (ctf_dict_t *fp, ctf_header_t *cth, int is_btf)
 
   for (tp = tbuf; tp < tend; typemax++)
     {
-      unsigned short kind = LCTF_INFO_UNPREFIXED_KIND (fp, tp->ctt_info);
+      ctf_kind_t kind = LCTF_INFO_UNPREFIXED_KIND (fp, tp->ctt_info);
       size_t vlen = LCTF_VLEN (fp, tp);
       int nonroot = 0;
       ssize_t size, increment, vbytes;
@@ -848,7 +848,7 @@ init_static_types_names_internal (ctf_dict_t *fp, ctf_header_t *cth, int is_btf,
 
   for (id = 1, tp = tbuf; tp < tend; xp++, id++)
     {
-      unsigned short kind = LCTF_KIND (fp, tp);
+      ctf_kind_t kind = LCTF_KIND (fp, tp);
       unsigned short isroot = LCTF_INFO_ISROOT (fp, tp->ctt_info);
       size_t vlen = LCTF_VLEN (fp, tp);
       ssize_t size, increment, vbytes;
@@ -1334,8 +1334,8 @@ flip_types (ctf_dict_t *fp, void *start, size_t len, int to_foreign)
 
   while ((uintptr_t) t < ((uintptr_t) start) + len)
     {
-      uint32_t kind;
-      uint32_t raw_kind;
+      ctf_kind_t kind;
+      ctf_kind_t raw_kind;
       uint32_t vlen;
       size_t vbytes;
       ctf_type_t *tprefixed;
index a098a4fe4e4371972ad972668b871fe2d67df8f0..695b899afa75b285bcf7bdb58913c0db1f26fef2 100644 (file)
@@ -769,7 +769,7 @@ symerr:
 /* Kind suppression.  */
 
 ctf_ret_t
-ctf_write_suppress_kind (ctf_dict_t *fp, int kind, int prohibited)
+ctf_write_suppress_kind (ctf_dict_t *fp, ctf_kind_t kind, int prohibited)
 {
   ctf_dynset_t *set;
 
@@ -793,7 +793,7 @@ ctf_write_suppress_kind (ctf_dict_t *fp, int kind, int prohibited)
        fp->ctf_write_suppressions = set;
     }
 
-  if ((ctf_dynset_cinsert (set, (const void *) (uintptr_t) kind)) < 0)
+  if ((ctf_dynset_cinsert (set, (const void *) (ctf_kind_t) kind)) < 0)
     return (ctf_set_errno (fp, errno));
 
   return 0;
@@ -808,7 +808,7 @@ static int
 ctf_prefix_elidable (ctf_dict_t *fp, uint32_t kind, ctf_dtdef_t *dtd,
                     ctf_type_t *prefix)
 {
-  int prefix_kind = LCTF_INFO_UNPREFIXED_KIND (fp, prefix->ctt_info);
+  ctf_kind_t prefix_kind = LCTF_INFO_UNPREFIXED_KIND (fp, prefix->ctt_info);
 
   if ((prefix_kind == CTF_K_BIG) && prefix->ctt_size == 0
       && LCTF_INFO_UNPREFIXED_VLEN (fp, prefix->ctt_info) == 0)
@@ -857,7 +857,7 @@ ctf_type_sect_is_btf (ctf_dict_t *fp, int force_ctf)
       while ((err = ctf_dynset_next (fp->ctf_write_prohibitions,
                                     &prohibit_i, &pkind)) == 0)
        {
-         int kind = (uintptr_t) pkind;
+         ctf_kind_t kind = (ctf_kind_t) pkind;
 
          if (ctf_type_kind_next (fp, &i, kind) != CTF_ERR)
            {
@@ -889,8 +889,8 @@ ctf_type_sect_is_btf (ctf_dict_t *fp, int force_ctf)
        dtd != NULL; dtd = ctf_list_next (dtd))
     {
       ctf_type_t *tp = dtd->dtd_buf;
-      uint32_t kind = LCTF_KIND (fp, dtd->dtd_buf);
-      uint32_t prefix_kind;
+      ctf_kind_t kind = LCTF_KIND (fp, dtd->dtd_buf);
+      ctf_kind_t prefix_kind;
 
       /* Any un-suppressed prefixes other than an empty/redundant CTF_K_BIG must
         be CTF. (Redundant CTF_K_BIGs will be elided instead.)  */
@@ -901,7 +901,7 @@ ctf_type_sect_is_btf (ctf_dict_t *fp, int force_ctf)
          if (!ctf_prefix_elidable (fp, kind, dtd, tp))
            if (!fp->ctf_write_suppressions
                || ctf_dynset_lookup (fp->ctf_write_suppressions,
-                                     (const void *) (uintptr_t) prefix_kind) == NULL)
+                                     (const void *) (ctf_kind_t) prefix_kind) == NULL)
            return 0;
 
          tp++;
@@ -912,7 +912,7 @@ ctf_type_sect_is_btf (ctf_dict_t *fp, int force_ctf)
 
       if (fp->ctf_write_suppressions
          && ctf_dynset_lookup (fp->ctf_write_suppressions,
-                               (const void *) (uintptr_t) kind))
+                               (const void *) (ctf_kind_t) kind))
        continue;
 
       if (kind == CTF_K_FLOAT || kind == CTF_K_SLICE)
@@ -937,8 +937,8 @@ ctf_type_sect_size (ctf_dict_t *fp)
   for (dtd = ctf_list_next (&fp->ctf_dtdefs);
        dtd != NULL; dtd = ctf_list_next (dtd))
     {
-      uint32_t kind = LCTF_KIND (fp, dtd->dtd_buf);
-      uint32_t prefix_kind;
+      ctf_kind_t kind = LCTF_KIND (fp, dtd->dtd_buf);
+      ctf_kind_t prefix_kind;
       ctf_type_t *tp = dtd->dtd_buf;
 
       /* Check for suppressions: a suppression consumes precisely one ctf_type_t
@@ -953,7 +953,7 @@ ctf_type_sect_size (ctf_dict_t *fp)
            {
              if (!ctf_prefix_elidable (fp, kind, dtd, tp)
                  && (ctf_dynset_lookup (fp->ctf_write_suppressions,
-                                        (const void *) (uintptr_t) prefix_kind) != NULL))
+                                        (const void *) (ctf_kind_t) prefix_kind) != NULL))
                {
                  type_size += sizeof (ctf_type_t);
                  suppress = 1;
@@ -1006,8 +1006,8 @@ ctf_emit_type_sect (ctf_dict_t *fp, unsigned char **tptr,
   for (dtd = ctf_list_next (&fp->ctf_dtdefs);
        dtd != NULL; dtd = ctf_list_next (dtd), id++)
     {
-      uint32_t prefix_kind;
-      uint32_t kind = LCTF_KIND (fp, dtd->dtd_buf);
+      ctf_kind_t prefix_kind;
+      ctf_kind_t kind = LCTF_KIND (fp, dtd->dtd_buf);
       size_t vlen = LCTF_VLEN (fp, dtd->dtd_buf);
       ctf_type_t *tp = dtd->dtd_buf;
       ctf_type_t *copied;
@@ -1037,7 +1037,7 @@ ctf_emit_type_sect (ctf_dict_t *fp, unsigned char **tptr,
 
          if (!fp->ctf_write_suppressions
              || ctf_dynset_lookup (fp->ctf_write_suppressions,
-                                   (const void *) (uintptr_t) prefix_kind) == NULL)
+                                   (const void *) (ctf_kind_t) prefix_kind) == NULL)
            {
              if (_libctf_btf_mode == LIBCTF_BTM_BTF)
                {
@@ -1056,7 +1056,7 @@ ctf_emit_type_sect (ctf_dict_t *fp, unsigned char **tptr,
 
       if (fp->ctf_write_suppressions
          && ctf_dynset_lookup (fp->ctf_write_suppressions,
-                               (const void *) (uintptr_t) kind) != NULL)
+                               (const void *) (ctf_kind_t) kind) != NULL)
        suppress = 1;
 
       if (suppress)
@@ -1152,6 +1152,22 @@ ctf_emit_type_sect (ctf_dict_t *fp, unsigned char **tptr,
            return -1;                          /* errno is set for us.  */
          break;
 
+       /* These kinds have no strings or type IDs in them, and so don't need
+          any special treatment.  */
+       case CTF_K_INTEGER:
+       case CTF_K_FORWARD:
+       case CTF_K_FLOAT:
+       case CTF_K_BTF_FLOAT:
+       case CTF_K_UNKNOWN:
+         break;
+
+       /* These kinds are prefixes, and cannot appear here.  */
+       case CTF_K_BIG:
+       case CTF_K_CONFLICTING:
+         ctf_err_warn (fp, 1, ECTF_INTERNAL, "type %lx: prefix type found during serialization",
+                       id);
+         break;
+
        case CTF_K_SLICE:
          {
            ctf_slice_t *slice = (ctf_slice_t *) t;
index 880b62604848eb35c470a5b65cba72863588669f..c96fa31ee4d519383025ca8a1b7bd31ba351d29e 100644 (file)
@@ -172,7 +172,7 @@ ctf_member_next (ctf_dict_t *fp, ctf_id_t type, ctf_next_t **it,
                 int *bit_width, int flags)
 {
   ctf_dict_t *ofp = fp;
-  uint32_t kind;
+  ctf_kind_t kind;
   ssize_t offset;
   size_t nmemb;
   unsigned char *vlen;
@@ -370,7 +370,7 @@ ctf_enum_next (ctf_dict_t *fp, ctf_id_t type, ctf_next_t **it,
               int64_t *val)
 {
   ctf_dict_t *ofp = fp;
-  uint32_t kind;
+  ctf_kind_t kind;
   const char *name;
   ctf_next_t *i = *it;
   ctf_error_t err;
@@ -550,7 +550,7 @@ ctf_type_next (ctf_dict_t *fp, ctf_next_t **it, int *flag, int want_hidden)
    of a single parent.  */
 
 ctf_id_t
-ctf_type_kind_next (ctf_dict_t *fp, ctf_next_t **it, int kind)
+ctf_type_kind_next (ctf_dict_t *fp, ctf_next_t **it, ctf_kind_t kind)
 {
   ctf_next_t *i = *it;
   ctf_error_t err;
@@ -897,7 +897,7 @@ ctf_get_dict (const ctf_dict_t *fp, ctf_id_t type)
 /* Look up a name in the given name table, in the appropriate hash given the
    kind of the identifier.  The name is a raw, undecorated identifier.  */
 
-ctf_id_t ctf_lookup_by_rawname (ctf_dict_t *fp, int kind, const char *name)
+ctf_id_t ctf_lookup_by_rawname (ctf_dict_t *fp, ctf_kind_t kind, const char *name)
 {
   return (ctf_id_t) (uintptr_t)
     ctf_dynhash_lookup (ctf_name_table (fp, kind), name);
@@ -1164,6 +1164,13 @@ ctf_type_aname (ctf_dict_t *fp, ctf_id_t type)
                ctf_decl_sprintf (&cd, _("(nonrepresentable type %s)"),
                                  name);
              break;
+           /* CTF_K_SLICE has no print representation: see ctf_decl_push().  */
+           case CTF_K_SLICE:
+           /* CTF_K_BIG and CTF_K_CONFLICTING cannot appear and have no print
+              representation.  */
+           case CTF_K_BIG:
+           case CTF_K_CONFLICTING:
+             break;
            }
 
          k = cdp->cd_kind;
@@ -1354,7 +1361,7 @@ ctf_type_align (ctf_dict_t *fp, ctf_id_t type)
 {
   const ctf_type_t *tp;
   ctf_dict_t *ofp = fp;
-  int kind;
+  ctf_kind_t kind;
 
   if ((type = ctf_type_resolve (fp, type)) == CTF_ERR)
     return -1;                 /* errno is set for us.  */
@@ -1416,7 +1423,7 @@ ctf_type_align (ctf_dict_t *fp, ctf_id_t type)
    Pretend that all forwards are of type CTF_K_FORWARD, for ease of
    use and compatibility.  */
 
-int
+ctf_kind_t
 ctf_type_kind_unsliced_tp (ctf_dict_t *fp, const ctf_type_t *tp)
 {
   if (LCTF_KIND (fp, tp) == CTF_K_ENUM
@@ -1429,10 +1436,10 @@ ctf_type_kind_unsliced_tp (ctf_dict_t *fp, const ctf_type_t *tp)
 /* Return the kind (CTF_K_* constant) for the specified type pointer.
    Slices are considered to be of the same kind as the type sliced.  */
 
-int
+ctf_kind_t
 ctf_type_kind_tp (ctf_dict_t *fp, const ctf_type_t *tp)
 {
-  int kind;
+  ctf_kind_t kind;
 
   if ((kind = ctf_type_kind_unsliced_tp (fp, tp)) < 0)
     return -1;                 /* errno is set for us.  */
@@ -1453,10 +1460,10 @@ ctf_type_kind_tp (ctf_dict_t *fp, const ctf_type_t *tp)
 
 /* Return the kind of this type pointer, except, for forwards, return the kind
    of thing this is a forward to.  */
-int
+ctf_kind_t
 ctf_type_kind_forwarded_tp (ctf_dict_t *fp, const ctf_type_t *tp)
 {
-  int kind;
+  ctf_kind_t kind;
 
   if ((kind = ctf_type_kind_tp (fp, tp)) < 0)
     return -1;                 /* errno is set for us.  */
@@ -1479,7 +1486,7 @@ ctf_type_kind_forwarded_tp (ctf_dict_t *fp, const ctf_type_t *tp)
    Pretend that all forwards are of type CTF_K_FORWARD, for ease of
    use and compatibility.  */
 
-int
+ctf_kind_t
 ctf_type_kind_unsliced (ctf_dict_t *fp, ctf_id_t type)
 {
   const ctf_type_t *tp;
@@ -1493,10 +1500,10 @@ ctf_type_kind_unsliced (ctf_dict_t *fp, ctf_id_t type)
 /* Return the kind (CTF_K_* constant) for the specified type ID.
    Slices are considered to be of the same kind as the type sliced.  */
 
-int
+ctf_kind_t
 ctf_type_kind (ctf_dict_t *fp, ctf_id_t type)
 {
-  int kind;
+  ctf_kind_t kind;
 
   if ((kind = ctf_type_kind_unsliced (fp, type)) < 0)
     return -1;
@@ -1513,10 +1520,10 @@ ctf_type_kind (ctf_dict_t *fp, ctf_id_t type)
 
 /* Return the kind of this type, except, for forwards, return the kind of thing
    this is a forward to.  */
-int
+ctf_kind_t
 ctf_type_kind_forwarded (ctf_dict_t *fp, ctf_id_t type)
 {
-  int ret;
+  ctf_kind_t ret;
   ctf_dict_t *ofp = fp;
   const ctf_type_t *tp, *suffix;
 
@@ -1643,7 +1650,7 @@ ctf_decl_tag (ctf_dict_t *fp, ctf_id_t decl_tag, int64_t *component_idx)
 ctf_id_t
 ctf_tag (ctf_dict_t *fp, ctf_id_t tag)
 {
-  int kind = ctf_type_kind (fp, tag);
+  ctf_kind_t kind = ctf_type_kind (fp, tag);
   int64_t component_idx;
   ctf_id_t ref;
 
@@ -1876,7 +1883,7 @@ ctf_type_compat (ctf_dict_t *lfp, ctf_id_t ltype,
   const ctf_type_t *ltp, *rtp;
   ctf_encoding_t le, re;
   ctf_arinfo_t la, ra;
-  int lkind, rkind;
+  ctf_kind_t lkind, rkind;
   int same_names = 0;
 
   if (lfp->ctf_flags & LCTF_NO_STR)
@@ -1977,7 +1984,7 @@ ctf_member_count (ctf_dict_t *fp, ctf_id_t type)
 {
   ctf_dict_t *ofp = fp;
   const ctf_type_t *tp;
-  uint32_t kind;
+  ctf_kind_t kind;
 
   if ((type = ctf_type_resolve (fp, type)) == CTF_ERR)
     return -1;                 /* errno is set for us.  */
@@ -2004,7 +2011,8 @@ ctf_member_info (ctf_dict_t *fp, ctf_id_t type, const char *name,
   int big = 0;
   size_t total_offset = 0;
   unsigned char *vlen;
-  uint32_t kind, i = 0;
+  ctf_kind_t kind;
+  uint32_t i = 0;
   size_t n;
 
   if (fp->ctf_flags & LCTF_NO_STR)
@@ -2119,7 +2127,7 @@ ctf_enum_name (ctf_dict_t *fp, ctf_id_t type, int64_t value)
   ctf_dict_t *ofp = fp;
   const ctf_type_t *tp;
   unsigned char *vlen;
-  int kind;
+  ctf_kind_t kind;
   size_t n;
 
   if (fp->ctf_flags & LCTF_NO_STR)
@@ -2179,7 +2187,7 @@ ctf_enum_value (ctf_dict_t *fp, ctf_id_t type, const char *name, int64_t *valp)
   ctf_dict_t *ofp = fp;
   const ctf_type_t *tp;
   unsigned char *vlen;
-  int kind;
+  ctf_kind_t kind;
   size_t n;
 
   if (fp->ctf_flags & LCTF_NO_STR)
@@ -2245,7 +2253,7 @@ ctf_enum_unsigned_value (ctf_dict_t *fp, ctf_id_t type, const char *name, uint64
 ctf_bool_t
 ctf_enum_unsigned (ctf_dict_t *fp, ctf_id_t type)
 {
-  int kind;
+  ctf_kind_t kind;
   const ctf_type_t *tp;                /* The suffixed kind, if prefixed */
 
   if ((kind = ctf_type_kind (fp, type)) < 0)
@@ -2264,7 +2272,7 @@ ctf_enum_unsigned (ctf_dict_t *fp, ctf_id_t type)
 ctf_bool_t
 ctf_struct_bitfield (ctf_dict_t * fp, ctf_id_t type)
 {
-  int kind;
+  ctf_kind_t kind;
   const ctf_type_t *tp;                /* The suffixed kind, if prefixed */
 
   if ((kind = ctf_type_kind (fp, type)) < 0)
@@ -2287,7 +2295,7 @@ ctf_func_type_info (ctf_dict_t *fp, ctf_id_t type, ctf_funcinfo_t *fip)
 {
   ctf_dict_t *ofp = fp;
   const ctf_type_t *tp, *suffix;
-  uint32_t kind;
+  ctf_kind_t kind;
   unsigned char *vlen;
   const ctf_param_t *args;
 
@@ -2393,8 +2401,7 @@ ctf_type_linkage (ctf_dict_t *fp, ctf_id_t type)
   const ctf_type_t *suffix;
   unsigned char *vlen;
   ctf_linkage_t *l;
-
-  int kind;
+  ctf_kind_t kind;
 
   if ((tp = ctf_lookup_by_id (&fp, type, &suffix)) == NULL)
     return -1;                 /* errno is set for us.  */
@@ -2532,7 +2539,7 @@ ctf_type_rvisit (ctf_dict_t *fp, ctf_id_t type, ctf_visit_f *func,
 {
   ctf_id_t otype = type;
   int nonrepresentable = 0;
-  uint32_t kind;
+  ctf_kind_t kind;
   ctf_next_t *it = NULL;
   ctf_id_t membtype;
   ssize_t this_offset;