This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH v6 2/2] Implement pahole-like 'ptype /o' option
- From: Pedro Alves <palves at redhat dot com>
- To: Sergio Durigan Junior <sergiodj at redhat dot com>, GDB Patches <gdb-patches at sourceware dot org>
- Cc: Tom Tromey <tom at tromey dot com>, Eli Zaretskii <eliz at gnu dot org>, Simon Marchi <simon dot marchi at ericsson dot com>, Keith Seitz <keiths at redhat dot com>
- Date: Thu, 14 Dec 2017 14:50:18 +0000
- Subject: Re: [PATCH v6 2/2] Implement pahole-like 'ptype /o' option
- Authentication-results: sourceware.org; auth=none
- References: <20171121160709.23248-1-sergiodj@redhat.com> <20171214024816.29629-1-sergiodj@redhat.com> <20171214024816.29629-3-sergiodj@redhat.com>
On 12/14/2017 02:48 AM, Sergio Durigan Junior wrote:
> A big part of this patch handles the formatting logic of 'ptype',
> which is a bit messy. The code to handle bitfield offsets, however,
> took some time to craft. My thanks to Pedro Alves for figuring things
> out and pointing me to the right direction, as well as coming up with
> a way to inspect the layout of structs with bitfields (see testcase
> for comments).
Why, thanks. :-)
> +Issuing a @kbd{ptype /o struct tuv} command would print:
> +
> +@smallexample
> +(@value{GDBP}) ptype /o struct tuv
> +/* offset | size */
> +struct tuv @{
> +/* 0 | 4 */ int a1;
> +/* XXX 4-byte hole */
> +/* 8 | 8 */ char *a2;
> +/* 16 | 4 */ int a3;
> +@} /* total size: 24 bytes */
> +@end smallexample
These examples need to be updated per the new output format.
> + You should have received a copy of the GNU General Public License
> + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> +
> +/* This file will be used to test 'ptype /o' on x86_64 only. */
No longer true...
> +
> +#include <stdint.h>
> +
> +
> +# Test only works on x86_64 LP64 targets. That's how we guarantee
Remove reference to x86_64; it's no longer true.
> +# that the expected holes will be present in the struct.
> +if { ![is_lp64_target] } {
> + untested "test work only on lp64 targets"
> + return 0
> +}
> +
> +if { [prepare_for_testing "failed to prepare" $testfile $srcfile \
> + { debug c++ }] } {
> + return -1
> +}
I think we're missing a test for "ptype /oTM", to make sure that
we can still override the fact that /o implies /tm ?
I'd add at least one for "/oTM" and one for "/TMo". The
latter ends up being the same as "/o".
> +/* The default values for a struct print_offset_data. */
> +
> +struct print_offset_data print_offset_default_data =
> +{
> + 0, /* offset_bitpos */
> + 0, /* endpos */
> +};
> +
Do we really need this object ? How about just defining
the default values in-class ? See below.
> --- a/gdb/typeprint.h
> +++ b/gdb/typeprint.h
> @@ -24,6 +24,22 @@ struct ui_file;
> struct typedef_hash_table;
> struct ext_lang_type_printers;
>
> +struct print_offset_data
> +{
> + /* The offset to be applied to bitpos when PRINT_OFFSETS is true.
> + This is needed for when we are printing nested structs and want
> + to make sure that the printed offset for each field carries over
> + the offset of the outter struct. */
> + unsigned int offset_bitpos;
So here:
unsigned int offset_bitpos = 0;
> +
> + /* ENDPOS is the one-past-the-end bit position of the previous field
> + (where we expect the current field to be if there is no
> + hole). */
> + unsigned int endpos;
and
unsigned int endpos = 0;
Then you default-constructed print_offset_data objects have
the fields automatically zeroed:
print_offset_data podata;
while at it, wouldn't it be better to name this one "end_bitpos" or
something like that with "bit" in it as well?
Thanks,
Pedro Alves