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

Step Over sometimes executes a lot more than one statement #109885

Closed
TonyValenti opened this issue Nov 16, 2024 · 58 comments · Fixed by #110484
Closed

Step Over sometimes executes a lot more than one statement #109885

TonyValenti opened this issue Nov 16, 2024 · 58 comments · Fixed by #110484
Assignees
Labels
area-Diagnostics-coreclr in-pr There is an active PR which will close this issue when it is merged
Milestone

Comments

@TonyValenti
Copy link

Description

When I'm debugging code, I use F10 (Step Over) to walk through one line of code at a time.
In .NET 8x, this worked fine.
In .NET 9x, sometimes it seems like it runs a TON more code until it hits a breakpoint.

I suspect I might be running into some variant of #109785 and I specifically notice this happening in ForEach code as described in #109812 .

I see this is slated to be fixed in .NET 10.0, however, this is a major annoyance and I am very hopeful this will be approved for servicing.

Reproduction Steps

Not sure.

Expected behavior

"Step Over" works like .NET 8.0

Actual behavior

"Step Over" sometimes works like "Continue"

Regression?

Yes.

Known Workarounds

Use .NET 8.0

Configuration

No response

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 16, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Nov 16, 2024
@huoyaoyuan huoyaoyuan added area-Diagnostics-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Nov 16, 2024
Copy link
Contributor

Tagging subscribers to this area: @tommcdon
See info in area-owners.md if you want to be subscribed.

@tommcdon tommcdon added this to the 10.0.0 milestone Nov 19, 2024
@tommcdon tommcdon removed the untriaged New issue has not been triaged by the area owner label Nov 19, 2024
@rowi123
Copy link

rowi123 commented Nov 29, 2024

I have this bug too.
For me it is not related to for each at all
Also i see this is added to the dotnet 10 milestone, that's crazy: this a bug preventing normal debugging workflow

For me hot reload also doesn't work in dot net 9

More info:
https://stackoverflow.com/questions/79212086/net-9-debugger-step-over-f10-behaving-like-continue-f5

@TonyValenti
Copy link
Author

Ya. Debugging really sucks in .NET 9.0 right now.

If I had to guess, it was added to 10.x as a matter of policy, but I'm about 100% certain that once everybody gets back from holiday (and enough people complain here), this will be approved for servicing pretty quickly.

@akalcik
Copy link

akalcik commented Nov 29, 2024

Same here

@Woudjee
Copy link

Woudjee commented Dec 2, 2024

I have the same issue. It happens all the time and is very tricky. I cannot debug effectively currently.

@Woudjee
Copy link

Woudjee commented Dec 2, 2024

I have this bug too. For me it is not related to for each at all Also i see this is added to the dotnet 10 milestone, that's crazy: this a bug preventing normal debugging workflow

For me hot reload also doesn't work in dot net 9

More info: https://stackoverflow.com/questions/79212086/net-9-debugger-step-over-f10-behaving-like-continue-f5

Wait what. Is this not going to be fixed anytime soon? Do you have a source?

@rowi123
Copy link

rowi123 commented Dec 2, 2024

Image

@Woudjee
Copy link

Woudjee commented Dec 2, 2024

This bug is genuinely unworkable for me. When pressing F10, it keeps going significantly further than what I want. I am trying to debug geometrical algorithms. I can only do this when I know exactly where I am in this process. It is impossible to do when it goes all over the place. I am trying to combat this by putting a breakpoint every other line, but this is simply not working.

When will this be fixed?

@rowi123
Copy link

rowi123 commented Dec 2, 2024

Why are you still on 9?
I moved back to 8 i am staying far far away from this for at least a quarter year.

@Woudjee
Copy link

Woudjee commented Dec 2, 2024

I put a lot of effort into moving all my projects to .NET 9.0 last week. I need it for MAUI Blazor Hybrid. It is not possible for me to go back. Have been looking forward to .NET 9.0 for a long time.

