From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 86309 invoked by alias); 26 Nov 2017 19:27:20 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 86296 invoked by uid 89); 26 Nov 2017 19:27:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL,BAYES_00,KB_WAM_FROM_NAME_SINGLEWORD,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=no version=3.3.2 spammy=Hx-languages-length:1724, hole, xxx X-HELO: gateway22.websitewelcome.com Received: from gateway22.websitewelcome.com (HELO gateway22.websitewelcome.com) (192.185.46.234) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 26 Nov 2017 19:27:17 +0000 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 9342D5C51 for ; Sun, 26 Nov 2017 13:27:16 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id J2aCeuxIlRtUXJ2aCe2fyN; Sun, 26 Nov 2017 13:27:16 -0600 Received: from 71-218-90-63.hlrn.qwest.net ([71.218.90.63]:36478 helo=bapiya) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eJ2aC-001DHg-CN; Sun, 26 Nov 2017 13:27:16 -0600 From: Tom Tromey To: Sergio Durigan Junior Cc: GDB Patches Subject: Re: [PATCH] Implement pahole-like 'ptype /o' option References: <20171121160709.23248-1-sergiodj@redhat.com> Date: Sun, 26 Nov 2017 19:27:00 -0000 In-Reply-To: <20171121160709.23248-1-sergiodj@redhat.com> (Sergio Durigan Junior's message of "Tue, 21 Nov 2017 11:07:09 -0500") Message-ID: <87tvxgvo18.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-BWhitelist: no X-Source-L: No X-Exim-ID: 1eJ2aC-001DHg-CN X-Source-Sender: 71-218-90-63.hlrn.qwest.net (bapiya) [71.218.90.63]:36478 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-SW-Source: 2017-11/txt/msg00673.txt.bz2 >>>>> "Sergio" == Sergio Durigan Junior writes: Sergio> This commit implements the pahole-like '/o' option for 'ptype', which Sergio> prints the offsets and sizes of struct fields, reporting whenever Sergio> there is a hole found. Thanks for doing this! Sergio> The idea is to print offsets and sizes only for structs, so unions and Sergio> other types are mostly ignored. I tried out the patch, since I want to add support for this feature to the Rust language code. I have two comments. First, I think it would be valuable to descend into embedded structures. This would make it simpler to review layout of the entire outer struct. That is, like this: struct t { int x; int y; }; struct s { int x; char c; struct t t; } s; The old pahole.py did do this, like (gdb) pahole struct s struct s { /* 0 4 */ int x /* 4 1 */ char c /* XXX 24 bit hole, try to pack */ /* 8 8 */ struct t { /* 0 4 */ int x /* 4 4 */ int y } t } ... though the old code's output is kind of confusing, restarting the offset at 0 in the embedded struct. Second, and similarly, descending into unions does seem to make sense sometimes (pahole.py didn't do this, but it seems like it should have). Continuing the above example, consider: union u { struct s s; int i; }; Here ptype shows: (gdb) ptype/o union u type = union u { struct s s; int i; } (The formatting looks weird without the layout info here...) I think one specific case where it is interesting to see the union's layout is when you want to know why a union field in a struct is as large as it is. That is, what is the largest member of the union, in case you want to try to shrink it? Tom