Rust-gdb and rust-lldb break with a `[Option<i32>]` array

Hi all!

This feels like a bug but I wanted to ask an audit to be sure (and don't unnecessarily bother the dev team). I have this MWE:

// main.rs
fn main() {
    let v = [Some(2), None, Some(3), None];
    dbg!(v);
}

Now, if I try to inspect the array v with rust-gdb, it panics:

[alessandro@commodoroII debugger-testing]$ rust-gdb target/debug/debugger-testingGNU gdb (GDB) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from target/debug/debugger-testing...
(gdb) b main
Breakpoint 1 at 0x80a7: main. (2 locations)
(gdb) r
Starting program: /home/alessandro/Rust/debugger-testing/target/debug/debugger-testing 

This GDB supports auto-downloading debuginfo from the following URLs:
https://debuginfod.archlinux.org 
Enable debuginfod for this session? (y or [n]) 
Debuginfod has been disabled.
To make this setting permanent, add 'set debuginfod enabled off' to .gdbinit.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".

Breakpoint 1, 0x000055555555c300 in main ()
(gdb) n
Single stepping until exit from function main,
which has no line number information.

Breakpoint 1, debugger_testing::main () at src/main.rs:2
2           let v = [Some(2), None, Some(3), None];
(gdb) 
3           dbg!(v);
(gdb) p v
$1 = [core::option::Option<i32>::Some(
../../gdb/gdbtypes.h:1064: internal-error: field: Assertion `idx >= 0 && idx < num_fields ()' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
----- Backtrace -----
0x5575a3777b0b ???
0x5575a3ab5cb4 ???
0x5575a3b78c23 ???
0x5575a36f7ed1 ???
0x5575a3ac7d93 ???
0x5575a39fb42c ???
0x5575a3ac304b ???
0x5575a3ac88a5 ???
0x5575a3ac9adb ???
0x5575a39fb01b ???
0x5575a3ac304b ???
0x5575a379b5c8 ???
0x5575a3ac4926 ???
0x5575a3986310 ???
0x5575a3987fc2 ???
0x5575a37add84 ???
0x5575a3a7d782 ???
0x5575a3873bac ???
0x5575a3873c4d ???
0x5575a3864fcf ???
0x7fba1dfeb246 ???
0x5575a38689eb ???
0x5575a3868bd3 ???
0x5575a3873adf ???
0x5575a3b79895 ???
0x5575a3b79c69 ???
0x5575a3937c74 ???
0x5575a36e3c14 ???
0x7fba1d2c628f ???
0x7fba1d2c6349 ???
0x5575a36ea1f4 ???
0xffffffffffffffff ???
---------------------
../../gdb/gdbtypes.h:1064: internal-error: field: Assertion `idx >= 0 && idx < num_fields ()' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) y

This is a bug, please report it.  For instructions, see:
<https://www.gnu.org/software/gdb/bugs/>.

../../gdb/gdbtypes.h:1064: internal-error: field: Assertion `idx >= 0 && idx < num_fields ()' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) n

If I try with rust-lldb, it cannot show the content of the array:

[alessandro@commodoroII debugger-testing]$ rust-lldb target/debug/debugger-testing
(lldb) command script import "/home/alessandro/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/etc/lldb_lookup.py"
(lldb) command source -s 0 '/home/alessandro/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/etc/lldb_commands'
Executing commands in '/home/alessandro/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/etc/lldb_commands'.
(lldb) type synthetic add -l lldb_lookup.synthetic_lookup -x ".*" --category Rust(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(alloc::([a-z_]+::)+)String$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^&(mut )?str$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^&(mut )?\\[.+\\]$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(std::ffi::([a-z_]+::)+)OsString$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(alloc::([a-z_]+::)+)Vec<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(alloc::([a-z_]+::)+)VecDeque<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(alloc::([a-z_]+::)+)BTreeSet<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(alloc::([a-z_]+::)+)BTreeMap<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(std::collections::([a-z_]+::)+)HashMap<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(std::collections::([a-z_]+::)+)HashSet<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(alloc::([a-z_]+::)+)Rc<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(alloc::([a-z_]+::)+)Arc<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(core::([a-z_]+::)+)Cell<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(core::([a-z_]+::)+)Ref<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(core::([a-z_]+::)+)RefMut<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^(core::([a-z_]+::)+)RefCell<.+>$" --category Rust
(lldb) type summary add -F lldb_lookup.summary_lookup  -e -x -h "^core::num::([a-z_]+::)*NonZero.+$" --category Rust
(lldb) type category enable Rust
(lldb) target create "target/debug/debugger-testing"
Current executable set to '/home/alessandro/Rust/debugger-testing/target/debug/debugger-testing' (x86_64).
(lldb) b main
Breakpoint 1: 2 locations.
(lldb) r
Process 80730 launched: '/home/alessandro/Rust/debugger-testing/target/debug/debugger-testing' (x86_64)

// some initialization assembly stepping which apparently
// lldb cannot trace to a source line

(lldb) 
Process 80730 stopped
* thread #1, name = 'debugger-testin', stop reason = breakpoint 1.1
    frame #0: 0x000055555555c0a7 debugger-testing`debugger_testing::main::h8edd840516b14e3e at main.rs:2:14
   1    fn main() {
-> 2        let v = [Some(2), None, Some(3), None];
   3        dbg!(v);
   4    }
(lldb) 
Process 80730 stopped
* thread #1, name = 'debugger-testin', stop reason = step over
    frame #0: 0x000055555555c12c debugger-testing`debugger_testing::main::h8edd840516b14e3e at main.rs:3:5
   1    fn main() {
   2        let v = [Some(2), None, Some(3), None];
-> 3        dbg!(v);
   4    }
(lldb) p v
(core::option::Option<>[4]) $0 = {
  [0] =
  [1] =
  [2] =
  [3] =
}
(lldb) q
Quitting LLDB will kill one or more processes. Do you really want to proceed: [Y/n] 

Note that, however, VSCode is able to inspect it!

Am I doing something wrong, or should I report this as a bug?

And bonus question: why is VSCode able to correctly view it?

Thanks!

VSCode is using lldb I think. In addition I believe it ships with a newer version than may be installed on your system.

1 Like

Thanks, so I assume rust-lldb can be patched to correctly display it? If so, where should I report the bug?

I would expect it to work with lldb even without using rust-lldb. Might be an lldb bug.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.