From 0ac6231298cbc5a3a16bd4e98d85d98700b81dee Mon Sep 17 00:00:00 2001 From: Nick Alcock Date: Sat, 13 Jul 2019 20:00:07 +0100 Subject: libctf: Add iteration over non-root types 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. --- libctf/ChangeLog | 4 ++++ libctf/ctf-types.c | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) (limited to 'libctf') diff --git a/libctf/ChangeLog b/libctf/ChangeLog index 64d644f..df52650 100644 --- a/libctf/ChangeLog +++ b/libctf/ChangeLog @@ -1,5 +1,9 @@ 2019-07-13 Nick Alcock + * ctf_types.c (ctf_type_iter_all): New. + +2019-07-13 Nick Alcock + * ctf-open.c (init_symtab): Check for overflow against the right section. (upgrade_header): Set cth_objtidxoff, cth_funcidxoff to zero-length. diff --git a/libctf/ctf-types.c b/libctf/ctf-types.c index 5068ff1..95c9c9a 100644 --- a/libctf/ctf-types.c +++ b/libctf/ctf-types.c @@ -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. */ -- cgit v1.1