From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 74792 invoked by alias); 11 Dec 2017 20:45:57 -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 74774 invoked by uid 89); 11 Dec 2017 20:45:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: sesbmg23.ericsson.net Received: from sesbmg23.ericsson.net (HELO sesbmg23.ericsson.net) (193.180.251.37) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 11 Dec 2017 20:45:54 +0000 Received: from ESESSHC001.ericsson.se (Unknown_Domain [153.88.183.21]) by sesbmg23.ericsson.net (Symantec Mail Security) with SMTP id F4.54.13339.F7EEE2A5; Mon, 11 Dec 2017 21:45:52 +0100 (CET) Received: from EUR03-VE1-obe.outbound.protection.outlook.com (153.88.183.145) by oa.msg.ericsson.com (153.88.183.21) with Microsoft SMTP Server (TLS) id 14.3.352.0; Mon, 11 Dec 2017 21:45:51 +0100 Received: from [142.133.49.104] (192.75.88.130) by AMSPR07MB310.eurprd07.prod.outlook.com (2a01:111:e400:802f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.323.4; Mon, 11 Dec 2017 20:45:46 +0000 Subject: Re: [PATCH v2] Implement pahole-like 'ptype /o' option To: Sergio Durigan Junior CC: GDB Patches , Tom Tromey , Eli Zaretskii References: <20171121160709.23248-1-sergiodj@redhat.com> <20171128212137.15655-1-sergiodj@redhat.com> <87o9n5drbn.fsf@redhat.com> From: Simon Marchi Message-ID: <99286acb-ce9f-42f0-41c3-ef10e03171ff@ericsson.com> Date: Mon, 11 Dec 2017 20:45:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <87o9n5drbn.fsf@redhat.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: MWHPR15CA0030.namprd15.prod.outlook.com (2603:10b6:300:ad::16) To AMSPR07MB310.eurprd07.prod.outlook.com (2a01:111:e400:802f::20) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ddb0df27-a0ba-4826-6137-08d540d828bd X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(5600026)(4604075)(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(2017052603307);SRVR:AMSPR07MB310; X-Microsoft-Exchange-Diagnostics: 1;AMSPR07MB310;3:we7dnQv8Uaun43Xr8vNS5P6eNgPZu8KN8ONMCPUp6oVV9etWbdOXcK6/lJqvfzYijqJjCCuVTN2DoRC1Uc0giW6LcdGNAIE6Vts7k6NRtLngM0HkQeVfQuLs1bYIQDFemxcnC/QwqQM3LndcVXTzTd0WWH9wADTGsNmFze8LsciAuL93gnHYSObULgBh5KybeFPGWZlgBFFSjaUM+osX1eyryllwXCNCSYm3gAAogR2pm91IDi/20GNi27w/nKV1;25:vt9u/b94xveF9axgdmIQjujmVCqixR48nVjmbYwzGlDaAji6fIqvUmHltnMeKey2nBcelbXVGgE60nngal2pRUJAmDfQFSPWWW3tOA809zQQJCGKH8wP2taft2lQHKJW658KXDtl3q+KBUSoYcwTTUWX9bDzOfQMaH9P+M0FH8LjbvxRo5WsV3q7XtdDuWQYSmFSH7G+gkGimhiVJDHgBl41DaKZKeiKpxA0mL19RWOfrlUcG2ioKnVMUNYC9fu0ziYFYLPXlbJn64TV/HnkrbKM5RWk3pw07kAjMzNiO8is63HntHEy/bYRK7WoMzftn3qs2V0vjs2N8rGCy6dXov6ZBPavUhlhquNtM7eTNrQ=;31:/cc9bEe5VYilVmAQhW+ZlUth41AeOCYQ0tUfoV142FNZnYhOIY5jLpL59vwgLuPRG1CfHScWBGeq4zxQ//9lekcGH49Co+c8BKARl6NazOiLvKFgj0Nn0M1P3x0uomwmLMYhgC9+GP+BnaUKrv/eEwlNSWLz4EY72blmYT8G0SxQQoPygBGv281QhfZCF9FFdzxKnq+SJunGcyZ6D+v5R4Bkr3zHMNfbjzJHUq80LdY= X-MS-TrafficTypeDiagnostic: AMSPR07MB310: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=simon.marchi@ericsson.com; X-Microsoft-Exchange-Diagnostics: 1;AMSPR07MB310;20:ozGOXZ3lgEQHrkfVe5v0ta6L2y/jid7r7KnSC5cdeiGFH6UE5iZU+0gaR0DxWsoY7hULlBqAP4EglhrmmQXOdtvRO+va1zvUIHyWBxrFNDWq35wKE2TzAIH+ogXCsXsMIAp4UkiECAWLs68ga1lfNaBKUYhUpL9+/tDyOwXdw5kmarFYDbC0yM8rlDqpz0tL+WS1q8ZsOaK5Lgfiz34KG6fWHZEw0DIz2us6WFD6rUD042Yyu+LHNXt2KBNfQaVTdX3HGIZIUyar9/RCmXFOMZ0sHVBms5/duzt9EoSwZI2OkHICZ9Vh0FoOQTHlSKfGECzvUiKewGr5Nsn7ogz4eH4TJnIp+Z7u0C9VQMhKtc/CXfyk+ndM+HMcdviJ8XpxAIK4zNcXOZe6pk7ehAd0hHeAW/tqM4DK4s14sjDxRrqXFr3cDmCI3neW/CsBQ3xCPrg43CqcfNbQv7S2kpjR1zkx9/PPz7ugrfNoIDHAlBzla2dtmJrGNFjjofXQE1lM;4:vxYIbP3w/q/U/RxVjMm4fiobna5J7dNCo3fT/axEhB1Om2as03oRoDzN/UCnnbmqSN0bU393UpKAFb0kJbFf4dbEpYeKRpn3cbi0B5xE3XLFyRZ4fyAj5QV6X07cybGYNIGANnTCZuizPyeuI3qBVa7IsYV9FXfkdPm+30d1z6A98oPcpIvh2x50P7FSI/6gnW+gD082F+Btpu+3bjD7Z1P3YD14OmApcmKPl/9l3QAwh+LNA7ZoB8R94fA5G0pusNtF5BPOs2/ifY4i042RjE+S244QF4JQjwyvUk5VbzKyn7JXOMPeVq3Ll/Fj4xwq X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(17755550239193); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(2401047)(8121501046)(5005006)(3231023)(3002001)(93006095)(93001095)(10201501046)(6041248)(20161123562025)(20161123555025)(20161123558100)(20161123560025)(201703131423075)(201703011903075)(201702281528075)(201703061421075)(20161123564025)(6072148)(201708071742011);SRVR:AMSPR07MB310;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:AMSPR07MB310; X-Forefront-PRVS: 0518EEFB48 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6049001)(7966004)(39860400002)(346002)(366004)(376002)(189003)(199004)(68736007)(36756003)(50466002)(229853002)(59450400001)(52146003)(52116002)(2486003)(23676004)(53936002)(76176011)(230700001)(6486002)(31686004)(16526018)(64126003)(6246003)(83506002)(3846002)(86362001)(6116002)(106356001)(6666003)(47776003)(16576012)(316002)(58126008)(5660300001)(105586002)(31696002)(4326008)(65956001)(65806001)(66066001)(65826007)(97736004)(305945005)(7736002)(93886005)(8936002)(8676002)(54906003)(81156014)(81166006)(49976008)(508600001)(2906002)(25786009)(6916009)(2950100002)(78286006);DIR:OUT;SFP:1101;SCL:1;SRVR:AMSPR07MB310;H:[142.133.49.104];FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; Received-SPF: None (protection.outlook.com: ericsson.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtBTVNQUjA3TUIzMTA7MjM6Vkh1cjRPTlFOV0E5UlI5RGkyeDE2OGZHMC9P?= =?utf-8?B?WE1qZnA4K2FVaDBjYjhvV2t3SXFDM3p0QUtmRWVRdzZMVmh0Ti9JOGlkVWFY?= =?utf-8?B?Y2p5Y2h3Q2Jub0JUWFRZc2Z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dvLTBxgCw3vqOTdanWJEJ5lOQn6zyAEB49vCzpMkcJdVIjzNxY//FZK+hfg20REmx9EVv43FVo1dJ4LJu9Mskv48RurhdpTotS20PN/QDjYX30xQIO42aB1YnZAcP191Z5TeBSAA3SRg0iOjgl8uc9jDw/uNM/ap4kMX+0DvUSj3J7FDdZCdRorg8/yzcn23m6vBJyAP34Hu+3jBaCq6uYHx9cAdgjbHOykrcajrJswqBOTWVIlNU3STXNsnJbenCe3imZq121FGU7Y9m7euwiNJzqzjyhvEzS82+G6zvkfqTDTFrmg+uRVsTnQ6Ka5Gzyl8=;5:5uIw1wIRogb03UMYrDdBipLitLqhp455ahf3l1UF5r4DWPw+GgquchsHEb8/LtPRpniaMORfmMMn9VWUD1xbNJOkWgJyGrpgvAqmBYBhCtm9efQyt7L7GpfA3+Nd0iAhHbBbzelPXIy3S+YfUxQdNrjJmq4+rn3G4Tn6zLLfA4s=;24:I7HqWUI5uy9riEzTEHOAHTyz8DX2N3aLx13QAW6ZYO9Fu35+Uv4RIC5GRrIDKKoyQxmZmW0VRe98PerLjLutC7dLEewrztKZk9MMYAlffrY=;7:hBDVoCrEDdyRkpccEg0PcrPUUyA2NSvPKrDb0ItyBUf7tmKWwuoRm7w1fwuSEtJZL4/fx/QMvCttdFtAWUR0iQQ+kISrsMMF1JXeA1/icAW8twLRR2nadKTEXR0t67w/G6vO7UBGJDAQUH9ZWTcJT0/tk9vHSMk+rAVwTCZdUTjIMKZzCN8Am3pVLXnsm7/pxCeJt6C+9vRctcPZNeCdyZOh/bSiI4tvd8dU67KAYGjAUDEHy0ie/N1doOJ/X2Gw SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2017 20:45:46.9969 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ddb0df27-a0ba-4826-6137-08d540d828bd X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AMSPR07MB310 X-OriginatorOrg: ericsson.com X-IsSubscribed: yes X-SW-Source: 2017-12/txt/msg00248.txt.bz2 >>> +/* Use 'print_spaces_filtered', but take into consideration the >>> + type_print_options FLAGS in order to determine how many whitespaces >>> + will be printed. */ >>> + >>> +static void >>> +print_spaces_filtered_with_print_options (int level, struct ui_file *stream, >>> + const struct type_print_options *flags) >> >> Missing spaces here. > > This is actually on purpose. If I indent the line, it will have more > than 80 chars. I believe this is a well known method for avoiding this > problem...? I am not aware of that. In this case I would put the parameter list on the next, I'm not sure if it's 100% GNU-style approved, but nobody complained when I did it so far :) static void print_spaces_filtered_with_print_options (int level, struct ui_file *stream, const struct type_print_options *flags); It helps with long function names. In this case, I would probably just drop the "struct" to save a few chars, because C++. >>> +if { [prepare_for_testing "failed to prepare" $testfile $srcfile \ >>> + { debug c++ optimize=-O0 }] } { >> >> optimize=-O0 seems unnecessary to me, I've never seen it specified explicitly in a test. > > There are very few tests that use it (2, currently). I understand it's > not very common to explicitly specify -O0, but I put it there because I > decided to be on the safe side. If the compiler performs any > optimization at all, it could mess with the layout of the structs. If GCC decided to optimize by default, so many things would break in the GDB testsuite. We would then probably make gdb_compile add -O0, so that we wouldn't need to do it in all tests. The point is that IMO, tests should expect no optimization by default. >> I also noticed that the offset is not shown in front of the struct-in-union, >> as show above, but it is in the case of struct-in-struct: >> >> /* offset | size */ >> type = struct my_struct_3 { >> /* 0 | 8 */ struct my_struct_1 { >> /* 0 | 4 */ int a; >> /* 4 | 4 */ int b; >> } /* total size: 8 bytes */ s1; >> /* 8 | 8 */ struct my_struct_2 { >> /* 8 | 4 */ int c; >> /* 12 | 4 */ int d; >> } /* total size: 8 bytes */ s2; >> } /* total size: 16 bytes */ >> >> Is this difference on purpose? > > Yes; offsets are not shown for fields inside unions (not only structs, > but all types of fields), because it doesn't make much sense: they'd be > 0 every time. This is also inspired from pahole's output. Not if that union is itself in a struct. For example with this: struct hello { int i; union { struct { int x, y; } a; struct { int x, y; } b; }; }; (gdb) ptype /o struct hello /* offset | size */ type = struct hello { /* 0 | 4 */ int i; /* 4 | 8 */ union { /* 8 */ struct { /* 4 | 4 */ int x; /* 8 | 4 */ int y; } /* total size: 8 bytes */ a; /* 8 */ struct { /* 4 | 4 */ int x; /* 8 | 4 */ int y; } /* total size: 8 bytes */ b; } /* total size: 8 bytes */; } /* total size: 12 bytes */ But I don't mind it, it just stuck out as a little inconsistency. I'll look at v3 now. Simon