@Woudjee
Copy link

Woudjee commented Dec 2, 2024

I also continue to have try-catches that are not catching errors. Is this also a .NET 9.0 thing?

@tommcdon
Copy link
Member

tommcdon commented Dec 2, 2024

Hello all! Our workflow is to fix issues in main, then backport to servicing as needed. Since this issue applies to both to main (.NET 10) and .NET 9, we put the issue in the .NET 10 milestone. Once we have a fix for the problem, we plan to backport a servicing-friendly version of it to .NET 9.

@tommcdon
Copy link
Member

tommcdon commented Dec 2, 2024

I also continue to have try-catches that are not catching errors. Is this also a .NET 9.0 thing?

Hello @Woudjee! This sounds like a different problem. Please feel free to open a new github issue to track it.

@Woudjee
Copy link

Woudjee commented Dec 3, 2024

Hello all! Our workflow is to fix issues in main, then backport to servicing as needed. Since this issue applies to both to main (.NET 10) and .NET 9, we put the issue in the .NET 10 milestone. Once we have a fix for the problem, we plan to backport a servicing-friendly version of it to .NET 9.

Thank you for your reply. That makes sense! In your experience, how much time does it usually take for these kinds of issues to be resolved? A week? A month? A quarter? Then I can somewhat anticipate on this during my work the upcoming period 👍

@rowi123
Copy link

rowi123 commented Dec 3, 2024

Hello all! Our workflow is to fix issues in main, then backport to servicing as needed. Since this issue applies to both to main (.NET 10) and .NET 9, we put the issue in the .NET 10 milestone. Once we have a fix for the problem, we plan to backport a servicing-friendly version of it to .NET 9.

Thank you for explaining this,

@f2bo
Copy link

f2bo commented Dec 6, 2024

Disabling CET in the project file seems to help in my case.

<CETCompat>false</CETCompat>

@Woudjee
Copy link

Woudjee commented Dec 6, 2024

@f2bo if that solves this, I consider it a solution. But what does it mean? I’ll try it out next week. 👍👍

@f2bo
Copy link

f2bo commented Dec 6, 2024

@Woudjee

if that solves this, I consider it a solution.

I don't know if this is the solution but I noticed that single-stepping appears to behave normally once you apply this setting, at least in my case and after a very quick test. I thought I'd mention it here and see what other people's experience is. I posted simple repro steps here, in case anyone wants to give it a try.

But what does it mean?

https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-9/runtime#control-flow-enforcement-technology

@Woudjee
Copy link

Woudjee commented Dec 6, 2024

@f2bo of course I understand. It’s more a temporary workaround than an actual solution. But if it - for now - allows me to debug, that’s immensely valuable.

I read the section you highlighted. For the software that I am currently developing I believe it’s fine to turn it off. I will let you know my findings later next week.

@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Dec 9, 2024
@Woudjee
Copy link

Woudjee commented Dec 19, 2024

@Woudjee It is labeled for milestone 9.0.2 so it should be included in the next upcoming service release of .NET 9

Ah good one. After reading your message, I managed to find that as well. Currently the 9.0.2 milestone is 72% completed so that’s looking promising 👍

@udlose
Copy link

udlose commented Jan 11, 2025

I know that you cannot give a "release date" for the fix, but can you at least provide a ballpark/approximate release? This is really causing headaches when trying to debug.

@Woudjee
Copy link

Woudjee commented Jan 11, 2025

I know that you cannot give a "release date" for the fix, but can you at least provide a ballpark/approximate release? This is really causing headaches when trying to debug.

In the meanwhile, use CETCOMPAT = true or = false. It is a workaround that triggers this issue almost never. I have been using it since the beginning of this issue and have been able to be productive with it. If you Google it I’m certain you’ll find it somewhere!

@udlose
Copy link

udlose commented Jan 11, 2025

