Пример #1
0
        private ClrInstance[] ComputeItems()
        {
            if (!IsArray)
            {
                return(Array.Empty <ClrInstance>());
            }

            Contract.AssertNotNull(Type, "Arrays should always have Type != null.");
            Contract.AssertNotNull(ObjectAddress);

            var address     = ObjectAddress.Value;
            var length      = Type.GetArrayLength(address);
            var items       = new ClrInstance[length];
            var elementType = Type.ComponentType;

            for (var i = 0; i < length; i++)
            {
                var tmp = GetElementAt(i);

                if (!(tmp is ClrInstance))
                {
                    tmp = CreateInterior(Heap, tmp, elementType);
                }

                items[i] = (ClrInstance)tmp;
                //var value = Type.GetArrayElementValue(address, i);
                //items[i] = CreateItemInstance(value, elementType, i);
            }

            return(items);
        }
Пример #2
0
 public static IEnumerable <ClrInstance> EnumerateClrObjects(this ClrHeap heap)
 {
     foreach (var address in heap.EnumerateObjectAddresses())
     {
         var result = ClrInstance.CreateInstance(heap, address);
         yield return(result);
     }
 }
Пример #3
0
        public static bool IsOfType(this ClrInstance instance, TypeIndex typeIndex)
        {
            if (instance.Type == null)
            {
                return(false);
            }

            return(typeIndex.ContainsType(instance.Type));
        }
Пример #4
0
        public static bool IsOfType(this ClrInstance instance, Type type, TypesRegistry registry)
        {
            if (instance.Type == null)
            {
                return(false);
            }

            return(registry.IsInstanceOfType(instance.Type, type));
        }
Пример #5
0
        public static bool IsTaskLike(this ClrInstance instance, TypesRegistry registry)
        {
            if (instance.IsOfType(typeof(Task), registry))
            {
                return(true);
            }

            // Add support for ValueTask and other task-like types.
            return(false);
        }
Пример #6
0
        public static IEnumerable <ClrInstance> EnumerateListOfObjects(this ClrInstance instance)
        {
            if (!instance.IsListOfObjects())
            {
                throw new ArgumentException($"'instance' should be of type 'List<object>' but was '{instance.Type}'");
            }

            var size  = (int)instance.GetField("_size").Instance.Value;
            var items = instance.GetField("_items").Instance.Items;

            for (int i = 0; i < size; i++)
            {
                yield return(items[i]);
            }
        }
Пример #7
0
        internal static ClrFieldValue?Create(ClrInstanceField typeField, ClrInstance instance, bool interior)
        {
            if (typeField.Type.MetadataToken == 0 && typeField.Type.Name == "ERROR")
            {
                return(null);
                // TODO: not sure about this!
                //throw new NotSupportedException();
            }

            Contract.AssertNotNull(instance.ObjectAddress);

            object?value = null;

            try
            {
                // This code could fail with NRE with no obvious reason.
                value = typeField.GetValue(instance.ObjectAddress.Value, interior);
            }
            catch (Exception)
            { }

            var type = typeField.Type;

            if (!type.IsIntrinsic() && value != null)
            {
                // instance.Heap.GetObjectType may return null. WHY?
                type = instance.Heap.GetObjectType((ulong)value) ?? type;
            }

            if (value == null)
            {
                value = instance.ObjectAddress.Value + (ulong)typeField.Offset;
            }

            return(new ClrFieldValue(typeField, new ClrInstance(instance.Heap, value, type, interior)));
        }
Пример #8
0
 private static string PrintArray(ClrInstance instance)
 {
     return($"[{string.Join(", ", instance.Items.Select(i => i.ToString()))}]");
 }
Пример #9
0
 private ClrFieldValue(ClrInstanceField field, ClrInstance instance)
 {
     Field    = field ?? throw new ArgumentNullException(nameof(field));
     Instance = instance ?? throw new ArgumentNullException(nameof(instance));
 }
Пример #10
0
 public static bool IsListOfObjects(this ClrInstance instance)
 {
     // Need to compare by name since GetTypeByName does not work for the generic type during initialization
     return(instance.Type?.Name == "System.Collections.Generic.List<System.Object>");
 }
Пример #11
0
 public static bool IsTaskCompletionSource(this ClrInstance continuation, CausalityContext context)
 {
     return(context.Registry.IsTaskCompletionSource(continuation.Type));
 }
Пример #12
0
 public static bool IsCompletedTaskContinuation(this ClrInstance continuation, CausalityContext context)
 {
     return(context.Registry.IsTaskCompletionSentinel(continuation));
 }
Пример #13
0
 public static bool IsTaskWhenAll(this ClrInstance instance, CausalityContext context)
 {
     return(context.Registry.IsTaskWhenAll(instance));
 }
Пример #14
0
 public static bool IsOfType(this ClrInstance instance, Type type, CausalityContext context)
 {
     return(instance.IsOfType(type, context.Registry));
 }