Search Unity

PackedMemorySnapshot: How to resolve System.Delegate method name?

Discussion in 'Scripting' started by Peter77, Feb 10, 2018.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,618
    TLDR; Is there a way to resolve the method name of a System.Delegate with the information provided in a PackedMemorySnapshot?

    Using the PackedMemorySnapshot API allows me to analyze the fields/values of a System.Delegate. I'm able to resolve the type of the m_target reference, which is already very useful, but I'm also interested if I can resolve the method name (the method the delegate is calling), which would be very valuable information for me, rather than being able to see the method address only.

    The fields in a System.Delegate I'm interested in are m_target, method_ptr, method and method_info, I guess:
    https://github.com/Unity-Technologies/mono/blob/unity-master/mcs/class/corlib/System/Delegate.cs

    I first looked in the UnityEditor.MemoryProfiler.TypeDescription to find method info's (address, name) of managed types, but the TypeDescription contains fields only, no method information.

    Then I hoped I could perhaps find the method name in-front of the actual method, like with the -mpoke-function-name compiler flag in C/C++, but I'm unable to map the method_ptr/method pointers to a managed memory section, which is the only memory I can access in a PackedMemorySnapshot.

    method_info does seem to be null in my tests always, I assumed this would be the reflected method data.