public override SourceLocation SourceLocationForManagedCode(uint methodMetadataToken, int ilOffset) { MethodDefinitionHandle methodDefinitionHandle = (MethodDefinitionHandle)MetadataTokens.Handle((int)methodMetadataToken); MethodDebugInformationHandle methodDebugInfoHandle = methodDefinitionHandle.ToDebugInformationHandle(); MethodDebugInformation methodDebugInfo = _metaData.GetMethodDebugInformation(methodDebugInfoHandle); int methodToken = MetadataTokens.GetToken(methodDebugInfoHandle.ToDefinitionHandle()); SequencePoint lastSequencePoint = default(SequencePoint); foreach (SequencePoint sequencePoint in methodDebugInfo.GetSequencePoints()) { if (sequencePoint.Offset > ilOffset) { if (lastSequencePoint.Document.IsNil) { lastSequencePoint = sequencePoint; } break; } lastSequencePoint = sequencePoint; } if (lastSequencePoint.Document.IsNil) { return(null); } return(new SourceLocation(GetSourceFile(lastSequencePoint.Document), lastSequencePoint.StartLine)); }
// TODO: Copied from PortablePdb. Share. public static AsyncMethodData ReadAsyncMethodData(MetadataReader metadataReader, MethodDebugInformationHandle debugHandle) { var reader = metadataReader; var body = reader.GetMethodDebugInformation(debugHandle); var kickoffMethod = body.GetStateMachineKickoffMethod(); if (kickoffMethod.IsNil) { return(AsyncMethodData.None); } var value = reader.GetCustomDebugInformation(debugHandle.ToDefinitionHandle(), MethodSteppingInformationBlobId); if (value.IsNil) { return(AsyncMethodData.None); } var blobReader = reader.GetBlobReader(value); long catchHandlerOffset = blobReader.ReadUInt32(); if (catchHandlerOffset > (uint)int.MaxValue + 1) { throw new BadImageFormatException(); } var yieldOffsets = ImmutableArray.CreateBuilder <int>(); var resultOffsets = ImmutableArray.CreateBuilder <int>(); var resumeMethods = ImmutableArray.CreateBuilder <int>(); while (blobReader.RemainingBytes > 0) { uint yieldOffset = blobReader.ReadUInt32(); if (yieldOffset > int.MaxValue) { throw new BadImageFormatException(); } uint resultOffset = blobReader.ReadUInt32(); if (resultOffset > int.MaxValue) { throw new BadImageFormatException(); } yieldOffsets.Add((int)yieldOffset); resultOffsets.Add((int)resultOffset); resumeMethods.Add(MethodDefToken(blobReader.ReadCompressedInteger())); } return(new AsyncMethodData( kickoffMethod, (int)(catchHandlerOffset - 1), yieldOffsets.ToImmutable(), resultOffsets.ToImmutable(), resumeMethods.ToImmutable())); }
public Method?GetMethod(MethodDebugInformationHandle h) { var methodToken = MetadataTokens.GetToken(h.ToDefinitionHandle()); var method = reader.GetMethod(methodToken); if (method != null) { if (method.GetSequencePointCount(out var count) != 0 || count == 0) { return(null); } var s = method.GetSequencePoints() .Where(sp => !sp.IsHidden) .Select(sp => new SequencePoint(sp.Offset, new Location( new Document(sp.Document), sp.StartLine, sp.StartColumn, sp.EndLine, sp.EndColumn))) .ToArray(); return(s.Any() ? new Method(s) : null); } return(null); }
/// <summary> /// Initializes a new instance of the <see cref="PdbFunction"/> class. /// </summary> /// <param name="pdbFile">Portable PDB file reader.</param> /// <param name="handle">Our metadata reader handle.</param> internal PdbFunction(PdbFile pdbFile, MethodDebugInformationHandle handle) { PdbFile = pdbFile; methodDebugInformationCache = SimpleCache.CreateStruct(() => pdbFile.Reader.GetMethodDebugInformation(handle)); localScopesCache = SimpleCache.CreateStruct(() => { var localScopes = pdbFile.Reader.GetLocalScopes(handle); IPdbLocalScope[] scopes = new IPdbLocalScope[localScopes.Count]; int i = 0; foreach (var l in localScopes) { scopes[i++] = new PdbLocalScope(this, l); } return(scopes); }); sequencePointsCache = SimpleCache.CreateStruct(() => { var sequencePoints = MethodDebugInformation.GetSequencePoints(); return(sequencePoints.Select(sp => new PdbSequencePoint(this, sp)).OfType <IPdbSequencePoint>().ToArray()); }); Token = System.Reflection.Metadata.Ecma335.MetadataTokens.GetToken(handle.ToDefinitionHandle()); }