Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unintuitve stepping behavior for match expressions in a debugger #87817

Closed
wesleywiser opened this issue Aug 6, 2021 · 0 comments · Fixed by #87832
Closed

Unintuitve stepping behavior for match expressions in a debugger #87817

wesleywiser opened this issue Aug 6, 2021 · 0 comments · Fixed by #87832
Assignees
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug.

Comments

@wesleywiser
Copy link
Member

Given some code like:

fn main() {
    foo(Some(42));
}

fn foo(bar: Option<u32>) -> u8 {
    match bar {
        Some(42) => 1,
        Some(_) => 2,
        None => 3,
    }
}

Stepping into foo, I would expect the sequence of executed lines to look like 6 -> 7 -> 11 but it currently is 7 -> 6 -> 11 which doesn't make much sense.

This behavior appears in all debuggers with any of stable (1.54), beta (1.55) or nightly (1.56) compilers.

Ubuntu.2021-08-06.10-33-55.mp4
@wesleywiser wesleywiser added A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. labels Aug 6, 2021
@wesleywiser wesleywiser self-assigned this Aug 6, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Aug 26, 2021
…twco

Fix debugger stepping behavior with `match` expressions

Previously, we would set up the source lines for `match` expressions so
that the code generated to perform the test of the scrutinee was matched
to the line of the arm that required the test and then jump from the arm
block to the "next" block was matched to all of the lines in the `match`
expression.

While that makes sense, it has the side effect of causing strange
stepping behavior in debuggers.

I've changed the source information so that all of the generated tests
are sourced to `match {scrutinee}` and the jumps are sourced to the last
line of the block they are inside. This resolves the weird stepping
behavior in all debuggers and resolves some instances of "ambiguous
symbol" errors in WinDbg preventing the user from setting breakpoints at
`match` expressions.

Before:

https://user-images.githubusercontent.com/831192/128577421-ee0c9c03-da28-4d16-997a-d57988a7bb7f.mp4

After:

https://user-images.githubusercontent.com/831192/128577433-2ceab04d-953e-4e31-9387-93f049c71ff3.mp4

Fixes rust-lang#87817
@bors bors closed this as completed in fb79597 Aug 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant