Example #1
0
        private void button4_Click(object sender, EventArgs e)
        {
            var types = env.GetAllTypes();

            foreach (var t in types)
            {
                CLRSharp.ICLRType_Sharp type = env.GetType(t, null) as CLRSharp.ICLRType_Sharp;
                if (type != null)
                {
                    type.ResetStaticInstace();
                }
            }
            int testcount = 0;
            int succcount = 0;

            foreach (TreeNode t in treeView1.Nodes)
            {
                foreach (TreeNode method in t.Nodes)
                {
                    Mono.Cecil.MethodDefinition m = method.Tag as Mono.Cecil.MethodDefinition;
                    if (m == null)
                    {
                        continue;
                    }
                    if (m.HasParameters == false && m.Name.Contains("UnitTest") && m.IsStatic)
                    {
                        testcount++;
                        try
                        {
                            object obj = RunTest(m);
                            method.BackColor = Color.YellowGreen;
                            succcount++;
                            Log("----TestOK----" + m.ToString());
                        }
                        catch (Exception err)
                        {
                            method.BackColor = Color.Red;
                            Log("----Test Fail----" + m.ToString());
                        }
                    }
                }
            }
            Log("----Test Succ(" + succcount + "/" + testcount + ")----");
        }
Example #2
0
 public override string ToString()
 {
     return(definition == null?base.ToString() : definition.ToString());
 }
Example #3
0
        void FillTree_Method(Mono.Cecil.MethodDefinition method)
        {
            treeView2.Tag = method;
            treeView2.Nodes.Clear();
            TreeNode methodinfo = new TreeNode(method.ToString());

            treeView2.Nodes.Add(methodinfo);

            if (method.HasParameters)
            {
                TreeNode paraminfo = new TreeNode("Params");
                treeView2.Nodes.Add(paraminfo);
                for (int i = 0; i < method.Parameters.Count; i++)
                {
                    TreeNode p = new TreeNode(method.Parameters[i].ParameterType + " " + method.Parameters[i].Name);
                    paraminfo.Nodes.Add(p);
                }
            }
            TreeNode body = new TreeNode("Body");

            treeView2.Nodes.Add(body);
            if (method.HasBody)
            {
                TreeNode variables = new TreeNode("Variables");
                body.Nodes.Add(variables);
                if (method.Body.HasVariables)
                {
                    foreach (var v in method.Body.Variables)
                    {
                        TreeNode var = new TreeNode(v.VariableType + " " + v.Name);
                        variables.Nodes.Add(var);
                    }
                }
                TreeNode eh = new TreeNode("ExceptionHandlers");
                body.Nodes.Add(eh);
                if (method.Body.HasExceptionHandlers)
                {
                    foreach (Mono.Cecil.Cil.ExceptionHandler v in method.Body.ExceptionHandlers)
                    {
                        TreeNode var = new TreeNode(v.ToString());
                        eh.Nodes.Add(v.HandlerType + " " + v.CatchType + "(" + v.HandlerStart + "," + v.HandlerEnd + ")");
                    }
                }
                TreeNode code = new TreeNode("Code");
                body.Nodes.Add(code);
                foreach (Mono.Cecil.Cil.Instruction i in method.Body.Instructions)
                {
                    string line = i.ToString();

                    //i.Offset
                    if (i.SequencePoint != null)
                    {
                        LoadCodeFile(i.SequencePoint.Document.Url);
                        line += " |(" + i.SequencePoint.StartLine + "," + i.SequencePoint.StartColumn + ")";

                        if (codes[i.SequencePoint.Document.Url] != null)
                        {
                            int lines = i.SequencePoint.StartLine;
                            if (lines - 1 < codes[i.SequencePoint.Document.Url].Length)
                            {
                                line += "| " + codes[i.SequencePoint.Document.Url][i.SequencePoint.StartLine - 1];
                            }
                        }
                    }
                    TreeNode op = new TreeNode(line);
                    op.Tag = i;
                    code.Nodes.Add(op);
                }
            }
            treeView2.ExpandAll();
        }
Example #4
0
        public object ExecuteFunc(Mono.Cecil.MethodDefinition func, object _this, object[] _params)
        {
            _activeContext = this;
            if (this.DebugLevel >= 9)
            {
                environment.logger.Log("<Call>::" + func.ToString());
            }
            StackFrame stack = new StackFrame(func.Name, func.IsStatic);

            stacks.Push(stack);
            object[] _withp = null;
            bool     isctor = func.Name == ".ctor";

            if (isctor)
            {
                //CLRSharp_Instance pthis = new CLRSharp_Instance(GetType(func.ReturnType) as Type_Common_CLRSharp);
                //StackFrame.RefObj pthis = new StackFrame.RefObj(stack, 0, StackFrame.RefType.arg);
                _withp = new object[_params == null ? 1 : (_params.Length + 1)];
                if (_params != null)
                {
                    _params.CopyTo(_withp, 1);
                }
                _withp[0] = _this;
            }
            else
            {
                if (!func.IsStatic)
                {
                    _withp    = new object[(_params == null) ? 1 : (_params.Length + 1)];
                    _withp[0] = _this;
                    if (_params != null)
                    {
                        _params.CopyTo(_withp, 1);
                    }
                }
                else
                {
                    _withp = _params;
                }
            }
            stack.SetParams(_withp);
            if (func.HasBody)
            {
                stack._pos = func.Body.Instructions[0];
                if (func.Body.HasExceptionHandlers)
                {
                    RunCodeWithTry(func, stack);
                }
                else
                {
                    RunCode(stack, func.Body.Instructions);
                }
            }

            if (this.DebugLevel >= 9)
            {
                environment.logger.Log("<CallEnd>");
            }
            var ret = stacks.Pop().Return();

            return(isctor ? _this : ret);

            //if (func.HasBody)
            //{
            //    RunCode(stack, func.Body.Instructions);
            //}
            //var ret = stacks.Pop().Return();
            //if (this.DebugLevel >= 9)
            //{
            //    environment.logger.Log("<CallEnd>");

            //}
            //return ret;
        }