icsharpcode / SharpDevelop

#develop (short for SharpDevelop) is a free IDE for .NET programming languages.
2.08k stars 771 forks source link

Debugger. Stepping over await for async methods. #778

Open rusanov-vladimir opened 7 years ago

rusanov-vladimir commented 7 years ago

Consider this program:

using System;
using System.Threading.Tasks;

class C
{
    public static void Main() {

        var instance = new Instance(); 
        instance.Start().Wait();
    }
}
class Instance
{
    public static async Task F() { for(var i=0; i<100; i++) { Console.WriteLine(i); await Task.Delay(10); } }
    public async Task Start() {
       var a = 1;
       await F();//<---------Breakpoint
       var z = 2;
       var x = 3;
    }
}

If I place breakpoint at line await F(); and when it hit I click on StepOver execution passes to instance.Start().Wait();. That is caused by side effects of method rewriting that compiler does under the hood. Is it possible to have more userfriendly experience and to continue on var z = 2; instead?

To achieve this I've been looking at ISymUnmanagedAsyncMethod::GetAsyncStepInfo, This method returns an await's return instruction, identifying a potential yield, and breakpointMethod/breakpointOffset pair that tells us where the asynchronous operation will resume. Yet, I cannot get my head around how to integrate it in project.

Any thoughts on this?

StepOver