Example #1
0
        private bool GetArrayValue(ClrType type, ulong addr, int index, out object result)
        {
            var componentType = type.ArrayComponentType;

            // componentType being null is a dac bug which should only happen when we have an array of
            // value types, where we have never *actually* constructed one of the types.  If there are
            // other dac bugs which cause this, we unfortunately cannot work around it.
            if (addr == 0 || componentType == null)
            {
                result = new ClrNullValue(m_heap);
                return(true);
            }

            if (index < 0 || index >= m_len)
            {
                throw new IndexOutOfRangeException();
            }

            // Now construct the value based on the element type.
            if (componentType.ElementType == ClrElementType.Struct)
            {
                addr   = type.GetArrayElementAddress(addr, index);
                result = new ClrObject(m_heap, componentType, addr, true);
                return(true);
            }
            else if (componentType.IsObjectReference)
            {
                addr = type.GetArrayElementAddress(addr, index);
                if (!m_heap.GetRuntime().ReadPointer(addr, out addr) || addr == 0)
                {
                    result = new ClrNullValue(m_heap);
                    return(true);
                }
                else
                {
                    result = new ClrObject(m_heap, componentType, addr);
                    return(true);
                }
            }
            else if (componentType.IsPrimitive)
            {
                result = new ClrPrimitiveValue(type.GetArrayElementValue(addr, index), componentType.ElementType);
                return(true);
            }

            result = null;
            return(false);
        }
Example #2
0
        private ClrType TryBuildType(ClrHeap heap)
        {
            var runtime = heap.GetRuntime();
            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);
        }
Example #3
0
        public dynamic GetValue(ClrAppDomain appDomain)
        {
            if (m_field.IsPrimitive())
            {
                object value = m_field.GetValue(appDomain);
                if (value != null)
                {
                    return(new ClrPrimitiveValue(value, m_field.ElementType));
                }
            }
            else if (m_field.IsValueClass())
            {
                ulong addr = m_field.GetAddress(appDomain);
                if (addr != 0)
                {
                    return(new ClrObject(m_heap, m_field.Type, addr, true));
                }
            }
            else if (m_field.ElementType == ClrElementType.String)
            {
                ulong addr = m_field.GetAddress(appDomain);
                if (m_heap.GetRuntime().ReadPointer(addr, out addr))
                {
                    return(new ClrObject(m_heap, m_field.Type, addr));
                }
            }
            else
            {
                object value = m_field.GetValue(appDomain);
                if (value != null)
                {
                    return(new ClrObject(m_heap, m_field.Type, (ulong)value));
                }
            }

            return(new ClrNullValue(m_heap));
        }
Example #4
0
        private ClrType TryBuildType(ClrHeap heap)
        {
            var runtime = heap.GetRuntime();
            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;
        }
Example #5
0
        public void DumpAllExceptions(IMDObjectEnum Exceptions)
        {
            Dictionary <string, List <ulong> > allExceptions = new Dictionary <string, List <ulong> >();

            foreach (var obj in ((MDObjectEnum)Exceptions).List)
            {
                ClrException ex = m_heap.GetExceptionObject(obj);
                if (ex != null)
                {
                    if (IsInterrupted())
                    {
                        return;
                    }
                    string key = String.Format("{0}\0{1}\0{2}", ex.Type.Name, ex.Message, DumpStack(ex.StackTrace, m_heap.GetRuntime().PointerSize, true));
                    if (!allExceptions.ContainsKey(key))
                    {
                        allExceptions[key] = new List <ulong>();
                    }
                    allExceptions[key].Add(obj);
                }
            }

            int exCount   = 0;
            int typeCount = 0;

            foreach (var key in allExceptions.Keys)
            {
                typeCount++;
                exCount += allExceptions[key].Count;
                Write("{0,8:#,#} of Type: {1}", allExceptions[key].Count, key.Split('\0')[0]);
                for (int i = 0; i < Math.Min(3, allExceptions[key].Count); i++)
                {
                    Write(" <link cmd=\"!wpe {0:%p}\">{0:%p}</link>", (allExceptions[key])[i]);
                }
                ClrException ex = m_heap.GetExceptionObject((allExceptions[key])[0]);
                WriteLine("");
                WriteLine("Message: {0}", key.Split('\0')[1]);
                WriteLine("Inner Exception: {0}", ex.Inner == null ? "(none)" : ex.Inner.Type.Name);
                WriteLine("Stack:");
                WriteLine("{0}", key.Split('\0')[2]);
                WriteLine("");
            }
            WriteLine("{0:#,#} Exceptions in {1:#,#} unique type/stack combinations (duplicate types in similar stacks may be rethrows)", exCount, typeCount);
            WriteLine("");
        }