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 PdbMethodTest() { // Ensure all methods in our source file is in the pdb. using (DataTarget dt = TestTargets.NestedException.LoadFullDump()) { ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime(); ClrModule module = runtime.Modules.Where(m => m.Name.Equals(TestTargets.NestedException.Executable, StringComparison.OrdinalIgnoreCase)).Single(); ClrType type = module.GetTypeByName("Program"); using (PdbReader pdb = new PdbReader(TestTargets.NestedException.Pdb)) { foreach (ClrMethod method in type.Methods) { // ignore inherited methods and constructors if (method.Type != type || method.IsConstructor || method.IsClassConstructor) continue; Assert.IsNotNull(pdb.GetFunctionFromToken(method.MetadataToken)); } } } }