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: Sergio Durigan Junior <sergiodj at redhat dot com>
- To: Pedro Alves <palves at redhat dot com>
- Cc: GDB Patches <gdb-patches at sourceware dot org>, 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 15:29:09 -0500
- 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> <afe48f6e-54af-6e64-fa73-786c8c3fa2a6@redhat.com>
Thanks for the review.
On Thursday, December 14 2017, Pedro Alves wrote:
> On 12/14/2017 02:48 AM, Sergio Durigan Junior wrote:
>
>> +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.
Done.
>> + 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...
Removed.
>> +
>> +#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.
Done.
>> +# 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".
Hm, OK. Added the tests.
>> +/* 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.
Indeed. I removed it in favour of initializing in-class.
>> --- 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?
Right; endpos is too generic indeed. Renamed to end_bitpos.
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/