]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/ctfread.c
CTF: handle forward reference type
[thirdparty/binutils-gdb.git] / gdb / ctfread.c
index b8d8434f6cab016719ac32ddbc246ee0d38e07a5..e2b65b622de20d6f5a0268931a64371264fba101 100644 (file)
@@ -1,6 +1,6 @@
 /* Compact ANSI-C Type Format (CTF) support in GDB.
 
-   Copyright (C) 2019-2020 Free Software Foundation, Inc.
+   Copyright (C) 2019-2021 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -91,30 +91,31 @@ static const struct objfile_key<htab, htab_deleter> ctf_tid_key;
 
 struct ctf_fp_info
 {
-  explicit ctf_fp_info (ctf_file_t *cfp) : fp (cfp) {}
+  explicit ctf_fp_info (ctf_dict_t *cfp) : fp (cfp) {}
   ~ctf_fp_info ();
-  ctf_file_t *fp;
+  ctf_dict_t *fp;
 };
 
-/* Cleanup function for the ctf_file_key data.  */
+/* Cleanup function for the ctf_dict_key data.  */
 ctf_fp_info::~ctf_fp_info ()
 {
-  if (!fp)
+  if (fp == nullptr)
     return;
 
   ctf_archive_t *arc = ctf_get_arc (fp);
-  ctf_file_close (fp);
+  ctf_dict_close (fp);
   ctf_close (arc);
 }
 
-static const objfile_key<ctf_fp_info> ctf_file_key;
+static const objfile_key<ctf_fp_info> ctf_dict_key;
 
 /* A CTF context consists of a file pointer and an objfile pointer.  */
 
 struct ctf_context
 {
-  ctf_file_t *fp;
+  ctf_dict_t *fp;
   struct objfile *of;
+  psymtab_storage *partial_symtabs;
   partial_symtab *pst;
   struct buildsym_compunit *builder;
 };
@@ -122,8 +123,11 @@ struct ctf_context
 /* A partial symtab, specialized for this module.  */
 struct ctf_psymtab : public standard_psymtab
 {
-  ctf_psymtab (const char *filename, struct objfile *objfile, CORE_ADDR addr)
-    : standard_psymtab (filename, objfile, addr)
+  ctf_psymtab (const char *filename,
+              psymtab_storage *partial_symtabs,
+              objfile_per_bfd_storage *objfile_per_bfd,
+              CORE_ADDR addr)
+    : standard_psymtab (filename, partial_symtabs, objfile_per_bfd, addr)
   {
   }
 
@@ -186,6 +190,8 @@ static void process_structure_type (struct ctf_context *cp, ctf_id_t tid);
 static void process_struct_members (struct ctf_context *cp, ctf_id_t tid,
                                    struct type *type);
 
+static struct type *read_forward_type (struct ctf_context *cp, ctf_id_t tid);
+
 static struct symbol *new_symbol (struct ctf_context *cp, struct type *type,
                                  ctf_id_t tid);
 
@@ -258,21 +264,40 @@ get_tid_type (struct objfile *of, ctf_id_t tid)
 
   htab = (htab_t) ctf_tid_key.get (of);
   if (htab == NULL)
-    return NULL;
+    return nullptr;
 
   ids.tid = tid;
-  ids.type = NULL;
+  ids.type = nullptr;
   slot = (struct ctf_tid_and_type *) htab_find (htab, &ids);
   if (slot)
     return slot->type;
   else
-    return NULL;
+    return nullptr;
+}
+
+/* Fetch the type for TID in CCP OF's tid_and_type hash, add the type to
+ *    context CCP if hash is empty or TID does not have a saved type.  */
+
+static struct type *
+fetch_tid_type (struct ctf_context *ccp, ctf_id_t tid)
+{
+  struct objfile *of = ccp->of;
+  struct type *typ;
+
+  typ = get_tid_type (of, tid);
+  if (typ == nullptr)
+    {
+      ctf_add_type_cb (tid, ccp);
+      typ = get_tid_type (of, tid);
+    }
+
+  return typ;
 }
 
 /* Return the size of storage in bits for INTEGER, FLOAT, or ENUM.  */
 
 static int
