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));
}
}
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));
}
}
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));
}
}
public void ResultsView_FrameworkTypes()
{
var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlibAndSystemCore());
var inspectionContext = CreateDkmInspectionContext(DkmEvaluationFlags.ResultsOnly);
// object: not enumerable
var value = CreateDkmClrValue(new object(), type: runtime.GetType(typeof(object)), inspectionContext: inspectionContext);
var evalResult = FormatResult("o", value);
Verify(evalResult,
EvalFailedResult("o", "Only Enumerable types can have Results View"));
// string: not considered enumerable which is consistent with legacy EE
value = CreateDkmClrValue("", type: runtime.GetType(typeof(string)), inspectionContext: inspectionContext);
evalResult = FormatResult("s", value);
Verify(evalResult,
EvalFailedResult("s", "Only Enumerable types can have Results View"));
// Array: not considered enumerable which is consistent with legacy EE
value = CreateDkmClrValue(new[] { 1 }, type: runtime.GetType(typeof(int[])), inspectionContext: inspectionContext);
evalResult = FormatResult("i", value);
Verify(evalResult,
EvalFailedResult("i", "Only Enumerable types can have Results View"));
// ArrayList
value = CreateDkmClrValue(new System.Collections.ArrayList(new[] { 2 }), type: runtime.GetType(typeof(System.Collections.ArrayList)), inspectionContext: inspectionContext);
evalResult = FormatResult("a", value);
Verify(evalResult,
EvalResult("a", "Expanding the Results View will enumerate the IEnumerable", "", "a, results", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Method));
var children = GetChildren(evalResult);
Verify(children,
EvalResult("[0]", "2", "object {int}", "new System.Linq.SystemCore_EnumerableDebugView(a).Items[0]"));
// List<object>
value = CreateDkmClrValue(new System.Collections.Generic.List<object>(new object[] { 3 }), type: runtime.GetType(typeof(System.Collections.Generic.List<object>)), inspectionContext: inspectionContext);
evalResult = FormatResult("l", value);
Verify(evalResult,
EvalResult("l", "Expanding the Results View will enumerate the IEnumerable", "", "l, results", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Method));
children = GetChildren(evalResult);
Verify(children,
EvalResult("[0]", "3", "object {int}", "new System.Linq.SystemCore_EnumerableDebugView<object>(l).Items[0]"));
// int?
value = CreateDkmClrValue(1, type: runtime.GetType(typeof(System.Nullable<>)).MakeGenericType(runtime.GetType(typeof(int))), inspectionContext: inspectionContext);
evalResult = FormatResult("i", value);
Verify(evalResult,
EvalFailedResult("i", "Only Enumerable types can have Results View"));
}
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 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 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));
}
}
请发表评论