rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.18k stars 12.7k forks source link

rust-gdb: Accessing tuple inside enum triggers invalid gdb expression syntax error. #132378

Open apodolsk opened 2 days ago

apodolsk commented 2 days ago

I tried this code:

fn main() {
    let a = Some((0u32, 1u32));
    dbg!(a);
}

When debugging in gdb, I expect to be able to write an expression to access a value inside a tuple, inside an enum. I want to do that so that I can e.g. dereference a pointer stored in such a tuple. It seems that a.0 accesses the Some branch of my option, so I would expect a.0.0 to access the first tuple elem.

Instead, a.0.0 triggers a gdb expression syntax error. Note that it does work to append .0 to a gdb variable storing a.0 to access the tuple, which further suggests that a.0.0 should work.

Breakpoint 2.1, gdb_tuple::main () at src/main.rs:3
3       dbg!(a);
(gdb) p a
$1 = core::option::Option<(u32, u32)>::Some((
    0,
    1
  ))
(gdb) p a.0
$2 = (
  0,
  1
)
(gdb) p a.0.0
field name expected
(gdb) p $2.0
$3 = 0

a.0 to access the Some admittedly seems like a bit of black magic. Helper functions like unwrap are consistently not available in the binaries that I've tried to debug thus far, so I'm not sure what else I should be doing.

Meta

rustc --version --verbose:

rustc 1.84.0-nightly (439284741 2024-10-21)
binary: rustc
commit-hash: 4392847410ddd67f6734dd9845f9742ff9e85c83
commit-date: 2024-10-21
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1
apodolsk commented 2 days ago

Can't add a label, so preemptively pinging debug wg: @pnkfelix @wesleywiser. Github noob, so let me know if that's in bad taste.

workingjubilee commented 2 days ago

@rustbot label: +A-debuginfo +WG-debugging

workingjubilee commented 2 days ago

...actually, I'm not sure debuginfo actually has anything to do with this, thinking about it. I don't know that we have a label for debugger expressions.

@rustbot label: -A-debuginfo