Example #1
0
        public override IEnumerable <KeyValuePair <PyObject, PointerProxy <PyObject> > > ReadElements()
        {
            if (ma_keys.IsNull)
            {
                yield break;
            }

            PyDictKeysObject33 keys = ma_keys.Read();
            var entries             = keys.dk_entries.Take(keys.dk_size.Read());

            PointerProxy <ArrayProxy <PointerProxy <PyObject> > > ma_values = this.ma_values;

            if (ma_values.IsNull)
            {
                foreach (var entry in entries)
                {
                    var key = entry.me_key.TryRead();
                    if (key != null)
                    {
                        yield return(new KeyValuePair <PyObject, PointerProxy <PyObject> >(key, entry.me_value));
                    }
                }
            }
            else
            {
                PointerProxy <PyObject> valuePtr = ma_values.Read()[0];
                foreach (var entry in entries)
                {
                    var key = entry.me_key.TryRead();
                    if (key != null)
                    {
                        yield return(new KeyValuePair <PyObject, PointerProxy <PyObject> >(key, valuePtr));
                    }
                    valuePtr = valuePtr.GetAdjacentProxy(1);
                }
            }
        }
Example #2
0
        private IEnumerable <PythonEvaluationResult> GetDebugChildrenFromSlots()
        {
            PointerProxy <ArrayProxy <PyMemberDef> > tp_members = ob_type.Read().tp_members;

            if (tp_members.IsNull)
            {
                yield break;
            }

            var langVer = Process.GetPythonRuntimeInfo().LanguageVersion;

            var memberDefs = tp_members.Read().TakeWhile(md => !md.name.IsNull);

            foreach (PyMemberDef memberDef in memberDefs)
            {
                var         offset = memberDef.offset.Read();
                IValueStore value;
                switch (memberDef.type.Read())
                {
                case PyMemberDefType.T_OBJECT:
                case PyMemberDefType.T_OBJECT_EX:
                {
                    var objProxy = GetFieldProxy(new StructField <PointerProxy <PyObject> > {
                            Process = Process, Offset = offset
                        });
                    if (!objProxy.IsNull)
                    {
                        value = objProxy;
                    }
                    else
                    {
                        value = new ValueStore <PyObject>(None(Process));
                    }
                }
                break;

                case PyMemberDefType.T_STRING:
                {
                    var ptr = GetFieldProxy(new StructField <PointerProxy> {
                            Process = Process, Offset = offset
                        }).Read();
                    if (ptr != 0)
                    {
                        CStringProxy proxy = new CStringProxy(Process, ptr);
                        if (langVer <= PythonLanguageVersion.V27)
                        {
                            value = new ValueStore <AsciiString>(proxy.ReadAscii());
                        }
                        else
                        {
                            value = new ValueStore <string>(proxy.ReadUnicode());
                        }
                    }
                    else
                    {
                        value = new ValueStore <PyObject>(None(Process));
                    }
                }
                break;

                case PyMemberDefType.T_STRING_INPLACE:
                {
                    CStringProxy proxy = new CStringProxy(Process, Address.OffsetBy(offset));
                    if (langVer <= PythonLanguageVersion.V27)
                    {
                        value = new ValueStore <AsciiString>(proxy.ReadAscii());
                    }
                    else
                    {
                        value = new ValueStore <string>(proxy.ReadUnicode());
                    }
                }
                break;

                case PyMemberDefType.T_BYTE:
                    value = GetFieldProxy(new StructField <SByteProxy> {
                        Process = Process, Offset = offset
                    });
                    break;

                case PyMemberDefType.T_UBYTE:
                    value = GetFieldProxy(new StructField <ByteProxy> {
                        Process = Process, Offset = offset
                    });
                    break;

                case PyMemberDefType.T_SHORT:
                    value = GetFieldProxy(new StructField <Int16Proxy> {
                        Process = Process, Offset = offset
                    });
                    break;

                case PyMemberDefType.T_USHORT:
                    value = GetFieldProxy(new StructField <UInt16Proxy> {
                        Process = Process, Offset = offset
                    });
                    break;

                case PyMemberDefType.T_INT:
                case PyMemberDefType.T_LONG:
                    value = GetFieldProxy(new StructField <Int32Proxy> {
                        Process = Process, Offset = offset
                    });
                    break;

                case PyMemberDefType.T_UINT:
                case PyMemberDefType.T_ULONG:
                    value = GetFieldProxy(new StructField <UInt32Proxy> {
                        Process = Process, Offset = offset
                    });
                    break;

                case PyMemberDefType.T_LONGLONG:
                    value = GetFieldProxy(new StructField <Int64Proxy> {
                        Process = Process, Offset = offset
                    });
                    break;

                case PyMemberDefType.T_ULONGLONG:
                    value = GetFieldProxy(new StructField <UInt64Proxy> {
                        Process = Process, Offset = offset
                    });
                    break;

                case PyMemberDefType.T_PYSSIZET:
                    value = GetFieldProxy(new StructField <SSizeTProxy> {
                        Process = Process, Offset = offset
                    });
                    break;

                case PyMemberDefType.T_FLOAT:
                    value = GetFieldProxy(new StructField <SingleProxy> {
                        Process = Process, Offset = offset
                    });
                    break;

                case PyMemberDefType.T_DOUBLE:
                    value = GetFieldProxy(new StructField <DoubleProxy> {
                        Process = Process, Offset = offset
                    });
                    break;

                case PyMemberDefType.T_BOOL:
                    value = GetFieldProxy(new StructField <BoolProxy> {
                        Process = Process, Offset = offset
                    });
                    break;

                case PyMemberDefType.T_CHAR:
                    value = GetFieldProxy(new StructField <CharProxy> {
                        Process = Process, Offset = offset
                    });
                    break;

                case PyMemberDefType.T_NONE:
                    value = new ValueStore <PyObject>(None(Process));
                    break;

                default:
                    continue;
                }

                yield return(new PythonEvaluationResult(value, memberDef.name.Read().ReadUnicode()));
            }
        }
Example #3
0
        public override IEnumerable <KeyValuePair <PyObject, PointerProxy <PyObject> > > ReadElements()
        {
            if (ma_keys.IsNull)
            {
                yield break;
            }

            PyDictKeysObject36 keys = ma_keys.Read();
            var size = keys.dk_size.Read();

            if (size <= 0)
            {
                yield break;
            }

            var n = keys.dk_nentries.Read();
            ArrayProxy <PyDictKeyEntry> dk_entries = keys.dk_entries;
            PyDictKeyEntry entry = dk_entries[0];

            if (!ma_values.IsNull)
            {
                ArrayProxy <PointerProxy <PyObject> > values = ma_values.Read();
                PointerProxy <PyObject> value = values[0];

                for (int i = 0; i < n; ++i)
                {
                    PointerProxy <PyObject> key = entry.me_key;
                    if (!value.IsNull && !key.IsNull)
                    {
                        yield return(new KeyValuePair <PyObject, PointerProxy <PyObject> >(key.Read(), value));
                    }
                    entry = entry.GetAdjacentProxy(1);
                    value = value.GetAdjacentProxy(1);
                }
            }
            else
            {
                for (int i = 0; i < n; ++i)
                {
                    PointerProxy <PyObject> key   = entry.me_key;
                    PointerProxy <PyObject> value = entry.me_value;
                    if (!key.IsNull && !value.IsNull)
                    {
                        yield return(new KeyValuePair <PyObject, PointerProxy <PyObject> >(key.Read(), value));
                    }
                    entry = entry.GetAdjacentProxy(1);
                }
            }
        }