From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 77157 invoked by alias); 3 Oct 2019 16:31:44 -0000 Mailing-List: contact gdb-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: , Sender: gdb-cvs-owner@sourceware.org List-Subscribe: Sender: gdb-cvs-owner@sourceware.org Received: (qmail 77111 invoked by uid 10018); 3 Oct 2019 16:31:44 -0000 Date: Thu, 03 Oct 2019 16:31:00 -0000 Message-ID: <20191003163144.77110.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jose E.Marchesi To: bfd-cvs@sourceware.org, gdb-cvs@sourceware.org Subject: [binutils-gdb] libctf: Add iteration over non-root types X-Act-Checkin: binutils-gdb X-Git-Author: Nick Alcock X-Git-Refname: refs/heads/master X-Git-Oldrev: 6b88d7d70c50fc320cd693fb3ddba6e28da839aa X-Git-Newrev: 0ac6231298cbc5a3a16bd4e98d85d98700b81dee X-SW-Source: 2019-10/txt/msg00038.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0ac6231298cbc5a3a16bd4e98d85d98700b81dee commit 0ac6231298cbc5a3a16bd4e98d85d98700b81dee Author: Nick Alcock Date: Sat Jul 13 20:00:07 2019 +0100 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. Diff: --- include/ChangeLog | 5 +++++ include/ctf-api.h | 2 ++ libctf/ChangeLog | 4 ++++ libctf/ctf-types.c | 21 +++++++++++++++++++++ 4 files changed, 32 insertions(+) diff --git a/include/ChangeLog b/include/ChangeLog index c2e8031..1fe3df4 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,8 @@ +2019-07-13 Nick Alcock + + * ctf-api.h (ctf_type_all_f): New. + (ctf_type_iter_all): New. + 2019-07-11 Nick Alcock * ctf.h: Add object index and function index sections. Describe diff --git a/include/ctf-api.h b/include/ctf-api.h index 28256a3..fa74788 100644 --- a/include/ctf-api.h +++ b/include/ctf-api.h @@ -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 *, 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. */