From: John Baldwin <jhb@FreeBSD.org>
To: Lancelot SIX <lsix@lancelotsix.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 2/2] ptype: add option to use hexadecimal notation
Date: Tue, 13 Apr 2021 16:18:24 -0700 [thread overview]
Message-ID: <8c431340-2115-c1f8-9568-620a175b35c9@FreeBSD.org> (raw)
In-Reply-To: <20201231125324.14779-3-lsix@lancelotsix.com>
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
next prev parent reply other threads:[~2021-04-13 23:18 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
2020-12-31 12:53 ` [PATCH 1/2] typeprint.h: reorder struct declaration Lancelot SIX
2020-12-31 13:01 ` Lancelot SIX
2020-12-31 15:51 ` Andrew Burgess
2020-12-31 12:53 ` [PATCH 2/2] ptype: add option to use hexadecimal notation Lancelot SIX
2021-04-13 23:18 ` John Baldwin [this message]
2021-04-14 0:08 ` Paul Koning
2021-04-14 22:45 ` Lancelot SIX
2021-04-15 0:08 ` Paul Koning
2021-04-14 22:33 ` Lancelot SIX
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=8c431340-2115-c1f8-9568-620a175b35c9@FreeBSD.org \
--to=jhb@freebsd.org \
--cc=gdb-patches@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).