rust-lang / rust-lang/rust

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

Open
#132,378 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug WG-debugging
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the nested tuple access failure with the Rust program and rust-gdb commands shown in the issue. Trace the expression handling for a.0.0, compare it with the successful $2.0 lookup, and consider the issue done when direct nested access works without a GDB syntax error and the behavior is covered by an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.