public void Member()
        {
            var source =
@"unsafe class C
{
    internal C(long p)
    {
        this.pfn = (int*)p;
    }
    int* pfn;
}";
            var assembly = GetUnsafeAssembly(source);
            const long ptr = 0x0;
            GetMemberValueDelegate getMemberValue = (v, m) => (m == "pfn") ? GetFunctionPointerField(v, m) : null;
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlibAndSystemCore(assembly), getMemberValue: getMemberValue);
            using (runtime.Load())
            {
                var type = runtime.GetType("C");
                var value = type.Instantiate(ptr);
                var evalResult = FormatResult("o", value);
                Verify(evalResult,
                    EvalResult("o", "{C}", "C", "o", DkmEvaluationResultFlags.Expandable, DkmEvaluationResultCategory.Other));
                var children = GetChildren(evalResult);
                Verify(children,
                    EvalResult("pfn", PointerToString(new IntPtr(ptr)), "int*", "o.pfn", DkmEvaluationResultFlags.None, DkmEvaluationResultCategory.Other));
            }
        }
Beispiel #2
0
        public void Member()
        {
            var source =
@"class C
{
    object pfn;
}";
            const int ptr = 0x0;
            GetMemberValueDelegate getMemberValue = (v, m) => (m == "pfn") ? CreateDkmClrValue(ptr, type: new DkmClrType(FunctionPointerType.Instance)) : null;
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlibAndSystemCore(GetAssembly(source)), getMemberValue: getMemberValue);
            using (runtime.Load())
            {
                var type = runtime.GetType("C");
                var value = CreateDkmClrValue(type.Instantiate(), type: type);
                var evalResult = FormatResult("o", value);
                Verify(evalResult,
                    EvalResult("o", "{C}", "C", "o", DkmEvaluationResultFlags.Expandable, DkmEvaluationResultCategory.Other));
                var children = GetChildren(evalResult);
                Verify(children,
                    EvalResult("pfn", PointerToString(new IntPtr(ptr)), "object {System.Object*}", "o.pfn", DkmEvaluationResultFlags.None, DkmEvaluationResultCategory.Other));
            }
        }
        public void ResultsView_NoSystemCore()
        {
            var source =
@"using System.Collections;
class C : IEnumerable
{
    public IEnumerator GetEnumerator()
    {
        yield return 1;
    }
}";
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(GetAssembly(source)));
            using (runtime.Load())
            {
                var type = runtime.GetType("C");
                var value = CreateDkmClrValue(
                    value: type.Instantiate(),
                    type: type,
                    inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.ResultsOnly));
                var evalResult = FormatResult("o", "o, results", value);
                Verify(evalResult,
                    EvalFailedResult("o", "Results View requires System.Core.dll to be referenced"));
            }
        }
        public void ResultsView_ExceptionThrown()
        {
            var source =
@"using System;
using System.Collections;
class E : Exception, IEnumerable
{
    IEnumerator IEnumerable.GetEnumerator()
    {
        yield return 1;
    }
}
class C
{
    internal ArrayList P
    {
        get { throw new NotImplementedException(); }
    }
    internal ArrayList Q
    {
        get { throw new E(); }
    }
}";
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlibAndSystemCore(GetAssembly(source)));
            using (runtime.Load())
            {
                var type = runtime.GetType("C");
                var value = CreateDkmClrValue(type.Instantiate(), type: type);
                var memberValue = value.GetMemberValue("P", (int)System.Reflection.MemberTypes.Property, "C").
                    WithInspectionContext(CreateDkmInspectionContext(DkmEvaluationFlags.ResultsOnly));
                var evalResult = FormatResult("o.P", "o.P, results", memberValue);
                Verify(evalResult,
                    EvalFailedResult("o.P", "'o.P' threw an exception of type 'System.NotImplementedException'"));
                memberValue = value.GetMemberValue("Q", (int)System.Reflection.MemberTypes.Property, "C").
                    WithInspectionContext(CreateDkmInspectionContext(DkmEvaluationFlags.ResultsOnly));
                evalResult = FormatResult("o.Q", "o.Q, results", memberValue);
                Verify(evalResult,
                    EvalFailedResult("o.Q", "'o.Q' threw an exception of type 'E'"));
            }
        }
        public void ResultsView_GetChildren()
        {
            var source =
@"using System.Collections;
using System.Collections.Generic;
class C
{
    IEnumerable<int> F
    {
        get { yield return 1; }
    }
    IEnumerable G
    {
        get { yield return 2; }
    }
    int H
    {
        get { return 3; }
    }
}";
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlibAndSystemCore(GetAssembly(source)));
            using (runtime.Load())
            {
                var type = runtime.GetType("C");
                var value = CreateDkmClrValue(type.Instantiate(), type: type);
                var evalResult = FormatResult("o", "o", value);
                Verify(evalResult,
                    EvalResult("o", "{C}", "C", "o", DkmEvaluationResultFlags.Expandable));
                // GetChildren without ResultsOnly
                var children = GetChildren(evalResult, inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.None));
                Verify(children,
                    EvalResult("F", "{C.<get_F>d__1}", "System.Collections.Generic.IEnumerable<int> {C.<get_F>d__1}", "o.F", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly),
                    EvalResult("G", "{C.<get_G>d__3}", "System.Collections.IEnumerable {C.<get_G>d__3}", "o.G", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly),
                    EvalResult("H", "3", "int", "o.H", DkmEvaluationResultFlags.ReadOnly));
                // GetChildren with ResultsOnly
                children = GetChildren(evalResult, inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.ResultsOnly));
                Verify(children,
                    EvalResult("F", "{C.<get_F>d__1}", "System.Collections.Generic.IEnumerable<int> {C.<get_F>d__1}", "o.F", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly),
                    EvalResult("G", "{C.<get_G>d__3}", "System.Collections.IEnumerable {C.<get_G>d__3}", "o.G", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly),
                    EvalResult("H", "3", "int", "o.H", DkmEvaluationResultFlags.ReadOnly));
            }
        }
        public void ResultsView_IEnumerable()
        {
            var source =
@"using System.Collections;
class C : IEnumerable
{
    public IEnumerator GetEnumerator()
    {
        yield return new C();
    }
}";
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlibAndSystemCore(GetAssembly(source)));
            using (runtime.Load())
            {
                var type = runtime.GetType("C");
                var value = CreateDkmClrValue(
                    value: type.Instantiate(),
                    type: type,
                    inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.ResultsOnly));
                var evalResult = FormatResult("o", "o, results, d", value);
                Verify(evalResult,
                    EvalResult("o", "Expanding the Results View will enumerate the IEnumerable", "", "o, results", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Method));
                var children = GetChildren(evalResult);
                // ResultsOnly is not inherited.
                Verify(children,
                    EvalResult("[0]", "{C}", "object {C}", "new System.Linq.SystemCore_EnumerableDebugView(o).Items[0]"));
            }
        }
Beispiel #7
0
        public void Keywords()
        {
            var source =
@"namespace @namespace
{
    struct @struct
    {
    }
}
class async
{
    static (async @var, @namespace.@struct @class) F() => (null, default(@namespace.@struct));
    object _f = F();
}";
            var assembly0 = GenerateTupleAssembly();
            var reference0 = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib(source, references: new[] { reference0 });
            var assembly1 = compilation1.EmitToArray();
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));
            using (runtime.Load())
            {
                var type = runtime.GetType("async");
                var value = type.Instantiate();
                var evalResult = FormatResult("o", value);
                Verify(evalResult,
                    EvalResult("o", "{async}", "async", "o", DkmEvaluationResultFlags.Expandable));
                var children = GetChildren(evalResult);
                Verify(children,
                    EvalResult("_f", "(null, {namespace.struct})", "object {(async, namespace.struct)}", "o._f", DkmEvaluationResultFlags.Expandable));
                children = GetChildren(children[0]);
                Verify(children,
                    EvalResult("Item1", "null", "async", "(((@async, @namespace.@struct))o._f).Item1"),
                    EvalResult("Item2", "{namespace.struct}", "namespace.struct", "(((@async, @namespace.@struct))o._f).Item2"));
            }
        }
