/// <summary> /// Initializes a new instance of the <see cref="PdbLocalScope"/> class. /// </summary> /// <param name="function">Function that contains this scope.</param> /// <param name="block">Block symbol read from PDB.</param> /// <param name="parent">Parent scope.</param> internal PdbLocalScope(PdbFunction function, BlockSymbol block, PdbLocalScope parent = null) { Function = function; Block = block; Parent = parent; childrenCache = SimpleCache.CreateStruct(() => { IEnumerable <BlockSymbol> blocks = Block.Children.OfType <BlockSymbol>(); int count = blocks.Count(); IPdbLocalScope[] children = new IPdbLocalScope[count]; int i = 0; foreach (BlockSymbol b in blocks) { children[i++] = new PdbLocalScope(Function, b, this); } return(children); }); constantsCache = SimpleCache.CreateStruct(() => { IEnumerable <ConstantSymbol> symbols = Block.Children.OfType <ConstantSymbol>(); int count = symbols.Count(); IPdbLocalConstant[] constants = new IPdbLocalConstant[count]; int i = 0; foreach (ConstantSymbol symbol in symbols) { constants[i++] = new PdbLocalConstant(this, symbol); } return(constants); }); variablesCache = SimpleCache.CreateStruct(() => { IEnumerable <AttributeSlotSymbol> slots = Block.Children.OfType <AttributeSlotSymbol>(); int count = slots.Count(); IPdbLocalVariable[] variables = new IPdbLocalVariable[count]; int i = 0; foreach (AttributeSlotSymbol slot in slots) { variables[i++] = new PdbLocalVariable(this, slot); } return(variables); }); }
public void Test3() { using (IPdbFile pdb = OpenManagedPdb(3)) { Assert.IsType <Windows.PdbFile>(pdb); Assert.Equal(1, pdb.Age); Assert.Equal(Guid.Parse("6a15f24f-b0ee-400f-9136-7950178b42f5"), pdb.Guid); Assert.Equal(2499347773U, pdb.Stamp); Assert.Equal(6, pdb.Functions.Count); IPdbFunction function = pdb.Functions[0]; Assert.Single(function.LocalScopes); Assert.Equal(100663297, function.Token); Assert.Equal(function, pdb.GetFunctionFromToken(function.Token)); Assert.Equal(1, function.SequencePoints.Count); IPdbLocalScope localScope = function.LocalScopes[0]; Assert.Equal(0, localScope.StartOffset); Assert.Equal(19, localScope.EndOffset); Assert.Equal(localScope.EndOffset - localScope.StartOffset, localScope.Length); Assert.Equal(function, localScope.Function); Assert.Null(localScope.Parent); Assert.Empty(localScope.Children); Assert.Empty(localScope.Constants); Assert.Empty(localScope.Variables); IPdbSequencePoint sequencePoint = function.SequencePoints[0]; Assert.Equal(0, sequencePoint.Offset); Assert.Equal(8, sequencePoint.StartLine); Assert.Equal(8, sequencePoint.EndLine); Assert.Equal(5, sequencePoint.StartColumn); Assert.Equal(55, sequencePoint.EndColumn); var sources = pdb.Functions.SelectMany(f => f.SequencePoints).Select(sp => sp.Source).GroupBy(s => s.Name).Select(sg => sg.First()); Assert.Single(sources); IPdbSource source = sources.First(); Assert.Equal(@"C:\projects\windbgcs-dumps\Source\Clr\LocalVariables\LocalVariables.cs", source.Name); Assert.Equal(Guid.Parse("3f5162f8-07c6-11d3-9053-00c04fa302a1"), source.Language); Assert.Equal(Guid.Parse("ff1816ec-aa5e-4d10-87f7-6f4963833460"), source.HashAlgorithm); Assert.Equal(new byte[] { 150, 161, 4, 5, 30, 51, 251, 92, 205, 46, 22, 14, 23, 237, 168, 175, 33, 178, 190, 218 }, source.Hash); } }
public void Test4() { using (IPdbFile pdb = OpenManagedPdb(4)) { Assert.IsType <Portable.PdbFile>(pdb); Assert.Equal(1, pdb.Age); Assert.Equal(Guid.Parse("2346b65a-d79a-43d6-8ca5-53c572af22f8"), pdb.Guid); Assert.Equal(2202009495U, pdb.Stamp); Assert.Equal(7, pdb.Functions.Count); IPdbFunction function = pdb.Functions[0]; Assert.Single(function.LocalScopes); Assert.Equal(100663297, function.Token); Assert.Equal(function, pdb.GetFunctionFromToken(function.Token)); Assert.Equal(2, function.SequencePoints.Count); IPdbLocalScope localScope = function.LocalScopes[0]; Assert.Equal(0, localScope.StartOffset); Assert.Equal(2, localScope.EndOffset); Assert.Equal(localScope.EndOffset - localScope.StartOffset, localScope.Length); Assert.Equal(function, localScope.Function); Assert.Null(localScope.Parent); Assert.Empty(localScope.Children); Assert.Empty(localScope.Constants); Assert.Empty(localScope.Variables); IPdbSequencePoint sequencePoint = function.SequencePoints[0]; Assert.Equal(0, sequencePoint.Offset); Assert.Equal(22, sequencePoint.StartLine); Assert.Equal(22, sequencePoint.EndLine); Assert.Equal(23, sequencePoint.StartColumn); Assert.Equal(24, sequencePoint.EndColumn); var sources = pdb.Functions.SelectMany(f => f.SequencePoints).Select(sp => sp.Source).GroupBy(s => s.Name).Select(sg => sg.First()); Assert.Single(sources); IPdbSource source = sources.First(); Assert.Equal("/home/travis/build/southpolenator/WinDbgCs_dumps/Source/Clr/SharedLibrary/SharedLibrary.cs", source.Name); Assert.Equal(Guid.Parse("3f5162f8-07c6-11d3-9053-00c04fa302a1"), source.Language); Assert.Equal(Guid.Parse("ff1816ec-aa5e-4d10-87f7-6f4963833460"), source.HashAlgorithm); Assert.Equal(new byte[] { 248, 0, 227, 166, 171, 152, 157, 122, 60, 185, 89, 14, 74, 143, 196, 154, 218, 146, 222, 2 }, source.Hash); } }
/// <summary> /// Initializes a new instance of the <see cref="PdbFunction"/> class. /// </summary> /// <param name="pdbFile">Portable PDB file reader.</param> /// <param name="procedure">Managed procedure symbol from PDB.</param> /// <param name="dbiModule">DBI module descriptor from PDB.</param> internal PdbFunction(PdbFile pdbFile, ManagedProcedureSymbol procedure, DbiModuleDescriptor dbiModule) { PdbFile = pdbFile; Procedure = procedure; DbiModule = dbiModule; localScopesCache = SimpleCache.CreateStruct(() => { IEnumerable <BlockSymbol> blocks = Procedure.Children.OfType <BlockSymbol>(); int count = blocks.Count(); IPdbLocalScope[] scopes = new IPdbLocalScope[count]; int i = 0; foreach (BlockSymbol block in blocks) { scopes[i++] = new PdbLocalScope(this, block); } return(scopes); }); sequencePointsCache = SimpleCache.CreateStruct(() => { var checksums = DbiModule.DebugSubsectionStream[DebugSubsectionKind.FileChecksums]; var linesSubsections = dbiModule.DebugSubsectionStream[DebugSubsectionKind.Lines]; List <IPdbSequencePoint> sequencePoints = new List <IPdbSequencePoint>(); foreach (LinesSubsection linesSubsection in linesSubsections) { foreach (var file in linesSubsection.Files) { var checksum = (FileChecksumSubsection)checksums[file.Index]; var source = PdbFile[checksum]; foreach (var line in file.Lines) { sequencePoints.Add(new PdbSequencePoint(this, source, line)); } } } return(sequencePoints); }); }
/// <summary> /// Gets the recursive slots. /// </summary> /// <param name="scope">The scope.</param> /// <param name="results">The results.</param> private static IEnumerable <IPdbLocalVariable> GetRecursiveSlots(IPdbLocalScope scope, List <IPdbLocalVariable> results = null) { if (results == null) { results = new List <IPdbLocalVariable>(); } foreach (var variable in scope.Variables) { while (results.Count <= variable.Index) { results.Add(null); } results[variable.Index] = variable; } foreach (var innerScope in scope.Children) { GetRecursiveSlots(innerScope, results); } return(results); }
/// <summary> /// Initializes a new instance of the <see cref="PdbLocalScope"/> class. /// </summary> /// <param name="function">Function that contains this scope.</param> /// <param name="handle">Our metadata reader handle.</param> /// <param name="parent">Parent scope.</param> internal PdbLocalScope(PdbFunction function, LocalScopeHandle handle, IPdbLocalScope parent = null) { Function = function; localScopeCache = SimpleCache.CreateStruct(() => function.PdbFile.Reader.GetLocalScope(handle)); childrenCache = SimpleCache.CreateStruct(() => { var enumerator = LocalScope.GetChildren(); List <IPdbLocalScope> children = new List <IPdbLocalScope>(); while (enumerator.MoveNext()) { children.Add(new PdbLocalScope(function, enumerator.Current, this)); } return(children); }); constantsCache = SimpleCache.CreateStruct(() => { var localConstants = LocalScope.GetLocalConstants(); IPdbLocalConstant[] constants = new IPdbLocalConstant[localConstants.Count]; int i = 0; foreach (var c in localConstants) { constants[i++] = new PdbLocalConstant(this, c); } return(constants); }); variablesCache = SimpleCache.CreateStruct(() => { var localVariables = LocalScope.GetLocalVariables(); IPdbLocalVariable[] variables = new IPdbLocalVariable[localVariables.Count]; int i = 0; foreach (var v in localVariables) { variables[i++] = new PdbLocalVariable(this, v); } return(variables); }); }
/// <summary> /// Initializes a new instance of the <see cref="PdbFunction"/> class. /// </summary> /// <param name="pdbFile">Portable PDB file reader.</param> /// <param name="handle">Our metadata reader handle.</param> internal PdbFunction(PdbFile pdbFile, MethodDebugInformationHandle handle) { PdbFile = pdbFile; methodDebugInformationCache = SimpleCache.CreateStruct(() => pdbFile.Reader.GetMethodDebugInformation(handle)); localScopesCache = SimpleCache.CreateStruct(() => { var localScopes = pdbFile.Reader.GetLocalScopes(handle); IPdbLocalScope[] scopes = new IPdbLocalScope[localScopes.Count]; int i = 0; foreach (var l in localScopes) { scopes[i++] = new PdbLocalScope(this, l); } return(scopes); }); sequencePointsCache = SimpleCache.CreateStruct(() => { var sequencePoints = MethodDebugInformation.GetSequencePoints(); return(sequencePoints.Select(sp => new PdbSequencePoint(this, sp)).OfType <IPdbSequencePoint>().ToArray()); }); Token = System.Reflection.Metadata.Ecma335.MetadataTokens.GetToken(handle.ToDefinitionHandle()); }