Пример #1
0
        /// <summary>
        /// Locate the containing module for a method and try to resolve its name based on start address.
        /// </summary>
        public static string GetMethodNameFromStartAddressIfAvailable(IntPtr methodStartAddress)
        {
            IntPtr moduleStartAddress = RuntimeAugments.GetOSModuleFromPointer(methodStartAddress);
            int    rva = (int)((nuint)methodStartAddress - (nuint)moduleStartAddress);

            foreach (TypeManagerHandle handle in ModuleList.Enumerate())
            {
                if (handle.OsModuleBase == moduleStartAddress)
                {
                    string name = _perModuleMethodNameResolverHashtable.GetOrCreateValue(handle.GetIntPtrUNSAFE()).GetMethodNameFromRvaIfAvailable(rva);
                    if (name != null)
                    {
                        return(name);
                    }
                }
            }

            // We haven't found information in the stack trace metadata tables, but maybe reflection will have this
            if (ReflectionExecution.TryGetMethodMetadataFromStartAddress(methodStartAddress,
                                                                         out MetadataReader reader,
                                                                         out TypeDefinitionHandle typeHandle,
                                                                         out MethodHandle methodHandle))
            {
                return(MethodNameFormatter.FormatMethodName(reader, typeHandle, methodHandle));
            }

            return(null);
        }
Пример #2
0
            /// <summary>
            /// Try to resolve method name based on its address using the stack trace metadata
            /// </summary>
            public string GetMethodNameFromRvaIfAvailable(int rva)
            {
                if (_methodRvaToTokenMap == null)
                {
                    // No stack trace metadata for this module
                    return(null);
                }

                int rawToken;

                if (!_methodRvaToTokenMap.TryGetValue(rva, out rawToken))
                {
                    // Method RVA not found in the map
                    return(null);
                }

                return(MethodNameFormatter.FormatMethodName(_metadataReader, Handle.FromIntToken(rawToken)));
            }