libctf: Add iteration over non-root types
authorNick Alcock <nick.alcock@oracle.com>
Sat, 13 Jul 2019 19:00:07 +0000 (20:00 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Thu, 3 Oct 2019 16:04:55 +0000 (17:04 +0100)
The existing function ctf_type_iter lets you iterate over root-visible
types (types you can look up by name).  There is no way to iterate over
non-root-visible types, which is troublesome because both the linker
and dumper want to do that.

So add a new function that can do it: the callback it takes accepts
an extra parameter which indicates whether the type is root-visible
or not.

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

libctf/
* ctf_types.c (ctf_type_iter_all): New.

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

index c2e80315aa1d4988d3edc3a3bd94bd1d59355287..1fe3df4562136fab74e178b1641f55836b0a8813 100644 (file)
@@ -1,3 +1,8 @@
+2019-07-13  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctf-api.h (ctf_type_all_f): New.
+       (ctf_type_iter_all): New.
+
 2019-07-11  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf.h: Add object index and function index sections.  Describe
index 28256a3c4e86aadbef21dcd7596b6cbfbe25714e..fa747888e04f60aee80934504c5a39b936e7ec81 100644 (file)
@@ -211,6 +211,7 @@ typedef int ctf_member_f (const char *name, ctf_id_t membtype,
 typedef int ctf_enum_f (const char *name, int val, void *arg);
 typedef int ctf_variable_f (const char *name, ctf_id_t type, void *arg);
 typedef int ctf_type_f (ctf_id_t type, void *arg);
+typedef int ctf_type_all_f (ctf_id_t type, int flag, void *arg);
 typedef int ctf_label_f (const char *name, const ctf_lblinfo_t *info,
                         void *arg);
 typedef int ctf_archive_member_f (ctf_file_t *fp, const char *name, void *arg);
@@ -317,6 +318,7 @@ extern int ctf_label_info (ctf_file_t *, const char *, ctf_lblinfo_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 *);
+extern int ctf_type_iter_all (ctf_file_t *, ctf_type_all_f *, void *);
 extern int ctf_label_iter (ctf_file_t *, ctf_label_f *, void *);
 extern int ctf_variable_iter (ctf_file_t *, ctf_variable_f *, void *);
 extern int ctf_archive_iter (const ctf_archive_t *, ctf_archive_member_f *,
index 64d644f8a6c2daf557ba342638be70ea1f033c55..df52650b16dce893d2d8b3b3af5015c93fa67728 100644 (file)
@@ -1,3 +1,7 @@
+2019-07-13  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctf_types.c (ctf_type_iter_all): New.
+
 2019-07-13  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf-open.c (init_symtab): Check for overflow against the right
index 5068ff16a560334e887e077bc0c600fa1d8ca447..95c9c9aca189eeccf5c53ba47102e21fbfe68ca9 100644 (file)
@@ -144,6 +144,27 @@ ctf_type_iter (ctf_file_t *fp, ctf_type_f *func, void *arg)
   return 0;
 }
 
+/* Iterate over every type in the given CTF container, user-visible or not.
+   We pass the type ID of each type to the specified callback function.  */
+
+int
+ctf_type_iter_all (ctf_file_t *fp, ctf_type_all_f *func, void *arg)
+{
+  ctf_id_t id, max = fp->ctf_typemax;
+  int rc, child = (fp->ctf_flags & LCTF_CHILD);
+
+  for (id = 1; id <= max; id++)
+    {
+      const ctf_type_t *tp = LCTF_INDEX_TO_TYPEPTR (fp, id);
+      if ((rc = func (LCTF_INDEX_TO_TYPE (fp, id, child),
+                     LCTF_INFO_ISROOT(fp, tp->ctt_info)
+                     ? CTF_ADD_ROOT : CTF_ADD_NONROOT, arg) != 0))
+       return rc;
+    }
+
+  return 0;
+}
+
 /* Iterate over every variable in the given CTF container, in arbitrary order.
    We pass the name of each variable to the specified callback function.  */
 
This page took 0.030481 seconds and 4 git commands to generate.