Beispiel #8
0
        public void IsTupleCompatible_NonStruct()
        {
            var source =
@"namespace System
{
    class ValueTuple<T1, T2> { }
    delegate void ValueTuple<T1, T2, T3>();
}";
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(GetAssembly(source)));
            using (runtime.Load())
            {
                var type = runtime.GetType("System.ValueTuple`2", typeof(object), typeof(object));
                int cardinality;
                Assert.True(type.GetLmrType().IsTupleCompatible(out cardinality));
                Assert.Equal(2, cardinality);

                type = runtime.GetType("System.ValueTuple`3", typeof(object), typeof(object), typeof(object));
                Assert.True(type.GetLmrType().IsTupleCompatible(out cardinality));
                Assert.Equal(3, cardinality);
            }
        }
Beispiel #9
0
        public void Names_LongTuple()
        {
            var source =
@"class C
{
    ((int A, (int B, int C) D, int E, int F, int G, int H, int I, int J) K, (int L, int M, int N) O) F =
        ((1, (2, 3), 4, 5, 6, 7, 8, 9), (10, 11, 12));
}";
            var assembly0 = GenerateTupleAssembly();
            var reference0 = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib45AndCSruntime(source, additionalRefs: new[] { reference0 });
            var assembly1 = compilation1.EmitToArray();
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));
            using (runtime.Load())
            {
                var type = runtime.GetType("C");
                var value = type.Instantiate();
                var evalResult = FormatResult("o", value);
                var children = GetChildren(evalResult);
                Verify(children,
                    EvalResult(
                        "F",
                        "((1, (2, 3), 4, 5, 6, 7, 8, 9), (10, 11, 12))",
                        "((int A, (int B, int C) D, int E, int F, int G, int H, int I, int J) K, (int L, int M, int N) O)",
                        "o.F",
                        DkmEvaluationResultFlags.Expandable));
            }
        }
Beispiel #10
0
        public void Dynamic()
        {
            var source =
@"class C
{
    (dynamic, (object, dynamic)) F = (1, (2, 3));
    (object, object, object, object, object, object, dynamic[], dynamic[]) G = (1, 2, 3, 4, 5, 6, new object[] { 7 }, new object[] { 8 });
}";
            var assembly0 = GenerateTupleAssembly();
            var reference0 = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib45AndCSruntime(source, additionalRefs: new[] { reference0 });
            var assembly1 = compilation1.EmitToArray();
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));
            using (runtime.Load())
            {
                var type = runtime.GetType("C");
                var value = type.Instantiate();
                var evalResult = FormatResult("o", value);
                var children = GetChildren(evalResult);
                Verify(children,
                    EvalResult(
                        "F",
                        "(1, (2, 3))",
                        "(dynamic, (object, dynamic)) {(object, (object, object))}",
                        "o.F",
                        DkmEvaluationResultFlags.Expandable),
                    EvalResult(
                        "G",
                        "(1, 2, 3, 4, 5, 6, {object[1]}, {object[1]})",
                        "(object, object, object, object, object, object, dynamic[], dynamic[]) {(object, object, object, object, object, object, object[], object[])}",
                        "o.G",
                        DkmEvaluationResultFlags.Expandable));
            }
        }
Beispiel #11
0
        public void NullNullableAndArray()
        {
            var source =
@"using System;
namespace System
{
    struct ValueTuple<T1, T2>
    {
        public T1 Item1;
        public T2 Item2;
    }
    struct ValueTuple<T1, T2, T3>
    {
        public T1 Item1;
        public T2 Item2;
        public T3 Item3;
    }
}
class C
{
    ValueTuple<object, int> _1 = default(ValueTuple<object, int>);
    ValueTuple<object, int, object>? _2 = new ValueTuple<object, int, object>();
    ValueTuple<object, int>[] _3 = new ValueTuple<object, int>[1];
}";
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(GetAssembly(source)));
            using (runtime.Load())
            {
                var type = runtime.GetType("C");
                var value = type.Instantiate();
                var evalResult = FormatResult("o", value);
                Verify(evalResult,
                    EvalResult("o", "{C}", "C", "o", DkmEvaluationResultFlags.Expandable));
                var children = GetChildren(evalResult);
                Verify(children,
                    EvalResult("_1", "(null, 0)", "(object, int)", "o._1", DkmEvaluationResultFlags.Expandable),
                    EvalResult("_2", "(null, 0, null)", "(object, int, object)?", "o._2", DkmEvaluationResultFlags.Expandable),
                    EvalResult("_3", "{(object, int)[1]}", "(object, int)[]", "o._3", DkmEvaluationResultFlags.Expandable));
            }
        }
Beispiel #12
0
        public void MissingFields()
        {
            var source =
@"namespace System
{
    public struct ValueTuple<T1, T2>
    {
        public T1 Item1;
        // No Item2.
        public ValueTuple(T1 _1, T2 _2)
        {
            Item1 = _1;
        }
    }
    public struct ValueTuple<T1, T2, T3>
    {
        // No Item*.
        public ValueTuple(T1 _1, T2 _2, T3 _3)
        {
        }
    }
    public struct ValueTuple<T1, T2, T3, T4, T5, T6, T7, T8>
    {
        public T1 Item1;
        public T2 Item2;
        public T3 Item3;
        public T4 Item4;
        public T5 Item5;
        public T6 Item6;
        public T7 Item7;
        // No Rest.
        public ValueTuple(T1 _1, T2 _2, T3 _3, T4 _4, T5 _5, T6 _6, T7 _7, T8 _8)
        {
            Item1 = _1;
            Item2 = _2;
            Item3 = _3;
            Item4 = _4;
            Item5 = _5;
            Item6 = _6;
            Item7 = _7;
        }
    }
}
namespace System.Runtime.CompilerServices
{
    public class TupleElementNamesAttribute : Attribute
    {
        public TupleElementNamesAttribute(string[] names)
        {
        }
    }
}
class C
{
    (int A, int B) F = (1, 2);
    (int, int, int C) G = (1, 2, 3);
    (int, int B, int, int D, int, int F, int, int H, int) H = (1, 2, 3, 4, 5, 6, 7, 8, 9);
}";
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(GetAssembly(source)));
            using (runtime.Load())
            {
                var type = runtime.GetType("C");
                var value = type.Instantiate();
                var evalResult = FormatResult("o", value);
                Verify(evalResult,
                    EvalResult("o", "{C}", "C", "o", DkmEvaluationResultFlags.Expandable));
                var children = GetChildren(evalResult);
                Verify(children,
                    EvalResult("F", "{(int, int)}", "(int A, int B)", "o.F", DkmEvaluationResultFlags.Expandable),
                    EvalResult("G", "{(int, int, int)}", "(int, int, int C)", "o.G", DkmEvaluationResultFlags.Expandable), // expandable, but with no children
                    EvalResult("H", "{(int, int, int, int, int, int, int, int, int)}", "(int, int B, int, int D, int, int F, int, int H, int)", "o.H", DkmEvaluationResultFlags.Expandable));
                var moreChildren = GetChildren(children[0]);
                Verify(moreChildren,
                    EvalResult("A", "1", "int", "o.F.Item1"),
                    EvalResult("Raw View", "{(int, int)}", "(int A, int B)", "o.F, raw", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly));
                moreChildren = GetChildren(children[1]);
                Verify(moreChildren);
                moreChildren = GetChildren(children[2]);
                Verify(moreChildren,
                    EvalResult("Item1", "1", "int", "o.H.Item1"),
                    EvalResult("B", "2", "int", "o.H.Item2"),
                    EvalResult("Item3", "3", "int", "o.H.Item3"),
                    EvalResult("D", "4", "int", "o.H.Item4"),
                    EvalResult("Item5", "5", "int", "o.H.Item5"),
                    EvalResult("F", "6", "int", "o.H.Item6"),
                    EvalResult("Item7", "7", "int", "o.H.Item7"),
                    EvalResult("Raw View", "{(int, int, int, int, int, int, int, int, int)}", "(int, int B, int, int D, int, int F, int, int H, int)", "o.H, raw", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly));
            }
        }
