Bug 23871 - better support for slices
Summary: better support for slices
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: rust (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 13.1
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-11-07 20:18 UTC by Tom Tromey
Modified: 2022-04-15 17:37 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Tromey 2018-11-07 20:18:34 UTC
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.
Comment 1 Tom Tromey 2022-03-27 21:22:20 UTC
I've got a patch for this.
Comment 2 Sourceware Commits 2022-04-15 17:35:58 UTC
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
Comment 3 Tom Tromey 2022-04-15 17:37:29 UTC
Fixed.