public void RefreshRow(int i)
        {
            if (this.watchList.Rows[i].Cells[0].Value != null)
            {
                if ((this.watchList.Rows[i] as AdvancedDataGridView.TreeGridNode).UserRow)
                {
                    string s = this.watchList.Rows[i].Cells[0].Value as string;
                    RetValue rv = WorkbenchServiceFactory.DebuggerManager.Evaluate(s);
                    if (rv.syn_err)
                    {
                        this.ClearRow(i);
                        FixedItem fi = new FixedItem(this.watchList.Rows[i].Cells[0].Value as string, PascalABCCompiler.StringResources.Get("EXPR_VALUE_SYNTAX_ERROR_IN_EXPR"), "");
                        fi.imageIndex = CodeCompletionProvider.ImagesProvider.IconNumberEvalError;
                        this.watchList.Rows[i].Cells[1].Value = fi.Text;
                        this.watchList.Rows[i].Cells[2].Value = fi.Type;
                        (this.watchList.Rows[i] as AdvancedDataGridView.TreeGridNode)._grid = this.watchList;
                        (this.watchList.Rows[i] as AdvancedDataGridView.TreeGridNode).Content = fi;
                    }
                    else
                        if (rv.obj_val != null)
                        {
                            //this.ClearRow(i);
                            try
                            {
                                ValueItem vi = new ValueItem(rv.obj_val, s, WorkbenchServiceFactory.DebuggerManager.evaluator.declaringType);
                                (this.watchList.Rows[i] as AdvancedDataGridView.TreeGridNode)._grid = this.watchList;
                                (this.watchList.Rows[i] as AdvancedDataGridView.TreeGridNode).Content = vi;
                                this.watchList.Rows[i].Cells[1].Value = WorkbenchServiceFactory.DebuggerManager.MakeValueView(rv.obj_val);//rv.obj_val.AsString;
                                this.watchList.Rows[i].Cells[2].Value = DebugUtils.WrapTypeName(rv.obj_val.Type);
                                this.watchList.InvalidateCell(0, i);
                            }
                            catch (System.Exception e)
                            {
                                
                            }
                        }
                        else if (rv.prim_val != null)
                        {
                            //this.ClearRow(i);
                            FixedItem fi = new FixedItem(s, WrapPrimValue(rv.prim_val), DebugUtils.WrapTypeName(rv.prim_val.GetType()));
                            this.watchList.Rows[i].Cells[1].Value = fi.Text;
                            this.watchList.Rows[i].Cells[2].Value = fi.Type;
                            (this.watchList.Rows[i] as AdvancedDataGridView.TreeGridNode)._grid = this.watchList;
                            (this.watchList.Rows[i] as AdvancedDataGridView.TreeGridNode).Content = fi;
                            this.watchList.InvalidateCell(0, i);
                        }
                        else if (rv.type != null)
                        {
                            //this.ClearRow(i);
                            BaseTypeItem bti = new BaseTypeItem(rv.type, rv.managed_type);
                            (this.watchList.Rows[i] as AdvancedDataGridView.TreeGridNode)._grid = this.watchList;
                            (this.watchList.Rows[i] as AdvancedDataGridView.TreeGridNode).Content = bti;
                        }
                        else
                        {
                            this.ClearRow(i);
                            FixedItem fi = null;
                            if (WorkbenchServiceFactory.DebuggerManager.IsRunning)
                            {
                                fi = new FixedItem(s, rv.err_mes != null ? rv.err_mes : PascalABCCompiler.StringResources.Get("EXPR_VALUE_UNDEFINED_VALUE"),/*PascalABCCompiler.StringResources.Get("EXPR_VALUE_UNDEFINED_TYPE")*/"");
                                fi.imageIndex = CodeCompletionProvider.ImagesProvider.IconNumberEvalError;
                            }
                            else
                            {
                                fi = new FixedItem(s, "", "");
                            }
                            this.watchList.Rows[i].Cells[1].Value = fi.Text;
                            this.watchList.Rows[i].Cells[2].Value = fi.Type;
                            (this.watchList.Rows[i] as AdvancedDataGridView.TreeGridNode)._grid = this.watchList;
                            (this.watchList.Rows[i] as AdvancedDataGridView.TreeGridNode).Content = fi;
                            this.watchList.InvalidateCell(0, i);
                        }
                }
                else
                {

                }
            }
            else
            {
                //this.watchList.Rows[i].Cells[1].Value = null;
                //this.watchList.Rows[i].Cells[2].Value = null;
                if (i != this.watchList.Rows.Count - 1)
                {
                    this.ClearRow(i);
                    FixedItem fi = new FixedItem("", "", "");
                    this.watchList.Rows[i].Cells[1].Value = "";
                    this.watchList.Rows[i].Cells[2].Value = "";
                    (this.watchList.Rows[i] as AdvancedDataGridView.TreeGridNode)._grid = this.watchList;
                    (this.watchList.Rows[i] as AdvancedDataGridView.TreeGridNode).Content = fi;
                    this.watchList.InvalidateCell(0, i);
                    this.watchList.Rows.RemoveAt(i);
                }
                //this.watchList.InvalidateCell(0,i);
            }
        }
