aboutsummaryrefslogtreecommitdiff
path: root/libctf/ctf-impl.h
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2021-01-05 13:25:56 +0000
committerNick Alcock <nick.alcock@oracle.com>2021-01-05 14:53:40 +0000
commit6c3a38777b38a2ad87e2b2bcec4567578d1c83ec (patch)
tree92e04a38161e85109281a2b3579036ca663865d1 /libctf/ctf-impl.h
parentabed0b0718a6a9cd24cc68fb1f73baf6b31d8ff4 (diff)
downloadgdb-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 'libctf/ctf-impl.h')
-rw-r--r--libctf/ctf-impl.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h
index b19ae69..8a173c1 100644
--- a/libctf/ctf-impl.h
+++ b/libctf/ctf-impl.h
@@ -532,13 +532,15 @@ struct ctf_next
ssize_t ctn_size;
ssize_t ctn_increment;
uint32_t ctn_n;
+
+ /* Some iterators contain other iterators, in addition to their other
+ state. */
+ ctf_next_t *ctn_next;
+
/* We can save space on this side of things by noting that a dictionary is
either dynamic or not, as a whole, and a given iterator can only iterate
over one kind of thing at once: so we can overlap the DTD and non-DTD
- members, and the structure, variable and enum members, etc.
-
- Some of the _next iterators actually thunk down to another _next iterator
- themselves, so one of the options in here is a _next iterator! */
+ members, and the structure, variable and enum members, etc. */
union
{
const ctf_member_t *ctn_mp;
@@ -546,10 +548,10 @@ struct ctf_next
const ctf_dmdef_t *ctn_dmd;
const ctf_enum_t *ctn_en;
const ctf_dvdef_t *ctn_dvd;
- ctf_next_t *ctn_next;
ctf_next_hkv_t *ctn_sorted_hkv;
void **ctn_hash_slot;
} u;
+
/* This union is of various sorts of dict we can iterate over:
currently dictionaries and archives, dynhashes, and dynsets. */
union