public void VariableRootTest() { // Test to make sure that a specific static and local variable exist. using DataTarget dt = TestTargets.Types.LoadFullDump(); using ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime(); ClrHeap heap = runtime.Heap; IEnumerable <IClrRoot> fooRoots = from root in heap.EnumerateRoots() where root.Object.Type.Name == "Foo" select root; IClrRoot[] localVarRoots = fooRoots.Where(r => r.RootKind == ClrRootKind.Stack).ToArray(); ClrThread thread = runtime.GetMainThread(); ClrStackFrame main = thread.GetFrame("Main"); ClrStackFrame inner = thread.GetFrame("Inner"); ulong low = thread.StackBase; ulong high = thread.StackLimit; // Account for different platform stack direction. if (low > high) { ulong tmp = low; low = high; high = tmp; } foreach (IClrRoot localVarRoot in localVarRoots) { Assert.True(low <= localVarRoot.Address && localVarRoot.Address <= high); } }
private static ProcessThread GetMainThread(Process process, DataTarget dataTarget) { using ClrRuntime runtime = dataTarget.ClrVersions.Single().CreateRuntime(); uint mainThreadId = runtime.GetMainThread().OSThreadId; return(process.Threads.Cast <ProcessThread>().Single(thread => thread.Id == mainThreadId)); }
public void MinidumpCallstackTest() { using DataTarget dt = TestTargets.NestedException.LoadMiniDump(); ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime(); ClrThread thread = runtime.GetMainThread(); string[] frames = IntPtr.Size == 8 ? new[] { "Inner", "Inner", "Middle", "Outer", "Main" } : new[] { "Inner", "Middle", "Outer", "Main" }; int i = 0; foreach (ClrStackFrame frame in thread.StackTrace) { if (frame.Kind == ClrStackFrameType.Runtime) { Assert.Equal(0ul, frame.InstructionPointer); Assert.NotEqual(0ul, frame.StackPointer); } else { Assert.NotEqual(0ul, frame.InstructionPointer); Assert.NotEqual(0ul, frame.StackPointer); Assert.NotNull(frame.Method); Assert.NotNull(frame.Method.Type); Assert.NotNull(frame.Method.Type.Module); Assert.Equal(frames[i++], frame.Method.Name); } } }
public void EnsureOSThreadOrdering() { using DataTarget dt = TestTargets.Types.LoadFullDump(); using ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime(); IThreadReader threadReader = (IThreadReader)dt.DataReader; var items = threadReader.EnumerateOSThreadIds().ToArray(); uint mainThreadId = runtime.GetMainThread().OSThreadId; Assert.Equal(mainThreadId, threadReader.EnumerateOSThreadIds().First()); }
internal static void TestProperties(ClrRuntime runtime) { ClrThread thread = runtime.GetMainThread(); ClrException?exNullable = thread.CurrentException; Assert.NotNull(exNullable); ClrException ex = exNullable.GetValueOrDefault(); ExceptionTestData testData = TestTargets.NestedExceptionData; Assert.Equal(testData.OuterExceptionMessage, ex.Message); Assert.Equal(testData.OuterExceptionType, ex.Type.Name); Assert.NotNull(ex.Inner); }
public void StackTraceTests() { string[] frames = new string[] { "Inner", "Inner", "Middle", "Outer", "Main" }; using DataTarget dt = TestTargets.NestedException.LoadFullDump(); using ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime(); var items = runtime.GetMainThread().EnumerateStackTrace().Where(f => f.Kind == ClrStackFrameKind.ManagedMethod).ToArray(); Assert.Equal(frames.Length, items.Length); for (int i = 0; i < frames.Length; i++) { Assert.StartsWith(frames[i], items[i].Method.Name); } }
public void TestStackTrace() { using DataTarget dt = TestTargets.NestedException.LoadFullDump(); using ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime(); ClrThread thread = runtime.GetMainThread(); ClrException exception = thread.CurrentException; Assert.NotNull(exception); ImmutableArray <ClrStackFrame> stackTrace = exception.StackTrace; foreach (ClrStackFrame stackFrame in stackTrace) { Assert.Equal(stackFrame.Thread, thread); } }
internal static void TestProperties(ClrRuntime runtime) { ClrThread thread = runtime.GetMainThread(); ClrException ex = thread.CurrentException; Assert.NotNull(ex); ExceptionTestData testData = TestTargets.NestedExceptionData; Assert.Equal(testData.OuterExceptionMessage, ex.Message); if (ex.Type.Name != null) { Assert.Equal(testData.OuterExceptionType, ex.Type.Name); } Assert.NotNull(ex.Inner); }
public void PdbSourceLineTest() { using (DataTarget dt = TestTargets.NestedException.LoadFullDump()) { ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime(); ClrThread thread = runtime.GetMainThread(); HashSet <int> sourceLines = new HashSet <int>(); using (PdbReader reader = new PdbReader(TestTargets.NestedException.Pdb)) { Assert.IsTrue(TestTargets.NestedException.Source.Equals(reader.Sources.Single().Name, StringComparison.OrdinalIgnoreCase)); var functions = from frame in thread.StackTrace where frame.Kind != ClrStackFrameType.Runtime select reader.GetFunctionFromToken(frame.Method.MetadataToken); foreach (PdbFunction function in functions) { PdbSequencePointCollection sourceFile = function.SequencePoints.Single(); foreach (int line in sourceFile.Lines.Select(l => l.LineBegin)) { sourceLines.Add(line); } } } int curr = 0; foreach (var line in File.ReadLines(TestTargets.NestedException.Source)) { curr++; if (line.Contains("/* seq */")) { Assert.IsTrue(sourceLines.Contains(curr)); } } } }
public void VariableRootTest() { // Test to make sure that a specific static and local variable exist. using (DataTarget dt = TestTargets.Types.LoadFullDump()) { ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime(); ClrHeap heap = runtime.Heap; heap.StackwalkPolicy = ClrRootStackwalkPolicy.Exact; var fooRoots = from root in heap.EnumerateRoots() where root.Type.Name == "Foo" select root; ClrRoot staticRoot = fooRoots.Where(r => r.Kind == GCRootKind.StaticVar).Single(); Assert.IsTrue(staticRoot.Name.Contains("s_foo")); var arr = fooRoots.Where(r => r.Kind == GCRootKind.LocalVar).ToArray(); ClrRoot localVarRoot = fooRoots.Where(r => r.Kind == GCRootKind.LocalVar).Single(); ClrThread thread = runtime.GetMainThread(); ClrStackFrame main = thread.GetFrame("Main"); ClrStackFrame inner = thread.GetFrame("Inner"); ulong low = thread.StackBase; ulong high = thread.StackLimit; // Account for different platform stack direction. if (low > high) { ulong tmp = low; low = high; high = tmp; } Assert.IsTrue(low <= localVarRoot.Address && localVarRoot.Address <= high); } }