Beispiel #2
0
        public ListItem FindVarByName(string var, int num_line)
        {
            try
            {
                if (!var.Contains("."))
                {
                    List<NamedValue> unit_vars = new List<NamedValue>();
                    NamedValueCollection nvc = null;
                    NamedValue global_nv = null;
                    NamedValue disp_nv = null;
                    NamedValue ret_nv = null;
                    nvc = debuggedProcess.SelectedFunction.LocalVariables;
                    foreach (NamedValue nv in nvc)//smotrim sredi lokalnyh peremennyh
                    {
                        if (nv.Name.IndexOf(':') != -1)
                        {
                            int pos = nv.Name.IndexOf(':');
                            string name = nv.Name.Substring(0, pos);
                            if (string.Compare(name, var, true) == 0)
                            {
                                int start_line = Convert.ToInt32(nv.Name.Substring(pos + 1, nv.Name.LastIndexOf(':') - pos - 1));
                                int end_line = Convert.ToInt32(nv.Name.Substring(nv.Name.LastIndexOf(':') + 1));
                                if (num_line >= start_line - 1 && num_line <= end_line - 1)
                                    return new ValueItem(nv, null);
                            }
                        }
                        if (string.Compare(nv.Name, var, true) == 0)
                        {
                            return new ValueItem(nv, null);
                        }
                        else if (string.Compare(nv.Name, "self", true) == 0 && debuggedProcess.SelectedFunction.ThisValue != null)
                            return new ValueItem(debuggedProcess.SelectedFunction.ThisValue, null);
                        else if (nv.Name.Contains("$class_var")) global_nv = nv;
                        else if (nv.Name.Contains("$unit_var")) unit_vars.Add(nv);
                        else if (nv.Name == "$disp$") disp_nv = nv;//vo vlozhennyh procedurah ssylka na verh zapis aktivacii
                        else if (nv.Name.StartsWith("$rv")) ret_nv = nv;//vozvrashaemoe znachenie
                    }
                    nvc = debuggedProcess.SelectedFunction.Arguments;
                    NamedValue self_nv = null;
                    foreach (NamedValue nv in nvc)
                    {
                        if (string.Compare(nv.Name, var, true) == 0) return new ValueItem(nv, null);
                        if (nv.Name == "$obj$")
                            self_nv = nv;
                    }
                    if (var.ToLower() == "self")
                    {
                        try
                        {
                            return new ValueItem(debuggedProcess.SelectedFunction.ThisValue, null);
                        }
                        catch
                        {
                            if (self_nv != null)
                                return new ValueItem(self_nv, null);
                        }
                    }
                    if (disp_nv != null)//prohodimsja po vlozhennym podprogrammam
                    {
                        NamedValue parent_val = null;
                        IList<FieldInfo> fields = disp_nv.Type.GetFields(BindingFlags.All);
                        foreach (FieldInfo fi in fields)
                            if (string.Compare(fi.Name, var, true) == 0) return new ValueItem(fi.GetValue(disp_nv), fi.DeclaringType);
                            else if (fi.Name == "$parent$") parent_val = fi.GetValue(disp_nv);
                        NamedValue pv = parent_val;
                        while (!pv.IsNull)
                        {
                            fields = parent_val.Type.GetFields(BindingFlags.All);
                            foreach (FieldInfo fi in fields)
                                if (string.Compare(fi.Name, var, true) == 0) return new ValueItem(fi.GetValue(parent_val), fi.DeclaringType);
                                else if (fi.Name == "$parent$") pv = fi.GetValue(parent_val);
                            if (!pv.IsNull) parent_val = pv;
                        }
                    }
                    //                nvc = debuggedProcess.SelectedFunction.ContaingClassVariables;
                    //                foreach (NamedValue nv in nvc)
                    //                {
                    //                    if (string.Compare(nv.Name, var, true) == 0) return new ValueItem(nv,null);
                    //                }
                    //				try
                    //				{
                    //				if (debuggedProcess.SelectedFunction.ThisValue != null)
                    //				{
                    //					NamedValue nv = debuggedProcess.SelectedFunction.ThisValue.GetMember(var);
                    //					if (nv != null) return new ValueItem(nv,null);
                    //				}
                    //				}
                    //				catch(System.Exception e)
                    //				{
                    //					
                    //				}
                    nvc = debuggedProcess.SelectedFunction.ContaingClassVariables;
                    foreach (NamedValue nv in nvc)//chleny klassa
                    {
                        if (string.Compare(nv.Name, var, true) == 0) return new ValueItem(nv, nv.Type);
                    }
                    if (self_nv != null)
                    {
                        IList<FieldInfo> fields = self_nv.Dereference.Type.GetFields(BindingFlags.All);
                        foreach (FieldInfo fi in fields)
                            if (string.Compare(fi.Name, var, true) == 0)
                                return new ValueItem(fi.GetValue(self_nv.Dereference), fi.DeclaringType);
                    }
                    if (global_nv != null)
                    {
                        IList<FieldInfo> fields = global_nv.Type.GetFields(BindingFlags.All);
                        foreach (FieldInfo fi in fields)
                            if (string.Compare(fi.Name, var, true) == 0) return new ValueItem(fi.GetValue(global_nv), fi.DeclaringType);
                    }

                    
                        List<DebugType> types = AssemblyHelper.GetUsesTypes(debuggedProcess, debuggedProcess.SelectedFunction.DeclaringType);
                        foreach (DebugType dt in types)
                        {
                            IList<FieldInfo> fields = dt.GetFields(BindingFlags.All);
                            foreach (FieldInfo fi in fields)
                                if (fi.IsStatic && string.Compare(fi.Name, var, true) == 0) return new ValueItem(fi.GetValue(null), fi.DeclaringType);
                        }
                    
                    /*foreach (NamedValue nv in unit_vars)
                    {
                        IList<FieldInfo> fields = nv.Type.GetFields(BindingFlags.All);
                        foreach (FieldInfo fi in fields)
                            if (string.Compare(fi.Name, var, true) == 0) return new ValueItem(fi.GetValue(nv),fi.DeclaringType);
                    }*/

                    if (ret_nv != null && string.Compare(var, "Result", true) == 0)
                        return new ValueItem(ret_nv, null);
                    Type t = AssemblyHelper.GetTypeForStatic(var);
                    if (t != null)
                    {
                        DebugType dt = DebugUtils.GetDebugType(t);//DebugType.Create(this.debuggedProcess.GetModule(var),(uint)t.MetadataToken);
                        return new BaseTypeItem(dt, t);
                    }
                }
                else
                {
                    if (evaluator == null) return null;
                    Debugger.Wrappers.CorSym.ISymUnmanagedMethod sym_meth = debuggedProcess.SelectedFunction.symMethod;
                    //            	if (sym_meth == null) return null;
                    //               		if (sym_meth.SequencePoints.Length > 0)
                    //                 	if (num_line < sym_meth.SequencePoints[0].Line || num_line > sym_meth.SequencePoints[sym_meth.SequencePoints.Length - 1].EndLine)
                    //                     return null;
                    string preformat;
                    RetValue rv = evaluator.GetValueForExpression(var, out preformat);
                    if (rv.obj_val != null && rv.obj_val is NamedValue)
                    {
                        Value v = rv.obj_val;
                        ValueItem vi = new ValueItem(v, var, evaluator.declaringType);
                        vi.SpecialName = preformat;
                        return vi;
                    }
                    else if (rv.prim_val != null)
                    {
                        ValueItem vi = new ValueItem(DebugUtils.MakeValue(rv.prim_val), var, evaluator.declaringType);
                        vi.SpecialName = preformat;
                        return vi;
                    }
                    else if (rv.type != null)
                    {
                        return new BaseTypeItem(rv.type, rv.managed_type);
                    }
                }
            }
            catch (System.Exception e)
            {

            }
            return null;
        }
        public void RefreshRow(int i)
        {
            if (this.watchList.Rows[i].Cells[0].Value != null)
            {
                if ((this.watchList.Rows[i] as AdvancedDataGridView.TreeGridNode).UserRow)
                {
                    RetValue rv = WorkbenchServiceFactory.DebuggerManager.Evaluate(this.watchList.Rows[i].Cells[0].Value as string);
                    if (rv.syn_err)
                    {
                        this.watchList.Rows[i].Cells[1].Value = PascalABCCompiler.StringResources.Get("EXPR_VALUE_SYNTAX_ERROR_IN_EXPR");
                        this.watchList.Rows[i].Cells[2].Value = null;//PascalABCCompiler.StringResources.Get("EXPR_VALUE_UNDEFINED_TYPE");
                    }
                    else
                        if (rv.obj_val != null)
                        {
                            try
                            {
                                ValueItem vi = new ValueItem(rv.obj_val, this.watchList.Rows[i].Cells[0].Value as string, WorkbenchServiceFactory.DebuggerManager.evaluator.declaringType);
                                (this.watchList.Rows[i] as AdvancedDataGridView.TreeGridNode)._grid = this.watchList;
                                (this.watchList.Rows[i] as AdvancedDataGridView.TreeGridNode).Content = vi;
                                this.watchList.Rows[i].Cells[1].Value = WorkbenchServiceFactory.DebuggerManager.MakeValueView(rv.obj_val);//rv.obj_val.AsString;
                                this.watchList.Rows[i].Cells[2].Value = DebugUtils.WrapTypeName(rv.obj_val.Type);
                                this.watchList.InvalidateCell(0, i);
                            }
                            catch (System.Exception e)
                            {
                                this.watchList.Rows[i].Cells[1].Value = PascalABCCompiler.StringResources.Get("EXPR_VALUE_UNDEFINED_VALUE");
                                this.watchList.Rows[i].Cells[2].Value = PascalABCCompiler.StringResources.Get("EXPR_VALUE_UNDEFINED_TYPE");
                                //								  FixedItem fi = new FixedItem(this.watchList.Rows[i].Cells[0].Value as string,PascalABCCompiler.StringResources.Get("EXPR_VALUE_UNDEFINED_VALUE"),PascalABCCompiler.StringResources.Get("EXPR_VALUE_UNDEFINED_TYPE"));
                                //								  fi.imageIndex = CodeCompletionProvider.ImagesProvider.IconNumberEvalError;
                                //								  (this.watchList.Rows[i] as AdvancedDataGridView.TreeGridNode)._grid = this.watchList;
                                //                            	  (this.watchList.Rows[i] as AdvancedDataGridView.TreeGridNode).Content = fi;
                            }
                        }
                        else if (rv.prim_val != null)
                        {
                            FixedItem fi = new FixedItem(this.watchList.Rows[i].Cells[0].Value as string, WrapPrimValue(rv.prim_val), DebugUtils.WrapTypeName(rv.prim_val.GetType()));
                            this.watchList.Rows[i].Cells[1].Value = fi.Text;
                            this.watchList.Rows[i].Cells[2].Value = fi.Type;
                            (this.watchList.Rows[i] as AdvancedDataGridView.TreeGridNode)._grid = this.watchList;
                            (this.watchList.Rows[i] as AdvancedDataGridView.TreeGridNode).Content = fi;
                        }
                        else
                        {
                            this.watchList.Rows[i].Cells[1].Value = PascalABCCompiler.StringResources.Get("EXPR_VALUE_UNDEFINED_VALUE");
                            this.watchList.Rows[i].Cells[2].Value = PascalABCCompiler.StringResources.Get("EXPR_VALUE_UNDEFINED_TYPE");
                            //                            FixedItem fi = new FixedItem(this.watchList.Rows[i].Cells[0].Value as string,PascalABCCompiler.StringResources.Get("EXPR_VALUE_UNDEFINED_VALUE"),PascalABCCompiler.StringResources.Get("EXPR_VALUE_UNDEFINED_TYPE"));
                            //							fi.imageIndex = CodeCompletionProvider.ImagesProvider.IconNumberEvalError;
                            //							(this.watchList.Rows[i] as AdvancedDataGridView.TreeGridNode)._grid = this.watchList;
                            //                            (this.watchList.Rows[i] as AdvancedDataGridView.TreeGridNode).Content = fi;
                            this.ClearRow(i);
                        }
                }
                else
                {

                }
            }
            else
            {
                this.watchList.Rows[i].Cells[1].Value = null;
                this.watchList.Rows[i].Cells[2].Value = null;
            }
        }