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

        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 [] 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 ();
    }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        #region IDebugProperty2 Members

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

        public override int EnumChildren(enum_DEBUGPROP_INFO_FLAGS dwFields, uint dwRadix, ref Guid guidFilter, enum_DBG_ATTRIB_FLAGS dwAttribFilter, string pszNameFilter, uint dwTimeout, out IEnumDebugPropertyInfo2 ppEnum)
        {
            //
            // Enumerates the children of a property. This provides support for dereferencing pointers, displaying members of an array, or fields of a class or struct.
            //

            LoggingUtils.PrintFunction();

            try
            {
                if (m_gdbVariable != null)
                {
                    if (m_gdbVariable.HasChildren && (m_gdbVariable.Children.Count == 0))
                    {
                        m_debugger.VariableManager.CreateChildVariables(m_gdbVariable, 1);
                    }

                    if (m_gdbVariable.Children.Count != m_children.Count)
                    {
                        // TODO: Dispose the properties as appropriate.

                        m_children.Clear();

                        foreach (MiVariable childVariable in m_gdbVariable.Children.Values)
                        {
                            if (childVariable.IsPseudoChild)
                            {
                                CLangDebuggeeProperty pseudoChildProperty = m_debugger.VariableManager.CreatePropertyFromVariable(m_stackFrame as CLangDebuggeeStackFrame, childVariable) ?? throw new InvalidOperationException("Failed to create child property.");

                                CLangDebuggeeProperty [] childSubProperties = m_debugger.VariableManager.GetChildProperties(m_stackFrame as CLangDebuggeeStackFrame, pseudoChildProperty);

                                m_children.AddRange(childSubProperties);
                            }
                            else
                            {
                                CLangDebuggeeProperty childProperty = m_debugger.VariableManager.CreatePropertyFromVariable(m_stackFrame as CLangDebuggeeStackFrame, childVariable) ?? throw new InvalidOperationException("Failed to create child property.");

                                m_children.Add(childProperty);
                            }
                        }
                    }
                }

                LoggingUtils.RequireOk(base.EnumChildren(dwFields, dwRadix, ref guidFilter, dwAttribFilter, pszNameFilter, dwTimeout, out ppEnum));

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

                ppEnum = null;

                return(Constants.E_FAIL);
            }
        }
Beispiel #4
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

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

            try
            {
                //
                // Returns a list of registers for the current stack level.
                //

                if (!m_queriedRegisters)
                {
                    uint threadId;

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

                    string command = string.Format("-data-list-register-values --thread {0} --frame {1} r", threadId, StackLevel);

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

                        if (!resultRecord.HasField("register-values"))
                        {
                            throw new InvalidOperationException("Failed to retrieve list of register values");
                        }

                        MiResultValue registerValues = resultRecord ["register-values"] [0];

                        int registerValuesCount = registerValues.Values.Count;

                        Dictionary <uint, string> registerIdMapping = m_debugger.GdbClient.GetRegisterIdMapping();

                        for (int i = 0; i < registerValuesCount; ++i)
                        {
                            uint registerId = registerValues [i] ["number"] [0].GetUnsignedInt();

                            string registerValue = registerValues [i] ["value"] [0].GetString();

                            string registerName = registerIdMapping [registerId];

                            string registerNamePrettified = "$" + registerName;

                            CLangDebuggeeProperty property = new CLangDebuggeeProperty(m_debugger, this, registerNamePrettified, registerValue);

                            m_stackRegisters.TryAdd(registerNamePrettified, property);

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

                        m_queriedRegisters = true;
                    });
                }

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

                return(Constants.E_FAIL);
            }
        }
Beispiel #5
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 (CLangDebuggeeProperty parent, MiVariable gdbVariable)
      : this (parent.m_debugger, parent.m_stackFrame as CLangDebuggeeStackFrame, gdbVariable)
    {
      m_parent = parent;
    }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

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

      try
      {
        // 
        // Returns a list of registers for the current stack level.
        // 

        if (!m_queriedRegisters)
        {
          uint threadId;

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

          string command = string.Format ("-data-list-register-values --thread {0} --frame {1} r", threadId, StackLevel);

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

            if (!resultRecord.HasField ("register-values"))
            {
              throw new InvalidOperationException ("Failed to retrieve list of register values");
            }

            MiResultValue registerValues = resultRecord ["register-values"] [0];

            int registerValuesCount = registerValues.Values.Count;

            Dictionary<uint, string> registerIdMapping = m_debugger.GdbClient.GetRegisterIdMapping ();

            for (int i = 0; i < registerValuesCount; ++i)
            {
              uint registerId = registerValues [i] ["number"] [0].GetUnsignedInt ();

              string registerValue = registerValues [i] ["value"] [0].GetString ();

              string registerName = registerIdMapping [registerId];

              string registerNamePrettified = "$" + registerName;

              CLangDebuggeeProperty property = new CLangDebuggeeProperty (m_debugger, this, registerNamePrettified, registerValue);

              m_stackRegisters.TryAdd (registerNamePrettified, property);

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

            m_queriedRegisters = true;
          });
        }

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

        return Constants.E_FAIL;
      }
    }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

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