Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Lancelot SIX via Gdb-patches <gdb-patches@sourceware.org>
To: John Baldwin <jhb@FreeBSD.org>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 2/2] ptype: add option to use hexadecimal notation
Date: Wed, 14 Apr 2021 23:33:41 +0100	[thread overview]
Message-ID: <20210414223226.6cucb2p4veq6nhku@Plymouth> (raw)
In-Reply-To: <8c431340-2115-c1f8-9568-620a175b35c9@FreeBSD.org>

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.

      parent reply	other threads:[~2021-04-14 22:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-31 12:53 [PATCH 0/2][PR cli/22640] Have ptype support hex display of offsets and sizes Lancelot SIX via Gdb-patches
2020-12-31 12:53 ` [PATCH 1/2] typeprint.h: reorder struct declaration Lancelot SIX via Gdb-patches
2020-12-31 13:01   ` Lancelot SIX via Gdb-patches
2020-12-31 15:51     ` Andrew Burgess
2020-12-31 12:53 ` [PATCH 2/2] ptype: add option to use hexadecimal notation Lancelot SIX via Gdb-patches
2021-04-13 23:18   ` John Baldwin
2021-04-14  0:08     ` Paul Koning via Gdb-patches
2021-04-14 22:45       ` Lancelot SIX via Gdb-patches
2021-04-15  0:08         ` Paul Koning via Gdb-patches
2021-04-14 22:33     ` Lancelot SIX via Gdb-patches [this message]

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=20210414223226.6cucb2p4veq6nhku@Plymouth \
    --to=gdb-patches@sourceware.org \
    --cc=jhb@FreeBSD.org \
    --cc=lsix@lancelotsix.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