Bug 24801 - Pretty-printing support for Rust generators
Summary: Pretty-printing support for Rust generators
Status: UNCONFIRMED
Alias: None
Product: gdb
Classification: Unclassified
Component: rust (show other bugs)
Version: unknown
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-07-10 22:29 UTC by Tyler Mandry
Modified: 2019-08-16 20:15 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.