Example #1
0
        private int InstrumentMethod(MethodDefinition method, InstrumentationRecorder recorder, Action <int, int, string> instructionInstrumented)
        {
            if (!method.HasBody)
            {
                return(0);
            }
            var processor = method.Body.GetILProcessor();

            method.Body.MaxStackSize += 4;

            var i      = 0;
            var unique = new List <string>();

            foreach (var instr in method.Body.Instructions.ToArray())
            {
                if (instr.SequencePoint != null &&
                    instr.SequencePoint.Document.Url != null &&
                    method.FullName != null)
                {
                    if (recorder.EmitRecord(processor, method, instr))
                    {
                        var hash = instr.SequencePoint.Document.Url + ":" + instr.SequencePoint.StartLine + "-" + instr.SequencePoint.EndLine;
                        if (!unique.Contains(hash))
                        {
                            unique.Add(hash);
                            instructionInstrumented(instr.SequencePoint.StartLine, instr.SequencePoint.EndLine, instr.SequencePoint.Document.Url);
                            i++;
                        }
                    }
                }
            }
            return(i);
        }
 private int InstrumentType(TypeDefinition type, InstrumentationRecorder recorder, Action<int, int, string> instructionInstrumented)
 {
     var i = 0;
     foreach (var method in type.Methods.Where(x => !HasSkipInstrumentation(x)))
         i += this.InstrumentMethod(method, recorder, instructionInstrumented);
     return i;
 }
 private int InstrumentModule(ModuleDefinition module, InstrumentationRecorder recorder, Action<int, int, string> instructionInstrumented)
 {
     var i = 0;
     foreach (var type in module.Types.Where(x => !HasSkipInstrumentation(x)))
         i += this.InstrumentType(type, recorder, instructionInstrumented);
     return i;
 }
        private int InstrumentMethod(MethodDefinition method, InstrumentationRecorder recorder, Action<int, int, string> instructionInstrumented)
        {
            if (!method.HasBody)
                return 0;
            var processor = method.Body.GetILProcessor();
            method.Body.MaxStackSize += 4;

            var i = 0;
            var unique = new List<string>();
            foreach (var instr in method.Body.Instructions.ToArray())
            {
                if (instr.SequencePoint != null &&
                    instr.SequencePoint.Document.Url != null &&
                    method.FullName != null)
                {
                    if (recorder.EmitRecord(processor, method, instr))
                    {
                        var hash = instr.SequencePoint.Document.Url + ":" + instr.SequencePoint.StartLine + "-" + instr.SequencePoint.EndLine;
                        if (!unique.Contains(hash))
                        {
                            unique.Add(hash);
                            instructionInstrumented(instr.SequencePoint.StartLine, instr.SequencePoint.EndLine, instr.SequencePoint.Document.Url);
                            i++;
                        }
                    }
                }
            }
            return i;
        }
 public int InstrumentAssembly(AssemblyDefinition assembly, string output, Action<int, int, string> instructionInstrumented)
 {
     var recorder = new InstrumentationRecorder(assembly, output);
     var i = 0;
     foreach (var module in assembly.Modules)
         i += this.InstrumentModule(module, recorder, instructionInstrumented);
     recorder.Finalise();
     return i;
 }
Example #6
0
        private int InstrumentType(TypeDefinition type, InstrumentationRecorder recorder, Action <int, int, string> instructionInstrumented)
        {
            var i = 0;

            foreach (var method in type.Methods.Where(x => !HasSkipInstrumentation(x)))
            {
                i += this.InstrumentMethod(method, recorder, instructionInstrumented);
            }
            return(i);
        }
Example #7
0
        private int InstrumentModule(ModuleDefinition module, InstrumentationRecorder recorder, Action <int, int, string> instructionInstrumented)
        {
            var i = 0;

            foreach (var type in module.Types.Where(x => !HasSkipInstrumentation(x)))
            {
                i += this.InstrumentType(type, recorder, instructionInstrumented);
            }
            return(i);
        }
Example #8
0
        public int InstrumentAssembly(AssemblyDefinition assembly, string output, Action <int, int, string> instructionInstrumented)
        {
            var recorder = new InstrumentationRecorder(assembly, output);
            var i        = 0;

            foreach (var module in assembly.Modules)
            {
                i += this.InstrumentModule(module, recorder, instructionInstrumented);
            }
            recorder.Finalise();
            return(i);
        }