Beispiel #13
0
        public void LongTuple_NoNames()
        {
            var source =
@"class C
{
    (short, short, short, short, short, short, short, short, short, short, short, short, short, short, short, short, short) _17 =
        (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17);
}";
            var assembly0 = GenerateTupleAssembly();
            var reference0 = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib(source, references: new[] { reference0 });
            var assembly1 = compilation1.EmitToArray();
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));
            using (runtime.Load())
            {
                var inspectionContext = CreateDkmInspectionContext(radix: 16);
                var type = runtime.GetType("C");
                var value = type.Instantiate();
                var evalResult = FormatResult("o", value, inspectionContext: inspectionContext);
                Verify(evalResult,
                    EvalResult("o", "{C}", "C", "o", DkmEvaluationResultFlags.Expandable));
                var children = GetChildren(evalResult, inspectionContext);
                Verify(children,
                    EvalResult(
                        "_17",
                        "(0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010, 0x0011)",
                        "(short, short, short, short, short, short, short, short, short, short, short, short, short, short, short, short, short)",
                        "o._17",
                        DkmEvaluationResultFlags.Expandable));
                children = GetChildren(children[0], inspectionContext);
                Verify(children,
                    EvalResult("Item1", "0x0001", "short", "o._17.Item1"),
                    EvalResult("Item2", "0x0002", "short", "o._17.Item2"),
                    EvalResult("Item3", "0x0003", "short", "o._17.Item3"),
                    EvalResult("Item4", "0x0004", "short", "o._17.Item4"),
                    EvalResult("Item5", "0x0005", "short", "o._17.Item5"),
                    EvalResult("Item6", "0x0006", "short", "o._17.Item6"),
                    EvalResult("Item7", "0x0007", "short", "o._17.Item7"),
                    EvalResult("Item8", "0x0008", "short", "o._17.Rest.Item1"),
                    EvalResult("Item9", "0x0009", "short", "o._17.Rest.Item2"),
                    EvalResult("Item10", "0x000a", "short", "o._17.Rest.Item3"),
                    EvalResult("Item11", "0x000b", "short", "o._17.Rest.Item4"),
                    EvalResult("Item12", "0x000c", "short", "o._17.Rest.Item5"),
                    EvalResult("Item13", "0x000d", "short", "o._17.Rest.Item6"),
                    EvalResult("Item14", "0x000e", "short", "o._17.Rest.Item7"),
                    EvalResult("Item15", "0x000f", "short", "o._17.Rest.Rest.Item1"),
                    EvalResult("Item16", "0x0010", "short", "o._17.Rest.Rest.Item2"),
                    EvalResult("Item17", "0x0011", "short", "o._17.Rest.Rest.Item3"),
                    EvalResult(
                        "Raw View",
                        "(0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010, 0x0011)",
                        "(short, short, short, short, short, short, short, short, short, short, short, short, short, short, short, short, short)",
                        "o._17, raw",
                        DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly));
                children = GetChildren(children[children.Length - 1], inspectionContext);
                Verify(children,
                    EvalResult("Item1", "0x0001", "short", "o._17.Item1"),
                    EvalResult("Item2", "0x0002", "short", "o._17.Item2"),
                    EvalResult("Item3", "0x0003", "short", "o._17.Item3"),
                    EvalResult("Item4", "0x0004", "short", "o._17.Item4"),
                    EvalResult("Item5", "0x0005", "short", "o._17.Item5"),
                    EvalResult("Item6", "0x0006", "short", "o._17.Item6"),
                    EvalResult("Item7", "0x0007", "short", "o._17.Item7"),
                    EvalResult("Rest", "(0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010, 0x0011)", "(short, short, short, short, short, short, short, short, short, short)", "o._17.Rest, raw", DkmEvaluationResultFlags.Expandable));
                children = GetChildren(children[children.Length - 1], inspectionContext);
                Verify(children,
                    EvalResult("Item1", "0x0008", "short", "o._17.Rest.Item1"),
                    EvalResult("Item2", "0x0009", "short", "o._17.Rest.Item2"),
                    EvalResult("Item3", "0x000a", "short", "o._17.Rest.Item3"),
                    EvalResult("Item4", "0x000b", "short", "o._17.Rest.Item4"),
                    EvalResult("Item5", "0x000c", "short", "o._17.Rest.Item5"),
                    EvalResult("Item6", "0x000d", "short", "o._17.Rest.Item6"),
                    EvalResult("Item7", "0x000e", "short", "o._17.Rest.Item7"),
                    EvalResult("Rest", "(0x000f, 0x0010, 0x0011)", "(short, short, short)", "o._17.Rest.Rest, raw", DkmEvaluationResultFlags.Expandable));
                children = GetChildren(children[children.Length - 1], inspectionContext);
                Verify(children,
                    EvalResult("Item1", "0x000f", "short", "o._17.Rest.Rest.Item1"),
                    EvalResult("Item2", "0x0010", "short", "o._17.Rest.Rest.Item2"),
                    EvalResult("Item3", "0x0011", "short", "o._17.Rest.Rest.Item3"));
            }
        }
