[PATCH] Print type name when printing Rust slice
Simon Marchi
simark@simark.ca
Mon Mar 11 16:19:17 GMT 2024
On 3/11/24 11:14, Tom Tromey wrote:
> The recent change to how unsized Rust values are printed included a
> small regression from past behavior. Previously, a slice's type would
> be printed, like:
>
> (gdb) print slice
> $80 = &[i32] [3]
>
> The patch changed this to just
>
> (gdb) print slice
> $80 = [3]
>
> This patch restores the previous behavior.
> ---
> gdb/rust-lang.c | 11 +++++++++++
> gdb/testsuite/gdb.rust/simple.exp | 2 +-
> gdb/testsuite/gdb.rust/unsized.exp | 2 +-
> 3 files changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
> index ab537cc9752..d7265f72770 100644
> --- a/gdb/rust-lang.c
> +++ b/gdb/rust-lang.c
> @@ -476,6 +476,17 @@ rust_language::val_print_slice
> }
> }
>
> + /* Print the slice type here. This was gdb's historical behavior
> + (from before unsized types were generically handled) and helps
> + make it clear that the user is seeing a slice, not an array.
> + Only arrays must be handled as the other cases are handled by
> + value_print_inner. */
> + if (type->code () == TYPE_CODE_ARRAY)
> + {
> + type_print (orig_type, "", stream, -1);
> + gdb_printf (stream, " ");
> + }
Just for me education, how are slices represented in the GDB type
system, as opposed to arrays? What are the value types that
rust_language::val_print_slice expects to receive, other than
TYPE_CODE_ARRAY?
You can add my:
Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
... although it's not worth much because I don't know this area.
Simon
More information about the Gdb-patches
mailing list