From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lndn.lancelotsix.com (lndn.lancelotsix.com [51.195.220.111]) by sourceware.org (Postfix) with ESMTPS id 0D3A9385800A for ; Wed, 14 Apr 2021 22:33:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0D3A9385800A Received: from Plymouth (unknown [IPv6:2a02:390:9086:0:9999:cdc9:65ae:899c]) by lndn.lancelotsix.com (Postfix) with ESMTPSA id 436F98183C; Wed, 14 Apr 2021 22:33:45 +0000 (UTC) Date: Wed, 14 Apr 2021 23:33:41 +0100 From: Lancelot SIX To: John Baldwin Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 2/2] ptype: add option to use hexadecimal notation Message-ID: <20210414223226.6cucb2p4veq6nhku@Plymouth> References: <20201231125324.14779-1-lsix@lancelotsix.com> <20201231125324.14779-3-lsix@lancelotsix.com> <8c431340-2115-c1f8-9568-620a175b35c9@FreeBSD.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <8c431340-2115-c1f8-9568-620a175b35c9@FreeBSD.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.11 (lndn.lancelotsix.com [0.0.0.0]); Wed, 14 Apr 2021 22:33:45 +0000 (UTC) X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Apr 2021 22:33:49 -0000 On Tue, Apr 13, 2021 at 04:18:24PM -0700, John Baldwin wrote: > On 12/31/20 4:53 AM, Lancelot SIX via Gdb-patches wrote: > > This commit adds a flag to the ptype command in order to print the > > offsets and sizes of struct members using the hexadecimal notation. The > > 'x' flag ensures use of the hexadecimal notation while the 'X' flag > > ensures use of the decimal notation. The default is to use decimal > > notation. > > > > Before this patch, gdb only uses decimal notation, as pointed out in bug > > cli/22640. > > > > Here is an example of this new behavior with hex output turned on: > > > > (gdb) ptype /ox struct type_print_options > > /* offset | size */ type = struct type_print_options { > > /* 0x00: 0 | 0x04 */ unsigned int raw : 1; > > /* 0x00: 1 | 0x04 */ unsigned int print_methods : 1; > > /* 0x00: 2 | 0x04 */ unsigned int print_typedefs : 1; > > /* 0x00: 3 | 0x04 */ unsigned int print_offsets : 1; > > /* 0x00: 4 | 0x04 */ unsigned int print_in_hex : 1; > > /* XXX 3-bit hole */ > > /* XXX 3-byte hole */ > > /* 0x04 | 0x04 */ int print_nested_type_limit; > > /* 0x08 | 0x08 */ typedef_hash_table *local_typedefs; > > /* 0x10 | 0x08 */ typedef_hash_table *global_typedefs; > > /* 0x18 | 0x08 */ ext_lang_type_printers *global_printers; > > > > /* total size (bytes): 32 */ > > } > > > > This patch also adds the 'set print type hex' and 'show print type hex' > > commands in order to set and inspect the default behavior regarding the > > use of decimal or hexadecimal notation when printing struct sizes and > > offsets. > > > > Tested using 'runtest -tool gdb ptype-offsets.exp' > > Thanks for working on this. In general I think this looks fine in > terms of new print flags, etc. My only concern might be that a > single byte worth of space might be a bit short. I frequently > use ptype with some larger data structures whose sizes in hex > run to 3 digits and would distort the formatting as a result. > > What would you think of using 6 character fields for hex values > such as 0x%04x? It would mean the entire display would shift left > by 4 characters and the header would have to be adjusted. Alternatively > if you are really concerned about horizontal space you could perhaps > only expand the offset portion to 4 hex digits? > > The other possible consideration is to not print leading zeroes > but instead use '%6s' with hex_string() for the hex fields. > > -- > John Baldwin Hi, Thanks for the feedback. For my initial take at this I kept the overall horizontal layout unchanged, but it is true that the 0x prefix consumes quite some space. I’ll increase the horizontal space and prepare a new version (with the 0x%04x approach I think). Lancelot.