Bug 24801

Summary: Pretty-printing support for Rust generators
Product: gdb Reporter: Tyler Mandry <tmandry>
Component: rustAssignee: Not yet assigned to anyone <unassigned>
Status: UNCONFIRMED ---    
Severity: normal CC: tromey
Priority: P2    
Version: unknown   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description Tyler Mandry 2019-07-10 22:29:23 UTC
Support printing Rust generators in a way that looks more like enums. Generators are represented in Rust as variant layouts with some extra fields on the outer layout. These extra fields (which are upvars, captured from the environment of the generator closure) seem to cause printing to become less pretty.

Today printing a Rust generator looks like this:

$2 = generator_objects::main::generator {__0: 0x7fffffffd204, <<variant>>: {__state: 3, 0: generator_objects::main::generator::Unresumed, 1: generator_objects::main::generator::Returned, 2: generator_objects::main::generator::Panicked, 3: generator_objects::main::generator::Suspend0 {c: 6, d: 7}, 4: generator_objects::main::generator::Suspend1 {c: 6, d: 7}}}

Note that we print the fields of every single variant, even though the discriminant is marked in DWARF.

Here's the source code: https://github.com/rust-lang/rust/blob/c6a9e766f90a5271c2356fbc7941e38559200ab5/src/test/debuginfo/generator-objects.rs. The above excerpt is from the second print in the test. __0 in the output is the upvar for `a` from the environment (it should be called `a` instead of `__0`, but this is a problem in the Rust compiler).

The corresponding DWARF: https://gist.github.com/tmandry/92e1368b51bea06d11da1e45218813db
Comment 1 Tyler Mandry 2019-07-10 22:43:42 UTC
Opened as https://github.com/rust-lang/rust/issues/62572 on the Rust project; if you feel it's more appropriate to track there then feel free to close this issue.
Comment 2 Tom Tromey 2019-08-16 20:15:44 UTC
It would be helpful to have a small Rust test program using generators.