summaryrefslogtreecommitdiff
path: root/gdb/rust-lang.c
diff options
context:
space:
mode:
authorLancelot SIX <lsix@lancelotsix.com>2021-04-17 12:10:23 +0100
committerLancelot SIX <lsix@lancelotsix.com>2021-04-25 18:00:54 +0100
commitfbb46296d7e0d09e792a7c9d7841cb26753cb3ce (patch)
tree57a8906aac5ac27c70664f749980f2d3b6c6f517 /gdb/rust-lang.c
parent18bbba46a974d8b667f9b60c5a7d41bb3cb07369 (diff)
downloadbinutils-gdb-fbb46296d7e0d09e792a7c9d7841cb26753cb3ce.tar.gz
[PR gdb/22640] ptype: add option to use hexadecimal notation
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 'd' 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 PR gdb/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 { /* 0x0000: 0x0 | 0x0004 */ unsigned int raw : 1; /* 0x0000: 0x1 | 0x0004 */ unsigned int print_methods : 1; /* 0x0000: 0x2 | 0x0004 */ unsigned int print_typedefs : 1; /* 0x0000: 0x3 | 0x0004 */ unsigned int print_offsets : 1; /* 0x0000: 0x4 | 0x0004 */ unsigned int print_in_hex : 1; /* XXX 3-bit hole */ /* XXX 3-byte hole */ /* 0x0004 | 0x0004 */ int print_nested_type_limit; /* 0x0008 | 0x0008 */ typedef_hash_table *local_typedefs; /* 0x0010 | 0x0008 */ typedef_hash_table *global_typedefs; /* 0x0018 | 0x0008 */ 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 on x86_64. gdb/ChangeLog: PR gdb/22640 * typeprint.h (struct type_print_options): Add print_in_hex flag. (struct print_offset_data): Add print_in_hex flag, add a constructor accepting a type_print_options* argument. * typeprint.c (type_print_raw_options, default_ptype_flags): Set default value for print_in_hex. (print_offset_data::indentation): Allow more horizontal space. (print_offset_data::print_offset_data): Add ctor. (print_offset_data::maybe_print_hole, print_offset_data::update): Handle the print_in_hex flag. (whatis_exp): Handle 'x' and 'd' flags. (print_offsets_and_sizes_in_hex): Declare. (set_print_offsets_and_sizes_in_hex): Create. (show_print_offsets_and_sizes_in_hex): Create. (_initialize_typeprint): Update help message for the ptype command, register the 'set print type hex' and 'show print type hex' commands. * c-typeprint.c (c_print_type, c_type_print_base_struct_union) (c_type_print_base): Construct the print_offset_data object using the type_print_optons parameter. * rust-lang.c (rust_language::print_type): Construct the print_offset_data object using the type_print_optons parameter. * NEWS: Mention the new flags of the ptype command. gdb/doc/ChangeLog: PR gdb/22640 * gdb.texinfo (Symbols): Describe the 'x' and 'd' flags of the ptype command, describe 'set print type hex' and 'show print type hex' commands. Update 'ptype/o' examples. gdb/testsuite/ChangeLog: PR gdb/22640 * gdb.base/ptype-offsets.exp: Add tests to verify the behavior of 'ptype/ox' and 'ptype/od'. Check that 'set print type hex' changes the default behavior of 'ptype/o'. Update to take into account new horizontal layout. * gdb.rust/simple.exp: Update ptype test to check new horizontal layout. * gdb.rust/union.exp: Same.
Diffstat (limited to 'gdb/rust-lang.c')
-rw-r--r--gdb/rust-lang.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index a57ee988668..8c4d209b07a 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1574,7 +1574,7 @@ rust_language::print_type (struct type *type, const char *varstring,
struct ui_file *stream, int show, int level,
const struct type_print_options *flags) const
{
- print_offset_data podata;
+ print_offset_data podata (flags);
rust_internal_print_type (type, varstring, stream, show, level,
flags, false, &podata);
}