aboutsummaryrefslogtreecommitdiff
path: root/libctf
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2020-06-02 21:11:25 +0100
committerNick Alcock <nick.alcock@oracle.com>2020-07-22 17:57:38 +0100
commite0325e2cede6f9da2560ede6d4a17d9e21fbea9c (patch)
tree387753f6792402171ec8f95b157859bb94c734ee /libctf
parent9b15cbb7891f6b8b185fed41e5e6ecea0a6a6c36 (diff)
downloadgdb-e0325e2cede6f9da2560ede6d4a17d9e21fbea9c.zip
gdb-e0325e2cede6f9da2560ede6d4a17d9e21fbea9c.tar.gz
gdb-e0325e2cede6f9da2560ede6d4a17d9e21fbea9c.tar.bz2
libctf: add ctf_member_count
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.
Diffstat (limited to 'libctf')
-rw-r--r--libctf/ChangeLog5
-rw-r--r--libctf/ctf-types.c24
-rw-r--r--libctf/libctf.ver1
3 files changed, 30 insertions, 0 deletions
diff --git a/libctf/ChangeLog b/libctf/ChangeLog
index 949e9d0..7df7867 100644
--- a/libctf/ChangeLog
+++ b/libctf/ChangeLog
@@ -1,5 +1,10 @@
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.
2020-07-22 Nick Alcock <nick.alcock@oracle.com>
diff --git a/libctf/ctf-types.c b/libctf/ctf-types.c
index d8f848c..93967c6 100644
--- a/libctf/ctf-types.c
+++ b/libctf/ctf-types.c
@@ -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
diff --git a/libctf/libctf.ver b/libctf/libctf.ver
index b8c5133..77b380c 100644
--- a/libctf/libctf.ver
+++ b/libctf/libctf.ver
@@ -73,6 +73,7 @@ LIBCTF_1.0 {
ctf_member_info;
ctf_array_info;
+ ctf_member_count;
ctf_enum_name;
ctf_enum_value;