From: Sergio Durigan Junior <sergiodj@redhat.com>
To: Pedro Alves <palves@redhat.com>
Cc: GDB Patches <gdb-patches@sourceware.org>,
Tom Tromey <tom@tromey.com>, Eli Zaretskii <eliz@gnu.org>,
Simon Marchi <simon.marchi@ericsson.com>,
Keith Seitz <keiths@redhat.com>
Subject: Re: [PATCH v5 2/2] Implement pahole-like 'ptype /o' option
Date: Wed, 13 Dec 2017 17:13:00 -0000 [thread overview]
Message-ID: <87r2ryk0ux.fsf@redhat.com> (raw)
In-Reply-To: <614d15fc-3793-8a55-b7cc-67570e8c46d3@redhat.com> (Pedro Alves's message of "Wed, 13 Dec 2017 16:18:59 +0000")
On Wednesday, December 13 2017, Pedro Alves wrote:
> On 12/13/2017 03:17 AM, Sergio Durigan Junior wrote:
>
>> +/* A struct with an union. */
>> +
>> +struct poi
>> +{
>> + int f1;
>> +
>> + union qwe f2;
>> +
>> + uint16_t f3;
>> +
>> + struct pqr f4;
>> +};
>> +
>> +/* A struct with bitfields. */
>> +
>> +struct tyu
>> +{
>> + int a1 : 1;
>> +
>> + int a2 : 3;
>> +
>> + int a3 : 23;
>> +
>> + char a4 : 2;
>> +
>> + int64_t a5;
>> +
>> + int a6 : 5;
>> +
>> + int64_t a7 : 3;
>> +};
>
> I think that the testcase should also make sure to exercise the new
> offset computations in the case c_print_type_struct_field_offset's
> 'offset_bitpos' parameter is > 0. Is it already covered?
> I assume we'll need a test like tyu (struct with bitfields with
> overlapping underlying objects), but that inherits some other
> base structure?
Ah, good point, I'll add this test.
>
>> +++ b/gdb/testsuite/gdb.base/ptype-offsets.exp
>> @@ -0,0 +1,192 @@
>> +# This testcase is part of GDB, the GNU debugger.
>> +
>> +# Copyright 2017 Free Software Foundation, Inc.
>> +
>> +# This program is free software; you can redistribute it and/or modify
>> +# it under the terms of the GNU General Public License as published by
>> +# the Free Software Foundation; either version 3 of the License, or
>> +# (at your option) any later version.
>> +#
>> +# This program is distributed in the hope that it will be useful,
>> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
>> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> +# GNU General Public License for more details.
>> +#
>> +# You should have received a copy of the GNU General Public License
>> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
>> +
>
> Please add an intro comment describing what this testcase is about.
OK.
>> +standard_testfile .cc
>> +
>> +# Test only works on x86_64 LP64 targets. That's how we guarantee
>> +# that the expected holes will be present in the struct.
>> +if { !([istarget "x86_64-*-*"] && [is_lp64_target]) } {
>> + untested "test work only on x86_64 lp64"
>> + return 0
>> +}
>
> I'm mildly worried about whether the bitfield handling is working
> correctly on big endian machines. We may want to lift this
> x86-64-only restriction, by using e.g., alignas(N) or
> __attribute__((aligned(N)) to take care of most of the differences
> between architectures and end up with few per-arch code in
> the .exp. But I'm fine with starting with only x86-64 if you
> confirm manually on e.g., a big endian PPC64 machine on the
> compile farm, and we can extend the testcase in that direction
> after this is merged.
OK, I'll confirm on PPC64BE.
>> +
>> +if { [prepare_for_testing "failed to prepare" $testfile $srcfile \
>> + { debug c++ optimize=-O0 }] } {
>> + return -1
>> +}
>
> Weren't you going to remove that optimize thing? :-)
Yes, sorry. Removed.
>> +# Test that the offset is properly reset when we are printing an union
>> +# and go inside two inner structs.
>> +# This also tests a struct inside a struct inside an union.
>
> "a union". (two times here; there may be other places.)
Fixed.
>> +gdb_test "ptype /o union qwe" \
>> + [multi_line \
>> +"/\\\* offset | size \\\*/" \
>> +"/\\\* 24 \\\*/ struct tuv {" \
>> +"/\\\* 0 | 4 \\\*/ int a1;" \
>> +"/\\\* XXX 4-byte hole \\\*/" \
>> +"/\\\* 8 | 8 \\\*/ char \\\*a2;" \
>> +"/\\\* 16 | 4 \\\*/ int a3;" \
>> +" } /\\\* total size: 24 bytes \\\*/ fff1;" \
>> +"/\\\* 40 \\\*/ struct xyz {" \
>> +"/\\\* 0 | 4 \\\*/ int f1;" \
>> +"/\\\* 4 | 1 \\\*/ char f2;" \
>> +"/\\\* XXX 3-byte hole \\\*/" \
>> +"/\\\* 8 | 8 \\\*/ void \\\*f3;" \
>> +"/\\\* 16 | 24 \\\*/ struct tuv {" \
>> +"/\\\* 16 | 4 \\\*/ int a1;" \
>> +"/\\\* XXX 4-byte hole \\\*/" \
>> +"/\\\* 24 | 8 \\\*/ char \\\*a2;" \
>> +"/\\\* 32 | 4 \\\*/ int a3;" \
>> +" } /\\\* total size: 24 bytes \\\*/ f4;" \
>> +" } /\\\* total size: 40 bytes \\\*/ fff2;" \
>> +"} /\\\* total size: 40 bytes \\\*/"] \
>> + "ptype offset union qwe"
>
> Did you try using {} instead of "" for these strings,
> avoiding all the escaping?
Yes, Simon also made the same comment. I tried replacing by {} but it
didn't work at the first attempt and since I was hacking other stuff at
the moment I dind't bother tweaking it and just reverted to using "".
If it's something you really want, I can do. Otherwise I'd prefer to
leave it like that.
>> @@ -499,6 +506,11 @@ whatis_exp (const char *exp, int show)
>> real_type = value_rtti_type (val, &full, &top, &using_enc);
>> }
>>
>> + if (flags.print_offsets &&
>
> && goes on the next line.
Fixed.
>> + (TYPE_CODE (type) == TYPE_CODE_STRUCT
>> + || TYPE_CODE (type) == TYPE_CODE_UNION))
>> + fprintf_filtered (gdb_stdout, "/* offset | size */\n");
>> +
>> printf_filtered ("type = ");
>
> Thanks,
> Pedro Alves
Thanks,
--
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/
next prev parent reply other threads:[~2017-12-13 17:13 UTC|newest]
Thread overview: 75+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-21 16:07 [PATCH] " Sergio Durigan Junior
2017-11-21 16:16 ` Sergio Durigan Junior
2017-11-21 16:50 ` Eli Zaretskii
2017-11-21 17:00 ` Sergio Durigan Junior
2017-11-21 19:14 ` Eli Zaretskii
2017-11-26 19:27 ` Tom Tromey
2017-11-27 19:54 ` Sergio Durigan Junior
2017-11-27 22:20 ` Tom Tromey
2017-11-28 0:39 ` Sergio Durigan Junior
2017-11-28 21:21 ` [PATCH v2] " Sergio Durigan Junior
2017-11-29 3:28 ` Eli Zaretskii
2017-12-04 15:03 ` Sergio Durigan Junior
2017-12-04 15:41 ` Eli Zaretskii
2017-12-04 16:47 ` Sergio Durigan Junior
2017-12-08 21:32 ` Sergio Durigan Junior
2017-12-11 15:43 ` Simon Marchi
2017-12-11 18:59 ` Sergio Durigan Junior
2017-12-11 20:45 ` Simon Marchi
2017-12-11 21:07 ` Sergio Durigan Junior
2017-12-11 22:42 ` Pedro Alves
2017-12-11 22:50 ` Sergio Durigan Junior
2017-12-11 23:46 ` Pedro Alves
2017-12-12 0:25 ` Sergio Durigan Junior
2017-12-12 0:52 ` Pedro Alves
2017-12-12 1:25 ` Simon Marchi
2017-12-12 15:50 ` John Baldwin
2017-12-12 17:04 ` Sergio Durigan Junior
2017-12-11 19:58 ` [PATCH v3 0/2] Implement pahole-like 'ptype /o' option (and do some code reorg) Sergio Durigan Junior
2017-12-11 19:58 ` [PATCH v3 1/2] Reorganize code to handle TYPE_CODE_{STRUCT,UNION} on 'c_type_print_base' Sergio Durigan Junior
2017-12-11 20:55 ` Simon Marchi
2017-12-11 23:05 ` Sergio Durigan Junior
2017-12-11 19:58 ` [PATCH v3 2/2] Implement pahole-like 'ptype /o' option Sergio Durigan Junior
2017-12-11 21:50 ` Simon Marchi
2017-12-11 23:24 ` Sergio Durigan Junior
2017-12-12 1:32 ` Simon Marchi
2017-12-12 6:19 ` Sergio Durigan Junior
2017-12-12 18:14 ` Pedro Alves
2017-12-12 18:40 ` Sergio Durigan Junior
2017-12-12 20:12 ` Pedro Alves
2017-12-11 23:43 ` [PATCH v4 0/2] Implement pahole-like 'ptype /o' option (and do some code reorg) Sergio Durigan Junior
2017-12-11 23:44 ` [PATCH v4 2/2] Implement pahole-like 'ptype /o' option Sergio Durigan Junior
2017-12-12 0:27 ` Sergio Durigan Junior
2017-12-12 0:29 ` Sergio Durigan Junior
2017-12-12 1:59 ` Simon Marchi
2017-12-12 3:39 ` Eli Zaretskii
2017-12-11 23:44 ` [PATCH v4 1/2] Reorganize code to handle TYPE_CODE_{STRUCT,UNION} on 'c_type_print_base' Sergio Durigan Junior
2017-12-13 3:17 ` [PATCH v5 0/2] Implement pahole-like 'ptype /o' option (and do some code reorg) Sergio Durigan Junior
2017-12-13 3:17 ` [PATCH v5 2/2] Implement pahole-like 'ptype /o' option Sergio Durigan Junior
2017-12-13 4:50 ` Simon Marchi
2017-12-13 16:42 ` Sergio Durigan Junior
2017-12-13 16:17 ` Eli Zaretskii
2017-12-13 17:14 ` Sergio Durigan Junior
2017-12-13 16:19 ` Pedro Alves
2017-12-13 17:13 ` Sergio Durigan Junior [this message]
2017-12-13 20:36 ` Sergio Durigan Junior
2017-12-13 21:22 ` Pedro Alves
2017-12-13 21:30 ` Pedro Alves
2017-12-13 21:34 ` Sergio Durigan Junior
2017-12-13 16:20 ` Pedro Alves
2017-12-13 17:41 ` Sergio Durigan Junior
2017-12-13 3:17 ` [PATCH v5 1/2] Reorganize code to handle TYPE_CODE_{STRUCT,UNION} on 'c_type_print_base' Sergio Durigan Junior
2017-12-14 2:48 ` [PATCH v6 0/2] Implement pahole-like 'ptype /o' option (and do some code reorg) Sergio Durigan Junior
2017-12-14 2:48 ` [PATCH v6 2/2] Implement pahole-like 'ptype /o' option Sergio Durigan Junior
2017-12-14 14:19 ` Pedro Alves
2017-12-14 20:31 ` Sergio Durigan Junior
2017-12-14 14:50 ` Pedro Alves
2017-12-14 20:29 ` Sergio Durigan Junior
2017-12-14 16:30 ` Eli Zaretskii
2017-12-14 2:48 ` [PATCH v6 1/2] Reorganize code to handle TYPE_CODE_{STRUCT,UNION} on 'c_type_print_base' Sergio Durigan Junior
2017-12-15 1:12 ` [PATCH v7 0/2] Implement pahole-like 'ptype /o' option (and do some code reorg) Sergio Durigan Junior
2017-12-15 1:12 ` [PATCH v7 1/2] Reorganize code to handle TYPE_CODE_{STRUCT,UNION} on 'c_type_print_base' Sergio Durigan Junior
2017-12-15 1:13 ` [PATCH v7 2/2] Implement pahole-like 'ptype /o' option Sergio Durigan Junior
2017-12-15 17:24 ` Pedro Alves
2017-12-15 20:04 ` Sergio Durigan Junior
2017-12-15 20:11 ` [PATCH v7 0/2] Implement pahole-like 'ptype /o' option (and do some code reorg) Sergio Durigan Junior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r2ryk0ux.fsf@redhat.com \
--to=sergiodj@redhat.com \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=keiths@redhat.com \
--cc=palves@redhat.com \
--cc=simon.marchi@ericsson.com \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox