Example #1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="vi"> Contains all information about a variable / expression. </param>
 public AD7Property(VariableInfo vi)
 {
     _variableInfo = vi;
 }
Example #2
0
        public static VariableInfo get(string name, EventDispatcher m_eventDispatcher, AD7StackFrame m_frame)
        {
            VariableInfo vi = null;
            string search = "";
            string separator = "";
            bool isArray = false;
            bool isRoot = true;

            do
            {
                int dot = name.IndexOf(".");
                int squareBracket = name.IndexOf("[");
                int pos = name.IndexOf("->");
                if (dot == -1)
                    dot = name.Length;
                if (squareBracket == -1)
                    squareBracket = name.Length;
                if (pos == -1)
                    pos = name.Length;
                int stop = dot < squareBracket ? dot : squareBracket;
                stop = stop < pos ? stop : pos;

                search = search + separator + name.Substring(0, stop);
                separator = "";

                if (stop < name.Length)
                {
                    separator = name.Substring(stop, 1);
                    if (separator == "-")
                    {
                        separator = "->";
                        name = name.Substring(stop + 2, name.Length - (stop + 2));
                    }
                    else if (separator == "[")
                    {
                        int aux = name.IndexOf("]");
                        isArray = true;
                        separator = name.Substring(stop, (aux - stop) + 1);
                        name = name.Substring(aux + 1, name.Length - (aux + 1));
                    }
                    else
                        name = name.Substring(stop + 1, name.Length - (stop + 1));
                }
                else
                    name = "";

                if (vi == null)
                {
                    if (m_frame._locals != null)
                    {
                        foreach (VariableInfo var in m_frame._locals)
                        {
                            if (var._name == search)
                            {
                                vi = var;
                                break;
                            }
                        }
                    }

                    if (vi == null)
                    {
                        if (m_frame._arguments != null)
                        {
                            foreach (VariableInfo var in m_frame._arguments)
                            {
                                if (var._name == search)
                                {
                                    vi = var;
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    isRoot = false;
                    VariableInfo vi_child = null;
                    if (vi._children != null)
                    {
                        foreach (VariableInfo var in vi._children)
                        {
                            if (var._name == search)
                            {
                                vi_child = var;
                                break;
                            }
                        }
                    }
                    vi = vi_child;
                }
            } while ((vi != null) && ((isArray) || (name != "")));

            if (name != "") // variable not found probably because it is in an expression, so return to the original name to evaluate it.
                search = search + separator + name;

            string result = "";
            bool valid;
            if (vi == null)
                valid = evaluateExpression(search, ref result, null);
            else
                valid = evaluateExpression(search, ref result, vi._GDBName);

            if (vi != null)
            {
                if ((vi._value != result) || (!isRoot))  // if is not root means that it can be expanded...
                {
                    vi._value = result;
                    if (vi._value == null || (vi._type.Contains("*") && (vi._value != "0x0")))
                    {
                        // This is an array, struct, union, or pointer.
                        // Create a variable object so we can list this variable's children.
                        ArrayList GDBNames = new ArrayList();
                        ArrayList VSNames = new ArrayList();
                        bool hasVsNdK_ = false;
                        m_eventDispatcher.createVar(vi._name, ref hasVsNdK_);
                        if (hasVsNdK_)
                        {
                            GDBNames.Add("VsNdK_" + vi._name);
                            VSNames.Add(vi._name);
                        }
                        vi._children = new ArrayList();
                        if (vi._type.Contains("struct"))
                            if (vi._type[vi._type.Length - 1] == '*')
                                vi.listChildren(m_eventDispatcher, "*", GDBNames, VSNames, hasVsNdK_, null);
                            else if (vi._type.Contains("["))
                                vi.listChildren(m_eventDispatcher, "struct[]", GDBNames, VSNames, hasVsNdK_, null);
                            else
                                vi.listChildren(m_eventDispatcher, "struct", GDBNames, VSNames, hasVsNdK_, null);
                        else if (vi._type.Contains("["))
                            vi.listChildren(m_eventDispatcher, "[]", GDBNames, VSNames, hasVsNdK_, null);
                        else if (vi._type.Contains("*"))
                            vi.listChildren(m_eventDispatcher, "*", GDBNames, VSNames, hasVsNdK_, null);
                        else
                            vi.listChildren(m_eventDispatcher, "", GDBNames, VSNames, hasVsNdK_, null);
                        m_eventDispatcher.deleteVar(vi._name, hasVsNdK_);
                    }
                }
            }
            else
            {
                if (!valid)
                    vi = new VariableInfo(search, "", result);
                else
                {
                    string aux_exp = search.Replace(" ", "");
                    string datatype;
                    string firstDatatype = GDBParser.parseCommand("whatis " + aux_exp, 3);
                    string baseDatatype = GDBParser.parseCommand("ptype " + aux_exp, 4);
                    if ((baseDatatype[baseDatatype.Length - 1] == '{') && (baseDatatype[baseDatatype.Length - 2] == ' '))
                        baseDatatype = baseDatatype.Remove(baseDatatype.Length - 2);
                    if (baseDatatype.Length < firstDatatype.Length)
                    {
                        if (firstDatatype.Contains(baseDatatype))
                        {
                            baseDatatype = firstDatatype;
                        }
                    }
                    if ((baseDatatype == firstDatatype) || ((baseDatatype.Contains("::")) && (!baseDatatype.Contains("union"))))
                    {
                        baseDatatype = "";
                        datatype = firstDatatype;
                    }
                    else
                    {
                        datatype = baseDatatype;
                    }
                    if (datatype[datatype.Length - 1] == '*')
                        if (result == "0x0")
                        {
                            vi = new VariableInfo(search, firstDatatype, result);
                        }
                        else
                        {
                            vi = new VariableInfo(search, firstDatatype, baseDatatype, result, m_eventDispatcher, null, null);
                        }
                    else if ((datatype.Contains("struct")) || (datatype.Contains("[")))
                    {
                        vi = new VariableInfo(search, firstDatatype, baseDatatype, null, m_eventDispatcher, null, null);
                    }
                    else
                    {
                        vi = new VariableInfo(search, firstDatatype, result);
                    }
                }
            }
            return vi;
        }
Example #3
0
 public static VariableInfo create(string name, string type, string value, EventDispatcher dispatcher)
 {
     VariableInfo newVar = new VariableInfo(name, type, "", value, dispatcher, null, null);
     return newVar;
 }
Example #4
0
        public void listChildren(EventDispatcher dispatcher, string parentType, ArrayList GDBNames, ArrayList VSNames, bool hasVsNdK_, string GDBName)
        {
            string childListResponse;
            if (GDBName == null)
            {
                if (hasVsNdK_)
                {
                    childListResponse = dispatcher.listChildren(_GDBName);
                }
                else
                {
                    childListResponse = dispatcher.listChildren(_name);
                    if ((childListResponse == "ERROR") && (_GDBName != null))
                    {
                        childListResponse = dispatcher.listChildren(_GDBName);
                    }
                }
            }
            else
                childListResponse = dispatcher.listChildren(GDBName);

            if (childListResponse != "ERROR")
            {
                childListResponse = (childListResponse.Substring(3)).Replace("#;;;", "");

                string[] childList = childListResponse.Split('#');
                foreach (string childString in childList)
                {
                    //                    bool complex = false;
                    string name = null;
                    string type = null;
                    string value = null;
                    string exp = null;
                    int numChildren = 0;
                    bool valid = true;

                    string[] childProperties = childString.Split(';');

                    if (childProperties[0] == "")
                        continue;

                    name = childProperties[0];

                    if (name.Contains("::"))
                    {
                        continue;
                    }

                    GDBName = name;
            //                    string old = name;

                    int end = name.Length;
                    if (name[end - 1] == '"')
                        end--;
                    if (((name.Length > 8) && (name.Substring(end - 8, 8) == ".private")) || ((name.Length > 7) && (name.Substring(end - 7, 7) == ".public")) || ((name.Length > 10) && (name.Substring(end - 10, 10) == ".protected")) || ((name.Length > 9) && (name.Substring(end - 9, 9) == ".private.")) || ((name.Length > 8) && (name.Substring(end - 8, 8) == ".public.")) || ((name.Length > 11) && (name.Substring(end - 11, 11) == ".protected.")))
                    {
                        int index = VSNames.IndexOf(_name);
                        if (index != -1)
                            GDBNames[index] = GDBName;
                        else
                        {
                            GDBNames.Add(GDBName);
                            VSNames.Add(_name);
                        }
                        this.listChildren(dispatcher, parentType, GDBNames, VSNames, hasVsNdK_, GDBName);
                        continue;
                    }
                    else
                    {
                        int dot = name.LastIndexOf(".");
                        if (dot != -1)
                        {
                            int index = GDBNames.IndexOf(name.Substring(0, dot));
                            if (index != -1)
                            {
                                name = VSNames[index].ToString() + name.Substring(dot);
                            }
                        }

                        name = name.Replace(".private", "");
                        name = name.Replace(".public", "");
                        name = name.Replace(".protected", "");
                        name = name.Replace("..", ".");

                        dot = name.LastIndexOf(".*");
                        if (dot != -1)
                        {
                            name = "*(" + name.Remove(dot) + ")";
                        }

                        if (parentType == "*")
                        {
                            dot = name.LastIndexOf('.');
                            if (dot != -1)
                            {
                                name = name.Substring(0, dot) + "->" + name.Substring(dot + 1, name.Length - (dot + 1));
                            }
                        }
                        else if (parentType == "[]")
                        {
                            dot = name.LastIndexOf('.');
                            name = name.Substring(0, dot) + "[" + name.Substring(dot + 1, name.Length - (dot + 1));
                            name = name + "]";
                        }
                        GDBNames.Add(GDBName);
                        VSNames.Add(name);
                    }

                    if (childProperties[1] != "")
                        numChildren = Convert.ToInt32(childProperties[1]);

                    value = childProperties[2];
                    if ((value == "") || (value.Contains("{...}")) || ((value.Length >= 2) && (value[0] == '[') && (value[value.Length - 1] == ']')))
                        valid = evaluateExpression(name, ref value, GDBName);

                    type = childProperties[3];

                    VariableInfo child = new VariableInfo(name, exp, type, value, GDBName);

                    if ((valid) && (numChildren > 0 && value != "0x0"))
                    {
                        child._children = new ArrayList();
                    }
                    if (VSNames.Contains(name))
                    {
                        int index = VSNames.IndexOf(name);
                        VSNames.RemoveAt(index);
                        GDBNames.RemoveAt(index);
                    }
                    _children.Add(child);
                    //                    }
                }
            }
            else
            {
                // ??? What to do in case of error???
            }
        }
Example #5
0
        public void addChild(VariableInfo child)
        {
            if (_children == null)
                _children = new ArrayList();

            _children.Add(child);
        }
Example #6
0
 public AD7Property()
 {
     _variableInfo = null;
 }