I know that you cannot give a "release date" for the fix, but can you at least provide a ballpark/approximate release? This is really causing headaches when trying to debug.

In the meanwhile, use CETCOMPAT = true or = false. It is a workaround that triggers this issue almost never. I have been using it since the beginning of this issue and have been able to be productive with it. If you Google it I’m certain you’ll find it somewhere!

I tried each setting in all of the projects and neither setting solved the intermittent issue. I hope a fix is released soon - this is a big problem.

@udlose
Copy link

udlose commented Jan 15, 2025

I saw that .NET 9.0.1 was released yesterday. I couldn't find any of the issues mentioned or the PR for the fix included in the Release Notes - maybe I just missed it - but I decided to look in the Release branch for the fix and was relieved to find that the fix was included in the .NET 9.0.1 Release!

@Woudjee
Copy link

Woudjee commented Jan 15, 2025

@udlose that is awesome news!

@rowi123
Copy link

rowi123 commented Jan 15, 2025

Can someone above report back if this version is working for you?

@udlose
Copy link

udlose commented Jan 15, 2025

Can someone above report back if this version is working for you?

I have not had the issue since updating yesterday. Seems to be fixed!

UPDATE: this is in fact NOT fixed in .NET 9.0.102 :(

@f2bo
Copy link

f2bo commented Jan 15, 2025

I decided to look in the Release branch for the fix and was relieved to find that the fix was included in the .NET 9.0.1 Release!

@udlose I haven't updated yet but are you sure this is the right place to look? I also noticed that it wasn't mentioned in the release notes, nor here. Furthermore, the milestone for the servicing PR is labeled 9.0.2.

@Woudjee
Copy link

Woudjee commented Jan 15, 2025

Can someone above report back if this version is working for you?

I have not had the issue since updating yesterday. Seems to be fixed!

How do I update? By simply updating using Visual Studio Installer?

@udlose
Copy link

udlose commented Jan 15, 2025

I decided to look in the Release branch for the fix and was relieved to find that the fix was included in the .NET 9.0.1 Release!

@udlose I haven't updated yet but are you sure this is the right place to look? I also noticed that it wasn't mentioned in the release notes, nor here. Furthermore, the milestone for the servicing PR is labeled 9.0.2.

I hadn't noticed it was labeled as 9.0.2 milestone. I'm not familiar with the branching strategy that MS uses but I do also see the fix included in the main branch which AFAIK is the source that is "live" in Production: https://github.com/dotnet/runtime/blob/main/src/coreclr/debug/ee/controller.cpp#L7588-L7596

@udlose
Copy link

udlose commented Jan 15, 2025

Can someone above report back if this version is working for you?

I have not had the issue since updating yesterday. Seems to be fixed!

How do I update? By simply updating using Visual Studio Installer?

VS Installer was what I used. It updated me to VS2022 v17.12.4. If you look at the .NET Downloads page you can see it says 9.0.102 is included in the latest VS version:

Image

@udlose
Copy link

udlose commented Jan 15, 2025

Since it is intermittent, it is possible that the fix wasn't included in 9.0.1 and is in fact scheduled for 9.0.2 as @f2bo points out above and I just haven't experienced it yet. I'll update this thread if I experience the bug again.

@udlose
Copy link

udlose commented Jan 15, 2025

After some focused debugging, I can confirm that I misspoke and the issue was not included in .NET 9.0.102 :( - apparently I just hadn't hit the intermittent issue yet. My optimism took over lol - I guess we have to wait until 9.0.2 (and I guess the main branch is NOT representative of what is out in PROD)....apologies for the confusion :)

@f2bo
Copy link

f2bo commented Jan 15, 2025

@udlose I understand that disabling CET didn't work in your case. I suppose that since the issue is caused by a race condition, not every environment behaves in the same way. But for other people having this problem, I would suggest trying <CETCompat>false</CETCompat> in the project file, at least while debugging and until 9.0.2 is released. This has been very effective in my case.

@Woudjee
Copy link

Woudjee commented Jan 15, 2025

@f2bo exactly!

@udlose thank you for your insights!

@ato321
Copy link

ato321 commented Jan 24, 2025

This program should trigger easily the debug bug.

namespace ConsoleApp42
{
    internal class Program
    {
        static void GenerateExceptions()
        {
            while (true)
            {
                try
                {
                    Thread.Sleep(1);
                    throw new Exception("This is an exception");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }

        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");
            (new Thread( GenerateExceptions)).Start();
            Console.WriteLine("Add break here and start debugging step-by-step");

            var list = new List<int>();
            for (var i = 0; i < 10; i++)
            {
                list.Add(i * 2);
            }

            // by now you should already see what is the problem with debugging step-by-step

            var uselessValue = "Not needed";
            var random = new Random();

            foreach (var item in list)
            {
                var temp = item + random.Next(0, 100);
                if (temp % 2 == 0)
                {
                    Console.WriteLine("Even value: " + temp);
                }
                else
                {
                    Console.WriteLine("Odd value: " + temp);
                }
            }

            for (var i = 0; i < 10; i++)
            {
                var notUsed = i * 5;
            }

            var moreRandom = new List<int>();
            for (var i = 0; i < 50; i++)
            {
                moreRandom.Add(random.Next(0, 100));
            }

            foreach (var number in moreRandom)
            {
                if (number > 25)
                {
                    var meaninglessString = "This value is high: " + number;
                    Console.WriteLine(meaninglessString);
                }
            }

            var redundantList = new List<string>();
            for (var i = 0; i < 20; i++)
            {
                redundantList.Add("Entry: " + i);
            }

            foreach (var str in redundantList)
            {
                if (str.Contains("1"))
                {
                    Console.WriteLine("Found 1 in: " + str);
                }
            }
        }
    }
}

@TonyValenti
Copy link
Author

This article seems to indicate that this bug is resolved but I am still running into it with VS 17.12.4 with .NET 9.0.1.

@Sean4572435243
Copy link

This article seems to indicate that this bug is resolved but I am still running into it with VS 17.12.4 with .NET 9.0.1.

Supposedly fixed for 9.0.2 (as yet unreleased). This issue was 'closed' so I have to believe it's imminent. Really looking forward to having my debugger back to normal, lol

@udlose
Copy link

udlose commented Jan 26, 2025

Based on their release cadence, I'd expect the fix to be available within the next 2 months or so.

@MrZakos
Copy link

MrZakos commented Feb 6, 2025

come on MICROSOFT , I can't even debug my hello world ...........

dotnet --version
9.0.102

@philipag
Copy link

philipag commented Feb 6, 2025

Adding this to my project made things work in the interim:

		<UseVSHostingProcess>false</UseVSHostingProcess>
		<CETCompat>false</CETCompat>

@Sean4572435243
Copy link

I have dozen of projects that I'd rather not doctor up for this purpose when hopefully the next release will take care of it. I have been using the little green continue-to-here button that appears to the left of all executable code during debugging. It's not quite as useful as the breakpoints, but it does allow you to control the code execution better than the current state of breakpoints does.

@tommcdon
Copy link
Member

The fix for this issue has shipped in 9.0.2 - available from https://dotnet.microsoft.com/en-us/download/dotnet/9.0.

@rowi123
Copy link

rowi123 commented Feb 15, 2025

can someone confirm this version is fixed and stable?

@ato321
Copy link

ato321 commented Feb 15, 2025

can someone confirm this version is fixed and stable?

At least it fixed the example I sent, and exceptions in other threads do not cause the bug anymore.

@PhotonicX7
Copy link

I can at least confirm it seems to have addressed it on the surface. I haven't noticed the behavior since updating.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Diagnostics-coreclr in-pr There is an active PR which will close this issue when it is merged
Projects
None yet
Development

Successfully merging a pull request may close this issue.