|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license.using System; |
| 3 | + |
| 4 | +using System.Collections.Generic; |
| 5 | + |
| 6 | +namespace Microsoft.Diagnostics.DataContractReader.Data; |
| 7 | + |
| 8 | +internal sealed class ArrayListBase : IData<ArrayListBase> |
| 9 | +{ |
| 10 | + static ArrayListBase IData<ArrayListBase>.Create(Target target, TargetPointer address) => new ArrayListBase(target, address); |
| 11 | + public ArrayListBase(Target target, TargetPointer address) |
| 12 | + { |
| 13 | + Target.TypeInfo type = target.GetTypeInfo(DataType.ArrayListBase); |
| 14 | + |
| 15 | + Count = target.Read<uint>(address + (ulong)type.Fields[nameof(Count)].Offset); |
| 16 | + FirstBlock = address + (ulong)type.Fields[nameof(FirstBlock)].Offset; |
| 17 | + |
| 18 | + TargetPointer next = FirstBlock; |
| 19 | + while (next != TargetPointer.Null) |
| 20 | + { |
| 21 | + ArrayListBlock block = target.ProcessedData.GetOrAdd<ArrayListBlock>(next); |
| 22 | + Blocks.Add(block); |
| 23 | + next = block.Next; |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + public uint Count { get; init; } |
| 28 | + public TargetPointer FirstBlock { get; init; } |
| 29 | + |
| 30 | + public List<ArrayListBlock> Blocks { get; init; } = []; |
| 31 | + public List<TargetPointer> Elements { get; init; } = []; |
| 32 | + |
| 33 | + internal sealed class ArrayListBlock : IData<ArrayListBlock> |
| 34 | + { |
| 35 | + static ArrayListBlock IData<ArrayListBlock>.Create(Target target, TargetPointer address) => new ArrayListBlock(target, address); |
| 36 | + public ArrayListBlock(Target target, TargetPointer address) |
| 37 | + { |
| 38 | + Target.TypeInfo type = target.GetTypeInfo(DataType.ArrayListBlock); |
| 39 | + |
| 40 | + Next = target.ReadPointer(address + (ulong)type.Fields[nameof(Next)].Offset); |
| 41 | + Size = target.Read<uint>(address + (ulong)type.Fields[nameof(Size)].Offset); |
| 42 | + ArrayStart = address + (ulong)type.Fields[nameof(ArrayStart)].Offset; |
| 43 | + |
| 44 | + for (ulong i = 0; i < Size; i++) |
| 45 | + { |
| 46 | + Elements.Add(target.ReadPointer(ArrayStart + (i * (ulong)target.PointerSize))); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + public TargetPointer Next { get; init; } |
| 51 | + public uint Size { get; init; } |
| 52 | + public TargetPointer ArrayStart { get; init; } |
| 53 | + |
| 54 | + public List<TargetPointer> Elements { get; init; } = []; |
| 55 | + } |
| 56 | +} |
0 commit comments