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

DumpIL SOS command does not properly handle DynamicMethods in .NET Core #4850

Closed
davidwrighton opened this issue Aug 12, 2024 · 2 comments
Closed
Assignees
Labels
bug Something isn't working sos
Milestone

Comments

@davidwrighton
Copy link
Member

Description

  • Create a DynamicMethod
  • Use the !dumpil command to examine the IL of the associated MethodDesc
  • This will fail with a message indicating "Error gathering dynamic info from object at ADDRESS"

Configuration

Any vaguely recent .NET Core build.

Regression?

This probably works targeting the .NET Framework

Other information

It appears that at some point in time the fields on the System.Reflection.Emit.DynamicMethod object were changed to change the m_ prefix to _. In addition, a few other fields look to have changed their name entirely. GatherDynamicInfo in the SOS codebase appears to need to be updated to handle the newer paths, and we probably need some testing for this scenario.

@davidwrighton davidwrighton added the bug Something isn't working label Aug 12, 2024
@tommcdon tommcdon modified the milestones: 8.0.0, 9.0.0 Aug 20, 2024
@tommcdon tommcdon added the sos label Aug 20, 2024
mikem8361 added a commit to mikem8361/diagnostics that referenced this issue Sep 7, 2024
@mikem8361
Copy link
Member

Do you have a simple test app that creates a dynamic method?

@davidwrighton
Copy link
Member Author

Here's a simple test app I wrote recently that generates a continuous stream of DynamicMethod objects. You should be able to tweak this to your needs.

using System.Reflection.Emit;
using System.Runtime.CompilerServices;

namespace TestInfiniteDynamicMethods
{
    internal class Program
    {
        [MethodImpl(MethodImplOptions.NoInlining)]
        static Func<int, int> GetFibDynamicMethod()
        {
            DynamicMethod dynamicMethod = new DynamicMethod("Fibonacci", typeof(int), new Type[] { typeof(int) });
            ILGenerator ilgen = dynamicMethod.GetILGenerator();
            Label labelAfterCmp0 = ilgen.DefineLabel();
            ilgen.Emit(OpCodes.Ldarg_0);
            ilgen.Emit(OpCodes.Ldc_I4_0);
            ilgen.Emit(OpCodes.Bne_Un_S, labelAfterCmp0);
            ilgen.Emit(OpCodes.Ldc_I4_0);
            ilgen.Emit(OpCodes.Ret);
            ilgen.MarkLabel(labelAfterCmp0);

            Label labelAfterCmp1 = ilgen.DefineLabel();
            ilgen.Emit(OpCodes.Ldarg_0);
            ilgen.Emit(OpCodes.Ldc_I4_1);
            ilgen.Emit(OpCodes.Bne_Un_S, labelAfterCmp1);
            ilgen.Emit(OpCodes.Ldc_I4_1);
            ilgen.Emit(OpCodes.Ret);
            ilgen.MarkLabel(labelAfterCmp1);

            ilgen.Emit(OpCodes.Ldarg_0);
            ilgen.Emit(OpCodes.Ldc_I4_1);
            ilgen.Emit(OpCodes.Sub);
            ilgen.Emit(OpCodes.Call, dynamicMethod);

            ilgen.Emit(OpCodes.Ldarg_0);
            ilgen.Emit(OpCodes.Ldc_I4_2);
            ilgen.Emit(OpCodes.Sub);
            ilgen.Emit(OpCodes.Call, dynamicMethod);

            ilgen.Emit(OpCodes.Add);
            ilgen.Emit(OpCodes.Ret);

            return dynamicMethod.CreateDelegate<Func<int, int>>();
        }

        static void Main(string[] args)
        {
            Console.WriteLine("Hello, World!");

            int count = 0;
            while (true)
            {
                GetFibDynamicMethod()(4);

                if (((++count) % 200) == 0)
                {
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }

                if (((++count) % 1000) == 0)
                    Console.WriteLine(count);
            }
        }
    }
}

mikem8361 added a commit to mikem8361/diagnostics that referenced this issue Sep 11, 2024
mikem8361 added a commit that referenced this issue Sep 12, 2024
Fix dynamic methods "resolver" field name.
@github-actions github-actions bot locked and limited conversation to collaborators Oct 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working sos
Projects
None yet
Development

No branches or pull requests

3 participants