VSNDK.DebugEngine.VariableInfo.get C# (CSharp) Method

get() public static method

Gets the information about a variable/expression.
public static get ( string name, EventDispatcher m_eventDispatcher, AD7StackFrame m_frame ) : VariableInfo
name string Variable name / expression.
m_eventDispatcher EventDispatcher The event dispatcher.
m_frame AD7StackFrame Current stack frame.
return VariableInfo
        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)
                            { // if the "search" expression is a local variable, it doesn't need to create a VariableInfo object for that.
                                vi = var;
                                break;
                            }
                        }
                    }

                    if (vi == null)
                    {
                        if (m_frame._arguments != null)
                        {
                            foreach (VariableInfo var in m_frame._arguments)
                            { // if the "search" expression is an argument, it doesn't need to create a VariableInfo object for that.
                                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, null);
                else
                {
                    string aux_exp = search.Replace(" ", "");
                    string datatype;

                    // Sending 2 GDB commands to get the data type of "aux_exp" because it is not known, at this moment, if "aux_exp"
                    // is an expression, a primitive or a compound variable.

                    // Gets the parsed response for the GDB command that returns the data type of "aux_exp".
                    // (http://sourceware.org/gdb/onlinedocs/gdb/Symbols.html)
                    string firstDatatype = GDBParser.parseCommand("whatis " + aux_exp, 3);

                    // Gets the parsed response for the GDB command that returns a detailed description of the type.
                    // (http://sourceware.org/gdb/onlinedocs/gdb/Symbols.html)
                    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, null);
                        }
                        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, null);
                    }
                }
            }
            return vi;
        }