[PATCH] Print type name when printing Rust slice

Tom Tromey tom@tromey.com
Mon Mar 11 17:32:50 GMT 2024


>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:

Simon> Just for me education, how are slices represented in the GDB type
Simon> system, as opposed to arrays?  What are the value types that
Simon> rust_language::val_print_slice expects to receive, other than
Simon> TYPE_CODE_ARRAY?

Under the hood a slice is a structure holding a pointer and a length.
However to the Rust programmer these look somewhat like arrays.  For
example, you can index into them like arrays.

rust_slice_type_p determines if something is "slice-like".

An "unsized" type is basically the same thing, but where the payload is
some object with an array at the end, like the C struct hack.
rust-lang.c calls these both "slice" at some spots, mainly because I
didn't understand this when I first wrote the code.

FWIW Ada has a similar concept but it is more general, because Ada has
multi-dimensional arrays and range types.

Tom


More information about the Gdb-patches mailing list