Beispiel #1
0
        public static string FormatMethodName(MetadataReader metadataReader, TypeDefinitionHandle enclosingTypeHandle, MethodHandle methodHandle)
        {
            MethodNameFormatter formatter = new MethodNameFormatter(metadataReader, SigTypeContext.FromMethod(metadataReader, enclosingTypeHandle, methodHandle));

            Method          method          = metadataReader.GetMethod(methodHandle);
            MethodSignature methodSignature = metadataReader.GetMethodSignature(method.Signature);

            formatter.EmitTypeName(enclosingTypeHandle, namespaceQualified: true);
            formatter._outputBuilder.Append('.');
            formatter.EmitString(method.Name);

            bool first = true;

            foreach (GenericParameterHandle handle in method.GenericParameters)
            {
                if (first)
                {
                    first = false;
                    formatter._outputBuilder.Append('[');
                }
                else
                {
                    formatter._outputBuilder.Append(", ");
                }
                formatter.EmitTypeName(handle, namespaceQualified: false);
            }
            if (!first)
            {
                formatter._outputBuilder.Append(']');
            }

            formatter.EmitMethodParameters(methodSignature);

            return(formatter._outputBuilder.ToString());
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public static string FormatMethodName(MetadataReader metadataReader, Handle methodHandle)
        {
            MethodNameFormatter formatter = new MethodNameFormatter(metadataReader, SigTypeContext.FromMethod(metadataReader, methodHandle));

            formatter.EmitMethodName(methodHandle);
            return(formatter._outputBuilder.ToString());
        }
Beispiel #4
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)));
            }