Exemplo n.º 1
0
    public static void PrintDict(ClrRuntime runtime, string args)
    {
        bool  failed = false;
        ulong obj    = 0;

        try
        {
            obj    = Convert.ToUInt64(args, 16);
            failed = obj == 0;
        }
        catch (ArgumentException)
        {
            failed = true;
        }

        if (failed)
        {
            Console.WriteLine("Usage: !PrintDict <dictionary>");
            return;
        }

        ClrHeap heap = runtime.GetHeap();
        ClrType type = heap.GetObjectType(obj);

        if (type == null)
        {
            Console.WriteLine("Invalid object {0:X}", obj);
            return;
        }

        if (!type.Name.StartsWith("System.Collections.Generic.Dictionary"))
        {
            Console.WriteLine("Error: Expected object {0:X} to be a dictionary, instead it's of type '{1}'.");
            return;
        }

        // Get the entries field.
        ulong entries = type.GetFieldValue(obj, "entries");

        if (entries == 0)
        {
            return;
        }

        ClrType          entryArray     = heap.GetObjectType(entries);
        ClrType          arrayComponent = entryArray.ArrayComponentType;
        ClrInstanceField hashCodeField  = arrayComponent.GetFieldByName("hashCode");
        ClrInstanceField keyField       = arrayComponent.GetFieldByName("key");
        ClrInstanceField valueField     = arrayComponent.GetFieldByName("value");

        Console.WriteLine("{0,8} {1,16} : {2}", "hash", "key", "value");
        int len = entryArray.GetArrayLength(entries);

        for (int i = 0; i < len; ++i)
        {
            ulong arrayElementAddr = entryArray.GetArrayElementAddress(entries, i);

            int    hashCode = (int)hashCodeField.GetFieldValue(arrayElementAddr, true);
            object key      = keyField.GetFieldValue(arrayElementAddr, true);
            object value    = valueField.GetFieldValue(arrayElementAddr, true);

            key   = Format(heap, key);
            value = Format(heap, value);

            bool skip = key is ulong && (ulong)key == 0 && value is ulong && (ulong)value == 0;

            if (!skip)
            {
                Console.WriteLine("{0,8:X} {1,16} : {2}", hashCode, key, value);
            }
        }
    }
Exemplo n.º 2
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            if (IsNull())
            {
                result = new ClrNullValue(m_heap);
                return(true);
            }

            ClrInstanceField field = null;

            if (binder.IgnoreCase)
            {
                foreach (var inst in m_type.Fields)
                {
                    if (inst.Name.Equals(binder.Name, StringComparison.CurrentCultureIgnoreCase))
                    {
                        field = inst;
                        break;
                    }
                }
            }
            else
            {
                field = m_type.GetFieldByName(binder.Name);
            }

            if (field == null)
            {
                if (ClrDynamicClass.GetStaticField(m_heap, m_type, binder, out result))
                {
                    return(true);
                }

                throw new InvalidOperationException(string.Format("Type '{0}' does not contain a '{1}' field.", m_type.Name, binder.Name));
            }

            if (field.IsPrimitive())
            {
                object value = field.GetFieldValue(m_addr, m_inner);
                if (value == null)
                {
                    result = new ClrNullValue(m_heap);
                }
                else
                {
                    result = new ClrPrimitiveValue(value, field.ElementType);
                }

                return(true);
            }
            else if (field.IsValueClass())
            {
                ulong addr = field.GetFieldAddress(m_addr, m_inner);
                result = new ClrObject(m_heap, field.Type, addr, true);
                return(true);
            }
            else if (field.ElementType == ClrElementType.String)
            {
                ulong addr = field.GetFieldAddress(m_addr, m_inner);
                if (!m_heap.GetRuntime().ReadPointer(addr, out addr))
                {
                    result = new ClrNullValue(m_heap);
                    return(true);
                }

                result = new ClrObject(m_heap, field.Type, addr);
                return(true);
            }
            else
            {
                object value = field.GetFieldValue(m_addr, m_inner);
                if (value == null)
                {
                    result = new ClrNullValue(m_heap);
                }
                else
                {
                    result = new ClrObject(m_heap, field.Type, (ulong)value);
                }

                return(true);
            }
        }
Exemplo n.º 3
0
        public void GetFieldValue(ulong objRef, int interior, out IMDValue ppValue)
        {
            object value = m_field.GetFieldValue(objRef, interior != 0);

            ppValue = new MDValue(value, m_field.ElementType);
        }