Beispiel #14
0
        public void IsTupleCompatible()
        {
            var source =
@"namespace System
{
    struct ValueTuple { }
    struct ValueTuple<T1> { }
    struct ValueTuple<T1, T2> { }
    struct ValueTuple<T1, T2, T3> { }
    struct ValueTuple<T1, T2, T3, T4> { }
    struct ValueTuple<T1, T2, T3, T4, T5> { }
    struct ValueTuple<T1, T2, T3, T4, T5, T6> { }
    struct ValueTuple<T1, T2, T3, T4, T5, T6, T7> { }
    struct ValueTuple<T1, T2, T3, T4, T5, T6, T7, T8> { }
    struct ValueTuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> { }
}";
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(GetAssembly(source)));
            using (runtime.Load())
            {
                var type = runtime.GetType("System.ValueTuple");
                int cardinality;
                Assert.False(type.GetLmrType().IsTupleCompatible(out cardinality));
                Assert.Equal(0, cardinality);

                type = runtime.GetType("System.ValueTuple`1", typeof(int));
                Assert.True(type.GetLmrType().IsTupleCompatible(out cardinality));
                Assert.Equal(1, cardinality);

                type = runtime.GetType("System.ValueTuple`2", typeof(int), typeof(string));
                Assert.True(type.GetLmrType().IsTupleCompatible(out cardinality));
                Assert.Equal(2, cardinality);

                type = runtime.GetType("System.ValueTuple`3", typeof(int), typeof(string), typeof(int));
                Assert.True(type.GetLmrType().IsTupleCompatible(out cardinality));
                Assert.Equal(3, cardinality);

                type = runtime.GetType("System.ValueTuple`4", typeof(int), typeof(string), typeof(int), typeof(string));
                Assert.True(type.GetLmrType().IsTupleCompatible(out cardinality));
                Assert.Equal(4, cardinality);

                type = runtime.GetType("System.ValueTuple`5", typeof(int), typeof(string), typeof(int), typeof(string), typeof(int));
                Assert.True(type.GetLmrType().IsTupleCompatible(out cardinality));
                Assert.Equal(5, cardinality);

                type = runtime.GetType("System.ValueTuple`6", typeof(int), typeof(string), typeof(int), typeof(string), typeof(int), typeof(string));
                Assert.True(type.GetLmrType().IsTupleCompatible(out cardinality));
                Assert.Equal(6, cardinality);

                type = runtime.GetType("System.ValueTuple`7", typeof(int), typeof(string), typeof(int), typeof(string), typeof(int), typeof(string), typeof(int));
                Assert.True(type.GetLmrType().IsTupleCompatible(out cardinality));
                Assert.Equal(7, cardinality);

                type = runtime.GetType("System.ValueTuple`8", typeof(int), typeof(string), typeof(int), typeof(string), typeof(int), typeof(string), typeof(int), typeof(string));
                Assert.False(type.GetLmrType().IsTupleCompatible(out cardinality));
                Assert.Equal(0, cardinality);

                type = runtime.GetType("System.ValueTuple`1", typeof(string));
                type = runtime.GetType("System.ValueTuple`8", typeof(int), typeof(string), typeof(int), typeof(string), typeof(int), typeof(string), typeof(int), ((TypeImpl)type.GetLmrType()).Type);
                Assert.True(type.GetLmrType().IsTupleCompatible(out cardinality));
                Assert.Equal(8, cardinality);

                type = runtime.GetType("System.ValueTuple`9", typeof(int), typeof(string), typeof(int), typeof(string), typeof(int), typeof(string), typeof(int), typeof(string), typeof(int));
                Assert.False(type.GetLmrType().IsTupleCompatible(out cardinality));
                Assert.Equal(0, cardinality);
            }
        }
Beispiel #15
0
        public void Tuples()
        {
            var source =
@"using System;
class C
{
    object _1 = new ValueTuple<int>(1);
    object _2 = new ValueTuple<int, int>(1, 2);
    object _3 = new ValueTuple<int, int, int>(1, 2, 3);
    object _4 = new ValueTuple<int, int, int, int>(1, 2, 3, 4);
    object _5 = new ValueTuple<int, int, int, int, int>(1, 2, 3, 4, 5);
    object _6 = new ValueTuple<int, int, int, int, int, int>(1, 2, 3, 4, 5, 6);
    object _7 = new ValueTuple<int, int, int, int, int, int, int>(1, 2, 3, 4, 5, 6, 7);
    object _8 = new ValueTuple<int, int, int, int, int, int, int, ValueTuple<int>>(1, 2, 3, 4, 5, 6, 7, new ValueTuple<int>(8));
    object _8A = new ValueTuple<int, int, int, int, int, int, int, int>(1, 2, 3, 4, 5, 6, 7, 8);
    object _9 = new ValueTuple<int, int, int, int, int, int, int, ValueTuple<int, int>>(1, 2, 3, 4, 5, 6, 7, new ValueTuple<int, int>(8, 9));
}";
            var assembly0 = GenerateTupleAssembly();
            var reference0 = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib(source, references: new[] { reference0 });
            var assembly1 = compilation1.EmitToArray();
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));
            using (runtime.Load())
            {
                var type = runtime.GetType("C");
                var value = type.Instantiate();
                var evalResult = FormatResult("o", value);
                Verify(evalResult,
                    EvalResult("o", "{C}", "C", "o", DkmEvaluationResultFlags.Expandable));
                var children = GetChildren(evalResult);
                Verify(children,
                    EvalResult("_1", "{System.ValueTuple<int>}", "object {System.ValueTuple<int>}", "o._1", DkmEvaluationResultFlags.Expandable),
                    EvalResult("_2", "(1, 2)", "object {(int, int)}", "o._2", DkmEvaluationResultFlags.Expandable),
                    EvalResult("_3", "(1, 2, 3)", "object {(int, int, int)}", "o._3", DkmEvaluationResultFlags.Expandable),
                    EvalResult("_4", "(1, 2, 3, 4)", "object {(int, int, int, int)}", "o._4", DkmEvaluationResultFlags.Expandable),
                    EvalResult("_5", "(1, 2, 3, 4, 5)", "object {(int, int, int, int, int)}", "o._5", DkmEvaluationResultFlags.Expandable),
                    EvalResult("_6", "(1, 2, 3, 4, 5, 6)", "object {(int, int, int, int, int, int)}", "o._6", DkmEvaluationResultFlags.Expandable),
                    EvalResult("_7", "(1, 2, 3, 4, 5, 6, 7)", "object {(int, int, int, int, int, int, int)}", "o._7", DkmEvaluationResultFlags.Expandable),
                    EvalResult("_8", "(1, 2, 3, 4, 5, 6, 7, 8)", "object {(int, int, int, int, int, int, int, int)}", "o._8", DkmEvaluationResultFlags.Expandable),
                    EvalResult("_8A", "{System.ValueTuple<int, int, int, int, int, int, int, int>}", "object {System.ValueTuple<int, int, int, int, int, int, int, int>}", "o._8A", DkmEvaluationResultFlags.Expandable),
                    EvalResult("_9", "(1, 2, 3, 4, 5, 6, 7, 8, 9)", "object {(int, int, int, int, int, int, int, int, int)}", "o._9", DkmEvaluationResultFlags.Expandable));
            }
        }
