src/AsyncDbg.Core/Causality/AsyncStateMachineNode.cs
/// <summary>
/// Gets a resulting task for a given state machine instance.
/// </summary>
Gets a resulting task for a given state machine instance.
Gets a resulting task for a given state machine instance .
public static ClrInstance GetResultingTask(ClrInstance stateMachine, TypesRegistry registry)
        {
            Contract.Requires(registry.IsAsyncStateMachine(stateMachine.Type), $"A given instance should be a compiler generated state machine. Actual type: '{stateMachine.Type!.Name}'.");
            if (stateMachine.TryGetFieldValue("<>t__builder", out var asyncMethodBuilderField))
            {
                var asyncMethodBuild = asyncMethodBuilderField.Instance;
                if (asyncMethodBuild.TryGetFieldValue("m_builder", out var innerAsyncMethodBuilderField) ||
                    asyncMethodBuild.TryGetFieldValue("_methodBuilder", out innerAsyncMethodBuilderField))
                {
                    asyncMethodBuild = innerAsyncMethodBuilderField.Instance;
                }
                if (asyncMethodBuild.TryGetFieldValue("m_task", out var asyncMethodBuilderTaskField))
                {
                    return asyncMethodBuilderTaskField.Instance;
                }
                 if (registry.IsTask(asyncMethodBuild.Type))
                {
                    return asyncMethodBuild;
                }
            }
            if (stateMachine.TryGetFieldValue("m_continuationObject", out var continuation))
            {
                return continuation.Instance;
            }
            Contract.Assert(false, "Can't find a resulting task for the instance.");
            throw new System.Exception("Not reachable");
        }
public static ClrInstance GetResultingTask ( ClrInstance stateMachine , TypesRegistry registry ) { Contract . Requires ( registry . IsAsyncStateMachine ( stateMachine . Type ) , $" A given instance should be a compiler generated state machine. Actual type: ' { stateMachine . Type ! . Name } '. " ) ; if ( stateMachine . TryGetFieldValue ( " " , out var asyncMethodBuilderField ) ) { var asyncMethodBuild = asyncMethodBuilderField . Instance ; if ( asyncMethodBuild . TryGetFieldValue ( " " , out var innerAsyncMethodBuilderField ) || asyncMethodBuild . TryGetFieldValue ( " " , out innerAsyncMethodBuilderField ) ) { asyncMethodBuild = innerAsyncMethodBuilderField . Instance ; } if ( asyncMethodBuild . TryGetFieldValue ( " " , out var asyncMethodBuilderTaskField ) ) { return asyncMethodBuilderTaskField . Instance ; } if ( registry . IsTask ( asyncMethodBuild . Type ) ) { return asyncMethodBuild ; } } if ( stateMachine . TryGetFieldValue ( " " , out var continuation ) ) { return continuation . Instance ; } Contract . Assert ( false , " " ) ; throw new System . Exception ( " " ) ; }
Gets a resulting task for a given state machine instance.
Gets a resulting task for a given state machine instance .
// Looking for a builder instance for async state machine generated for async Task and async ValueTask methods. // CoreCLR case
stateMachine
ClrInstance
registry
TypesRegistry