public void TrackCallsTest() { MethodTableCursor cur = CLIFile.FindMethod(typeof(GenericsUnitTest).GetMethod("ExpressionInput")); CLIFileRW.MethodBody cb = cur.MethodBody; LocalsVarSig locals = cb.LocalsSignature; CLIType[] vars = locals.GetVariables().ToArray <CLIType>(); CLIType[] args = cur.GetMethodSignature().GetParameters(cur.FindCLIType()).ToArray <CLIType>(); ILCursor ilc = cb.ILInstructions; ilc.TrackStack(args, vars, cb.MaxStack); while (ilc.Next()) { ILInstruction instr = ilc.Instr; object o = instr.ResolveParameter(f); if (ilc.IsCall) { Target[] cargs = ilc.CallLoadArguments(); MethodDesc m = (MethodDesc)o; System.Diagnostics.Debug.WriteLine(string.Format("{0} to {1} at offset {2:X4}", ilc.Instr.op, m.Name, ilc.Position)); for (int i = 0; i < cargs.Length; i++) { System.Diagnostics.Debug.WriteLine(string.Format("\tPar {0} at offset {1:X4}", i, cargs[i].Position)); } } } }
public void StatementsBodyTest() { MethodTableCursor cur = CLIFile.FindMethod(typeof(GenericsUnitTest).GetMethod("MethodTest")); CLIFileRW.MethodBody cb = cur.MethodBody; LocalsVarSig locals = cb.LocalsSignature; CLIType[] vars = locals.GetVariables().ToArray <CLIType>(); CLIType[] args = cur.GetMethodSignature().GetParameters(cur.FindCLIType()).ToArray <CLIType>(); ILCursor ilc = cb.ILInstructions; ilc.TrackStack(args, vars, cb.MaxStack); while (ilc.Next()) { ILInstruction instr = ilc.Instr; object o = instr.ResolveParameter(f); if (ilc.BeginStatement) { System.Diagnostics.Debug.WriteLine(string.Format("MethodTest statement at offset: {0:X4}", ilc.Position)); } } }