Compile & debug this program: pub fn main() { let x = &[1, 2, 3, 4, 5]; let y = &x[..]; let z = 7; } First, 'x' is not recognized as a slice: (gdb) p x $1 = (i32 (*)[5]) 0x555555577b40 The DWARF says it is a pointer to an array: <1><30d>: Abbrev Number: 6 (DW_TAG_pointer_type) <30e> DW_AT_type : <0x316> <312> DW_AT_name : (indirect string, offset: 0x2bd): &[i32; 5] <1><316>: Abbrev Number: 7 (DW_TAG_array_type) <317> DW_AT_type : <0x323> <2><31b>: Abbrev Number: 8 (DW_TAG_subrange_type) <31c> DW_AT_type : <0x32a> <320> DW_AT_lower_bound : 0 <321> DW_AT_count : 5 <2><322>: Abbrev Number: 0 ... maybe this should be fixed in rustc, but maybe in gdb. Second, rust-gdb's pretty-printer shows this for 'y': (gdb) p y $2 = &[i32](len: 5) = {1, 2, 3, 4, 5} But gdb shows: (gdb) p/r y $3 = &[i32] { data_ptr: 0x555555577b40, length: 5 } It might make sense to have the built-in printer work more like rust-gdb's.
I've got a patch for this.
The master branch has been updated by Tom Tromey <tromey@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=506ec52e8805d8edd538d6bd11750489a8c8bbee commit 506ec52e8805d8edd538d6bd11750489a8c8bbee Author: Tom Tromey <tom@tromey.com> Date: Fri Mar 25 13:36:53 2022 -0600 Reimplement Rust slice printing The current nightly Rust compiler (aka 1.61) added better DWARF representation for unsized types. Fixing this is PR rust/21466; but the code is actually the same as what is required to make slice printing more useful, which is PR rust/23871. This patch implements this. I tested this against various Rust compilers: 1.48, current stable, current beta, and current nightly. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=21466 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23871
Fixed.