private void AddSeqPoint(SequencePoint currentSeqPoint, LineNumberWriter lineNumberWriter) { if (currentSeqPoint != null) { if (fileName == null && currentSeqPoint.Document != null) { var url = currentSeqPoint.Document.Url; if (url != null) { try { fileName = new FileInfo(url).Name; } catch { // for mono } } } if (currentSeqPoint.StartLine == 0xFeeFee && currentSeqPoint.EndLine == 0xFeeFee) { if (lineNumberWriter.LineNo > 0) { lineNumberWriter.AddMapping(currentSeqPoint.Offset, -1); } } else { if (lineNumberWriter.LineNo != currentSeqPoint.StartLine) { lineNumberWriter.AddMapping(currentSeqPoint.Offset, currentSeqPoint.StartLine); } } } }
public void PreMethodBodyRepack(MethodBody body, MethodDefinition parent) { if (!enabled) return; Reset(); if (!parent.CustomAttributes.Any(x => x.Constructor.DeclaringType.Name == "LineNumberTableAttribute")) { lineNumberWriter = new LineNumberWriter(body.Instructions.Count / 4); } }
public void PreMethodBodyRepack(MethodBody body, MethodDefinition parent) { if (!enabled) { return; } Reset(); if (!parent.CustomAttributes.Any(x => x.Constructor.DeclaringType.Name == "LineNumberTableAttribute")) { lineNumberWriter = new LineNumberWriter(body.Instructions.Count / 4); } }
private void PostMethodBodyRepack(MethodDefinition parent, LineNumberWriter lineNumberWriter) { if (lineNumberWriter.Count > 0) { CustomAttribute ca; if (lineNumberWriter.Count == 1) { ca = new CustomAttribute(lineNumberTableAttributeConstructor1) { ConstructorArguments = { new CustomAttributeArgument(TargetAssemblyMainModule.TypeSystem.UInt16, (ushort)lineNumberWriter.LineNo) } }; } else { ca = new CustomAttribute(lineNumberTableAttributeConstructor2) { ConstructorArguments = { new CustomAttributeArgument(new ArrayType(TargetAssemblyMainModule.TypeSystem.Byte), lineNumberWriter.ToArray().Select(b => new CustomAttributeArgument(TargetAssemblyMainModule.TypeSystem.Byte, b)).ToArray()) } }; } parent.CustomAttributes.Add(ca); if (fileName != null) { var type = parent.DeclaringType; var exist = type.CustomAttributes.FirstOrDefault(x => x.Constructor.DeclaringType.Name == "SourceFileAttribute"); if (exist == null) { // put the filename on the type first type.CustomAttributes.Add(new CustomAttribute(sourceFileAttributeConstructor) { ConstructorArguments = { new CustomAttributeArgument(TargetAssemblyMainModule.TypeSystem.String, fileName) } }); } else if (fileName != (string)exist.ConstructorArguments[0].Value) { // if already specified on the type, but different (e.g. for partial classes), put the attribute on the method. // Note: attribute isn't allowed for Methods, but that restriction doesn't apply to IL generation (or runtime use) parent.CustomAttributes.Add(new CustomAttribute(sourceFileAttributeConstructor) { ConstructorArguments = { new CustomAttributeArgument(TargetAssemblyMainModule.TypeSystem.String, fileName) } }); } } } }
public void PreMethodBodyRepack(MethodBody body, MethodDefinition parent) { if (!enabled || !parent.DebugInformation.HasSequencePoints) { return; } Reset(); if (!parent.CustomAttributes.Any(x => x.Constructor.DeclaringType.Name == "LineNumberTableAttribute")) { var lineNumberWriter = new LineNumberWriter(body.Instructions.Count / 4); foreach (var sp in parent.DebugInformation.SequencePoints) { AddSeqPoint(sp, lineNumberWriter); } PostMethodBodyRepack(parent, lineNumberWriter); } }
public void Reset() { lineNumberWriter = null; fileName = null; }