diff options
author | Nick Alcock <nick.alcock@oracle.com> | 2021-01-05 13:25:56 +0000 |
---|---|---|
committer | Nick Alcock <nick.alcock@oracle.com> | 2021-01-05 14:53:40 +0000 |
commit | 6c3a38777b38a2ad87e2b2bcec4567578d1c83ec (patch) | |
tree | 92e04a38161e85109281a2b3579036ca663865d1 /include | |
parent | abed0b0718a6a9cd24cc68fb1f73baf6b31d8ff4 (diff) | |
download | gdb-6c3a38777b38a2ad87e2b2bcec4567578d1c83ec.zip gdb-6c3a38777b38a2ad87e2b2bcec4567578d1c83ec.tar.gz gdb-6c3a38777b38a2ad87e2b2bcec4567578d1c83ec.tar.bz2 |
libctf, include: support unnamed structure members better
libctf has no intrinsic support for the GCC unnamed structure member
extension. This principally means that you can't look up named members
inside unnamed struct or union members via ctf_member_info: you have to
tiresomely find out the type ID of the unnamed members via iteration,
then look in each of these.
This is ridiculous. Fix it by extending ctf_member_info so that it
recurses into unnamed members for you: this is still unambiguous because
GCC won't let you create ambiguously-named members even in the presence
of this extension.
For consistency, and because the release hasn't happened and we can
still do this, break the ctf_member_next API and add flags: we specify
one flag, CTF_MN_RECURSE, which if set causes ctf_member_next to
automatically recurse into unnamed members for you, returning not only
the members themselves but all their contained members, so that you can
use ctf_member_next to identify every member that it would be valid to
call ctf_member_info with.
New lookup tests are added for all of this.
include/ChangeLog
2021-01-05 Nick Alcock <nick.alcock@oracle.com>
* ctf-api.h (CTF_MN_RECURSE): New.
(ctf_member_next): Add flags argument.
libctf/ChangeLog
2021-01-05 Nick Alcock <nick.alcock@oracle.com>
* ctf-impl.h (struct ctf_next) <u.ctn_next>: Move to...
<ctn_next>: ... here.
* ctf-util.c (ctf_next_destroy): Unconditionally destroy it.
* ctf-lookup.c (ctf_symbol_next): Adjust accordingly.
* ctf-types.c (ctf_member_iter): Reimplement in terms of...
(ctf_member_next): ... this. Support recursive unnamed member
iteration (off by default).
(ctf_member_info): Look up members in unnamed sub-structs.
* ctf-dedup.c (ctf_dedup_rhash_type): Adjust ctf_member_next call.
(ctf_dedup_emit_struct_members): Likewise.
* testsuite/libctf-lookup/struct-iteration-ctf.c: Test empty unnamed
members, and a normal member after the end.
* testsuite/libctf-lookup/struct-iteration.c: Verify that
ctf_member_count is consistent with the number of successful returns
from a non-recursive ctf_member_next.
* testsuite/libctf-lookup/struct-iteration-*: New, test iteration
over struct members.
* testsuite/libctf-lookup/struct-lookup.c: New test.
* testsuite/libctf-lookup/struct-lookup.lk: New test.
Diffstat (limited to 'include')
-rw-r--r-- | include/ChangeLog | 5 | ||||
-rw-r--r-- | include/ctf-api.h | 7 |
2 files changed, 11 insertions, 1 deletions
diff --git a/include/ChangeLog b/include/ChangeLog index 1b56987..ab2aa33 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,5 +1,10 @@ 2021-01-05 Nick Alcock <nick.alcock@oracle.com> + * ctf-api.h (CTF_MN_RECURSE): New. + (ctf_member_next): Add flags argument. + +2021-01-05 Nick Alcock <nick.alcock@oracle.com> + * ctf-api.h (ECTF_INCOMPLETE): New. (ECTF_NERR): Adjust. diff --git a/include/ctf-api.h b/include/ctf-api.h index b3cfd39..5cf3257 100644 --- a/include/ctf-api.h +++ b/include/ctf-api.h @@ -264,6 +264,10 @@ _CTF_ERRORS #define CTF_ADD_NONROOT 0 /* Type only visible in nested scope. */ #define CTF_ADD_ROOT 1 /* Type visible at top-level scope. */ +/* Flags for ctf_member_next. */ + +#define CTF_MN_RECURSE 0x1 /* Recurse into unnamed members. */ + /* These typedefs are used to define the signature for callback functions that can be used with the iteration and visit functions below. There is also a family of iteration functions that do not require callbacks. */ @@ -411,7 +415,8 @@ extern int ctf_label_info (ctf_dict_t *, const char *, ctf_lblinfo_t *); extern int ctf_member_count (ctf_dict_t *, ctf_id_t); extern int ctf_member_iter (ctf_dict_t *, ctf_id_t, ctf_member_f *, void *); extern ssize_t ctf_member_next (ctf_dict_t *, ctf_id_t, ctf_next_t **, - const char **name, ctf_id_t *membtype); + const char **name, ctf_id_t *membtype, + int flags); extern int ctf_enum_iter (ctf_dict_t *, ctf_id_t, ctf_enum_f *, void *); extern const char *ctf_enum_next (ctf_dict_t *, ctf_id_t, ctf_next_t **, int *); |