示例#1
0
        /// <summary>
        /// Find function by the specified token.
        /// </summary>
        /// <param name="token">Method definition token.</param>
        /// <returns><see cref="IPdbFunction"/> object if found, <c>null</c> otherwise.</returns>
        public IPdbFunction GetFunctionFromToken(int token)
        {
            IPdbFunction function = null;

            FunctionsByToken.TryGetValue(token, out function);
            return(function);
        }
示例#2
0
        public void Test2()
        {
            using (IPdbFile pdb = OpenManagedPdb(2))
            {
                Assert.IsType <Windows.PdbFile>(pdb);
                Assert.Equal(1, pdb.Age);
                Assert.Equal(Guid.Parse("483548d2-af63-4b4e-bce0-41e1bd07d062"), pdb.Guid);
                Assert.Equal(3243434163U, pdb.Stamp);

                Assert.Equal(7, pdb.Functions.Count);
                IPdbFunction function = pdb.Functions[0];

                Assert.Empty(function.LocalScopes);
                Assert.Equal(100663297, function.Token);
                Assert.Equal(function, pdb.GetFunctionFromToken(function.Token));
                Assert.Equal(23, function.SequencePoints.Count);

                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(@"C:\projects\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);
            }
        }
示例#3
0
        /// <summary>
        /// Reads the name of the source file, line and displacement.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="method">The CLR method.</param>
        /// <param name="address">The address.</param>
        internal static Tuple <string, uint, ulong> ReadSourceFileNameAndLine(ClrMdModule module, Microsoft.Diagnostics.Runtime.ClrMethod method, ulong address)
        {
            IPdbFile     pdbReader = module.ClrPdbReader;
            IPdbFunction function  = pdbReader.GetFunctionFromToken((int)method.MetadataToken);
            uint         ilOffset  = FindIlOffset(method, address);

            ulong  distance       = ulong.MaxValue;
            string sourceFileName = "";
            uint   sourceFileLine = uint.MaxValue;

            foreach (IPdbSequencePoint point in function.SequencePoints)
            {
                if (point.Offset <= ilOffset)
                {
                    ulong dist = (ulong)(ilOffset - point.Offset);

                    if (dist < distance)
                    {
                        sourceFileName = point.Source.Name;
                        sourceFileLine = (uint)point.StartLine;
                        distance       = dist;
                    }
                }
            }
            return(Tuple.Create(sourceFileName, sourceFileLine, distance));
        }
示例#4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PdbFile"/> class.
        /// </summary>
        /// <param name="reader">Portable PDB metadata reader.</param>
        internal PdbFile(MetadataReader reader)
        {
            Reader         = reader;
            idCache        = SimpleCache.CreateStruct(() => new BlobContentId(Reader.DebugMetadataHeader.Id));
            functionsCache = SimpleCache.CreateStruct(() =>
            {
                IPdbFunction[] functions = new IPdbFunction[Reader.MethodDebugInformation.Count];
                int i = 0;

                foreach (var f in Reader.MethodDebugInformation)
                {
                    functions[i++] = functionsByHandle[f];
                }
                return(functions);
            });
            sourcesCache      = new DictionaryCache <DocumentHandle, IPdbSource>(GetSource);
            functionsByHandle = new DictionaryCache <MethodDebugInformationHandle, PdbFunction>(f => new PdbFunction(this, f));
        }
示例#5
0
        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);
            }
        }
示例#6
0
        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);
            }
        }