Skip to content

gdb "cannot subscript non-array type" to index a Vec #66482

Open
@Hi-Angel

Description

@Hi-Angel

Attempt to print content of a Vec at index results in error. Since it works fine for C++, I think the problem is in rustc not providing the necessary debug information for this to work.

Vecs are a widely used type, and not being able to print their content at index hurts debugging process noticeably.

Steps to reproduce (in terms of terminal commands)

$ cat -n test2.rs
     1  fn main() {
     2      let x: Vec<usize> = vec![1,2,3];
     3      println!("{:?}", x);
     4  }
$ rustc test2.rs -o a -g
$ gdb ./a
Reading symbols from ./a...
warning: Missing auto-load script at offset 0 in section .debug_gdb_scripts
of file /tmp/a.
Use `info auto-load python-scripts [REGEXP]' to list them.
gdb λ br 3
Breakpoint 1 at 0x5c05: file test2.rs, line 3.
gdb λ r
Starting program: /tmp/a
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".

Breakpoint 1, test2::main () at test2.rs:3
3           println!("{:?}", x);
gdb λ p x[0]

Expected

A print:

1

Actual

It prints:

Cannot subscript non-array type

Additional information

rustc version: rustc 1.41.0-nightly (1bd30ce2a 2019-11-15)
gdb version: 8.3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)C-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions