EgorBo / Disasmo

VS2022 Add-in. Click on any method or class to see what .NET Core's JIT generates for them (ASM).
MIT License
656 stars 41 forks source link

Inserting code at the first left brace past where Roslyn claims the entry point is doesn't seem to be very reliable #3

Closed Zhentar closed 2 years ago

Zhentar commented 5 years ago

I've been trying to get 'where Roslyn tells Disasmo the entrypoint is' to match up with 'where the entry point actually is' with a disappointingly low success rate....

    class Program
    {/*disasmo{*/System.Linq.Enumerable.ToList(System.Linq.Enumerable.Where(typeof(TestHarness.IndexOfTesting.InvertedIndexOfAdder).GetMethods(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic), w => w.DeclaringType == typeof(TestHarness.IndexOfTesting.InvertedIndexOfAdder))).ForEach(m => System.Runtime.CompilerServices.RuntimeHelpers.PrepareMethod(m.MethodHandle));System.Console.WriteLine(" ");System.Console.ReadLine();System.Environment.Exit(0);/*}disasmo*/
        static void Main(string[] args)
        {
    class Program
    {
        static void Main(string[] args)
        {
            //for (int i = 0; i < 1000; i++)
            //{/*disasmo{*/System.Linq.Enumerable.ToList(System.Linq.Enumerable.Where(typeof(TestHarness.IndexOfTesting.InvertedIndexOfAdder).GetMethods(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic), w => w.DeclaringType == typeof(TestHarness.IndexOfTesting.InvertedIndexOfAdder))).ForEach(m => System.Runtime.CompilerServices.RuntimeHelpers.PrepareMethod(m.MethodHandle));System.Console.WriteLine(" ");System.Console.ReadLine();System.Environment.Exit(0);/*}disasmo*/

Perhaps Mono.Cecil to add a module initializer, or hijacking the entrypoint to a different file, might be more reliable?

EgorBo commented 5 years ago

@Zhentar yeah that was a quick solution I am going to remove ;-)

Zhentar commented 5 years ago

No worries, I've written enough terrible hack prototypes to know it when I see one 😁 I report this partly as 'this is the particular hack that broke for me' and partly as a way of saying 'I like what your code does do enough to care about what it doesn't do' 😉

EgorBo commented 2 years ago

Closing since Disasmo no longer does it