Ejemplo n.º 1
0
        private ClrType TryBuildType(ClrHeap heap)
        {
            var runtime = heap.Runtime;
            var domains = runtime.AppDomains;

            ClrType[] types = new ClrType[domains.Count];

            ClrElementType elType = ElementType;

            if (ClrRuntime.IsPrimitive(elType) || elType == ClrElementType.String)
            {
                return(((DesktopGCHeap)heap).GetBasicType(elType));
            }

            int count = 0;

            foreach (var domain in domains)
            {
                object value = GetValue(domain);
                if (value != null && value is ulong && ((ulong)value != 0))
                {
                    types[count++] = heap.GetObjectType((ulong)value);
                }
            }

            int     depth  = int.MaxValue;
            ClrType result = null;

            for (int i = 0; i < count; ++i)
            {
                ClrType curr = types[i];
                if (curr == result || curr == null)
                {
                    continue;
                }

                int nextDepth = GetDepth(curr);
                if (nextDepth < depth)
                {
                    result = curr;
                    depth  = nextDepth;
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        }// SkipAnyVASentinel

        public bool SkipExactlyOne()
        {
            if (!GetElemType(out int typ))
            {
                return(false);
            }

            int tmp;

            if (!ClrRuntime.IsPrimitive((ClrElementType)typ))
            {
                switch (typ)
                {
                default:
                    return(false);

                case ELEMENT_TYPE_VAR:
                case ELEMENT_TYPE_MVAR:
                    if (!GetData(out tmp))
                    {
                        return(false);
                    }
                    break;

                case ELEMENT_TYPE_OBJECT:
                case ELEMENT_TYPE_STRING:
                case ELEMENT_TYPE_TYPEDBYREF:
                    break;

                case ELEMENT_TYPE_BYREF:
                case ELEMENT_TYPE_PTR:
                case ELEMENT_TYPE_PINNED:
                case ELEMENT_TYPE_SZARRAY:
                    if (!SkipExactlyOne())
                    {
                        return(false);
                    }
                    break;

                case ELEMENT_TYPE_VALUETYPE:
                case ELEMENT_TYPE_CLASS:
                    if (!GetToken(out tmp))
                    {
                        return(false);
                    }
                    break;

                case ELEMENT_TYPE_FNPTR:
                    if (!SkipSignature())
                    {
                        return(false);
                    }
                    break;

                case ELEMENT_TYPE_ARRAY:
                    // Skip element type
                    if (!SkipExactlyOne())
                    {
                        return(false);
                    }

                    // Get rank;
                    int rank;
                    if (!GetData(out rank))
                    {
                        return(false);
                    }

                    if (rank > 0)
                    {
                        if (!GetData(out int sizes))
                        {
                            return(false);
                        }

                        while (sizes-- != 0)
                        {
                            if (!GetData(out tmp))
                            {
                                return(false);
                            }
                        }

                        if (!GetData(out int bounds))
                        {
                            return(false);
                        }
                        while (bounds-- != 0)
                        {
                            if (!GetData(out tmp))
                            {
                                return(false);
                            }
                        }
                    }
                    break;

                case ELEMENT_TYPE_SENTINEL:
                    // Should be unreachable since GetElem strips it
                    break;

                case ELEMENT_TYPE_INTERNAL:
                    if (!GetData(out tmp))
                    {
                        return(false);
                    }
                    break;

                case ELEMENT_TYPE_GENERICINST:
                    // Skip generic type
                    if (!SkipExactlyOne())
                    {
                        return(false);
                    }

                    // Get number of parameters
                    int argCnt;
                    if (!GetData(out argCnt))
                    {
                        return(false);
                    }

                    // Skip the parameters
                    while (argCnt-- != 0)
                    {
                        SkipExactlyOne();
                    }
                    break;
                }
            }

            return(true);
        }