
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.
24 lines
1.4 KiB
Text
24 lines
1.4 KiB
Text
# source: struct-iteration-ctf.c
|
|
# link: on
|
|
iter test: foo, offset [0-9a-f]*, has type [0-9a-f]*/int
|
|
iter test: bar, offset [0-9a-f]*, has type [0-9a-f]*/size_t
|
|
iter test: baz, offset [0-9a-f]*, has type [0-9a-f]*/const char \*
|
|
iter test: self, offset [0-9a-f]*, has type [0-9a-f]*/struct foo_t \*
|
|
iter test: named, offset [0-9a-f]*, has type [0-9a-f]*/union
|
|
iter test: , offset [0-9a-f]*, has type [0-9a-f]*/struct
|
|
iter test: , offset [0-9a-f]*, has type [0-9a-f]*/struct
|
|
iter test: , offset [0-9a-f]*, has type [0-9a-f]*/union
|
|
iter test: after_the_end, offset [0-9a-f]*, has type [0-9a-f]*/int
|
|
next test: foo, offset [0-9a-f]*, has type [0-9a-f]*/int
|
|
next test: bar, offset [0-9a-f]*, has type [0-9a-f]*/size_t
|
|
next test: baz, offset [0-9a-f]*, has type [0-9a-f]*/const char \*
|
|
next test: self, offset [0-9a-f]*, has type [0-9a-f]*/struct foo_t \*
|
|
next test: named, offset [0-9a-f]*, has type [0-9a-f]*/union
|
|
next test: , offset [0-9a-f]*, has type [0-9a-f]*/struct
|
|
next test: unnamed_sub_member, offset [0-9a-f]*, has type [0-9a-f]*/long int
|
|
next test: , offset [0-9a-f]*, has type [0-9a-f]*/union
|
|
next test: one_more_level, offset [0-9a-f]*, has type [0-9a-f]*/double
|
|
next test: yes_really_one_more, offset [0-9a-f]*, has type [0-9a-f]*/long int
|
|
next test: , offset [0-9a-f]*, has type [0-9a-f]*/struct
|
|
next test: , offset [0-9a-f]*, has type [0-9a-f]*/union
|
|
next test: after_the_end, offset [0-9a-f]*, has type [0-9a-f]*/int
|