////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public CLangDebuggeeProperty [] GetChildProperties(CLangDebuggeeStackFrame stackFrame, CLangDebuggeeProperty parentProperty)
        {
            LoggingUtils.PrintFunction();

            MiVariable parentVariable = parentProperty.GdbVariable;

            List <CLangDebuggeeProperty> childProperties = new List <CLangDebuggeeProperty> ();

            if (parentVariable.HasChildren && (parentVariable.Children.Count > 0))
            {
                foreach (MiVariable childVariable in parentVariable.Children.Values)
                {
                    CLangDebuggeeProperty childProperty = new CLangDebuggeeProperty(m_debugger, stackFrame, childVariable);

                    if (childVariable.IsPseudoChild)
                    {
                        CLangDebuggeeProperty [] childSubProperties = GetChildProperties(stackFrame, childProperty);

                        childProperties.AddRange(childSubProperties);
                    }
                    else
                    {
                        childProperties.Add(childProperty);
                    }
                }
            }

            return(childProperties.ToArray());
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public CLangDebuggeeProperty(CLangDebugger debugger, CLangDebuggeeStackFrame stackFrame, MiVariable gdbVariable)
            : base(debugger.Engine, stackFrame, gdbVariable.Expression, string.Empty)
        {
            m_debugger = debugger;

            m_gdbVariable = gdbVariable;
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public CLangDebuggeeProperty(CLangDebugger debugger, CLangDebuggeeStackFrame stackFrame, string expression, string value)
            : base(debugger.Engine, stackFrame, expression, value)
        {
            m_debugger = debugger;

            m_gdbVariable = null;
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        private void DeleteGdbVariable(MiVariable gdbVariable)
        {
            LoggingUtils.PrintFunction();

            string command = string.Format("-var-delete \"{0}\"", gdbVariable.Name);

            MiResultRecord resultRecord = m_debugger.GdbClient.SendSyncCommand(command);

            MiResultRecord.RequireOk(resultRecord, command);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public void UpdateVariable(MiVariable variable)
        {
            LoggingUtils.PrintFunction();

            string command = string.Format("-var-update --all-values \"{0}\"", variable.Name);

            MiResultRecord resultRecord = m_debugger.GdbClient.SendSyncCommand(command);

            MiResultRecord.RequireOk(resultRecord, command);

            if (resultRecord.HasField("changelist"))
            {
                variable.Populate(resultRecord ["changelist"]);
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public void CreateChildVariables(MiVariable parentVariable, int depth)
        {
            LoggingUtils.PrintFunction();

            if ((depth > 0) && (parentVariable.HasChildren))
            {
                MiVariable [] evaluatedChildren = GetChildVariables(parentVariable, depth);

                foreach (MiVariable child in evaluatedChildren)
                {
                    CreateChildVariables(child, depth - 1);

                    parentVariable.AddChild(child);
                }
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public CLangDebuggeeProperty CreatePropertyFromVariable(CLangDebuggeeStackFrame stackFrame, MiVariable variable)
        {
            return(new CLangDebuggeeProperty(m_debugger, stackFrame, variable));
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        private MiVariable [] GetChildVariables(MiVariable parentVariable, int depth)
        {
            LoggingUtils.PrintFunction();

            List <MiVariable> childVariables = new List <MiVariable> ();

            if ((depth > 0) && (parentVariable.HasChildren))
            {
                string command = string.Format("-var-list-children --all-values \"{0}\"", parentVariable.Name);

                MiResultRecord resultRecord = m_debugger.GdbClient.SendSyncCommand(command);

                MiResultRecord.RequireOk(resultRecord, command);

                if (resultRecord.HasField("children"))
                {
                    List <MiResultValue> childrenList = resultRecord ["children"] [0] ["child"];

                    for (int i = 0; i < childrenList.Count; ++i)
                    {
                        MiResultValueTuple childTuple = childrenList [i] as MiResultValueTuple;

                        string variableName = childTuple ["name"] [0].GetString();

                        MiVariable childVariable = null;

                        bool isPseudoChild = false;

                        if (childTuple.HasField("exp"))
                        {
                            string variableExpression = childTuple ["exp"] [0].GetString();

                            if (!string.IsNullOrEmpty(variableExpression))
                            {
                                childVariable = new MiVariable(variableName, variableExpression);

                                childVariable.Populate(childTuple.Values);

                                isPseudoChild = childVariable.IsPseudoChild;
                            }
                        }

                        if (childVariable == null)
                        {
                            childVariable = new MiVariable(variableName, childTuple.Values);
                        }

                        if (isPseudoChild)
                        {
                            depth += 1; // need an additional level of children.

                            MiVariable [] evaluatedChildren = GetChildVariables(childVariable, depth - 1);

                            foreach (MiVariable child in evaluatedChildren)
                            {
                                childVariable.AddChild(child);
                            }
                        }

                        childVariables.Add(childVariable);
                    }
                }
            }

            return(childVariables.ToArray());
        }
Beispiel #9
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public DebuggeeProperty EvaluateCustomExpression(enum_EVALFLAGS evaluateFlags, string expression, uint radix)
        {
            //
            // Evaluates a custom property lookup, and registers a new entry for this expression if one can't be found.
            //

            LoggingUtils.PrintFunction();

            DebuggeeProperty property = null;

            try
            {
                if (m_stackRegisters.TryGetValue(expression, out property))
                {
                    return(property);
                }

                if (m_stackArguments.TryGetValue(expression, out property))
                {
                    return(property);
                }

                if (m_stackLocals.TryGetValue(expression, out property))
                {
                    return(property);
                }

                if (m_customExpressions.TryGetValue(expression, out property))
                {
                    return(property);
                }


                //
                // Check if this expression has already been queried via a child property.
                //

                // TODO.

                //
                // Couldn't find a pre-registered matching property for this expression, creating a new custom one.
                //

                MiVariable customExpressionVariable = m_debugger.VariableManager.CreateVariableFromExpression(this, expression);

                if (customExpressionVariable != null)
                {
                    property = m_debugger.VariableManager.CreatePropertyFromVariable(this, customExpressionVariable);

                    if (property != null)
                    {
                        m_customExpressions.TryAdd(expression, property);

                        LoggingUtils.RequireOk(m_property.AddChildren(new DebuggeeProperty [] { property }));
                    }
                }
            }
            catch (Exception e)
            {
                LoggingUtils.HandleException(e);
            }

            return(property);
        }
Beispiel #10
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        protected override int QueryArgumentsAndLocals()
        {
            LoggingUtils.PrintFunction();

            try
            {
                if (!m_queriedArgumentsAndLocals)
                {
                    uint threadId;

                    LoggingUtils.RequireOk(m_thread.GetThreadId(out threadId));

                    string command = string.Format("-stack-list-variables --thread {0} --frame {1} --no-values", threadId, StackLevel);

                    m_debugger.GdbClient.SendCommand(command, delegate(MiResultRecord resultRecord)
                    {
                        MiResultRecord.RequireOk(resultRecord, command);

                        if (resultRecord.HasField("variables"))
                        {
                            MiResultValue localVariables = resultRecord ["variables"] [0];

                            for (int i = 0; i < localVariables.Values.Count; ++i)
                            {
                                string variableName = localVariables [i] ["name"] [0].GetString();

                                MiVariable variable = m_debugger.VariableManager.CreateVariableFromExpression(this, variableName);

                                if (variable == null)
                                {
                                    continue;
                                }

                                CLangDebuggeeProperty property = m_debugger.VariableManager.CreatePropertyFromVariable(this, variable);

                                if (property == null)
                                {
                                    throw new InvalidOperationException();
                                }

                                if (localVariables [i].HasField("arg"))
                                {
                                    m_stackArguments.TryAdd(variableName, property);

                                    LoggingUtils.RequireOk(m_property.AddChildren(new DebuggeeProperty [] { property }));
                                }
                                else
                                {
                                    m_stackLocals.TryAdd(variableName, property);

                                    LoggingUtils.RequireOk(m_property.AddChildren(new DebuggeeProperty [] { property }));
                                }

                                //LoggingUtils.RequireOk (m_property.AddChildren (new DebuggeeProperty [] { property }));
                            }

                            m_queriedArgumentsAndLocals = true;
                        }
                    });
                }

                return(Constants.S_OK);
            }
            catch (Exception e)
            {
                LoggingUtils.HandleException(e);

                return(Constants.E_FAIL);
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public CLangDebuggeeProperty CreatePropertyFromVariable(CLangDebuggeeStackFrame stackFrame, MiVariable variable)
        {
            LoggingUtils.PrintFunction();

            try
            {
                if (stackFrame == null)
                {
                    throw new ArgumentNullException("stackFrame");
                }

                if (variable == null)
                {
                    throw new ArgumentNullException("variable");
                }

                /*CLangDebuggeeProperty [] childProperties = GetChildProperties (stackFrame, parentProperty);
                 *
                 * parentProperty.AddChildren (childProperties);*/

                return(new CLangDebuggeeProperty(m_debugger, stackFrame, variable));;
            }
            catch (Exception e)
            {
                LoggingUtils.HandleException(e);

                return(null);
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public CLangDebuggeeProperty(CLangDebuggeeProperty parent, MiVariable gdbVariable)
            : this(parent.m_debugger, parent.m_stackFrame as CLangDebuggeeStackFrame, gdbVariable)
        {
            m_parent = parent;
        }