From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from beryx.lancelotsix.com (beryx.lancelotsix.com [IPv6:2001:41d0:401:3000::1ab3]) by sourceware.org (Postfix) with ESMTPS id 2DC513857830 for ; Thu, 31 Dec 2020 12:53:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2DC513857830 Received: from gwenhwyvar.lan (unknown [IPv6:2a02:390:8443:0:c4c8:3723:2c37:f63b]) by beryx.lancelotsix.com (Postfix) with ESMTPSA id 07FE32E070; Thu, 31 Dec 2020 13:53:47 +0100 (CET) From: Lancelot SIX To: gdb-patches@sourceware.org Cc: Lancelot SIX 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 Message-Id: <20201231125324.14779-1-lsix@lancelotsix.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.11 (beryx.lancelotsix.com [0.0.0.0]); Thu, 31 Dec 2020 13:53:48 +0100 (CET) X-Spam-Status: No, score=-5.7 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: Thu, 31 Dec 2020 12:53:51 -0000 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