Beispiel #16
0
        public void InvalidElementName()
        {
            var source =
@".assembly extern Tuples { }
.class public C
{
  .method public hidebysig specialname rtspecialname instance void .ctor() { ret }
  .field private valuetype [Tuples]System.ValueTuple`2<object, object> F
  .custom instance void [Tuples]System.Runtime.CompilerServices.TupleElementNamesAttribute::.ctor(string[]) = {string[2]('Item2' 'struct { }')}
}";
            var assembly0 = GenerateTupleAssembly();
            var reference0 = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            ImmutableArray<byte> assembly1;
            ImmutableArray<byte> pdb1;
            CommonTestBase.EmitILToArray(source, appendDefaultHeader: true, includePdb: false, assemblyBytes: out assembly1, pdbBytes: out pdb1);
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));
            using (runtime.Load())
            {
                var type = runtime.GetType("C");
                var value = type.Instantiate();
                var evalResult = FormatResult("o", value);
                var children = GetChildren(evalResult);
                Verify(children,
                    EvalResult("F", "(null, null)", "(object Item2, object struct { })", "o.F", DkmEvaluationResultFlags.Expandable));
                children = GetChildren(children[0]);
                Verify(children,
                    EvalResult("Item2", "null", "object", "o.F.Item1"),
                    EvalResult("struct { }", "null", "object", "o.F.Item2"),
                    EvalResult("Raw View", "(null, null)", "(object Item2, object struct { })", "o.F, raw", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly));
                children = GetChildren(children[children.Length - 1]);
                Verify(children,
                    EvalResult("Item1", "null", "object", "o.F.Item1"),
                    EvalResult("Item2", "null", "object", "o.F.Item2"));
            }
        }
Beispiel #17
0
        public void LongTuple_ElementNames()
        {
            // Define in IL to include tuple element names
            // for the Rest elements.
            var source =
@".assembly extern Tuples { }
.class public C
{
  .method public hidebysig specialname rtspecialname instance void .ctor() { ret }
  .field private valuetype [Tuples]System.ValueTuple`8<int32,int32,int32,int32,int32,int32,int32,valuetype [Tuples]System.ValueTuple`8<int32,int32,int32,int32,int32,int32,int32,valuetype [Tuples]System.ValueTuple`1<int32>>> F
  .custom instance void [Tuples]System.Runtime.CompilerServices.TupleElementNamesAttribute::.ctor(string[]) = {string[26]('One' 'Two' '' '' 'Five' 'Six' '' '' 'Nine' 'Ten' '' '' 'Thirteen' 'Fourteen' '' '' 'Seventeen' 'Eighteen' '' '' 'TwentyOne' 'TwentyTwo' '' '' 'TwentyFive' 'TwentySix')}
}";
            var assembly0 = GenerateTupleAssembly();
            var reference0 = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            ImmutableArray<byte> assembly1;
            ImmutableArray<byte> pdb1;
            CommonTestBase.EmitILToArray(source, appendDefaultHeader: true, includePdb: false, assemblyBytes: out assembly1, pdbBytes: out pdb1);
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));
            using (runtime.Load())
            {
                var type = runtime.GetType("C");
                var value = type.Instantiate();
                var evalResult = FormatResult("o", value);
                var children = GetChildren(evalResult);
                Verify(children,
                    EvalResult(
                        "F",
                        "(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)",
                        "(int One, int Two, int, int, int Five, int Six, int, int, int Nine, int Ten, int, int, int Thirteen, int Fourteen, int)",
                        "o.F",
                        DkmEvaluationResultFlags.Expandable));
                children = GetChildren(children[0]);
                Verify(children,
                    EvalResult("One", "0", "int", "o.F.Item1"),
                    EvalResult("Two", "0", "int", "o.F.Item2"),
                    EvalResult("Item3", "0", "int", "o.F.Item3"),
                    EvalResult("Item4", "0", "int", "o.F.Item4"),
                    EvalResult("Five", "0", "int", "o.F.Item5"),
                    EvalResult("Six", "0", "int", "o.F.Item6"),
                    EvalResult("Item7", "0", "int", "o.F.Item7"),
                    EvalResult("Item8", "0", "int", "o.F.Rest.Item1"),
                    EvalResult("Nine", "0", "int", "o.F.Rest.Item2"),
                    EvalResult("Ten", "0", "int", "o.F.Rest.Item3"),
                    EvalResult("Item11", "0", "int", "o.F.Rest.Item4"),
                    EvalResult("Item12", "0", "int", "o.F.Rest.Item5"),
                    EvalResult("Thirteen", "0", "int", "o.F.Rest.Item6"),
                    EvalResult("Fourteen", "0", "int", "o.F.Rest.Item7"),
                    EvalResult("Item15", "0", "int", "o.F.Rest.Rest.Item1"),
                    EvalResult(
                        "Raw View",
                        "(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)", "(int One, int Two, int, int, int Five, int Six, int, int, int Nine, int Ten, int, int, int Thirteen, int Fourteen, int)",
                        "o.F, raw",
                        DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly));
                children = GetChildren(children[children.Length - 1]);
                Verify(children,
                    EvalResult("Item1", "0", "int", "o.F.Item1"),
                    EvalResult("Item2", "0", "int", "o.F.Item2"),
                    EvalResult("Item3", "0", "int", "o.F.Item3"),
                    EvalResult("Item4", "0", "int", "o.F.Item4"),
                    EvalResult("Item5", "0", "int", "o.F.Item5"),
                    EvalResult("Item6", "0", "int", "o.F.Item6"),
                    EvalResult("Item7", "0", "int", "o.F.Item7"),
                    EvalResult("Rest", "(0, 0, 0, 0, 0, 0, 0, 0)", "(int, int Seventeen, int Eighteen, int, int, int TwentyOne, int TwentyTwo, int)", "o.F.Rest, raw", DkmEvaluationResultFlags.Expandable));
                children = GetChildren(children[children.Length - 1]);
                Verify(children,
                    EvalResult("Item1", "0", "int", "o.F.Rest.Item1"),
                    EvalResult("Item2", "0", "int", "o.F.Rest.Item2"),
                    EvalResult("Item3", "0", "int", "o.F.Rest.Item3"),
                    EvalResult("Item4", "0", "int", "o.F.Rest.Item4"),
                    EvalResult("Item5", "0", "int", "o.F.Rest.Item5"),
                    EvalResult("Item6", "0", "int", "o.F.Rest.Item6"),
                    EvalResult("Item7", "0", "int", "o.F.Rest.Item7"),
                    EvalResult("Rest", "{System.ValueTuple<int>}", "System.ValueTuple<int>", "o.F.Rest.Rest, raw", DkmEvaluationResultFlags.Expandable));
                children = GetChildren(children[children.Length - 1]);
                Verify(children,
                    EvalResult("Item1", "0", "int", "o.F.Rest.Rest.Item1"));
            }
        }
Beispiel #18
0
        public void PartialNames()
        {
            var source =
@"class C
{
    ((int A, (int B, int C) D, int, int F, int G, int, int I, int J, int K, int L) M, (int N, int, int P) Q) F =
        ((1, (2, 3), 4, 5, 6, 7, 8, 9, 10, 11), (12, 13, 14));
    (int A, (int B, int)[] C, (object, object), (int, int D, int E, int F, int G, int H, int I, int J, int) K)[] G =
        new[] { (1, new[] { (2, 3) }, ((object, object))(4, 5), (6, 7, 8, 9, 10, 11, 12, 13, 14)) };
}";
            var assembly0 = GenerateTupleAssembly();
            var reference0 = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib45AndCSruntime(source, additionalRefs: new[] { reference0 });
            var assembly1 = compilation1.EmitToArray();
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));
            using (runtime.Load())
            {
                var type = runtime.GetType("C");
                var value = type.Instantiate();
                var evalResult = FormatResult("o", value);
                var children = GetChildren(evalResult);
                Verify(children,
                    EvalResult(
                        "F",
                        "((1, (2, 3), 4, 5, 6, 7, 8, 9, 10, 11), (12, 13, 14))",
                        "((int A, (int B, int C) D, int, int F, int G, int, int I, int J, int K, int L) M, (int N, int, int P) Q)",
                        "o.F",
                        DkmEvaluationResultFlags.Expandable),
                    EvalResult(
                        "G",
                        "{(int, (int, int)[], (object, object), (int, int, int, int, int, int, int, int, int))[1]}",
                        "(int A, (int B, int)[] C, (object, object), (int, int D, int E, int F, int G, int H, int I, int J, int) K)[]",
                        "o.G",
                        DkmEvaluationResultFlags.Expandable));
                children = GetChildren(children[1]);
                Verify(children,
                    EvalResult(
                        "[0]",
                        "(1, {(int, int)[1]}, (4, 5), (6, 7, 8, 9, 10, 11, 12, 13, 14))",
                        "(int A, (int B, int)[] C, (object, object), (int, int D, int E, int F, int G, int H, int I, int J, int) K)",
                        "o.G[0]",
                        DkmEvaluationResultFlags.Expandable));
            }
        }
