Exemplo n.º 1
0
        public TypeInfo GetDereference()
        {
            Debug.Assert(mPointerLevel > 0);

            TypeInfo dereferenceType = new TypeInfo();

            dereferenceType.mFlags = mFlags;
            //dereferenceType.mMemberNameOrNull = mMemberNameOrNull;
            dereferenceType.mPointerLevel = (uint)Math.Max((int)mPointerLevel - 1, 0);

            if (dereferenceType.mPointerLevel > 0)
            {
                dereferenceType.mFlags &= ~(EMemoryTypeFlags.POINTER | EMemoryTypeFlags.ARRAY);
                dereferenceType.SetByString(mPureName + ' ' + new string('*', (int)dereferenceType.mPointerLevel));
                dereferenceType.mSize = TypeInfo.POINTER_SIZE;
            }
            else
            {
                dereferenceType.SetByString(mPureName);
                dereferenceType.mMembers = PureTypeManager.GetType(mPureName).Members;
                dereferenceType.mSize    = PureTypeManager.GetType(mPureName).mSize;
            }

            return(dereferenceType);
        }
        public void UpdateMemorySegements()
        {
            if (null == TypeInfoOrNull || null == TypeInfoOrNull.PureName)
            {
                return;
            }

            List <MemorySegmentViewModel> segments;
            var stackKeys = new Stack <StackKey>();

            {
                TypeInfo pureType       = PureTypeManager.GetType(TypeInfoOrNull.PureName);
                uint     sizePerSegment = TypeInfoOrNull.PointerLevel > 0 ? TypeInfo.POINTER_SIZE : pureType.Size;
                uint     totalLength    = Size / sizePerSegment;
                uint     remainSegment  = Size % sizePerSegment;

                segments = new List <MemorySegmentViewModel>((int)totalLength);

                for (uint i = 0; i < totalLength; ++i)
                {
                    var vm = new MemorySegmentViewModel()
                    {
                        TypeName         = TypeInfoOrNull.FullNameOrNull,
                        MemberNameOrNull = TypeInfoOrNull.MemberNameOrNull,
                        Memory           = new ArraySegment <byte>(ByteValues, (int)(i * sizePerSegment), (int)sizePerSegment),
                        Address          = Address + i * sizePerSegment,
                        AncestorOrNull   = null,
                        Children         = new ObservableCollection <List <MemorySegmentViewModel> >()
                    };

                    segments.Add(vm);
                    stackKeys.Push(new StackKey()
                    {
                        ViewModel = vm,
                        Type      = TypeInfoOrNull
                    });
                }
            }

            while (stackKeys.Count > 0)
            {
                StackKey popKey = stackKeys.Pop();

                if (popKey.Type.PointerLevel > 0 || popKey.Type.ArrayOrFunctionPointerLevels.Count > 0)
                {
                    continue;
                }

                foreach (TypeInfo memberType in popKey.Type.Members)
                {
                    uint totalLength    = memberType.GetTotalLength();
                    uint sizePerSegment = memberType.Size / totalLength;

                    TypeInfo elementOfArrayType = memberType.GetElementOfArray();

                    var memberArray = new List <MemorySegmentViewModel>((int)totalLength);
                    for (uint i = 0; i < totalLength; ++i)
                    {
                        var vm = new MemorySegmentViewModel()
                        {
                            TypeName         = totalLength > 1 ? elementOfArrayType.FullNameOrNull : memberType.FullNameOrNull,
                            MemberNameOrNull = memberType.MemberNameOrNull,
                            Memory           = new ArraySegment <byte>(ByteValues, popKey.ViewModel.Memory.Offset + (int)((memberType.Offset - popKey.Type.Offset) + i * sizePerSegment), (int)sizePerSegment),
                            Address          = popKey.ViewModel.Address + (memberType.Offset - popKey.Type.Offset) + i * sizePerSegment,
                            AncestorOrNull   = popKey.ViewModel,
                            Children         = new ObservableCollection <List <MemorySegmentViewModel> >()
                        };

                        stackKeys.Push(new StackKey()
                        {
                            ViewModel = vm,
                            Type      = memberType
                        });
                        memberArray.Add(vm);
                    }
                    popKey.ViewModel.Children.Add(memberArray);
                }
            }

            MemorySegments = segments;
        }