private void InsertReportValue( ILProcessor il, Instruction instruction, Instruction getValue, TypeReference valueType, string valueName, int line, ReportMethods flow, ref int index ) { il.InsertBefore(instruction, getValue); il.InsertBefore(instruction, valueName != null ? il.Create(OpCodes.Ldstr, valueName) : il.Create(OpCodes.Ldnull)); il.InsertBefore(instruction, il.CreateLdcI4Best(line)); if (valueType is RequiredModifierType requiredType) { valueType = requiredType.ElementType; // not the same as GetElementType() which unwraps nested ref-types etc } var report = PrepareReportValue(valueType, flow.ReportValue, flow.ReportSpanValue, flow.ReportReadOnlySpanValue); if (valueType is ByReferenceType byRef) { report = PrepareReportValue(byRef.ElementType, flow.ReportRefValue, flow.ReportRefSpanValue, flow.ReportRefReadOnlySpanValue); } il.InsertBefore(instruction, il.CreateCall(report)); index += 4; }
private void RewriteInspectMemoryGraph(MethodDefinition method, ILProcessor il, Instruction call, IWorkSession session, ArgumentMethods argumentMethods) { var sequencePoint = FindClosestSequencePoint(method, call); if (sequencePoint == null) { return; } var arguments = _languages[session.LanguageName] .GetCallArgumentIdentifiers(session, sequencePoint.StartLine, sequencePoint.StartColumn); if (arguments.Length == 0) { return; } il.InsertBefore(call, il.CreateLdcI4Best(arguments.Length)); il.InsertBefore(call, il.CreateCall(argumentMethods.AllocateNext)); foreach (var argument in arguments) { il.InsertBefore(call, argument != null ? il.Create(OpCodes.Ldstr, argument) : il.Create(OpCodes.Ldnull)); il.InsertBefore(call, il.CreateCall(argumentMethods.AddToNext)); } }
private void InsertReportValue( ILProcessor il, Instruction instruction, Instruction getValue, TypeReference valueType, string valueName, int line, ReportMethods flow, ref int index ) { il.InsertBefore(instruction, getValue); il.InsertBefore(instruction, valueName != null ? il.Create(OpCodes.Ldstr, valueName) : il.Create(OpCodes.Ldnull)); il.InsertBefore(instruction, il.CreateLdcI4Best(line)); var report = flow.ReportValue; if (valueType is RequiredModifierType requiredType) { valueType = requiredType.ElementType; // not the same as GetElementType() which unwraps nested ref-types etc } if (valueType.IsByReference) { report = flow.ReportRefValue; valueType = valueType.GetElementType(); } il.InsertBefore(instruction, il.CreateCall(new GenericInstanceMethod(report) { GenericArguments = { valueType } })); index += 4; }
private void InsertReportValue(ILProcessor il, Instruction instruction, Instruction getValue, TypeReference valueType, string valueName, int line, ReportMethods flow, ref int index) { il.InsertBefore(instruction, getValue); il.InsertBefore(instruction, valueName != null ? il.Create(OpCodes.Ldstr, valueName) : il.Create(OpCodes.Ldnull)); il.InsertBefore(instruction, il.CreateLdcI4Best(line)); il.InsertBefore(instruction, il.CreateCall(new GenericInstanceMethod(flow.ReportValue) { GenericArguments = { valueType } })); index += 4; }