示例#1
0
        public InstrumentationHelper UntilExit(InstrumentationPoint ip)
        {
            List <Instruction> closingInstructions = InstrumentationHelperClosingInstructions(ip);

            InstrumentationPositionInMethodHelper.WeaveInstructionsAtMethodExit(ip.instrumentationPointMethodDefinition, closingInstructions);
            return(_Save(ip));
        }
示例#2
0
        public InstrumentationHelper StartingAtExit(InstrumentationPoint ip)
        {
            InstrumentationHelperInitialization(ip);
            List <Instruction> openingInstructions = InstrumentationHelperOpeningInstructions(ip);

            InstrumentationPositionInMethodHelper.WeaveInstructionsAtMethodExit(ip.instrumentationPointMethodDefinition, openingInstructions);
            return(_Save(ip));
        }
示例#3
0
        protected override void InstrumentationHelperInitialization(
            InstrumentationPoint ip
            )
        {
            // TODO --- need a more graceful way to name these
            mSnapshotFieldDefinition =
                new FieldDefinition(
                    "snapshot_" + ip.Name,
                    FieldAttributes.Public,
                    ip.instrumentationPointTypeDefinition.Module.Import(typeof(WovenSnapshot))
                    );

            ip.instrumentationPointTypeDefinition.Fields.Add(mSnapshotFieldDefinition);

            // TODO might want a special case of this for constructors, static classes/constructors get messy
            List <Instruction> wovenFieldInitializationInstructions = new List <Instruction>();
            MethodDefinition   ipParentTypeConstructor = ip.instrumentationPointTypeDefinition.Methods.Single(m => m.Name == ".ctor");
            FieldDefinition    snapshotTargetField     =
                ip.instrumentationPointTypeDefinition.Fields
                .Single(f => f.Name == snapshotFieldName);
            ILProcessor ctorIlp = ipParentTypeConstructor.Body.GetILProcessor();

            // Load self
            wovenFieldInitializationInstructions.Add(
                ctorIlp.Create(OpCodes.Ldarg_0)
                );

            // Load arguments to WovenSnapshot constructor: IP Name
            wovenFieldInitializationInstructions.Add(
                ctorIlp.Create(OpCodes.Ldstr, ip.Name)
                );

            // Load arguments to WovenSnapshot constructor: Target field
            wovenFieldInitializationInstructions.Add(
                ctorIlp.Create(OpCodes.Ldarg_0)
                );
            wovenFieldInitializationInstructions.Add(
                ctorIlp.Create(OpCodes.Ldfld, snapshotTargetField)
                );
            wovenFieldInitializationInstructions.Add(
                ctorIlp.Create(OpCodes.Box, snapshotTargetField.FieldType)
                );

            // Create with constructor call and store into field
            wovenFieldInitializationInstructions.Add(
                ctorIlp.Create(
                    OpCodes.Newobj,
                    ipParentTypeConstructor.Module.Import(
                        typeof(WovenSnapshot).GetConstructor(new Type[] { typeof(string), typeof(object) }))
                    )
                );

            wovenFieldInitializationInstructions.Add(
                ctorIlp.Create(OpCodes.Stfld, mSnapshotFieldDefinition)
                );

            InstrumentationPositionInMethodHelper.WeaveInstructionsAtMethodExit(ipParentTypeConstructor, wovenFieldInitializationInstructions);
        }