-get_bitsize (ctf_file_t *fp, ctf_id_t tid, uint32_t kind)
+get_bitsize (ctf_dict_t *fp, ctf_id_t tid, uint32_t kind)
 {
   ctf_encoding_t cet;
 
@@ -292,12 +317,12 @@ set_symbol_address (struct objfile *of, struct symbol *sym, const char *name)
 {
   struct bound_minimal_symbol msym;
 
-  msym = lookup_minimal_symbol (name, NULL, of);
+  msym = lookup_minimal_symbol (name, nullptr, of);
   if (msym.minsym != NULL)
     {
       SET_SYMBOL_VALUE_ADDRESS (sym, BMSYMBOL_VALUE_ADDRESS (msym));
       SYMBOL_ACLASS_INDEX (sym) = LOC_STATIC;
-      SYMBOL_SECTION (sym) = MSYMBOL_SECTION (msym.minsym);
+      sym->set_section_index (msym.minsym->section_index ());
     }
 }
 
@@ -339,7 +364,7 @@ ctf_init_float_type (struct objfile *objfile,
   struct type *type;
 
   format = gdbarch_floatformat_for_type (gdbarch, name_hint, bits);
-  if (format != NULL)
+  if (format != nullptr)
     type = init_float_type (objfile, bits, name, format);
   else
     type = init_type (objfile, TYPE_CODE_ERROR, bits, name);
@@ -368,11 +393,11 @@ ctf_add_member_cb (const char *name,
   FIELD_NAME (*fp) = name;
 
   kind = ctf_type_kind (ccp->fp, tid);
-  t = get_tid_type (ccp->of, tid);
-  if (t == NULL)
+  t = fetch_tid_type (ccp, tid);
+  if (t == nullptr)
     {
       t = read_type_record (ccp, tid);
-      if (t == NULL)
+      if (t == nullptr)
        {
          complaint (_("ctf_add_member_cb: %s has NO type (%ld)"), name, tid);
          t = objfile_type (ccp->of)->builtin_error;
@@ -405,11 +430,11 @@ ctf_add_enum_member_cb (const char *name, int enum_value, void *arg)
 
   fp = &new_field.field;
   FIELD_NAME (*fp) = name;
-  fp->set_type (NULL);
+  fp->set_type (nullptr);
   SET_FIELD_ENUMVAL (*fp, enum_value);
   FIELD_BITSIZE (*fp) = 0;
 
-  if (name != NULL)
+  if (name != nullptr)
     {
       struct symbol *sym = new (&ccp->of->objfile_obstack) symbol;
       OBJSTAT (ccp->of, n_syms++);
@@ -434,11 +459,11 @@ static struct symbol *
 new_symbol (struct ctf_context *ccp, struct type *type, ctf_id_t tid)
 {
   struct objfile *objfile = ccp->of;
-  ctf_file_t *fp = ccp->fp;
-  struct symbol *sym = NULL;
+  ctf_dict_t *fp = ccp->fp;
+  struct symbol *sym = nullptr;
 
   gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (fp, tid));
-  if (name != NULL)
+  if (name != nullptr)
     {
       sym = new (&objfile->objfile_obstack) symbol;
       OBJSTAT (objfile, n_syms++);
@@ -448,7 +473,7 @@ new_symbol (struct ctf_context *ccp, struct type *type, ctf_id_t tid)
       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
       SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
 
-      if (type != NULL)
+      if (type != nullptr)
        SYMBOL_TYPE (sym) = type;
 
       uint32_t kind = ctf_type_kind (fp, tid);
@@ -497,9 +522,9 @@ static struct type *
 read_base_type (struct ctf_context *ccp, ctf_id_t tid)
 {
   struct objfile *of = ccp->of;
-  ctf_file_t *fp = ccp->fp;
+  ctf_dict_t *fp = ccp->fp;
   ctf_encoding_t cet;
-  struct type *type = NULL;
+  struct type *type = nullptr;
   char *name;
   uint32_t kind;
 
@@ -507,14 +532,14 @@ read_base_type (struct ctf_context *ccp, ctf_id_t tid)
     {
       complaint (_("ctf_type_encoding read_base_type failed - %s"),
                 ctf_errmsg (ctf_errno (fp)));
-      return NULL;
+      return nullptr;
     }
 
   gdb::unique_xmalloc_ptr<char> copied_name (ctf_type_aname_raw (fp, tid));
-  if (copied_name == NULL || strlen (copied_name.get ()) == 0)
+  if (copied_name == nullptr || strlen (copied_name.get ()) == 0)
     {
       name = ctf_type_aname (fp, tid);
-      if (name == NULL)
+      if (name == nullptr)
        complaint (_("ctf_type_aname read_base_type failed - %s"),
                   ctf_errmsg (ctf_errno (fp)));
     }
@@ -566,7 +591,7 @@ read_base_type (struct ctf_context *ccp, ctf_id_t tid)
       type = init_type (of, TYPE_CODE_ERROR, cet.cte_bits, name);
     }
 
-  if (name != NULL && strcmp (name, "char") == 0)
+  if (name != nullptr && strcmp (name, "char") == 0)
     type->set_has_no_signedness (true);
 
   return set_tid_type (of, tid, type);
@@ -592,14 +617,14 @@ static struct type *
 read_structure_type (struct ctf_context *ccp, ctf_id_t tid)
 {
   struct objfile *of = ccp->of;
-  ctf_file_t *fp = ccp->fp;
+  ctf_dict_t *fp = ccp->fp;
   struct type *type;
   uint32_t kind;
 
   type = alloc_type (of);
 
   gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (fp, tid));
-  if (name != NULL && strlen (name.get() ) != 0)
+  if (name != nullptr && strlen (name.get ()) != 0)
     type->set_name (obstack_strdup (&of->objfile_obstack, name.get ()));
 
   kind = ctf_type_kind (fp, tid);
@@ -650,22 +675,49 @@ static struct type *
 read_func_kind_type (struct ctf_context *ccp, ctf_id_t tid)
 {
   struct objfile *of = ccp->of;
-  ctf_file_t *fp = ccp->fp;
-  struct type *type, *rettype;
+  ctf_dict_t *fp = ccp->fp;
+  struct type *type, *rettype, *atype;
   ctf_funcinfo_t cfi;
+  uint32_t argc;
 
   type = alloc_type (of);
 
   gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (fp, tid));
-  if (name != NULL && strlen (name.get ()) != 0)
+  if (name != nullptr && strlen (name.get ()) != 0)
     type->set_name (obstack_strdup (&of->objfile_obstack, name.get ()));
 
   type->set_code (TYPE_CODE_FUNC);
   ctf_func_type_info (fp, tid, &cfi);
-  rettype = get_tid_type (of, cfi.ctc_return);
+  rettype = fetch_tid_type (ccp, cfi.ctc_return);
   TYPE_TARGET_TYPE (type) = rettype;
   set_type_align (type, ctf_type_align (fp, tid));
 
+  /* Set up function's arguments.  */
+  argc = cfi.ctc_argc;
+  type->set_num_fields (argc);
+  if ((cfi.ctc_flags & CTF_FUNC_VARARG) != 0)
+    type->set_has_varargs (true);
+
+  if (argc != 0)
+    {
+      std::vector<ctf_id_t> argv (argc);
+      if (ctf_func_type_args (fp, tid, argc, argv.data ()) == CTF_ERR)
+       return nullptr;
+
+      type->set_fields
+       ((struct field *) TYPE_ZALLOC (type, argc * sizeof (struct field)));
+      struct type *void_type = objfile_type (of)->builtin_void;
+      /* If failed to find the argument type, fill it with void_type.  */
+      for (int iparam = 0; iparam < argc; iparam++)
+       {
+         atype = get_tid_type (of, argv[iparam]);
+         if (atype != nullptr)
+           type->field (iparam).set_type (atype);
+         else
+           type->field (iparam).set_type (void_type);
+       }
+    }
+
   return set_tid_type (of, tid, type);
 }
 
@@ -676,14 +728,14 @@ static struct type *
 read_enum_type (struct ctf_context *ccp, ctf_id_t tid)
 {
   struct objfile *of = ccp->of;
-  ctf_file_t *fp = ccp->fp;
+  ctf_dict_t *fp = ccp->fp;
   struct type *type, *target_type;
   ctf_funcinfo_t fi;
 
   type = alloc_type (of);
 
   gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (fp, tid));
-  if (name != NULL && strlen (name.get ()) != 0)
+  if (name != nullptr && strlen (name.get ()) != 0)
     type->set_name (obstack_strdup (&of->objfile_obstack, name.get ()));
 
   type->set_code (TYPE_CODE_ENUM);
@@ -740,7 +792,7 @@ add_array_cv_type (struct ctf_context *ccp,
   el_type = TYPE_TARGET_TYPE (inner_array);
   cnst |= TYPE_CONST (el_type);
   voltl |= TYPE_VOLATILE (el_type);
-  TYPE_TARGET_TYPE (inner_array) = make_cv_type (cnst, voltl, el_type, NULL);
+  TYPE_TARGET_TYPE (inner_array) = make_cv_type (cnst, voltl, el_type, nullptr);
 
   return set_tid_type (ccp->of, tid, base_type);
 }
@@ -751,7 +803,7 @@ static struct type *
 read_array_type (struct ctf_context *ccp, ctf_id_t tid)
 {
   struct objfile *objfile = ccp->of;
-  ctf_file_t *fp = ccp->fp;
+  ctf_dict_t *fp = ccp->fp;
   struct type *element_type, *range_type, *idx_type;
   struct type *type;
   ctf_arinfo_t ar;
@@ -760,15 +812,15 @@ read_array_type (struct ctf_context *ccp, ctf_id_t tid)
     {
       complaint (_("ctf_array_info read_array_type failed - %s"),
                 ctf_errmsg (ctf_errno (fp)));
-      return NULL;
+      return nullptr;
     }
 
-  element_type = get_tid_type (objfile, ar.ctr_contents);
-  if (element_type == NULL)
-    return NULL;
+  element_type = fetch_tid_type (ccp, ar.ctr_contents);
+  if (element_type == nullptr)
+    return nullptr;
 
-  idx_type = get_tid_type (objfile, ar.ctr_index);
-  if (idx_type == NULL)
+  idx_type = fetch_tid_type (ccp, ar.ctr_index);
+  if (idx_type == nullptr)
     idx_type = objfile_type (objfile)->builtin_int;
 
   range_type = create_static_range_type (NULL, idx_type, 0, ar.ctr_nelems - 1);
@@ -795,11 +847,11 @@ read_const_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid)
   struct objfile *objfile = ccp->of;
   struct type *base_type, *cv_type;
 
-  base_type = get_tid_type (objfile, btid);
-  if (base_type == NULL)
+  base_type = fetch_tid_type (ccp, btid);
+  if (base_type == nullptr)
     {
       base_type = read_type_record (ccp, btid);
-      if (base_type == NULL)
+      if (base_type == nullptr)
        {
          complaint (_("read_const_type: NULL base type (%ld)"), btid);
          base_type = objfile_type (objfile)->builtin_error;
@@ -816,14 +868,14 @@ static struct type *
 read_volatile_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid)
 {
   struct objfile *objfile = ccp->of;
-  ctf_file_t *fp = ccp->fp;
+  ctf_dict_t *fp = ccp->fp;
   struct type *base_type, *cv_type;
 
-  base_type = get_tid_type (objfile, btid);
-  if (base_type == NULL)
+  base_type = fetch_tid_type (ccp, btid);
+  if (base_type == nullptr)
     {
       base_type = read_type_record (ccp, btid);
-      if (base_type == NULL)
+      if (base_type == nullptr)
        {
          complaint (_("read_volatile_type: NULL base type (%ld)"), btid);
          base_type = objfile_type (objfile)->builtin_error;
@@ -845,11 +897,11 @@ read_restrict_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid)
   struct objfile *objfile = ccp->of;
   struct type *base_type, *cv_type;
 
-  base_type = get_tid_type (objfile, btid);
-  if (base_type == NULL)
+  base_type = fetch_tid_type (ccp, btid);
+  if (base_type == nullptr)
     {
       base_type = read_type_record (ccp, btid);
-      if (base_type == NULL)
+      if (base_type == nullptr)
        {
          complaint (_("read_restrict_type: NULL base type (%ld)"), btid);
          base_type = objfile_type (objfile)->builtin_error;
@@ -872,11 +924,11 @@ read_typedef_type (struct ctf_context *ccp, ctf_id_t tid,
   char *aname = obstack_strdup (&objfile->objfile_obstack, name);
   this_type = init_type (objfile, TYPE_CODE_TYPEDEF, 0, aname);
   set_tid_type (objfile, tid, this_type);
-  target_type = get_tid_type (objfile, btid);
+  target_type = fetch_tid_type (ccp, btid);
   if (target_type != this_type)
     TYPE_TARGET_TYPE (this_type) = target_type;
   else
-    TYPE_TARGET_TYPE (this_type) = NULL;
+    TYPE_TARGET_TYPE (this_type) = nullptr;
 
   this_type->set_target_is_stub (TYPE_TARGET_TYPE (this_type) != nullptr);
 
@@ -891,11 +943,11 @@ read_pointer_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid)
   struct objfile *of = ccp->of;
   struct type *target_type, *type;
 
-  target_type = get_tid_type (of, btid);
-  if (target_type == NULL)
+  target_type = fetch_tid_type (ccp, btid);
+  if (target_type == nullptr)
     {
       target_type = read_type_record (ccp, btid);
-      if (target_type == NULL)
+      if (target_type == nullptr)
        {
          complaint (_("read_pointer_type: NULL target type (%ld)"), btid);
          target_type = objfile_type (ccp->of)->builtin_error;
@@ -908,14 +960,42 @@ read_pointer_type (struct ctf_context *ccp, ctf_id_t tid, ctf_id_t btid)
   return set_tid_type (of, tid, type);
 }
 
+/* Read information from a TID of CTF_K_FORWARD.  */
+
+static struct type *
+read_forward_type (struct ctf_context *ccp, ctf_id_t tid)
+{
+  struct objfile *of = ccp->of;
+  ctf_dict_t *fp = ccp->fp;
+  struct type *type;
+  uint32_t kind;
+
+  type = alloc_type (of);
+
+  gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (fp, tid));
+  if (name != NULL && strlen (name.get()) != 0)
+    type->set_name (obstack_strdup (&of->objfile_obstack, name.get ()));
+
+  kind = ctf_type_kind_forwarded (fp, tid);
+  if (kind == CTF_K_UNION)
+    type->set_code (TYPE_CODE_UNION);
+  else
+    type->set_code (TYPE_CODE_STRUCT);
+
+  TYPE_LENGTH (type) = 0;
+  type->set_is_stub (true);
+
+  return set_tid_type (of, tid, type);
+}
+
 /* Read information associated with type TID.  */
 
 static struct type *
 read_type_record (struct ctf_context *ccp, ctf_id_t tid)
 {
-  ctf_file_t *fp = ccp->fp;
+  ctf_dict_t *fp = ccp->fp;
   uint32_t kind;
-  struct type *type = NULL;
+  struct type *type = nullptr;
   ctf_id_t btid;
 
   kind = ctf_type_kind (fp, tid);
@@ -961,6 +1041,9 @@ read_type_record (struct ctf_context *ccp, ctf_id_t tid)
       case CTF_K_ARRAY:
        type = read_array_type (ccp, tid);
        break;
+      case CTF_K_FORWARD:
+       type = read_forward_type (ccp, tid);
+       break;
       case CTF_K_UNKNOWN:
        break;
       default:
@@ -981,7 +1064,7 @@ ctf_add_type_cb (ctf_id_t tid, void *arg)
 
   /* Check if tid's type has already been defined.  */
   type = get_tid_type (ccp->of, tid);
-  if (type != NULL)
+  if (type != nullptr)
     return 0;
 
   ctf_id_t btid = ctf_type_reference (ccp->fp, tid);
@@ -1041,7 +1124,7 @@ static int
 ctf_add_var_cb (const char *name, ctf_id_t id, void *arg)
 {
   struct ctf_context *ccp = (struct ctf_context *) arg;
-  struct symbol *sym = NULL;
+  struct symbol *sym = nullptr;
   struct type *type;
   uint32_t kind;
 
@@ -1051,7 +1134,7 @@ ctf_add_var_cb (const char *name, ctf_id_t id, void *arg)
   switch (kind)
     {
       case CTF_K_FUNCTION:
-       if (name && !strcmp(name, "main"))
+       if (name != nullptr && strcmp (name, "main") == 0)
          set_objfile_main_name (ccp->of, name, language_c);
        break;
       case CTF_K_INTEGER:
@@ -1071,7 +1154,7 @@ ctf_add_var_cb (const char *name, ctf_id_t id, void *arg)
       case CTF_K_STRUCT:
       case CTF_K_UNION:
       case CTF_K_ENUM:
-       if (type == NULL)
+       if (type == nullptr)
        {
          complaint (_("ctf_add_var_cb: %s has NO type (%ld)"), name, id);
          type = objfile_type (ccp->of)->builtin_error;
@@ -1089,7 +1172,7 @@ ctf_add_var_cb (const char *name, ctf_id_t id, void *arg)
        break;
     }
 
-  if (sym)
+  if (sym != nullptr)
     set_symbol_address (ccp->of, sym, name);
 
   return 0;
@@ -1105,11 +1188,11 @@ add_stt_obj (struct ctf_context *ccp, unsigned long idx)
   ctf_id_t tid;
 
   if ((tid = ctf_lookup_by_symbol (ccp->fp, idx)) == CTF_ERR)
-    return NULL;
+    return nullptr;
 
-  type = get_tid_type (ccp->of, tid);
-  if (type == NULL)
-    return NULL;
+  type = fetch_tid_type (ccp, tid);
+  if (type == nullptr)
+    return nullptr;
 
   sym = new_symbol (ccp, type, tid);
 
@@ -1130,19 +1213,19 @@ add_stt_func (struct ctf_context *ccp, unsigned long idx)
   struct type *void_type = objfile_type (ccp->of)->builtin_void;
 
   if (ctf_func_info (ccp->fp, idx, &finfo) == CTF_ERR)
-    return NULL;
+    return nullptr;
 
   argc = finfo.ctc_argc;
   if (ctf_func_args (ccp->fp, idx, argc, argv) == CTF_ERR)
-    return NULL;
+    return nullptr;
 
   gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (ccp->fp, idx));
-  if (name == NULL)
-    return NULL;
+  if (name == nullptr)
+    return nullptr;
 
   tid = ctf_lookup_by_symbol (ccp->fp, idx);
-  ftype = get_tid_type (ccp->of, tid);
-  if (finfo.ctc_flags & CTF_FUNC_VARARG)
+  ftype = fetch_tid_type (ccp, tid);
+  if ((finfo.ctc_flags & CTF_FUNC_VARARG) != 0)
     ftype->set_has_varargs (true);
   ftype->set_num_fields (argc);
 
@@ -1155,7 +1238,7 @@ add_stt_func (struct ctf_context *ccp, unsigned long idx)
      to find the argument type.  */
   for (int iparam = 0; iparam < argc; iparam++)
     {
-      atyp = get_tid_type (ccp->of, argv[iparam]);
+      atyp = fetch_tid_type (ccp, argv[iparam]);
       if (atyp)
        ftype->field (iparam).set_type (atyp);
       else
@@ -1163,8 +1246,8 @@ add_stt_func (struct ctf_context *ccp, unsigned long idx)
     }
 
   sym = new_symbol (ccp, ftype, tid);
-  rettyp = get_tid_type (ccp->of, finfo.ctc_return);
-  if (rettyp != NULL)
+  rettyp = fetch_tid_type (ccp, finfo.ctc_return);
+  if (rettyp != nullptr)
     SYMBOL_TYPE (sym) = rettyp;
   else
     SYMBOL_TYPE (sym) = void_type;
@@ -1195,7 +1278,7 @@ ctf_start_symtab (ctf_psymtab *pst,
 
   ccp = pst->context;
   ccp->builder = new buildsym_compunit
-                      (of, of->original_name, NULL,
+                      (of, of->original_name, nullptr,
                       language_c, text_offset);
   ccp->builder->record_debugformat ("ctf");
 }
@@ -1214,10 +1297,31 @@ ctf_end_symtab (ctf_psymtab *pst,
   struct compunit_symtab *result
     = ccp->builder->end_symtab (end_addr, section);
   delete ccp->builder;
-  ccp->builder = NULL;
+  ccp->builder = nullptr;
   return result;
 }
 
+/* Add all members of an enum with type TID to partial symbol table.  */
+
+static void
+ctf_psymtab_add_enums (struct ctf_context *ccp, ctf_id_t tid)
+{
+  int val;
+  const char *ename;
+  ctf_next_t *i = nullptr;
+
+  while ((ename = ctf_enum_next (ccp->fp, tid, &i, &val)) != nullptr)
+    {
+      ccp->pst->add_psymbol (ename, true,
+                            VAR_DOMAIN, LOC_CONST, -1,
+                            psymbol_placement::GLOBAL,
+                            0, language_c, ccp->partial_symtabs, ccp->of);
+    }
+  if (ctf_errno (ccp->fp) != ECTF_NEXT_END)
+    complaint (_("ctf_enum_next ctf_psymtab_add_enums failed - %s"),
+              ctf_errmsg (ctf_errno (ccp->fp)));
+}
+
 /* Read in full symbols for PST, and anything it depends on.  */
 
 void
@@ -1245,14 +1349,14 @@ ctf_psymtab::expand_psymtab (struct objfile *objfile)
   for (unsigned long i = 0; ; i++)
     {
       sym = add_stt_obj (ccp, i);
-      if (sym == NULL)
+      if (sym == nullptr)
        {
          if (ctf_errno (ccp->fp) == EINVAL
              || ctf_errno (ccp->fp) == ECTF_NOSYMTAB)
            break;
          sym = add_stt_func (ccp, i);
        }
-      if (sym == NULL)
+      if (sym == nullptr)
        continue;
 
       set_symbol_address (ccp->of, sym, sym->linkage_name ());
@@ -1310,17 +1414,19 @@ ctf_psymtab::read_symtab (struct objfile *objfile)
 
 static ctf_psymtab *
 create_partial_symtab (const char *name,
-                      ctf_file_t *cfp,
+                      ctf_dict_t *cfp,
+                      psymtab_storage *partial_symtabs,
                       struct objfile *objfile)
 {
   ctf_psymtab *pst;
   struct ctf_context *ccx;
 
-  pst = new ctf_psymtab (name, objfile, 0);
+  pst = new ctf_psymtab (name, partial_symtabs, objfile->per_bfd, 0);
 
   ccx = XOBNEW (&objfile->objfile_obstack, struct ctf_context);
   ccx->fp = cfp;
   ccx->of = objfile;
+  ccx->partial_symtabs = partial_symtabs;
   ccx->pst = pst;
   ccx->builder = nullptr;
   pst->context = ccx;
@@ -1339,17 +1445,17 @@ ctf_psymtab_type_cb (ctf_id_t tid, void *arg)
 
   ccp = (struct ctf_context *) arg;
   gdb::unique_xmalloc_ptr<char> name (ctf_type_aname_raw (ccp->fp, tid));
-  if (name == NULL || strlen (name.get ()) == 0)
-    return 0;
 
   domain_enum domain = UNDEF_DOMAIN;
   enum address_class aclass = LOC_UNDEF;
   kind = ctf_type_kind (ccp->fp, tid);
   switch (kind)
     {
+      case CTF_K_ENUM:
+       ctf_psymtab_add_enums (ccp, tid);
+       /* FALL THROUGH */
       case CTF_K_STRUCT:
       case CTF_K_UNION:
-      case CTF_K_ENUM:
        domain = STRUCT_DOMAIN;
        aclass = LOC_TYPEDEF;
        break;
@@ -1380,10 +1486,13 @@ ctf_psymtab_type_cb (ctf_id_t tid, void *arg)
        return 0;
     }
 
+  if (name == nullptr || strlen (name.get ()) == 0)
+    return 0;
+
   ccp->pst->add_psymbol (name.get (), true,
                         domain, aclass, section,
                         psymbol_placement::GLOBAL,
-                        0, language_c, ccp->of);
+                        0, language_c, ccp->partial_symtabs, ccp->of);
 
   return 0;
 }
@@ -1398,7 +1507,7 @@ ctf_psymtab_var_cb (const char *name, ctf_id_t id, void *arg)
   ccp->pst->add_psymbol (name, true,
                         VAR_DOMAIN, LOC_STATIC, -1,
                         psymbol_placement::GLOBAL,
-                        0, language_c, ccp->of);
+                        0, language_c, ccp->partial_symtabs, ccp->of);
   return 0;
 }
 
@@ -1406,11 +1515,12 @@ ctf_psymtab_var_cb (const char *name, ctf_id_t id, void *arg)
    debugging information is available.  */
 
 static void
-scan_partial_symbols (ctf_file_t *cfp, struct objfile *of)
+scan_partial_symbols (ctf_dict_t *cfp, psymtab_storage *partial_symtabs,
+                     struct objfile *of)
 {
   bfd *abfd = of->obfd;
   const char *name = bfd_get_filename (abfd);
-  ctf_psymtab *pst = create_partial_symtab (name, cfp, of);
+  ctf_psymtab *pst = create_partial_symtab (name, cfp, partial_symtabs, of);
 
   struct ctf_context *ccx = pst->context;
 
@@ -1461,10 +1571,10 @@ scan_partial_symbols (ctf_file_t *cfp, struct objfile *of)
       pst->add_psymbol (tname.get (), true,
                        tdomain, aclass, -1,
                        psymbol_placement::STATIC,
-                       0, language_c, of);
+                       0, language_c, partial_symtabs, of);
     }
 
-  end_psymtab_common (pst);
+  pst->end ();
 }
 
 /* Read CTF debugging information from a BFD section.  This is
@@ -1478,17 +1588,20 @@ elfctf_build_psymtabs (struct objfile *of)
   int err;
 
   ctf_archive_t *arc = ctf_bfdopen (abfd, &err);
-  if (arc == NULL)
+  if (arc == nullptr)
     error (_("ctf_bfdopen failed on %s - %s"),
           bfd_get_filename (abfd), ctf_errmsg (err));
 
-  ctf_file_t *fp = ctf_arc_open_by_name (arc, NULL, &err);
-  if (fp == NULL)
-    error (_("ctf_arc_open_by_name failed on %s - %s"),
+  ctf_dict_t *fp = ctf_dict_open (arc, NULL, &err);
+  if (fp == nullptr)
+    error (_("ctf_dict_open failed on %s - %s"),
           bfd_get_filename (abfd), ctf_errmsg (err));
-  ctf_file_key.emplace (of, fp);
+  ctf_dict_key.emplace (of, fp);
 
-  scan_partial_symbols (fp, of);
+  psymbol_functions *psf = new psymbol_functions ();
+  psymtab_storage *partial_symtabs = psf->get_partial_symtabs ().get ();
+  of->qf.emplace_front (psf);
+  scan_partial_symbols (fp, partial_symtabs, of);
 }
 
 #else