Beispiel #19
0
        public void RawView()
        {
            var source =
@"class C
{
    (int A, int, (int C, int D) E, int, int, int H, int, int J) T = (1, 2, (3, 4), 5, 6, 7, 8, 9);
}";
            var assembly0 = GenerateTupleAssembly();
            var reference0 = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib(source, references: new[] { reference0 });
            var assembly1 = compilation1.EmitToArray();
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));
            using (runtime.Load())
            {
                var inspectionContext = CreateDkmInspectionContext(DkmEvaluationFlags.ShowValueRaw);
                var type = runtime.GetType("C");
                var value = type.Instantiate();
                var evalResult = FormatResult("o", value, inspectionContext: inspectionContext);
                Verify(evalResult,
                    EvalResult("o", "{C}", "C", "o, raw", DkmEvaluationResultFlags.Expandable));
                var children = GetChildren(evalResult, inspectionContext);
                Verify(children,
                    EvalResult(
                        "T",
                        "(1, 2, (3, 4), 5, 6, 7, 8, 9)",
                        "(int A, int, (int C, int D) E, int, int, int H, int, int J)",
                        "o.T, raw",
                        DkmEvaluationResultFlags.Expandable));
                children = GetChildren(children[0], inspectionContext);
                Verify(children,
                    EvalResult("Item1", "1", "int", "o.T.Item1, raw"),
                    EvalResult("Item2", "2", "int", "o.T.Item2, raw"),
                    EvalResult("Item3", "(3, 4)", "(int C, int D)", "o.T.Item3, raw", DkmEvaluationResultFlags.Expandable),
                    EvalResult("Item4", "5", "int", "o.T.Item4, raw"),
                    EvalResult("Item5", "6", "int", "o.T.Item5, raw"),
                    EvalResult("Item6", "7", "int", "o.T.Item6, raw"),
                    EvalResult("Item7", "8", "int", "o.T.Item7, raw"),
                    EvalResult("Rest", "{System.ValueTuple<int>}", "System.ValueTuple<int>", "o.T.Rest, raw", DkmEvaluationResultFlags.Expandable));
                children = GetChildren(children[7], inspectionContext);
                Verify(children,
                    EvalResult("Item1", "9", "int", "o.T.Rest.Item1, raw"));
            }
        }
Beispiel #20
0
        public void NamesAndValueTuple1()
        {
            var source =
@"using System;
class C<T>
{
    internal C(T t) { }
}
class C
{
    (ValueTuple<int> A, int B) F = (new ValueTuple<int>(1), 2);
    (int A, ValueTuple<int> B) G = (3, new ValueTuple<int>(4));
    ValueTuple<(int A, int B)> H = new ValueTuple<(int, int)>((5, 6));
    (int A, ValueTuple<(int B, int C)> D) I = (7, new ValueTuple<(int, int)>((8, 9)));
    C<(int A, int B)> J = new C<(int, int)>((10, 11));
}";
            var assembly0 = GenerateTupleAssembly();
            var reference0 = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib45AndCSruntime(source, additionalRefs: new[] { reference0 });
            var assembly1 = compilation1.EmitToArray();
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));
            using (runtime.Load())
            {
                var type = runtime.GetType("C");
                var value = type.Instantiate();
                var evalResult = FormatResult("o", value);
                var children = GetChildren(evalResult);
                Verify(children,
                    EvalResult("F", "({System.ValueTuple<int>}, 2)", "(System.ValueTuple<int> A, int B)", "o.F", DkmEvaluationResultFlags.Expandable),
                    EvalResult("G", "(3, {System.ValueTuple<int>})", "(int A, System.ValueTuple<int> B)", "o.G", DkmEvaluationResultFlags.Expandable),
                    EvalResult("H", "{System.ValueTuple<(int, int)>}", "System.ValueTuple<(int A, int B)>", "o.H", DkmEvaluationResultFlags.Expandable),
                    EvalResult("I", "(7, {System.ValueTuple<(int, int)>})", "(int A, System.ValueTuple<(int B, int C)> D)", "o.I", DkmEvaluationResultFlags.Expandable),
                    EvalResult("J", "{C<(int, int)>}", "C<(int A, int B)>", "o.J"));
            }
        }
        public void RawView()
        {
            var source =
@"using System.Diagnostics;
internal class P
{
    public P(C c)
    {
        this.G = c.F != null;
    }
    public readonly bool G;
}
[DebuggerTypeProxy(typeof(P))]
class C
{
    internal C() : this(new C(null))
    {
    }
    internal C(C f)
    {
        this.F = f;
    }
    internal readonly C F;
}
class Program
{
    static void Main()
    {
        var o = new C();
        System.Diagnostics.Debugger.Break();
    }
}";
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(GetAssembly(source)));
            using (runtime.Load())
            {
                var type = runtime.GetType("C");

                // Non-null value.
                var value = CreateDkmClrValue(
                    value: type.Instantiate(),
                    type: type,
                    inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.ShowValueRaw));
                var evalResult = FormatResult("o", "o, raw", value);
                Verify(evalResult,
                    EvalResult("o", "{C}", "C", "o, raw", DkmEvaluationResultFlags.Expandable));
                var children = GetChildren(evalResult);
                Verify(children,
                    EvalResult("F", "{C}", "C", "o.F", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly));
                children = GetChildren(children[0]);
                // ShowValueRaw is not inherited.
                Verify(children,
                    EvalResult("G", "false", "bool", "new P(o.F).G", DkmEvaluationResultFlags.Boolean | DkmEvaluationResultFlags.ReadOnly),
                    EvalResult("Raw View", null, "", "o.F, raw", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Data));

                // Null value.
                value = CreateDkmClrValue(
                    value: null,
                    type: type,
                    inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.ShowValueRaw));
                evalResult = FormatResult("o", "o, raw", value);
                Verify(evalResult,
                    EvalResult("o", "null", "C", "o, raw"));
            }
        }
Beispiel #22
0
        public void NamesAndDynamic()
        {
            var source =
@"class C
{
    (dynamic A, (int B, dynamic C)[] D, dynamic E, (int F, dynamic G, int H, int I, int J, int K, int L, int M, int N) O) F =
        (1, new (int, dynamic)[] { (2, 3) }, (4, 5), (6, 7, 8, 9, 10, 11, 12, 13, 14));
}";
            var assembly0 = GenerateTupleAssembly();
            var reference0 = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib45AndCSruntime(source, additionalRefs: new[] { reference0 });
            var assembly1 = compilation1.EmitToArray();
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));
            using (runtime.Load())
            {
                var type = runtime.GetType("C");
                var value = type.Instantiate();
                var evalResult = FormatResult("o", value);
                var children = GetChildren(evalResult);
                Verify(children,
                    EvalResult(
                        "F",
                        "(1, {(int, object)[1]}, (4, 5), (6, 7, 8, 9, 10, 11, 12, 13, 14))",
                        "(dynamic A, (int B, dynamic C)[] D, dynamic E, (int F, dynamic G, int H, int I, int J, int K, int L, int M, int N) O) {(object, (int, object)[], object, (int, object, int, int, int, int, int, int, int))}",
                        "o.F",
                        DkmEvaluationResultFlags.Expandable));
            }
        }
        public void ResultsView_IEnumerableOfT()
        {
            var source =
@"using System;
using System.Collections;
using System.Collections.Generic;
struct S<T> : IEnumerable<T>
{
    private readonly T t;
    internal S(T t)
    {
        this.t = t;
    }
    IEnumerator<T> IEnumerable<T>.GetEnumerator()
    {
        yield return t;
    }
    IEnumerator IEnumerable.GetEnumerator()
    {
        throw new NotImplementedException();
    }
}";
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlibAndSystemCore(GetAssembly(source)));
            using (runtime.Load())
            {
                var type = runtime.GetType("S`1").MakeGenericType(runtime.GetType(typeof(int)));
                var value = CreateDkmClrValue(
                    value: type.Instantiate(2),
                    type: type,
                    inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.ResultsOnly));
                var evalResult = FormatResult("o", "o, results", value);
                Verify(evalResult,
                    EvalResult("o", "Expanding the Results View will enumerate the IEnumerable", "", "o, results", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Method));
                var children = GetChildren(evalResult);
                Verify(children,
                    EvalResult("[0]", "2", "int", "new System.Linq.SystemCore_EnumerableDebugView<int>(o).Items[0]"));
            }
        }
