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