]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
libctf: add ctf_member_count
authorNick Alcock <nick.alcock@oracle.com>
Tue, 2 Jun 2020 20:11:25 +0000 (21:11 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Wed, 22 Jul 2020 16:57:38 +0000 (17:57 +0100)
This returns the number of members in a struct or union, or the number
of enumerations in an enum.  (This was only available before now by
iterating across every member, but it can be returned much faster than
that.)

include/
* ctf-api.h (ctf_member_count): New.

libctf/
* ctf-types.c (ctf_member_count): New.
* libctf.ver: New public function.

include/ChangeLog
include/ctf-api.h
libctf/ChangeLog
libctf/ctf-types.c
libctf/libctf.ver

index 18b0b0b84c64247f5bfc3e58362d613b0c428b1c..27ffb9051ed87ab10a4ea6ca8e6b1a9b4cae35c1 100644 (file)
@@ -1,3 +1,7 @@
+2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctf-api.h (ctf_member_count): New.
+
 2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf-api.h (ctf_type_kind_forwarded): New.
index 87446a5f7d1b63ac7d02229efae1469830cd8c9d..7cdf4a562355154cf931779c24014c9c29113674 100644 (file)
@@ -349,6 +349,7 @@ extern const char *ctf_label_get (ctf_file_t *);
 extern const char *ctf_label_topmost (ctf_file_t *);
 extern int ctf_label_info (ctf_file_t *, const char *, ctf_lblinfo_t *);
 
+extern int ctf_member_count (ctf_file_t *, ctf_id_t);
 extern int ctf_member_iter (ctf_file_t *, ctf_id_t, ctf_member_f *, void *);
 extern int ctf_enum_iter (ctf_file_t *, ctf_id_t, ctf_enum_f *, void *);
 extern int ctf_type_iter (ctf_file_t *, ctf_type_f *, void *);
index 949e9d047b89b25f8a79957892cb5b0059c9b0b6..7df7867b4cb21f0159770d7930d73c4d72bdeaeb 100644 (file)
@@ -1,3 +1,8 @@
+2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctf-types.c (ctf_member_count): New.
+       * libctf.ver: New public function.
+
 2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf-types.c (ctf_type_kind_forwarded): New.
index d8f848cf893e5cc0f3d44b6adce198a554d195dd..93967c6aa8ddcc16899fc1d7656c9d8b82714293 100644 (file)
@@ -963,6 +963,30 @@ ctf_type_compat (ctf_file_t *lfp, ctf_id_t ltype,
     }
 }
 
+/* Return the number of members in a STRUCT or UNION, or the number of
+   enumerators in an ENUM.  */
+
+int
+ctf_member_count (ctf_file_t *fp, ctf_id_t type)
+{
+  ctf_file_t *ofp = fp;
+  const ctf_type_t *tp;
+  uint32_t kind;
+
+  if ((type = ctf_type_resolve (fp, type)) == CTF_ERR)
+    return -1;                 /* errno is set for us.  */
+
+  if ((tp = ctf_lookup_by_id (&fp, type)) == NULL)
+    return -1;                 /* errno is set for us.  */
+
+  kind = LCTF_INFO_KIND (fp, tp->ctt_info);
+
+  if (kind != CTF_K_STRUCT && kind != CTF_K_UNION && kind != CTF_K_ENUM)
+    return (ctf_set_errno (ofp, ECTF_NOTSUE));
+
+  return LCTF_INFO_VLEN (fp, tp->ctt_info);
+}
+
 /* Return the type and offset for a given member of a STRUCT or UNION.  */
 
 int
index b8c5133d3f9436920589078775e946206f32bb1b..77b380ca99127e74c6b83031acd5e39ee6ade299 100644 (file)
@@ -73,6 +73,7 @@ LIBCTF_1.0 {
 
        ctf_member_info;
        ctf_array_info;
+       ctf_member_count;
 
        ctf_enum_name;
        ctf_enum_value;