Beispiel #24
0
        public void NamesAndDynamic_Other()
        {
            var source =
@"class C1 { }
class C2 { }
class C3 { }
class C4 { }
class C5 { }
class C6 { }
class C7 { }
class C8 { }
class C9 { }
class C10 { }
class C11 { }
class C12 { }
class C
{
    (((C1 C1, dynamic C2) B1, (C3 C3, dynamic C4)) A1, (dynamic B3, (C7 C7, C8 C8) B4) A2, ((C9 C9, C10 C10), dynamic B6) A3) F =
        ((
            ((new C1(), new C2()), (new C3(), new C4())),
            ((new C5(), new C6()), (new C7(), new C8())),
            ((new C9(), new C10()), (new C11(), new C12()))
        ));
}";
            var assembly0 = GenerateTupleAssembly();
            var reference0 = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib45AndCSruntime(source, additionalRefs: new[] { reference0 });
            var assembly1 = compilation1.EmitToArray();
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));
            using (runtime.Load())
            {
                var type = runtime.GetType("C");
                var value = type.Instantiate();
                var evalResult = FormatResult("o", value);
                var children = GetChildren(evalResult);
                Verify(children,
                    EvalResult(
                        "F",
                        "((({C1}, {C2}), ({C3}, {C4})), (({C5}, {C6}), ({C7}, {C8})), (({C9}, {C10}), ({C11}, {C12})))",
                        "(((C1 C1, dynamic C2) B1, (C3 C3, dynamic C4)) A1, (dynamic B3, (C7 C7, C8 C8) B4) A2, ((C9 C9, C10 C10), dynamic B6) A3) {(((C1, object), (C3, object)), (object, (C7, C8)), ((C9, C10), object))}",
                        "o.F",
                        DkmEvaluationResultFlags.Expandable));
            }
        }
        public void ResultsView_TypeProxy()
        {
            var source =
@"using System.Collections;
using System.Diagnostics;
[DebuggerTypeProxy(typeof(P))]
class C : IEnumerable
{
    public IEnumerator GetEnumerator()
    {
        yield return 1;
    }
}
class P
{
    public P(C c)
    {
    }
    public object F
    {
        get { return 2; }
    }
}";
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlibAndSystemCore(GetAssembly(source)));
            using (runtime.Load())
            {
                var type = runtime.GetType("C");
                var value = CreateDkmClrValue(
                    value: type.Instantiate(),
                    type: type,
                    inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.ResultsOnly));
                var evalResult = FormatResult("o", "o, results", value);
                Verify(evalResult,
                    EvalResult("o", "Expanding the Results View will enumerate the IEnumerable", "", "o, results", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Method));
            }
        }
Beispiel #26
0
        public void NamesFromTypeArguments()
        {
            var source =
@"class A<T, U>
{
    T F;
    U[] G = new U[0];
}
class B<T>
{
    internal struct S { }
    (dynamic X, T Y) F = (null, default(T));
}
class C
{
    A<(dynamic A, object B)[], (object C, dynamic[] D)> F = new A<(dynamic A, object B)[], (object, dynamic[])>();
    B<(object E, B<(object F, dynamic G)>.S H)> G = new B<(object E, B<(object F, dynamic G)>.S H)>();
}";
            var assembly0 = GenerateTupleAssembly();
            var reference0 = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib45AndCSruntime(source, additionalRefs: new[] { reference0 });
            var assembly1 = compilation1.EmitToArray();
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));
            using (runtime.Load())
            {
                var type = runtime.GetType("C");
                var value = type.Instantiate();
                var evalResult = FormatResult("o", value);
                var children = GetChildren(evalResult);
                Verify(children,
                    EvalResult("F", "{A<(object, object)[], (object, object[])>}", "A<(dynamic A, object B)[], (object C, dynamic[] D)> {A<(object, object)[], (object, object[])>}", "o.F", DkmEvaluationResultFlags.Expandable),
                    EvalResult("G", "{B<(object, B<(object, object)>.S)>}", "B<(object E, B<(object F, dynamic G)>.S H)> {B<(object, B<(object, object)>.S)>}", "o.G", DkmEvaluationResultFlags.Expandable));
                var moreChildren = GetChildren(children[0]);
                Verify(moreChildren,
                    EvalResult("F", "null", "(dynamic A, object B)[] {(object, object)[]}", "o.F.F"),
                    EvalResult("G", "{(object, object[])[0]}", "(object C, dynamic[] D)[] {(object, object[])[]}", "o.F.G"));
                moreChildren = GetChildren(children[1]);
                Verify(moreChildren,
                    EvalResult("F", "(null, (null, {B<(object, object)>.S}))", "(dynamic X, (object E, B<(object F, dynamic G)>.S H) Y) {(object, (object, B<(object, object)>.S))}", "o.G.F", DkmEvaluationResultFlags.Expandable));
                moreChildren = GetChildren(moreChildren[0]);
                Verify(moreChildren,
                    EvalResult("X", "null", "dynamic {object}", "o.G.F.Item1"),
                    EvalResult("Y", "(null, {B<(object, object)>.S})", "(object E, B<(object F, dynamic G)>.S H) {(object, B<(object, object)>.S)}", "o.G.F.Item2", DkmEvaluationResultFlags.Expandable),
                    EvalResult("Raw View", "(null, (null, {B<(object, object)>.S}))", "(dynamic X, (object E, B<(object F, dynamic G)>.S H) Y) {(object, (object, B<(object, object)>.S))}", "o.G.F, raw", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly));
                moreChildren = GetChildren(moreChildren[1]);
                Verify(moreChildren,
                    EvalResult("E", "null", "object", "o.G.F.Item2.Item1"),
                    EvalResult("H", "{B<(object, object)>.S}", "B<(object F, dynamic G)>.S {B<(object, object)>.S}", "o.G.F.Item2.Item2"),
                    EvalResult("Raw View", "(null, {B<(object, object)>.S})", "(object E, B<(object F, dynamic G)>.S H) {(object, B<(object, object)>.S)}", "o.G.F.Item2, raw", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly));
            }
        }
        public void ResultsView_Error()
        {
            var source =
@"using System.Collections;
class C
{
    bool f;
    internal ArrayList P
    {
        get { while (!this.f) { } return new ArrayList(); }
    }
    internal int Q
    {
        get { while (!this.f) { } return 3; }
    }
}";
            DkmClrRuntimeInstance runtime = null;
            GetMemberValueDelegate getMemberValue = (v, m) =>
                {
                    switch (m)
                    {
                        case "P":
                            return CreateErrorValue(runtime.GetType(typeof(System.Collections.ArrayList)), "Property 'P' evaluation timed out");
                        case "Q":
                            return CreateErrorValue(runtime.GetType(typeof(string)), "Property 'Q' evaluation timed out");
                        default:
                            return null;
                    }
                };
            runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlibAndSystemCore(GetAssembly(source)), getMemberValue: getMemberValue);
            using (runtime.Load())
            {
                var type = runtime.GetType("C");
                var value = CreateDkmClrValue(type.Instantiate(), type: type);
                var memberValue = value.GetMemberValue("P", (int)System.Reflection.MemberTypes.Property, "C").
                    WithInspectionContext(CreateDkmInspectionContext(DkmEvaluationFlags.ResultsOnly));
                var evalResult = FormatResult("o.P", "o.P, results", memberValue);
                Verify(evalResult,
                    EvalFailedResult("o.P", "Property 'P' evaluation timed out"));
                memberValue = value.GetMemberValue("Q", (int)System.Reflection.MemberTypes.Property, "C").
                    WithInspectionContext(CreateDkmInspectionContext(DkmEvaluationFlags.ResultsOnly));
                evalResult = FormatResult("o.Q", "o.Q, results", memberValue);
                Verify(evalResult,
                    EvalFailedResult("o.Q", "Property 'Q' evaluation timed out"));
            }
        }
