public IList <Variable> GetVariables(SRM.MethodDefinitionHandle handle) { var method = this.module.LookupToken(MetadataTokens.GetToken(handle)) as MethodDefinition; if (method?.DebugInformation == null) { return(EmptyList <Variable> .Instance); } return(method.DebugInformation.GetScopes() .SelectMany(s => s.Variables) .Select(v => new Variable { Name = v.Name }).ToList()); }
public bool TryGetName(SRM.MethodDefinitionHandle handle, int index, out string name) { var method = this.module.LookupToken(MetadataTokens.GetToken(handle)) as MethodDefinition; name = null; if (method?.DebugInformation == null || !method.HasBody) { return(false); } var variable = method.Body.Variables.FirstOrDefault(v => v.Index == index); if (variable == null) { return(false); } return(method.DebugInformation.TryGetName(variable, out name)); }
public IList <SequencePoint> GetSequencePoints(SRM.MethodDefinitionHandle handle) { var method = this.module.LookupToken(MetadataTokens.GetToken(handle)) as MethodDefinition; if (method?.DebugInformation == null || !method.DebugInformation.HasSequencePoints) { return(EmptyList <SequencePoint> .Instance); } return(method.DebugInformation.SequencePoints.Select(point => new SequencePoint { Offset = point.Offset, StartLine = point.StartLine, StartColumn = point.StartColumn, EndLine = point.EndLine, EndColumn = point.EndColumn, DocumentUrl = point.Document.Url }).ToList()); }
private uint CalculateMethodDefTreatmentAndRowId(MethodDefinitionHandle methodDef) { MethodDefTreatment treatment = MethodDefTreatment.Implementation; TypeDefinitionHandle parentTypeDef = GetDeclaringType(methodDef); TypeAttributes parentFlags = TypeDefTable.GetFlags(parentTypeDef); if ((parentFlags & TypeAttributes.WindowsRuntime) != 0) { if (IsClrImplementationType(parentTypeDef)) { treatment = MethodDefTreatment.Implementation; } else if (parentFlags.IsNested()) { treatment = MethodDefTreatment.Implementation; } else if ((parentFlags & TypeAttributes.Interface) != 0) { treatment = MethodDefTreatment.InterfaceMethod; } else if (_metadataKind == MetadataKind.ManagedWindowsMetadata && (parentFlags & TypeAttributes.Public) == 0) { treatment = MethodDefTreatment.Implementation; } else { treatment = MethodDefTreatment.Other; var parentBaseType = TypeDefTable.GetExtends(parentTypeDef); if (parentBaseType.Kind == HandleKind.TypeReference) { switch (GetSpecialTypeRefTreatment((TypeReferenceHandle)parentBaseType)) { case TypeRefTreatment.SystemAttribute: treatment = MethodDefTreatment.AttributeMethod; break; case TypeRefTreatment.SystemDelegate: treatment = MethodDefTreatment.DelegateMethod | MethodDefTreatment.MarkPublicFlag; break; } } } } if (treatment == MethodDefTreatment.Other) { // we want to hide the method if it implements // only redirected interfaces // We also want to check if the methodImpl is IClosable.Close, // so we can change the name bool seenRedirectedInterfaces = false; bool seenNonRedirectedInterfaces = false; bool isIClosableClose = false; foreach (var methodImplHandle in new MethodImplementationHandleCollection(this, parentTypeDef)) { MethodImplementation methodImpl = GetMethodImplementation(methodImplHandle); if (methodImpl.MethodBody == methodDef) { EntityHandle declaration = methodImpl.MethodDeclaration; // See if this MethodImpl implements a redirected interface // In WinMD, MethodImpl will always use MemberRef and TypeRefs to refer to redirected interfaces, // even if they are in the same module. if (declaration.Kind == HandleKind.MemberReference && ImplementsRedirectedInterface((MemberReferenceHandle)declaration, out isIClosableClose)) { seenRedirectedInterfaces = true; if (isIClosableClose) { // This method implements IClosable.Close // Let's rename to IDisposable later // Once we know this implements IClosable.Close, we are done // looking break; } } else { // Now we know this implements a non-redirected interface // But we need to keep looking, just in case we got a methodimpl that // implements the IClosable.Close method and needs to be renamed seenNonRedirectedInterfaces = true; } } } if (isIClosableClose) { treatment = MethodDefTreatment.DisposeMethod; } else if (seenRedirectedInterfaces && !seenNonRedirectedInterfaces) { // Only hide if all the interfaces implemented are redirected treatment = MethodDefTreatment.HiddenInterfaceImplementation; } } // If treatment is other, then this is a non-managed WinRT runtime class definition // Find out about various bits that we apply via attributes and name parsing if (treatment == MethodDefTreatment.Other) { treatment |= GetMethodTreatmentFromCustomAttributes(methodDef); } return(TreatmentAndRowId((byte)treatment, methodDef.RowId)); }
internal DebugMetadataHeader(ImmutableArray <byte> id, MethodDefinitionHandle entryPoint, int idStartOffset) { Id = id; EntryPoint = entryPoint; IdStartOffset = idStartOffset; }
/// <summary> /// Returns a handle to <see cref="MethodDefinition"/> corresponding to this handle. /// </summary> /// <remarks> /// The resulting handle is only valid within the context of a <see cref="MetadataReader"/> open on the type system metadata blob, /// which in case of standalone PDB file is a different reader than the one containing this method debug information. /// </remarks> public MethodDefinitionHandle ToDefinitionHandle() { return(MethodDefinitionHandle.FromRowId(_rowId)); }
internal DebugMetadataHeader(ImmutableArray <byte> id, MethodDefinitionHandle entryPoint) { Id = id; EntryPoint = entryPoint; }