Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Lancelot SIX via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Cc: Lancelot SIX <lsix@lancelotsix.com>
Subject: [PATCH 0/2][PR cli/22640] Have ptype support hex display of offsets and sizes
Date: Thu, 31 Dec 2020 12:53:22 +0000	[thread overview]
Message-ID: <20201231125324.14779-1-lsix@lancelotsix.com> (raw)

Hi,

Here is a series of patch designed to address PR cli/22640.

The idea is to allow 'ptype' to print offsets and sizes of struct
members using hex notation if desired. Currently, gdb only uses the
decimal notation.

Before:

    (gdb) ptype /o struct type_print_options
    /* offset    |  size */  type = struct type_print_options {
    /*    0: 0   |     4 */    unsigned int raw : 1;
    /*    0: 1   |     4 */    unsigned int print_methods : 1;
    /*    0: 2   |     4 */    unsigned int print_typedefs : 1;
    /*    0: 3   |     4 */    unsigned int print_offsets : 1;
    /*    0: 4   |     4 */    unsigned int print_in_hex : 1;
    /* XXX  3-bit hole   */
    /* XXX  3-byte hole  */
    /*    4      |     4 */    int print_nested_type_limit;
    /*    8      |     8 */    typedef_hash_table *local_typedefs;
    /*   16      |     8 */    typedef_hash_table *global_typedefs;
    /*   24      |     8 */    ext_lang_type_printers *global_printers;
    
                               /* total size (bytes):   32 */
                             }

With the patches and hex option 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 series also allows the user to set the default behavior using
the 'set print type hex' command.

I am happy to discuss any improvement on the commands and options names
if desired.

The first patch of the series only swaps two types declaration (leaving
them unchanged otherwise) because the second will rely on this new order.

My copyright assignment have not yet been finalized, I’ll notify
maintainers as soon as it is.

Lancelot SIX (2):
  typeprint.h: reorder struct declaration
  ptype: add option to use hexadecimal notation

 gdb/c-typeprint.c                        |   8 +-
 gdb/doc/gdb.texinfo                      |  27 ++++++
 gdb/rust-lang.c                          |   2 +-
 gdb/testsuite/gdb.base/ptype-offsets.exp | 114 +++++++++++++++++++++++
 gdb/typeprint.c                          |  72 +++++++++++++-
 gdb/typeprint.h                          |  69 ++++++++------
 6 files changed, 252 insertions(+), 40 deletions(-)

-- 
2.29.2


             reply	other threads:[~2020-12-31 12:53 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-31 12:53 Lancelot SIX via Gdb-patches [this message]
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

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=20201231125324.14779-1-lsix@lancelotsix.com \
    --to=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