Beispiel #28
0
        public void NamesFromTypeArguments_LongTuples()
        {
            var source =
@"class A1 { }
class A2 { }
class A3 { }
class A4 { }
class A5 { }
class A6 { }
class A7 { }
class A8 { }
class B1 { }
class B2 { }
class B3 { }
class B4 { }
class B5 { }
class B6 { }
class B7 { }
class B8 { }
class B9 { }
class B10 { }
class C1 { }
class C2 { }
class A<T, U>
{
    (dynamic A1, A2 A2, T A3, A4 A4, A5 A5, U A6, A7 A7, A8 A8, (T A9, U A10) A11) F =
        (new A1(), new A2(), default(T), new A4(), new A5(), default(U), new A7(), new A8(), (default(T), default(U)));
}
class B
{
    A<((dynamic B1, B2 B2) B3, B4 B4, dynamic B5, B6 B6, B7 B7, dynamic B8, B9 B9, B10 B10, dynamic B11), (C1 C1, (C2 C2, dynamic C3) C4)> G =
        new A<((dynamic B1, B2 B2) B3, B4 B4, dynamic B5, B6 B6, B7 B7, dynamic B8, B9 B9, B10 B10, dynamic B11), (C1 C1, (C2 C2, dynamic C3) C4)>();
}";
            var assembly0 = GenerateTupleAssembly();
            var reference0 = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib45AndCSruntime(source, additionalRefs: new[] { reference0 });
            var assembly1 = compilation1.EmitToArray();
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));
            using (runtime.Load())
            {
                var type = runtime.GetType("B");
                var value = type.Instantiate();
                var evalResult = FormatResult("o", value);
                var children = GetChildren(evalResult);
                Verify(children,
                    EvalResult(
                        "G",
                        "{A<((object, B2), B4, object, B6, B7, object, B9, B10, object), (C1, (C2, object))>}",
                        "A<((dynamic B1, B2 B2) B3, B4 B4, dynamic B5, B6 B6, B7 B7, dynamic B8, B9 B9, B10 B10, dynamic B11), (C1 C1, (C2 C2, dynamic C3) C4)> {A<((object, B2), B4, object, B6, B7, object, B9, B10, object), (C1, (C2, object))>}",
                        "o.G",
                        DkmEvaluationResultFlags.Expandable));
                children = GetChildren(children[0]);
                Verify(children,
                    EvalResult(
                        "F",
                        "({A1}, {A2}, ((null, null), null, null, null, null, null, null, null, null), {A4}, {A5}, (null, (null, null)), {A7}, {A8}, (((null, null), null, null, null, null, null, null, null, null), (null, (null, null))))",
                        "(dynamic A1, A2 A2, ((dynamic B1, B2 B2) B3, B4 B4, dynamic B5, B6 B6, B7 B7, dynamic B8, B9 B9, B10 B10, dynamic B11) A3, A4 A4, A5 A5, (C1 C1, (C2 C2, dynamic C3) C4) A6, A7 A7, A8 A8, (((dynamic B1, B2 B2) B3, B4 B4, dynamic B5, B6 B6, B7 B7, dynamic B8, B9 B9, B10 B10, dynamic B11) A9, (C1 C1, (C2 C2, dynamic C3) C4) A10) A11) {(object, A2, ((object, B2), B4, object, B6, B7, object, B9, B10, object), A4, A5, (C1, (C2, object)), A7, A8, (((object, B2), B4, object, B6, B7, object, B9, B10, object), (C1, (C2, object))))}",
                        "o.G.F",
                        DkmEvaluationResultFlags.Expandable));
            }
        }
        public void NoQuotes_DebuggerDisplay()
        {
            var source =
@"using System.Diagnostics;
[DebuggerDisplay(""{F}+{G}"")]
class C
{
    string F = ""f"";
    object G = 'g';
}";
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(GetAssembly(source)));
            using (runtime.Load())
            {
                var type = runtime.GetType("C");
                var value = CreateDkmClrValue(
                    value: type.Instantiate(),
                    type: type,
                    inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.NoQuotes));
                var evalResult = FormatResult("o", value);
                Verify(evalResult,
                    EvalResult("o", "f+103 g", "C", "o", DkmEvaluationResultFlags.Expandable));
            }
        }
Beispiel #30
0
        public void TupleElementNames_IncorrectCount()
        {
            var source =
@".assembly extern Tuples { }
.class public C
{
  .method public hidebysig specialname rtspecialname instance void .ctor() { ret }
  .field private valuetype [Tuples]System.ValueTuple`8<int32,int32,int32,int32,int32,int32,int32,valuetype [Tuples]System.ValueTuple`8<int32,int32,int32,int32,int32,int32,int32,valuetype [Tuples]System.ValueTuple`1<int32>>> F
  .custom instance void [Tuples]System.Runtime.CompilerServices.TupleElementNamesAttribute::.ctor(string[]) = {string[6]('A' 'B' 'C' 'D' 'E' 'F')}
  .field private valuetype [Tuples]System.ValueTuple`8<int32,int32,int32,int32,int32,int32,int32,valuetype [Tuples]System.ValueTuple`2<int32,int32>> G
  .custom instance void [Tuples]System.Runtime.CompilerServices.TupleElementNamesAttribute::.ctor(string[]) = {string[12]('A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L')}
}";
            var assembly0 = GenerateTupleAssembly();
            var reference0 = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            ImmutableArray<byte> assembly1;
            ImmutableArray<byte> pdb1;
            CommonTestBase.EmitILToArray(source, appendDefaultHeader: true, includePdb: false, assemblyBytes: out assembly1, pdbBytes: out pdb1);
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));
            using (runtime.Load())
            {
                var type = runtime.GetType("C");
                var value = type.Instantiate();
                var evalResult = FormatResult("o", value);
                var children = GetChildren(evalResult);
                Verify(children,
                    EvalResult(
                        "F",
                        "(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)",
                        "(int A, int B, int C, int D, int E, int F, int, int, int, int, int, int, int, int, int)",
                        "o.F",
                        DkmEvaluationResultFlags.Expandable),
                    EvalResult(
                        "G",
                        "(0, 0, 0, 0, 0, 0, 0, 0, 0)",
                        "(int A, int B, int C, int D, int E, int F, int G, int H, int I)",
                        "o.G",
                        DkmEvaluationResultFlags.Expandable));
            }
        }